]> Git Repo - VerusCoin.git/blame - src/komodo_bitcoind.h
test
[VerusCoin.git] / src / komodo_bitcoind.h
CommitLineData
d019c447 1/******************************************************************************
2 * Copyright © 2014-2016 The SuperNET Developers. *
3 * *
4 * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
5 * the top-level directory of this distribution for the individual copyright *
6 * holder information and the developer policies on copyright and licensing. *
7 * *
8 * Unless otherwise agreed in a custom licensing agreement, no part of the *
9 * SuperNET software, including this file may be copied, modified, propagated *
10 * or distributed except according to the terms contained in the LICENSE file *
11 * *
12 * Removal or modification of this copyright notice is prohibited. *
13 * *
14 ******************************************************************************/
15
3eea72f2 16// komodo functions that interact with bitcoind C++
17
18uint32_t komodo_txtime(uint256 hash)
19{
20 CTransaction tx;
21 uint256 hashBlock;
22 if (!GetTransaction(hash, tx, hashBlock, true))
23 {
24 //printf("null GetTransaction\n");
25 return(tx.nLockTime);
26 }
27 return(0);
28}
29
30void komodo_disconnect(CBlockIndex *pindex,CBlock& block)
31{
32 komodo_init();
33 //uint256 zero;
34 //printf("disconnect ht.%d\n",pindex->nHeight);
35 //memset(&zero,0,sizeof(zero));
36 //komodo_stateupdate(-pindex->nHeight,0,0,0,zero,0,0,0,0);
37}
38
39int32_t komodo_block2height(CBlock *block)
40{
41 int32_t i,n,height = 0; uint8_t *ptr = (uint8_t *)block->vtx[0].vin[0].scriptSig.data();
42 komodo_init();
43 if ( block->vtx[0].vin[0].scriptSig.size() > 5 )
44 {
45 //for (i=0; i<6; i++)
46 // printf("%02x",ptr[i]);
47 n = ptr[0];
48 for (i=0; i<n; i++)
49 {
50 //03bb81000101(bb 187) (81 48001) (00 12288256) <- coinbase.6 ht.12288256
51 height += ((uint32_t)ptr[i+1] << (i*8));
52 //printf("(%02x %x %d) ",ptr[i+1],((uint32_t)ptr[i+1] << (i*8)),height);
53 }
54 //printf(" <- coinbase.%d ht.%d\n",(int32_t)block->vtx[0].vin[0].scriptSig.size(),height);
55 }
56 return(height);
57}
58
59void komodo_block2pubkey33(uint8_t *pubkey33,CBlock& block)
60{
61 uint8_t *ptr = (uint8_t *)block.vtx[0].vout[0].scriptPubKey.data();
62 komodo_init();
63 memcpy(pubkey33,ptr+1,33);
64}
65
66void komodo_index2pubkey33(uint8_t *pubkey33,CBlockIndex *pindex,int32_t height)
67{
68 CBlock block;
69 komodo_init();
70 memset(pubkey33,0,33);
71 if ( pindex != 0 )
72 {
73 if ( ReadBlockFromDisk(block,(const CBlockIndex *)pindex) != 0 )
74 {
75 komodo_block2pubkey33(pubkey33,block);
76 }
77 }
78 else
79 {
80 // height -> pubkey33
81 //printf("extending chaintip komodo_index2pubkey33 height.%d need to get pubkey33\n",height);
82 }
83}
84
b62d7030 85int32_t komodo_checkpoint(int32_t *notarized_heightp,int32_t nHeight,uint256 hash)
86{
87 int32_t notarized_height; uint256 notarized_hash,notarized_desttxid; CBlockIndex *notary;
88 notarized_height = komodo_notarizeddata(chainActive.Tip()->nHeight,&notarized_hash,&notarized_desttxid);
89 *notarized_heightp = notarized_height;
d9d3a941 90 if ( notarized_height >= 0 && notarized_height <= chainActive.Tip()->nHeight && (notary= mapBlockIndex[notarized_hash]) != 0 )
b62d7030 91 {
92 //printf("nHeight.%d -> (%d %s)\n",chainActive.Tip()->nHeight,notarized_height,notarized_hash.ToString().c_str());
93 if ( notary->nHeight == notarized_height ) // if notarized_hash not in chain, reorg
94 {
95 if ( nHeight < notarized_height )
96 {
97 fprintf(stderr,"nHeight.%d < NOTARIZED_HEIGHT.%d\n",nHeight,notarized_height);
98 return(-1);
99 }
100 else if ( nHeight == notarized_height && memcmp(&hash,&notarized_hash,sizeof(hash)) != 0 )
101 {
102 fprintf(stderr,"nHeight.%d == NOTARIZED_HEIGHT.%d, diff hash\n",nHeight,notarized_height);
103 return(-1);
104 }
105 } else fprintf(stderr,"unexpected error notary_hash %s ht.%d at ht.%d\n",notarized_hash.ToString().c_str(),notarized_height,notary->nHeight);
106 } else if ( notarized_height > 0 )
107 fprintf(stderr,"couldnt find notary_hash %s ht.%d\n",notarized_hash.ToString().c_str(),notarized_height);
108 return(0);
109}
This page took 0.031158 seconds and 4 git commands to generate.