]> 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
3eea72f2 19// Todo: handle reorg: clear all entries above reorged height
755ead98 20// smooth consensus price
21//
3eea72f2 22
9499e4de 23#include <stdint.h>
24#include <stdio.h>
975b2ddb 25#include <pthread.h>
88f973c2 26#include <ctype.h>
9499e4de 27
429dabb5 28void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotaries,uint8_t notaryid,uint256 txhash,uint64_t voutmask,uint8_t numvouts,uint32_t *pvals,uint8_t numpvals,int32_t kheight,uint64_t opretvalue,uint8_t *opretbuf,uint16_t opretlen,uint16_t vout);
58c94994 29void komodo_init();
d9d3a941 30int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *notarized_desttxidp);
3c0f5d94 31char *komodo_issuemethod(char *method,char *params,uint16_t port);
9499e4de 32
9c05b959 33#define GENESIS_NBITS 0x1f00ffff
755ead98 34#define KOMODO_MINRATIFY 7
35
98f2e433 36#include "komodo_globals.h"
46beb55e 37#include "komodo_utils.h"
6210f328 38//queue_t DepositsQ,PendingsQ;
429dabb5 39
8d6bd385 40#include "cJSON.c"
a40be56e 41#include "komodo_bitcoind.h"
3eea72f2 42#include "komodo_interest.h"
3eea72f2 43#include "komodo_pax.h"
3eea72f2 44#include "komodo_notary.h"
88593976 45#include "komodo_gateway.h"
9499e4de 46
01f9cb3d 47
429dabb5 48void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotaries,uint8_t notaryid,uint256 txhash,uint64_t voutmask,uint8_t numvouts,uint32_t *pvals,uint8_t numpvals,int32_t KMDheight,uint64_t opretvalue,uint8_t *opretbuf,uint16_t opretlen,uint16_t vout)
5cea7725 49{
e9595d76 50 static FILE *fp; static int32_t errs; char fname[512]; int32_t ht,func; uint8_t num,pubkeys[64][33];
e402ebee 51#ifdef WIN32
52 sprintf(fname,"%s\\%s",GetDataDir(false).string().c_str(),(char *)"komodostate");
53#else
073594aa 54 sprintf(fname,"%s/%s",GetDataDir(false).string().c_str(),(char *)"komodostate");
e402ebee 55#endif
bafc61f3 56 if ( fp == 0 )
57 {
58 if ( (fp= fopen(fname,"rb+")) != 0 )
59 {
60 while ( (func= fgetc(fp)) != EOF )
61 {
c50ec0fb 62 if ( fread(&ht,1,sizeof(ht),fp) != sizeof(ht) )
63 errs++;
2578b002 64 //printf("fpos.%ld func.(%d %c) ht.%d ",ftell(fp),func,func,ht);
bafc61f3 65 if ( func == 'P' )
66 {
67 if ( (num= fgetc(fp)) < 64 )
dd7b22ad 68 {
52ed4002 69 if ( fread(pubkeys,33,num,fp) != num )
70 errs++;
732fdf87 71 else
72 {
5203fc4b 73 printf("updated %d pubkeys at ht.%d\n",num,ht);
74 komodo_notarysinit(ht,pubkeys,num);
732fdf87 75 }
76 } else printf("illegal num.%d\n",num);
2578b002 77 //printf("P[%d]\n",num);
bafc61f3 78 }
79 else if ( func == 'N' )
80 {
52ed4002 81 if ( fread(&NOTARIZED_HEIGHT,1,sizeof(NOTARIZED_HEIGHT),fp) != sizeof(NOTARIZED_HEIGHT) )
82 errs++;
83 if ( fread(&NOTARIZED_HASH,1,sizeof(NOTARIZED_HASH),fp) != sizeof(NOTARIZED_HASH) )
84 errs++;
1e81ccb7 85 if ( fread(&NOTARIZED_DESTTXID,1,sizeof(NOTARIZED_DESTTXID),fp) != sizeof(NOTARIZED_DESTTXID) )
52ed4002 86 errs++;
81bac2f0 87 printf("load NOTARIZED %d %s\n",NOTARIZED_HEIGHT,NOTARIZED_HASH.ToString().c_str());
1e81ccb7 88 komodo_notarized_update(ht,NOTARIZED_HEIGHT,NOTARIZED_HASH,NOTARIZED_DESTTXID);
bafc61f3 89 }
671187dd 90 else if ( func == 'U' )
91 {
92 uint8_t n,nid; uint256 hash; uint64_t mask;
93 n = fgetc(fp);
94 nid = fgetc(fp);
2578b002 95 //printf("U %d %d\n",n,nid);
671187dd 96 if ( fread(&mask,1,sizeof(mask),fp) != sizeof(mask) )
97 errs++;
98 if ( fread(&hash,1,sizeof(hash),fp) != sizeof(hash) )
99 errs++;
3eea72f2 100 komodo_nutxoadd(ht,nid,hash,mask,n);
4355e769 101 }
2b84e06c 102 else if ( func == 'K' )
103 {
104 int32_t kheight;
105 if ( fread(&kheight,1,sizeof(kheight),fp) != sizeof(kheight) )
106 errs++;
107 if ( kheight > KMDHEIGHT )
108 {
109 KMDHEIGHT = kheight;
2b84e06c 110 }
2578b002 111 //printf("ht.%d KMDHEIGHT <- %d\n",ht,kheight);
2b84e06c 112 }
01f9cb3d 113 else if ( func == 'R' )
64bb0834 114 {
429dabb5 115 uint16_t olen,v; uint64_t ovalue; uint256 txid; uint8_t opret[10000];
116 if ( fread(&txid,1,sizeof(txid),fp) != sizeof(txid) )
117 errs++;
118 if ( fread(&v,1,sizeof(v),fp) != sizeof(v) )
119 errs++;
33935bd0 120 if ( fread(&ovalue,1,sizeof(ovalue),fp) != sizeof(ovalue) )
121 errs++;
289dc57b 122 if ( fread(&olen,1,sizeof(olen),fp) != sizeof(olen) )
64bb0834 123 errs++;
289dc57b 124 if ( olen < sizeof(opret) )
125 {
126 if ( fread(opret,1,olen,fp) != olen )
127 errs++;
429dabb5 128 komodo_opreturn(ht,ovalue,opret,olen,txid,v);
289dc57b 129 } else printf("illegal olen.%u\n",olen);
01f9cb3d 130 }
4355e769 131 else if ( func == 'D' )
132 {
9997caa0 133 //printf("D[%d]\n",ht);
671187dd 134 }
b673d264 135//#ifdef KOMODO_PAX
5cea7725 136 else if ( func == 'V' )
137 {
138 int32_t numpvals; uint32_t pvals[128];
139 numpvals = fgetc(fp);
4a41b0b2 140 if ( numpvals*sizeof(uint32_t) <= sizeof(pvals) && fread(pvals,sizeof(uint32_t),numpvals,fp) == numpvals )
5cea7725 141 {
142 komodo_pvals(ht,pvals,numpvals);
8bc1bcad 143 //printf("load pvals ht.%d numpvals.%d\n",ht,numpvals);
4a41b0b2 144 } else printf("error loading pvals[%d]\n",numpvals);
5cea7725 145 }
b673d264 146//#endif
bafc61f3 147 else printf("illegal func.(%d %c)\n",func,func);
148 }
149 } else fp = fopen(fname,"wb+");
150 printf("fname.(%s) fpos.%ld\n",fname,ftell(fp));
63c30610 151 KOMODO_INITDONE = (uint32_t)time(NULL);
bafc61f3 152 }
49df008c 153 if ( height <= 0 )
154 {
155 printf("early return: stateupdate height.%d\n",height);
156 return;
157 }
3eea72f2 158 if ( fp != 0 ) // write out funcid, height, other fields, call side effect function
bafc61f3 159 {
2578b002 160 //printf("fpos.%ld ",ftell(fp));
4355e769 161 if ( height < 0 )
162 {
9997caa0 163 height = -height;
2578b002 164 //printf("func D[%d] errs.%d\n",height,errs);
4355e769 165 fputc('D',fp);
166 if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) )
167 errs++;
168 }
2b84e06c 169 else if ( KMDheight > 0 )
170 {
171 fputc('K',fp);
172 if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) )
173 errs++;
174 if ( fwrite(&KMDheight,1,sizeof(KMDheight),fp) != sizeof(KMDheight) )
175 errs++;
2578b002 176 //printf("ht.%d K %d\n",height,KMDheight);
2b84e06c 177 }
01f9cb3d 178 else if ( opretbuf != 0 && opretlen > 0 )
64bb0834 179 {
01f9cb3d 180 uint16_t olen = opretlen;
181 fputc('R',fp);
64bb0834 182 if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) )
183 errs++;
429dabb5 184 if ( fwrite(&txhash,1,sizeof(txhash),fp) != sizeof(txhash) )
185 errs++;
186 if ( fwrite(&vout,1,sizeof(vout),fp) != sizeof(vout) )
187 errs++;
30df2e00 188 if ( fwrite(&opretvalue,1,sizeof(opretvalue),fp) != sizeof(opretvalue) )
33935bd0 189 errs++;
289dc57b 190 if ( fwrite(&olen,1,sizeof(olen),fp) != olen )
191 errs++;
01f9cb3d 192 if ( fwrite(opretbuf,1,olen,fp) != olen )
64bb0834 193 errs++;
2578b002 194 //printf("ht.%d R opret[%d]\n",height,olen);
f671a131 195 komodo_opreturn(height,opretvalue,opretbuf,olen,txhash,vout);
01f9cb3d 196 }
9997caa0 197 else if ( notarypubs != 0 && numnotaries > 0 )
bafc61f3 198 {
2578b002 199 //printf("ht.%d func P[%d] errs.%d\n",height,numnotaries,errs);
bafc61f3 200 fputc('P',fp);
c50ec0fb 201 if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) )
202 errs++;
bafc61f3 203 fputc(numnotaries,fp);
52ed4002 204 if ( fwrite(notarypubs,33,numnotaries,fp) != numnotaries )
205 errs++;
3eea72f2 206 komodo_notarysinit(height,notarypubs,numnotaries);
bafc61f3 207 }
671187dd 208 else if ( voutmask != 0 && numvouts > 0 )
209 {
2578b002 210 //printf("ht.%d func U %d %d errs.%d hashsize.%ld\n",height,numvouts,notaryid,errs,sizeof(txhash));
671187dd 211 fputc('U',fp);
c50ec0fb 212 if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) )
213 errs++;
671187dd 214 fputc(numvouts,fp);
215 fputc(notaryid,fp);
216 if ( fwrite(&voutmask,1,sizeof(voutmask),fp) != sizeof(voutmask) )
217 errs++;
218 if ( fwrite(&txhash,1,sizeof(txhash),fp) != sizeof(txhash) )
219 errs++;
3eea72f2 220 komodo_nutxoadd(height,notaryid,txhash,voutmask,numvouts);
671187dd 221 }
b673d264 222//#ifdef KOMODO_PAX
4a41b0b2 223 else if ( pvals != 0 && numpvals > 0 )
224 {
bfa5b4f2 225 int32_t i,nonz = 0;
1bf82154 226 for (i=0; i<32; i++)
227 if ( pvals[i] != 0 )
228 nonz++;
229 if ( nonz >= 32 )
230 {
231 fputc('V',fp);
232 if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) )
233 errs++;
234 fputc(numpvals,fp);
235 if ( fwrite(pvals,sizeof(uint32_t),numpvals,fp) != numpvals )
236 errs++;
237 komodo_pvals(height,pvals,numpvals);
2578b002 238 //printf("ht.%d V numpvals[%d]\n",height,numpvals);
1bf82154 239 }
ef7a3548 240 //printf("save pvals height.%d numpvals.%d\n",height,numpvals);
4a41b0b2 241 }
b673d264 242//#endif
6dabcca4 243 else if ( height != 0 )
671187dd 244 {
2578b002 245 //printf("ht.%d func N ht.%d errs.%d\n",height,NOTARIZED_HEIGHT,errs);
671187dd 246 fputc('N',fp);
c50ec0fb 247 if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) )
248 errs++;
671187dd 249 if ( fwrite(&NOTARIZED_HEIGHT,1,sizeof(NOTARIZED_HEIGHT),fp) != sizeof(NOTARIZED_HEIGHT) )
250 errs++;
251 if ( fwrite(&NOTARIZED_HASH,1,sizeof(NOTARIZED_HASH),fp) != sizeof(NOTARIZED_HASH) )
252 errs++;
1e81ccb7 253 if ( fwrite(&NOTARIZED_DESTTXID,1,sizeof(NOTARIZED_DESTTXID),fp) != sizeof(NOTARIZED_DESTTXID) )
671187dd 254 errs++;
1e81ccb7 255 komodo_notarized_update(height,NOTARIZED_HEIGHT,NOTARIZED_HASH,NOTARIZED_DESTTXID);
671187dd 256 }
47f47733 257 fflush(fp);
bafc61f3 258 }
259}
260
844a6138 261int32_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,uint64_t value)
1390456b 262{
4b13149d 263 static uint256 zero; int32_t opretlen,nid,len = 0; uint256 kmdtxid,desttxid; uint8_t crypto777[33];
9c406099 264 if ( scriptlen == 35 && scriptbuf[0] == 33 && scriptbuf[34] == 0xac )
1390456b 265 {
c23dd601 266 decode_hex(crypto777,33,(char *)CRYPTO777_PUBSECPSTR);
986d3459 267 /*for (k=0; k<33; k++)
e1be360e 268 printf("%02x",crypto777[k]);
269 printf(" crypto777 ");
270 for (k=0; k<scriptlen; k++)
271 printf("%02x",scriptbuf[k]);
986d3459 272 printf(" <- script ht.%d i.%d j.%d cmp.%d\n",height,i,j,memcmp(crypto777,scriptbuf+1,33));*/
1390456b 273 if ( memcmp(crypto777,scriptbuf+1,33) == 0 )
274 {
275 *specialtxp = 1;
276 printf(">>>>>>>> ");
277 }
a5f315c7 278 else if ( komodo_chosennotary(&nid,height,scriptbuf + 1) >= 0 )
1390456b 279 {
84e843cd 280 //printf("found notary.k%d\n",k);
281 if ( notaryid < 64 )
1390456b 282 {
84e843cd 283 if ( notaryid < 0 )
284 {
a5f315c7 285 notaryid = nid;
84e843cd 286 *voutmaskp |= (1LL << j);
287 }
a5f315c7 288 else if ( notaryid != nid )
84e843cd 289 {
a5f315c7 290 printf("mismatch notaryid.%d k.%d\n",notaryid,nid);
84e843cd 291 notaryid = 64;
292 *voutmaskp = 0;
293 }
294 else *voutmaskp |= (1LL << j);
1390456b 295 }
1390456b 296 }
297 }
844a6138 298 if ( scriptbuf[len++] == 0x6a )
1390456b 299 {
300 if ( (opretlen= scriptbuf[len++]) == 0x4c )
301 opretlen = scriptbuf[len++];
302 else if ( opretlen == 0x4d )
303 {
304 opretlen = scriptbuf[len++];
305 opretlen = (opretlen << 8) + scriptbuf[len++];
306 }
429dabb5 307 //for (k=0; k<scriptlen; k++)
308 // printf("%02x",scriptbuf[k]);
309 //printf(" <- script ht.%d i.%d j.%d value %.8f\n",height,i,j,dstr(value));
a6400079 310 if ( j == 1 && opretlen >= 32*2+4 && strcmp(ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,(char *)&scriptbuf[len+32*2+4]) == 0 )
1390456b 311 {
4a41b0b2 312 len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&kmdtxid);
313 len += iguana_rwnum(0,&scriptbuf[len],4,(uint8_t *)notarizedheightp);
3eea72f2 314 len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&desttxid);
bc1d085a 315 if ( *notarizedheightp > NOTARIZED_HEIGHT && *notarizedheightp < height )
1390456b 316 {
eff7174e 317 printf("ht.%d NOTARIZED.%d %s.%s %sTXID.%s (%s)\n",height,*notarizedheightp,ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,kmdtxid.ToString().c_str(),ASSETCHAINS_SYMBOL[0]==0?"BTC":"KMD",desttxid.ToString().c_str(),(char *)&scriptbuf[len]);
4a41b0b2 318 NOTARIZED_HEIGHT = *notarizedheightp;
319 NOTARIZED_HASH = kmdtxid;
1e81ccb7 320 NOTARIZED_DESTTXID = desttxid;
429dabb5 321 komodo_stateupdate(height,0,0,0,zero,0,0,0,0,0,0,0,0,0);
a6400079 322 } else printf("reject ht.%d NOTARIZED.%d %s.%s DESTTXID.%s (%s)\n",height,*notarizedheightp,ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,kmdtxid.ToString().c_str(),desttxid.ToString().c_str(),(char *)&scriptbuf[len]);
1390456b 323 }
babdc001 324 else if ( i == 0 && j == 1 && opretlen == 149 )
0201d1a6 325 komodo_paxpricefeed(height,&scriptbuf[len],opretlen);
429dabb5 326 else komodo_stateupdate(height,0,0,0,txhash,0,0,0,0,0,value,&scriptbuf[len],opretlen,j);
1390456b 327 }
328 return(notaryid);
329}
330
f38345e9 331int32_t komodo_isratify(int32_t isspecial,int32_t numvalid)
332{
755ead98 333 if ( isspecial != 0 && numvalid >= KOMODO_MINRATIFY )
f38345e9 334 return(1);
335 else return(0);
336}
337
338// Special tx have vout[0] -> CRYPTO777
755ead98 339// with more than KOMODO_MINRATIFY pay2pubkey outputs -> ratify
f38345e9 340// if all outputs to notary -> notary utxo
341// if txi == 0 && 2 outputs and 2nd OP_RETURN, len == 32*2+4 -> notarized, 1st byte 'P' -> pricefeed
420d7311 342// OP_RETURN: 'D' -> deposit, 'W' -> withdraw
f38345e9 343
651989c7 344void komodo_connectblock(CBlockIndex *pindex,CBlock& block)
50027f06 345{
a7f0d3e4 346 static int32_t hwmheight;
e9595d76 347 uint64_t signedmask,voutmask;
dd7b22ad 348 uint8_t scriptbuf[4096],pubkeys[64][33]; uint256 kmdtxid,btctxid,txhash;
e9595d76 349 int32_t i,j,k,numvalid,specialtx,notarizedheight,notaryid,len,numvouts,numvins,height,txn_count;
77117dbe 350 komodo_init();
a7f0d3e4 351 if ( pindex->nHeight > hwmheight )
352 hwmheight = pindex->nHeight;
353 else
354 {
355 printf("hwmheight.%d vs pindex->nHeight.%d reorg.%d\n",hwmheight,pindex->nHeight,hwmheight-pindex->nHeight);
356 // reset komodostate
357 }
2d657c5b 358 if ( ASSETCHAINS_SYMBOL[0] != 0 )
359 {
f67800d0 360 while ( KOMODO_REALTIME == 0 || time(NULL) <= KOMODO_REALTIME )
2d657c5b 361 {
1fdfe03c 362 fprintf(stderr,"komodo_connect.(%s) waiting for realtime RT.%u now.%u\n",ASSETCHAINS_SYMBOL,KOMODO_REALTIME,(uint32_t)time(NULL));
2d657c5b 363 sleep(3);
364 }
2d657c5b 365 }
755ead98 366 KOMODO_INITDONE = (uint32_t)time(NULL);
68916cc6 367 if ( pindex != 0 )
b501ded2 368 {
656eddcd 369 height = pindex->nHeight;
01cc012f 370 txn_count = block.vtx.size();
371 for (i=0; i<txn_count; i++)
dc64de68 372 {
352f8081 373 txhash = block.vtx[i].GetHash();
01cc012f 374 numvouts = block.vtx[i].vout.size();
352f8081 375 notaryid = -1;
1390456b 376 voutmask = specialtx = notarizedheight = 0;
01cc012f 377 for (j=0; j<numvouts; j++)
dc64de68 378 {
1390456b 379 len = block.vtx[i].vout[j].scriptPubKey.size();
380 if ( len <= sizeof(scriptbuf) )
01cc012f 381 {
189d9dee 382#ifdef KOMODO_ZCASH
484f8777 383 memcpy(scriptbuf,block.vtx[i].vout[j].scriptPubKey.data(),len);
189d9dee 384#else
385 memcpy(scriptbuf,(uint8_t *)&block.vtx[i].vout[j].scriptPubKey[0],len);
386#endif
bfa5b4f2 387 // signedmask is needed here!
629e8f37 388 notaryid = komodo_voutupdate(notaryid,scriptbuf,len,height,txhash,i,j,&voutmask,&specialtx,&notarizedheight,(uint64_t)block.vtx[i].vout[j].nValue);
a01acef4 389 if ( 0 && i > 0 )
e69a0833 390 {
391 for (k=0; k<len; k++)
392 printf("%02x",scriptbuf[k]);
a8832194 393 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 394 }
01cc012f 395 }
352f8081 396 }
cf9538e0 397 if ( i != 0 && notaryid >= 0 && notaryid < 64 && voutmask != 0 )
3eea72f2 398 {
429dabb5 399 komodo_stateupdate(height,0,0,notaryid,txhash,voutmask,numvouts,0,0,0,0,0,0,0);
3eea72f2 400 //komodo_nutxoadd(height,notaryid,txhash,voutmask,numvouts);
401 }
1390456b 402 signedmask = 0;
403 numvins = block.vtx[i].vin.size();
5bdebffe 404 for (j=0; j<numvins; j++)
352f8081 405 {
4355e769 406 if ( (k= komodo_nutxofind(height,block.vtx[i].vin[j].prevout.hash,block.vtx[i].vin[j].prevout.n)) >= 0 )
1390456b 407 signedmask |= (1LL << k);
21cc1d3e 408 else if ( 0 && signedmask != 0 )
bc6fd011 409 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 410 }
06f0ed43 411 if ( signedmask != 0 && (notarizedheight != 0 || specialtx != 0) )
1390456b 412 {
e69a0833 413 printf("NOTARY SIGNED.%llx numvins.%d ht.%d txi.%d notaryht.%d specialtx.%d\n",(long long)signedmask,numvins,height,i,notarizedheight,specialtx);
3eea72f2 414 if ( specialtx != 0 && numvouts > 2 && komodo_ratify_threshold(height,signedmask) > 0 )
84e843cd 415 {
29e69b85 416 numvalid = 0;
dd7b22ad 417 memset(pubkeys,0,sizeof(pubkeys));
84e843cd 418 for (j=1; j<numvouts; j++)
419 {
420 len = block.vtx[i].vout[j].scriptPubKey.size();
421 if ( len <= sizeof(scriptbuf) )
422 {
189d9dee 423#ifdef KOMODO_ZCASH
484f8777 424 memcpy(scriptbuf,block.vtx[i].vout[j].scriptPubKey.data(),len);
189d9dee 425#else
426 memcpy(scriptbuf,(uint8_t *)&block.vtx[i].vout[j].scriptPubKey[0],len);
427#endif
84e843cd 428 if ( len == 35 && scriptbuf[0] == 33 && scriptbuf[34] == 0xac )
429 {
29e69b85 430 memcpy(pubkeys[numvalid++],scriptbuf+1,33);
e7f99312 431 for (k=0; k<33; k++)
84e843cd 432 printf("%02x",scriptbuf[k+1]);
433 printf(" <- new notary.[%d]\n",j-1);
434 }
435 }
436 }
755ead98 437 if ( komodo_isratify(1,numvalid) >= KOMODO_MINRATIFY && numvouts > 13 )
d8ce705a 438 {
439 memset(&txhash,0,sizeof(txhash));
429dabb5 440 komodo_stateupdate(height,pubkeys,numvalid,0,txhash,0,0,0,0,0,0,0,0,0);
d8ce705a 441 }
835c617e 442 printf("new notaries.%d newheight.%d from height.%d\n",numvouts-1,KOMODO_PUBKEYS_HEIGHT(height),height);
84e843cd 443 }
a96439f5 444 }
656eddcd 445 }
44c4fbbd 446 } else printf("komodo_connectblock: unexpected null pindex\n");
63c30610 447 KOMODO_INITDONE = (uint32_t)time(NULL);
3d35aa5b 448}
449
0f24f245 450
fcd36118 451#endif
This page took 0.194222 seconds and 4 git commands to generate.