]> Git Repo - VerusCoin.git/blame - src/komodo.h
test
[VerusCoin.git] / src / komodo.h
CommitLineData
fcd36118 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
16#ifndef H_KOMODO_H
17#define H_KOMODO_H
18
01cc012f 19int32_t iguana_rwnum(int32_t rwflag,uint8_t *serialized,int32_t len,void *endianedp)
20{
21 int32_t i; uint64_t x;
22 if ( rwflag == 0 )
23 {
24 x = 0;
25 for (i=len-1; i>=0; i--)
26 {
27 x <<= 8;
28 x |= serialized[i];
29 }
30 switch ( len )
31 {
32 case 1: *(uint8_t *)endianedp = (uint8_t)x; break;
33 case 2: *(uint16_t *)endianedp = (uint16_t)x; break;
34 case 4: *(uint32_t *)endianedp = (uint32_t)x; break;
35 case 8: *(uint64_t *)endianedp = (uint64_t)x; break;
36 }
37 }
38 else
39 {
40 x = 0;
41 switch ( len )
42 {
43 case 1: x = *(uint8_t *)endianedp; break;
44 case 2: x = *(uint16_t *)endianedp; break;
45 case 4: x = *(uint32_t *)endianedp; break;
46 case 8: x = *(uint64_t *)endianedp; break;
47 }
48 for (i=0; i<len; i++,x >>= 8)
49 serialized[i] = (uint8_t)(x & 0xff);
50 }
51 return(len);
52}
53
54int32_t iguana_rwbignum(int32_t rwflag,uint8_t *serialized,int32_t len,uint8_t *endianedp)
55{
56 int32_t i;
57 if ( rwflag == 0 )
58 {
59 for (i=0; i<len; i++)
53b58ced 60 endianedp[i] = serialized[i];
01cc012f 61 }
62 else
63 {
64 for (i=0; i<len; i++)
53b58ced 65 serialized[i] = endianedp[i];
01cc012f 66 }
67 return(len);
68}
69
70int32_t _unhex(char c)
71{
72 if ( c >= '0' && c <= '9' )
73 return(c - '0');
74 else if ( c >= 'a' && c <= 'f' )
75 return(c - 'a' + 10);
76 else if ( c >= 'A' && c <= 'F' )
77 return(c - 'A' + 10);
78 return(-1);
79}
80
81int32_t is_hexstr(char *str,int32_t n)
82{
83 int32_t i;
84 if ( str == 0 || str[0] == 0 )
85 return(0);
86 for (i=0; str[i]!=0; i++)
87 {
88 if ( n > 0 && i >= n )
89 break;
90 if ( _unhex(str[i]) < 0 )
91 break;
92 }
93 if ( n == 0 )
94 return(i);
95 return(i == n);
96}
97
98int32_t unhex(char c)
99{
100 int32_t hex;
101 if ( (hex= _unhex(c)) < 0 )
102 {
103 //printf("unhex: illegal hexchar.(%c)\n",c);
104 }
105 return(hex);
106}
107
108unsigned char _decode_hex(char *hex) { return((unhex(hex[0])<<4) | unhex(hex[1])); }
109
110int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex)
111{
112 int32_t adjust,i = 0;
113 //printf("decode.(%s)\n",hex);
114 if ( is_hexstr(hex,n) == 0 )
115 {
116 memset(bytes,0,n);
117 return(n);
118 }
119 if ( n == 0 || (hex[n*2+1] == 0 && hex[n*2] != 0) )
120 {
121 if ( n > 0 )
122 {
123 bytes[0] = unhex(hex[0]);
124 printf("decode_hex n.%d hex[0] (%c) -> %d hex.(%s) [n*2+1: %d] [n*2: %d %c] len.%ld\n",n,hex[0],bytes[0],hex,hex[n*2+1],hex[n*2],hex[n*2],(long)strlen(hex));
125 }
126 bytes++;
127 hex++;
128 adjust = 1;
129 } else adjust = 0;
130 if ( n > 0 )
131 {
132 for (i=0; i<n; i++)
133 bytes[i] = _decode_hex(&hex[i*2]);
134 }
135 //bytes[i] = 0;
136 return(n + adjust);
137}
138
93b5c955 139#include <stdint.h>
778ca57b 140#include <stdio.h>
93b5c955 141
44c4fbbd 142#define CRYPTO777_PUBSECPSTR "020e46e79a2a8d12b9b5d12c7a91adb4e454edfae43c0a0cb805427d2ac7613fd9"
143
acb1f4f1 144const char *Notaries[64][2] =
df1620e2 145{
146 { "jl777_testA", "03b7621b44118017a16043f19b30cc8a4cfe068ac4e42417bae16ba460c80f3828" },
147 { "jl777_testB", "02ebfc784a4ba768aad88d44d1045d240d47b26e248cafaf1c5169a42d7a61d344" },
148 { "pondsea_SH", "02209073bc0943451498de57f802650311b1f12aa6deffcd893da198a544c04f36" },
149 { "crackers_EU", "0340c66cf2c41c41efb420af57867baa765e8468c12aa996bfd816e1e07e410728" },
150 { "pondsea_EU", "0225aa6f6f19e543180b31153d9e6d55d41bc7ec2ba191fd29f19a2f973544e29d" },
151 { "locomb_EU", "025c6d26649b9d397e63323d96db42a9d3caad82e1d6076970efe5056c00c0779b" },
152 { "fullmoon_AE", "0204a908350b8142698fdb6fabefc97fe0e04f537adc7522ba7a1e8f3bec003d4a" },
153 { "movecrypto_EU", "021ab53bc6cf2c46b8a5456759f9d608966eff87384c2b52c0ac4cc8dd51e9cc42" },
154 { "badass_EU", "0209d48554768dd8dada988b98aca23405057ac4b5b46838a9378b95c3e79b9b9e" },
155 { "crackers_NA", "029e1c01131974f4cd3f564cc0c00eb87a0f9721043fbc1ca60f9bd0a1f73f64a1" },
156 { "proto_EU", "03681ffdf17c8f4f0008cefb7fa0779c5e888339cdf932f0974483787a4d6747c1" },
157 { "jeezy_EU", "023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6" },
158 { "farl4web_EU", "035caa40684ace968677dca3f09098aa02b70e533da32390a7654c626e0cf908e1" },
159 { "nxtswe_EU", "032fb104e5eaa704a38a52c126af8f67e870d70f82977e5b2f093d5c1c21ae5899" },
160 { "traderbill_EU", "03196e8de3e2e5d872f31d79d6a859c8704a2198baf0af9c7b21e29656a7eb455f" },
161 { "vanbreuk_EU", "024f3cad7601d2399c131fd070e797d9cd8533868685ddbe515daa53c2e26004c3" },
162 { "titomane_EU", "03517fcac101fed480ae4f2caf775560065957930d8c1facc83e30077e45bdd199" },
163 { "supernet_AE", "029d93ef78197dc93892d2a30e5a54865f41e0ca3ab7eb8e3dcbc59c8756b6e355" },
164 { "supernet_EU", "02061c6278b91fd4ac5cab4401100ffa3b2d5a277e8f71db23401cc071b3665546" },
21cc1d3e 165 { "supernet_NA", "033c073366152b6b01535e15dd966a3a8039169584d06e27d92a69889b720d44e1" },
df1620e2 166 { "yassin_EU", "033fb7231bb66484081952890d9a03f91164fb27d392d9152ec41336b71b15fbd0" },
167 { "durerus_EU", "02bcbd287670bdca2c31e5d50130adb5dea1b53198f18abeec7211825f47485d57" },
168 { "badass_SH", "026b49dd3923b78a592c1b475f208e23698d3f085c4c3b4906a59faf659fd9530b" },
bafc61f3 169 { "badass_NA", "02afa1a9f948e1634a29dc718d218e9d150c531cfa852843a1643a02184a63c1a7" },
df1620e2 170 { "pondsea_NA", "031bcfdbb62268e2ff8dfffeb9ddff7fe95fca46778c77eebff9c3829dfa1bb411" },
171 { "rnr_EU", "0287aa4b73988ba26cf6565d815786caf0d2c4af704d7883d163ee89cd9977edec" },
172 { "crackers_SH", "02313d72f9a16055737e14cfc528dcd5d0ef094cfce23d0348fe974b6b1a32e5f0" },
173 { "grewal_SH", "03212a73f5d38a675ee3cdc6e82542a96c38c3d1c79d25a1ed2e42fcf6a8be4e68" },
174 { "polycryptoblock_NA", "02708dcda7c45fb54b78469673c2587bfdd126e381654819c4c23df0e00b679622" },
175 { "titomane_NA", "0387046d9745414fb58a0fa3599078af5073e10347e4657ef7259a99cb4f10ad47" },
176 { "titomane_AE", "03cda6ca5c2d02db201488a54a548dbfc10533bdc275d5ea11928e8d6ab33c2185" },
52275d67 177 { "kolo_EU", "03f5c08dadffa0ffcafb8dd7ffc38c22887bd02702a6c9ac3440deddcf2837692b" },
bc6fd011 178 { "artik_NA", "0224e31f93eff0cc30eaf0b2389fbc591085c0e122c4d11862c1729d090106c842" },
bafc61f3 179 { "eclips_EU", "0339369c1f5a2028d44be7be6f8ec3b907fdec814f87d2dead97cab4edb71a42e9" },
df1620e2 180};
181
352f8081 182int32_t IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,NOTARIZED_HEIGHT,Num_nutxos;
998397aa 183std::string NOTARY_PUBKEY;
d6202b40 184uint256 NOTARIZED_HASH,NOTARIZED_BTCHASH;
352f8081 185struct nutxo_entry { uint256 txhash; uint64_t voutmask; int32_t notaryid; };
186struct nutxo_entry NUTXOS[10000];
187
53bb4eda 188void komodo_nutxoadd(int32_t notaryid,uint256 txhash,uint64_t voutmask,int32_t numvouts);
671187dd 189
6f3bcbea 190int32_t komodo_threshold(uint64_t signedmask)
191{
192 return(1); // N/2+1 || N/3 + devsig
193}
194
671187dd 195int32_t komodo_stateupdate(uint8_t notarypubs[][33],uint8_t numnotaries,int32_t notaryid,uint256 txhash,uint64_t voutmask,int32_t numvouts)
bafc61f3 196{
52ed4002 197 static FILE *fp; static int32_t errs; char fname[512]; uint8_t func,num,pubkeys[64][33];
073594aa 198 sprintf(fname,"%s/%s",GetDataDir(false).string().c_str(),(char *)"komodostate");
bafc61f3 199 if ( fp == 0 )
200 {
201 if ( (fp= fopen(fname,"rb+")) != 0 )
202 {
203 while ( (func= fgetc(fp)) != EOF )
204 {
205 if ( func == 'P' )
206 {
207 if ( (num= fgetc(fp)) < 64 )
dd7b22ad 208 {
52ed4002 209 if ( fread(pubkeys,33,num,fp) != num )
210 errs++;
dd7b22ad 211 else printf("updated %d pubkeys\n",num);
212 }
bafc61f3 213 else printf("illegal num.%d\n",num);
214 }
215 else if ( func == 'N' )
216 {
52ed4002 217 if ( fread(&NOTARIZED_HEIGHT,1,sizeof(NOTARIZED_HEIGHT),fp) != sizeof(NOTARIZED_HEIGHT) )
218 errs++;
219 if ( fread(&NOTARIZED_HASH,1,sizeof(NOTARIZED_HASH),fp) != sizeof(NOTARIZED_HASH) )
220 errs++;
221 if ( fread(&NOTARIZED_BTCHASH,1,sizeof(NOTARIZED_BTCHASH),fp) != sizeof(NOTARIZED_BTCHASH) )
222 errs++;
bafc61f3 223 }
671187dd 224 else if ( func == 'U' )
225 {
226 uint8_t n,nid; uint256 hash; uint64_t mask;
227 n = fgetc(fp);
228 nid = fgetc(fp);
229 if ( fread(&mask,1,sizeof(mask),fp) != sizeof(mask) )
230 errs++;
231 if ( fread(&hash,1,sizeof(hash),fp) != sizeof(hash) )
232 errs++;
233 komodo_nutxoadd(nid,hash,mask,n);
234 }
bafc61f3 235 else printf("illegal func.(%d %c)\n",func,func);
236 }
237 } else fp = fopen(fname,"wb+");
238 printf("fname.(%s) fpos.%ld\n",fname,ftell(fp));
239 }
240 if ( fp != 0 )
241 {
242 if ( notarypubs != 0 && numnotaries > 0 )
243 {
244 fputc('P',fp);
245 fputc(numnotaries,fp);
52ed4002 246 if ( fwrite(notarypubs,33,numnotaries,fp) != numnotaries )
247 errs++;
bafc61f3 248 }
671187dd 249 else if ( voutmask != 0 && numvouts > 0 )
250 {
251 fputc('U',fp);
252 fputc(numvouts,fp);
253 fputc(notaryid,fp);
254 if ( fwrite(&voutmask,1,sizeof(voutmask),fp) != sizeof(voutmask) )
255 errs++;
256 if ( fwrite(&txhash,1,sizeof(txhash),fp) != sizeof(txhash) )
257 errs++;
258 }
259 else
260 {
261 fputc('N',fp);
262 if ( fwrite(&NOTARIZED_HEIGHT,1,sizeof(NOTARIZED_HEIGHT),fp) != sizeof(NOTARIZED_HEIGHT) )
263 errs++;
264 if ( fwrite(&NOTARIZED_HASH,1,sizeof(NOTARIZED_HASH),fp) != sizeof(NOTARIZED_HASH) )
265 errs++;
266 if ( fwrite(&NOTARIZED_BTCHASH,1,sizeof(NOTARIZED_BTCHASH),fp) != sizeof(NOTARIZED_BTCHASH) )
267 errs++;
268 }
bafc61f3 269 }
270}
271
b9bfc77d 272void komodo_nutxoadd(int32_t notaryid,uint256 txhash,uint64_t voutmask,int32_t numvouts)
352f8081 273{
671187dd 274 if ( numvouts > 1 && notaryid < 64 ) // change to ADD_HASH() and file based
b9bfc77d 275 {
276 NUTXOS[Num_nutxos].txhash = txhash;
277 NUTXOS[Num_nutxos].voutmask = voutmask;
278 NUTXOS[Num_nutxos].notaryid = notaryid;
21cc1d3e 279 printf("Add NUTXO[%d] <- %s notaryid.%d %s %llx\n",Num_nutxos,Notaries[notaryid][0],notaryid,txhash.ToString().c_str(),(long long)voutmask);
671187dd 280 komodo_stateupdate(0,0,notaryid,txhash,voutmask,numvouts);
b9bfc77d 281 Num_nutxos++;
282 }
352f8081 283}
284
671187dd 285int32_t komodo_nutxofind(uint256 txhash,int32_t vout) // change to HASH_FIND()
352f8081 286{
287 int32_t i;
288 for (i=0; i<Num_nutxos; i++)
289 {
290 if ( memcmp(&txhash,&NUTXOS[i].txhash,sizeof(txhash)) == 0 && ((1LL << vout) & NUTXOS[i].voutmask) != 0 )
291 return(NUTXOS[i].notaryid);
292 }
293 return(-1);
294}
50027f06 295
84e843cd 296int32_t komodo_notaryfind(uint8_t *pubkey) // change to ADD_HASH()
1390456b 297{
6f3bcbea 298 static int didinit; static uint8_t notarypubs[64][33];
299 int32_t i,k; uint8_t notarypub[33];
300 if ( didinit == 0 )
301 {
302 for (k=0; k<64; k++)
303 {
304 if ( Notaries[k][0] == 0 || Notaries[k][1] == 0 || Notaries[k][0][0] == 0 || Notaries[k][1][0] == 0 )
305 break;
306 decode_hex(notarypubs[k],33,(char *)Notaries[k][1]);
d6202b40 307 printf("k.%d (%s) (%s) ",k,Notaries[k][0],Notaries[k][1]);
6f3bcbea 308 for (i=0; i<33; i++)
309 printf("%02x",notarypubs[k][i]);
310 printf(" notarypubs.[%d]\n",k);
311 }
312 didinit = 1;
313 }
1390456b 314 for (k=0; k<64; k++)
315 {
6f3bcbea 316 if ( memcmp(notarypubs[k],pubkey,33) == 0 )
1390456b 317 return(k);
1390456b 318 }
319 return(-1);
320}
321
322int32_t komodo_voutupdate(int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen,int32_t height,uint256 txhash,int32_t i,int32_t j,uint64_t *voutmaskp,int32_t *specialtxp,int32_t *notarizedheightp)
323{
550fcab6 324 int32_t k,opretlen,len = 0; uint256 kmdtxid,btctxid; uint8_t crypto777[33];
9c406099 325 if ( scriptlen == 35 && scriptbuf[0] == 33 && scriptbuf[34] == 0xac )
1390456b 326 {
c23dd601 327 decode_hex(crypto777,33,(char *)CRYPTO777_PUBSECPSTR);
986d3459 328 /*for (k=0; k<33; k++)
e1be360e 329 printf("%02x",crypto777[k]);
330 printf(" crypto777 ");
331 for (k=0; k<scriptlen; k++)
332 printf("%02x",scriptbuf[k]);
986d3459 333 printf(" <- script ht.%d i.%d j.%d cmp.%d\n",height,i,j,memcmp(crypto777,scriptbuf+1,33));*/
1390456b 334 if ( memcmp(crypto777,scriptbuf+1,33) == 0 )
335 {
336 *specialtxp = 1;
337 printf(">>>>>>>> ");
338 }
339 else if ( (k= komodo_notaryfind(scriptbuf + 1)) >= 0 )
340 {
84e843cd 341 //printf("found notary.k%d\n",k);
342 if ( notaryid < 64 )
1390456b 343 {
84e843cd 344 if ( notaryid < 0 )
345 {
346 notaryid = k;
347 *voutmaskp |= (1LL << j);
348 }
349 else if ( notaryid != k )
350 {
351 printf("mismatch notaryid.%d k.%d\n",notaryid,k);
352 notaryid = 64;
353 *voutmaskp = 0;
354 }
355 else *voutmaskp |= (1LL << j);
1390456b 356 }
1390456b 357 }
358 }
359 if ( j == 1 && scriptbuf[len++] == 0x6a )
360 {
361 if ( (opretlen= scriptbuf[len++]) == 0x4c )
362 opretlen = scriptbuf[len++];
363 else if ( opretlen == 0x4d )
364 {
365 opretlen = scriptbuf[len++];
366 opretlen = (opretlen << 8) + scriptbuf[len++];
367 }
368 if ( opretlen >= 32*2+4 )
369 {
370 len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&kmdtxid);
371 len += iguana_rwnum(0,&scriptbuf[len],4,(uint8_t *)notarizedheightp);
372 len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&btctxid);
5b760d3f 373 //for (k=0; k<scriptlen; k++)
374 // printf("%02x",scriptbuf[k]);
375 //printf(" <- script ht.%d i.%d j.%d\n",height,i,j);
c23dd601 376 printf("ht.%d NOTARIZED.%d KMD.%s BTC.%s\n",height,*notarizedheightp,kmdtxid.ToString().c_str(),btctxid.ToString().c_str());
1390456b 377 if ( *notarizedheightp > NOTARIZED_HEIGHT )
378 {
d8ce705a 379 static uint256 zero;
1390456b 380 NOTARIZED_HEIGHT = *notarizedheightp;
381 NOTARIZED_HASH = kmdtxid;
d6202b40 382 NOTARIZED_BTCHASH = btctxid;
d8ce705a 383 komodo_stateupdate(0,0,0,zero,0,0);
1390456b 384 }
385 }
386 }
387 return(notaryid);
388}
389
651989c7 390void komodo_connectblock(CBlockIndex *pindex,CBlock& block)
50027f06 391{
bafc61f3 392 static int32_t didinit;
acb3f1d8 393 char *scriptstr,*opreturnstr; uint64_t signedmask,voutmask;
dd7b22ad 394 uint8_t scriptbuf[4096],pubkeys[64][33]; uint256 kmdtxid,btctxid,txhash;
29e69b85 395 int32_t i,j,k,numvalid,specialtx,notarizedheight,notaryid,len,numvouts,numvins,height,txn_count,flag;
bafc61f3 396 if ( didinit == 0 )
397 {
d8ce705a 398 memset(&txhash,0,sizeof(txhash));
399 komodo_stateupdate(0,0,0,txhash,0,0);
bafc61f3 400 didinit = 1;
401 }
3d35aa5b 402 // update voting results and official (height, notaries[])
68916cc6 403 if ( pindex != 0 )
b501ded2 404 {
656eddcd 405 height = pindex->nHeight;
01cc012f 406 txn_count = block.vtx.size();
407 for (i=0; i<txn_count; i++)
dc64de68 408 {
352f8081 409 txhash = block.vtx[i].GetHash();
01cc012f 410 numvouts = block.vtx[i].vout.size();
352f8081 411 notaryid = -1;
1390456b 412 voutmask = specialtx = notarizedheight = 0;
01cc012f 413 for (j=0; j<numvouts; j++)
dc64de68 414 {
1390456b 415 len = block.vtx[i].vout[j].scriptPubKey.size();
416 if ( len <= sizeof(scriptbuf) )
01cc012f 417 {
1390456b 418 memcpy(scriptbuf,block.vtx[i].vout[j].scriptPubKey.data(),len);
acb3f1d8 419 notaryid = komodo_voutupdate(notaryid,scriptbuf,len,height,txhash,i,j,&voutmask,&specialtx,&notarizedheight);
a01acef4 420 if ( 0 && i > 0 )
e69a0833 421 {
422 for (k=0; k<len; k++)
423 printf("%02x",scriptbuf[k]);
a8832194 424 printf(" <- notaryid.%d ht.%d i.%d j.%d numvouts.%d numvins.%d voutmask.%llx txid.(%s)\n",notaryid,height,i,j,numvouts,numvins,(long long)voutmask,txhash.ToString().c_str());
e69a0833 425 }
01cc012f 426 }
352f8081 427 }
1390456b 428 if ( notaryid >= 0 && voutmask != 0 )
429 komodo_nutxoadd(notaryid,txhash,voutmask,numvouts);
430 signedmask = 0;
431 numvins = block.vtx[i].vin.size();
5bdebffe 432 for (j=0; j<numvins; j++)
352f8081 433 {
1390456b 434 if ( (k= komodo_nutxofind(block.vtx[i].vin[j].prevout.hash,block.vtx[i].vin[j].prevout.n)) >= 0 )
435 signedmask |= (1LL << k);
21cc1d3e 436 else if ( 0 && signedmask != 0 )
bc6fd011 437 printf("signedmask.%llx but ht.%d i.%d j.%d not found (%s %d)\n",(long long)signedmask,height,i,j,block.vtx[i].vin[j].prevout.hash.ToString().c_str(),block.vtx[i].vin[j].prevout.n);
1390456b 438 }
06f0ed43 439 if ( signedmask != 0 && (notarizedheight != 0 || specialtx != 0) )
1390456b 440 {
e69a0833 441 printf("NOTARY SIGNED.%llx numvins.%d ht.%d txi.%d notaryht.%d specialtx.%d\n",(long long)signedmask,numvins,height,i,notarizedheight,specialtx);
29a14325 442 if ( specialtx != 0 && numvouts > 2 && komodo_threshold(signedmask) > 0 )
84e843cd 443 {
29e69b85 444 numvalid = 0;
dd7b22ad 445 memset(pubkeys,0,sizeof(pubkeys));
84e843cd 446 for (j=1; j<numvouts; j++)
447 {
448 len = block.vtx[i].vout[j].scriptPubKey.size();
449 if ( len <= sizeof(scriptbuf) )
450 {
451 memcpy(scriptbuf,block.vtx[i].vout[j].scriptPubKey.data(),len);
452 if ( len == 35 && scriptbuf[0] == 33 && scriptbuf[34] == 0xac )
453 {
29e69b85 454 memcpy(pubkeys[numvalid++],scriptbuf+1,33);
e7f99312 455 for (k=0; k<33; k++)
84e843cd 456 printf("%02x",scriptbuf[k+1]);
457 printf(" <- new notary.[%d]\n",j-1);
458 }
459 }
460 }
29e69b85 461 if ( numvalid > 13 )
d8ce705a 462 {
463 memset(&txhash,0,sizeof(txhash));
464 komodo_stateupdate(pubkeys,numvalid,0,txhash,0,0);
465 }
84e843cd 466 printf("new notaries.%d newheight.%d from height.%d\n",numvouts-1,(((height+500)/1000)+1)*1000,height);
467 }
a96439f5 468 }
656eddcd 469 }
44c4fbbd 470 } else printf("komodo_connectblock: unexpected null pindex\n");
3d35aa5b 471}
472
e1be360e 473int32_t komodo_blockindexcheck(CBlockIndex *pindex,uint32_t *nBitsp)
474{
475 // 1 -> valid notary block, change nBits to KOMODO_MINDIFF_NBITS
476 // -1 -> invalid, ie, prior to notarized block
477 CBlock block; int32_t i,height; char *coinbasestr;
478 if ( pindex == 0 )
479 return(0);
480 if ( ReadBlockFromDisk(block,pindex,1) == 0 )
481 return(0);
482 if ( block.vtx.size() > 0 )
483 {
484 height = pindex->nHeight;
485 coinbasestr = (char *)block.vtx[0].vout[0].scriptPubKey.ToString().c_str();
486 for (i=0; i<64; i++)
487 {
488 if ( Notaries[i][0] == 0 || Notaries[i][1] == 0 || Notaries[i][0][0] == 0 || Notaries[i][1][0] == 0 )
489 break;
490 if ( strncmp(Notaries[i][1],coinbasestr,66) == 0 )
491 {
492 //printf("Notary.[%d] %s ht.%d (%s)\n",i,Notaries[i][0],height,coinbasestr);
493 //*nBitsp = KOMODO_MINDIFF_NBITS;
494 return(1);
495 }
496 }
497 }
498 // compare against elected notary pubkeys as of height
499 return(0);
500}
501
0570045c 502int32_t komodo_is_notaryblock(CBlockHeader& blockhdr)
3d35aa5b 503{
68916cc6 504 //uint32_t nBits = 0;
505 //return(komodo_blockindexcheck(mapBlockIndex[blockhdr.GetHash()],&nBits));
506 return(0);
3d35aa5b 507}
508
0570045c 509int32_t komodo_blockhdrcheck(CBlockHeader& blockhdr,uint32_t *nBitsp)
3d35aa5b 510{
aa8b56ea 511 int32_t retval;
512 if ( (retval= komodo_is_notaryblock(blockhdr)) > 0 )
0570045c 513 *nBitsp = KOMODO_MINDIFF_NBITS;
aa8b56ea 514 return(retval);
3d35aa5b 515}
516
0570045c 517int32_t komodo_blockcheck(CBlock& block,uint32_t *nBitsp)
d27afb07 518{
c9b8b8b0 519 return(komodo_blockhdrcheck(block,nBitsp));
d27afb07 520}
fcd36118 521
522#endif
This page took 0.108566 seconds and 4 git commands to generate.