]> Git Repo - VerusCoin.git/blame - src/komodo.h
Revert "Use kmdtxid"
[VerusCoin.git] / src / komodo.h
CommitLineData
fcd36118 1/******************************************************************************
37fed603 2 * Copyright © 2014-2017 The SuperNET Developers. *
fcd36118 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
5416af1d 18#include "komodo_defs.h"
fcd36118 19
b71b045a 20#ifdef _WIN32
21#define printf(...)
22#endif
23
27bf3c5e 24// Todo:
aa114a60 25// verify: reorgs
3ec03ada 26
26ac06c4 27#define KOMODO_ASSETCHAINS_WAITNOTARIZE
fa8d44fc 28#define KOMODO_PAXMAX (10000 * COIN)
aa114a60 29
9499e4de 30#include <stdint.h>
31#include <stdio.h>
975b2ddb 32#include <pthread.h>
88f973c2 33#include <ctype.h>
6d5cb6d4 34#include "uthash.h"
35#include "utlist.h"
9499e4de 36
fc318ffe 37int32_t gettxout_scriptPubKey(uint8_t *scriptPubkey,int32_t maxsize,uint256 txid,int32_t n);
f3a1de3a 38void komodo_event_rewind(struct komodo_state *sp,char *symbol,int32_t height);
875cf683 39void komodo_connectblock(CBlockIndex *pindex,CBlock& block);
3face669 40
fc318ffe 41#include "komodo_structs.h"
9fb37168 42#include "komodo_globals.h"
46beb55e 43#include "komodo_utils.h"
6b5cfbb4 44#include "komodo_curve25519.h"
1bfdde1d 45
d430a5e8 46#include "komodo_cJSON.c"
e4e76989 47#include "komodo_bitcoind.h"
48#include "komodo_interest.h"
49#include "komodo_pax.h"
50#include "komodo_notary.h"
ab918767 51
52int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char *dest);
6b5cfbb4 53#include "komodo_kv.h"
eeaaf554 54#include "komodo_jumblr.h"
e4e76989 55#include "komodo_gateway.h"
56#include "komodo_events.h"
57
c75c18fc 58void komodo_currentheight_set(int32_t height)
59{
7c130297 60 char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; struct komodo_state *sp;
c75c18fc 61 if ( (sp= komodo_stateptr(symbol,dest)) != 0 )
62 sp->CURRENT_HEIGHT = height;
63}
64
65int32_t komodo_currentheight()
66{
7c130297 67 char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; struct komodo_state *sp;
c75c18fc 68 if ( (sp= komodo_stateptr(symbol,dest)) != 0 )
69 return(sp->CURRENT_HEIGHT);
70 else return(0);
71}
72
73int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char *dest)
74{
75 static int32_t errs;
2df2f193 76 int32_t func,ht,notarized_height,num,matched=0; uint256 notarized_hash,notarized_desttxid; uint8_t pubkeys[64][33];
c75c18fc 77 if ( (func= fgetc(fp)) != EOF )
78 {
79 if ( ASSETCHAINS_SYMBOL[0] == 0 && strcmp(symbol,"KMD") == 0 )
80 matched = 1;
81 else matched = (strcmp(symbol,ASSETCHAINS_SYMBOL) == 0);
82 if ( fread(&ht,1,sizeof(ht),fp) != sizeof(ht) )
83 errs++;
34c68daa 84 if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 && func != 'T' )
d0d61f8f 85 printf("[%s] matched.%d fpos.%ld func.(%d %c) ht.%d\n",ASSETCHAINS_SYMBOL,matched,ftell(fp),func,func,ht);
c75c18fc 86 if ( func == 'P' )
87 {
f3a1de3a 88 if ( (num= fgetc(fp)) <= 64 )
c75c18fc 89 {
90 if ( fread(pubkeys,33,num,fp) != num )
91 errs++;
92 else
93 {
ec368288 94 //printf("updated %d pubkeys at %s ht.%d\n",num,symbol,ht);
15724d02 95 if ( (KOMODO_EXTERNAL_NOTARIES != 0 && matched != 0) || (strcmp(symbol,"KMD") == 0 && KOMODO_EXTERNAL_NOTARIES == 0) )
c75c18fc 96 komodo_eventadd_pubkeys(sp,symbol,ht,num,pubkeys);
97 }
98 } else printf("illegal num.%d\n",num);
99 }
100 else if ( func == 'N' )
101 {
102 if ( fread(&notarized_height,1,sizeof(notarized_height),fp) != sizeof(notarized_height) )
103 errs++;
104 if ( fread(&notarized_hash,1,sizeof(notarized_hash),fp) != sizeof(notarized_hash) )
105 errs++;
106 if ( fread(&notarized_desttxid,1,sizeof(notarized_desttxid),fp) != sizeof(notarized_desttxid) )
107 errs++;
5d119304 108 if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 && sp != 0 )
514018d9 109 printf("%s load[%s.%d -> %s] NOTARIZED %d %s\n",ASSETCHAINS_SYMBOL,symbol,sp->NUM_NPOINTS,dest,notarized_height,notarized_hash.ToString().c_str());
1ebb14e7 110 //if ( matched != 0 ) global independent states -> inside *sp
111 komodo_eventadd_notarized(sp,symbol,ht,dest,notarized_hash,notarized_desttxid,notarized_height);
c75c18fc 112 }
1ebb14e7 113 else if ( func == 'U' ) // deprecated
c75c18fc 114 {
115 uint8_t n,nid; uint256 hash; uint64_t mask;
116 n = fgetc(fp);
117 nid = fgetc(fp);
118 //printf("U %d %d\n",n,nid);
119 if ( fread(&mask,1,sizeof(mask),fp) != sizeof(mask) )
120 errs++;
121 if ( fread(&hash,1,sizeof(hash),fp) != sizeof(hash) )
122 errs++;
6f3cb4d0 123 //if ( matched != 0 )
124 // komodo_eventadd_utxo(sp,symbol,ht,nid,hash,mask,n);
c75c18fc 125 }
126 else if ( func == 'K' )
127 {
128 int32_t kheight;
129 if ( fread(&kheight,1,sizeof(kheight),fp) != sizeof(kheight) )
130 errs++;
1ebb14e7 131 //if ( matched != 0 ) global independent states -> inside *sp
a8f4e85e 132 //printf("%s.%d load[%s] ht.%d\n",ASSETCHAINS_SYMBOL,ht,symbol,kheight);
e155dbe9 133 komodo_eventadd_kmdheight(sp,symbol,ht,kheight,0);
134 }
135 else if ( func == 'T' )
136 {
137 int32_t kheight,ktimestamp;
138 if ( fread(&kheight,1,sizeof(kheight),fp) != sizeof(kheight) )
139 errs++;
140 if ( fread(&ktimestamp,1,sizeof(ktimestamp),fp) != sizeof(ktimestamp) )
141 errs++;
142 //if ( matched != 0 ) global independent states -> inside *sp
a8f4e85e 143 //printf("%s.%d load[%s] ht.%d t.%u\n",ASSETCHAINS_SYMBOL,ht,symbol,kheight,ktimestamp);
e155dbe9 144 komodo_eventadd_kmdheight(sp,symbol,ht,kheight,ktimestamp);
c75c18fc 145 }
146 else if ( func == 'R' )
147 {
ef1a9636 148 uint16_t olen,v; uint64_t ovalue; uint256 txid; uint8_t opret[16384];
c75c18fc 149 if ( fread(&txid,1,sizeof(txid),fp) != sizeof(txid) )
150 errs++;
151 if ( fread(&v,1,sizeof(v),fp) != sizeof(v) )
152 errs++;
153 if ( fread(&ovalue,1,sizeof(ovalue),fp) != sizeof(ovalue) )
154 errs++;
155 if ( fread(&olen,1,sizeof(olen),fp) != sizeof(olen) )
156 errs++;
157 if ( olen < sizeof(opret) )
158 {
159 if ( fread(opret,1,olen,fp) != olen )
160 errs++;
34c68daa 161 if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 && matched != 0 )
e2a12abf 162 {
163 int32_t i; for (i=0; i<olen; i++)
164 printf("%02x",opret[i]);
165 printf(" %s.%d load[%s] opret[%c] len.%d %.8f\n",ASSETCHAINS_SYMBOL,ht,symbol,opret[0],olen,(double)ovalue/COIN);
166 }
167 komodo_eventadd_opreturn(sp,symbol,ht,txid,ovalue,v,opret,olen); // global shared state -> global PAX
939a5a45 168 } else
169 {
66d02e79 170 int32_t i;
939a5a45 171 for (i=0; i<olen; i++)
172 fgetc(fp);
dff4ef45 173 //printf("illegal olen.%u\n",olen);
939a5a45 174 }
c75c18fc 175 }
176 else if ( func == 'D' )
177 {
178 printf("unexpected function D[%d]\n",ht);
179 }
180 else if ( func == 'V' )
181 {
182 int32_t numpvals; uint32_t pvals[128];
183 numpvals = fgetc(fp);
184 if ( numpvals*sizeof(uint32_t) <= sizeof(pvals) && fread(pvals,sizeof(uint32_t),numpvals,fp) == numpvals )
185 {
1ebb14e7 186 //if ( matched != 0 ) global shared state -> global PVALS
335f2ea7 187 //printf("%s load[%s] prices %d\n",ASSETCHAINS_SYMBOL,symbol,ht);
15724d02 188 komodo_eventadd_pricefeed(sp,symbol,ht,pvals,numpvals);
c75c18fc 189 //printf("load pvals ht.%d numpvals.%d\n",ht,numpvals);
190 } else printf("error loading pvals[%d]\n",numpvals);
191 }
98dc898d 192 // else printf("[%s] %s illegal func.(%d %c)\n",ASSETCHAINS_SYMBOL,symbol,func,func);
c75c18fc 193 return(func);
194 } else return(-1);
195}
17746e45 196
197int32_t memread(void *dest,int32_t size,uint8_t *filedata,long *fposp,long datalen)
198{
199 if ( *fposp+size <= datalen )
200 {
201 memcpy(dest,&filedata[*fposp],size);
202 (*fposp) += size;
203 return(size);
204 }
205 return(-1);
206}
207
3b40d631 208int32_t komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long *fposp,long datalen,char *symbol,char *dest)
17746e45 209{
210 static int32_t errs;
3b40d631 211 int32_t func= -1,ht,notarized_height,num,matched=0; uint256 notarized_hash,notarized_desttxid; uint8_t pubkeys[64][33]; long fpos = *fposp;
17746e45 212 if ( fpos < datalen )
213 {
214 func = filedata[fpos++];
215 if ( ASSETCHAINS_SYMBOL[0] == 0 && strcmp(symbol,"KMD") == 0 )
216 matched = 1;
217 else matched = (strcmp(symbol,ASSETCHAINS_SYMBOL) == 0);
218 if ( memread(&ht,sizeof(ht),filedata,&fpos,datalen) != sizeof(ht) )
219 errs++;
220 if ( func == 'P' )
221 {
222 if ( (num= filedata[fpos++]) <= 64 )
223 {
224 if ( memread(pubkeys,33*num,filedata,&fpos,datalen) != 33*num )
225 errs++;
226 else
227 {
228 //printf("updated %d pubkeys at %s ht.%d\n",num,symbol,ht);
229 if ( (KOMODO_EXTERNAL_NOTARIES != 0 && matched != 0) || (strcmp(symbol,"KMD") == 0 && KOMODO_EXTERNAL_NOTARIES == 0) )
230 komodo_eventadd_pubkeys(sp,symbol,ht,num,pubkeys);
231 }
232 } else printf("illegal num.%d\n",num);
233 }
234 else if ( func == 'N' )
235 {
236 if ( memread(&notarized_height,sizeof(notarized_height),filedata,&fpos,datalen) != sizeof(notarized_height) )
237 errs++;
238 if ( memread(&notarized_hash,sizeof(notarized_hash),filedata,&fpos,datalen) != sizeof(notarized_hash) )
239 errs++;
240 if ( memread(&notarized_desttxid,sizeof(notarized_desttxid),filedata,&fpos,datalen) != sizeof(notarized_desttxid) )
241 errs++;
f7ec3a98 242 if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 && sp != 0 )
17746e45 243 printf("%s load[%s.%d -> %s] NOTARIZED %d %s\n",ASSETCHAINS_SYMBOL,symbol,sp->NUM_NPOINTS,dest,notarized_height,notarized_hash.ToString().c_str());
244 //if ( matched != 0 ) global independent states -> inside *sp
245 komodo_eventadd_notarized(sp,symbol,ht,dest,notarized_hash,notarized_desttxid,notarized_height);
246 }
247 else if ( func == 'U' ) // deprecated
248 {
249 uint8_t n,nid; uint256 hash; uint64_t mask;
250 n = filedata[fpos++];
251 nid = filedata[fpos++];
252 //printf("U %d %d\n",n,nid);
253 if ( memread(&mask,sizeof(mask),filedata,&fpos,datalen) != sizeof(mask) )
254 errs++;
255 if ( memread(&hash,sizeof(hash),filedata,&fpos,datalen) != sizeof(hash) )
256 errs++;
257 }
258 else if ( func == 'K' )
259 {
260 int32_t kheight;
261 if ( memread(&kheight,sizeof(kheight),filedata,&fpos,datalen) != sizeof(kheight) )
262 errs++;
263 komodo_eventadd_kmdheight(sp,symbol,ht,kheight,0);
264 }
265 else if ( func == 'T' )
266 {
267 int32_t kheight,ktimestamp;
268 if ( memread(&kheight,sizeof(kheight),filedata,&fpos,datalen) != sizeof(kheight) )
269 errs++;
270 if ( memread(&ktimestamp,sizeof(ktimestamp),filedata,&fpos,datalen) != sizeof(ktimestamp) )
271 errs++;
272 //if ( matched != 0 ) global independent states -> inside *sp
273 //printf("%s.%d load[%s] ht.%d t.%u\n",ASSETCHAINS_SYMBOL,ht,symbol,kheight,ktimestamp);
274 komodo_eventadd_kmdheight(sp,symbol,ht,kheight,ktimestamp);
275 }
276 else if ( func == 'R' )
277 {
278 uint16_t olen,v; uint64_t ovalue; uint256 txid; uint8_t opret[16384];
279 if ( memread(&txid,sizeof(txid),filedata,&fpos,datalen) != sizeof(txid) )
280 errs++;
281 if ( memread(&v,sizeof(v),filedata,&fpos,datalen) != sizeof(v) )
282 errs++;
283 if ( memread(&ovalue,sizeof(ovalue),filedata,&fpos,datalen) != sizeof(ovalue) )
284 errs++;
285 if ( memread(&olen,sizeof(olen),filedata,&fpos,datalen) != sizeof(olen) )
286 errs++;
287 if ( olen < sizeof(opret) )
288 {
289 if ( memread(opret,olen,filedata,&fpos,datalen) != olen )
290 errs++;
291 if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 && matched != 0 )
292 {
293 int32_t i; for (i=0; i<olen; i++)
294 printf("%02x",opret[i]);
295 printf(" %s.%d load[%s] opret[%c] len.%d %.8f\n",ASSETCHAINS_SYMBOL,ht,symbol,opret[0],olen,(double)ovalue/COIN);
296 }
297 komodo_eventadd_opreturn(sp,symbol,ht,txid,ovalue,v,opret,olen); // global shared state -> global PAX
298 } else
299 {
300 int32_t i;
301 for (i=0; i<olen; i++)
302 filedata[fpos++];
303 //printf("illegal olen.%u\n",olen);
304 }
305 }
306 else if ( func == 'D' )
307 {
308 printf("unexpected function D[%d]\n",ht);
309 }
310 else if ( func == 'V' )
311 {
312 int32_t numpvals; uint32_t pvals[128];
313 numpvals = filedata[fpos++];
314 if ( numpvals*sizeof(uint32_t) <= sizeof(pvals) && memread(pvals,(int32_t)(sizeof(uint32_t)*numpvals),filedata,&fpos,datalen) == numpvals*sizeof(uint32_t) )
315 {
316 //if ( matched != 0 ) global shared state -> global PVALS
317 //printf("%s load[%s] prices %d\n",ASSETCHAINS_SYMBOL,symbol,ht);
318 komodo_eventadd_pricefeed(sp,symbol,ht,pvals,numpvals);
319 //printf("load pvals ht.%d numpvals.%d\n",ht,numpvals);
320 } else printf("error loading pvals[%d]\n",numpvals);
321 }
98dc898d 322 // else printf("[%s] %s illegal func.(%d %c)\n",ASSETCHAINS_SYMBOL,symbol,func,func);
17746e45 323 *fposp = fpos;
3b40d631 324 return(func);
325 }
326 return(-1);
17746e45 327}
328
e155dbe9 329void 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,uint32_t KMDtimestamp,uint64_t opretvalue,uint8_t *opretbuf,uint16_t opretlen,uint16_t vout)
5cea7725 330{
15d0fbd4 331 static FILE *fp; static int32_t errs,didinit;
7c130297 332 struct komodo_state *sp; char fname[512],symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; int32_t retval,ht,func; uint8_t num,pubkeys[64][33];
15d0fbd4 333 if ( didinit == 0 )
334 {
335 portable_mutex_init(&KOMODO_KV_mutex);
336 didinit = 1;
337 }
c75c18fc 338 if ( (sp= komodo_stateptr(symbol,dest)) == 0 )
15373725 339 {
340 KOMODO_INITDONE = (uint32_t)time(NULL);
fac8d1ff 341 printf("[%s] no komodo_stateptr\n",ASSETCHAINS_SYMBOL);
c75c18fc 342 return;
15373725 343 }
ca74f186 344 //printf("[%s] (%s) -> (%s)\n",ASSETCHAINS_SYMBOL,symbol,dest);
888cf827 345 if ( fp == 0 )
346 {
055db9b6 347 komodo_statefname(fname,ASSETCHAINS_SYMBOL,(char *)"komodostate");
bafc61f3 348 if ( (fp= fopen(fname,"rb+")) != 0 )
349 {
f7f96087 350 if ( (retval= komodo_faststateinit(sp,fname,symbol,dest)) > 0 )
58f293eb 351 fseek(fp,0,SEEK_END);
08775bc1 352 else
353 {
a3a7ec85 354 fprintf(stderr,"komodo_faststateinit retval.%d\n",retval);
08775bc1 355 while ( komodo_parsestatefile(sp,fp,symbol,dest) >= 0 )
356 ;
357 }
bafc61f3 358 } else fp = fopen(fname,"wb+");
63c30610 359 KOMODO_INITDONE = (uint32_t)time(NULL);
bafc61f3 360 }
e98e2aec 361 if ( height <= 0 )
49df008c 362 {
6458297e 363 //printf("early return: stateupdate height.%d\n",height);
49df008c 364 return;
365 }
3eea72f2 366 if ( fp != 0 ) // write out funcid, height, other fields, call side effect function
bafc61f3 367 {
2578b002 368 //printf("fpos.%ld ",ftell(fp));
ab918767 369 if ( KMDheight != 0 )
2b84e06c 370 {
e155dbe9 371 if ( KMDtimestamp != 0 )
372 {
373 fputc('T',fp);
374 if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) )
375 errs++;
376 if ( fwrite(&KMDheight,1,sizeof(KMDheight),fp) != sizeof(KMDheight) )
377 errs++;
378 if ( fwrite(&KMDtimestamp,1,sizeof(KMDtimestamp),fp) != sizeof(KMDtimestamp) )
379 errs++;
380 }
381 else
382 {
383 fputc('K',fp);
384 if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) )
385 errs++;
386 if ( fwrite(&KMDheight,1,sizeof(KMDheight),fp) != sizeof(KMDheight) )
387 errs++;
388 }
389 komodo_eventadd_kmdheight(sp,symbol,height,KMDheight,KMDtimestamp);
2b84e06c 390 }
01f9cb3d 391 else if ( opretbuf != 0 && opretlen > 0 )
64bb0834 392 {
01f9cb3d 393 uint16_t olen = opretlen;
394 fputc('R',fp);
64bb0834 395 if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) )
396 errs++;
429dabb5 397 if ( fwrite(&txhash,1,sizeof(txhash),fp) != sizeof(txhash) )
398 errs++;
399 if ( fwrite(&vout,1,sizeof(vout),fp) != sizeof(vout) )
400 errs++;
30df2e00 401 if ( fwrite(&opretvalue,1,sizeof(opretvalue),fp) != sizeof(opretvalue) )
33935bd0 402 errs++;
289dc57b 403 if ( fwrite(&olen,1,sizeof(olen),fp) != olen )
404 errs++;
01f9cb3d 405 if ( fwrite(opretbuf,1,olen,fp) != olen )
64bb0834 406 errs++;
088b1fa8 407//printf("ht.%d R opret[%d] sp.%p\n",height,olen,sp);
c75c18fc 408 //komodo_opreturn(height,opretvalue,opretbuf,olen,txhash,vout);
409 komodo_eventadd_opreturn(sp,symbol,height,txhash,opretvalue,vout,opretbuf,olen);
01f9cb3d 410 }
9997caa0 411 else if ( notarypubs != 0 && numnotaries > 0 )
bafc61f3 412 {
f3a1de3a 413 printf("ht.%d func P[%d] errs.%d\n",height,numnotaries,errs);
bafc61f3 414 fputc('P',fp);
c50ec0fb 415 if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) )
416 errs++;
bafc61f3 417 fputc(numnotaries,fp);
52ed4002 418 if ( fwrite(notarypubs,33,numnotaries,fp) != numnotaries )
419 errs++;
c75c18fc 420 komodo_eventadd_pubkeys(sp,symbol,height,numnotaries,notarypubs);
bafc61f3 421 }
671187dd 422 else if ( voutmask != 0 && numvouts > 0 )
423 {
2578b002 424 //printf("ht.%d func U %d %d errs.%d hashsize.%ld\n",height,numvouts,notaryid,errs,sizeof(txhash));
671187dd 425 fputc('U',fp);
c50ec0fb 426 if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) )
427 errs++;
671187dd 428 fputc(numvouts,fp);
429 fputc(notaryid,fp);
430 if ( fwrite(&voutmask,1,sizeof(voutmask),fp) != sizeof(voutmask) )
431 errs++;
432 if ( fwrite(&txhash,1,sizeof(txhash),fp) != sizeof(txhash) )
433 errs++;
6f3cb4d0 434 //komodo_eventadd_utxo(sp,symbol,height,notaryid,txhash,voutmask,numvouts);
671187dd 435 }
4a41b0b2 436 else if ( pvals != 0 && numpvals > 0 )
437 {
bfa5b4f2 438 int32_t i,nonz = 0;
1bf82154 439 for (i=0; i<32; i++)
440 if ( pvals[i] != 0 )
441 nonz++;
442 if ( nonz >= 32 )
443 {
444 fputc('V',fp);
445 if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) )
446 errs++;
447 fputc(numpvals,fp);
448 if ( fwrite(pvals,sizeof(uint32_t),numpvals,fp) != numpvals )
449 errs++;
c75c18fc 450 komodo_eventadd_pricefeed(sp,symbol,height,pvals,numpvals);
2578b002 451 //printf("ht.%d V numpvals[%d]\n",height,numpvals);
1bf82154 452 }
ef7a3548 453 //printf("save pvals height.%d numpvals.%d\n",height,numpvals);
4a41b0b2 454 }
6dabcca4 455 else if ( height != 0 )
671187dd 456 {
2578b002 457 //printf("ht.%d func N ht.%d errs.%d\n",height,NOTARIZED_HEIGHT,errs);
b148643e 458 if ( sp != 0 )
807200e4 459 {
460 fputc('N',fp);
461 if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) )
462 errs++;
463 if ( fwrite(&sp->NOTARIZED_HEIGHT,1,sizeof(sp->NOTARIZED_HEIGHT),fp) != sizeof(sp->NOTARIZED_HEIGHT) )
464 errs++;
465 if ( fwrite(&sp->NOTARIZED_HASH,1,sizeof(sp->NOTARIZED_HASH),fp) != sizeof(sp->NOTARIZED_HASH) )
466 errs++;
467 if ( fwrite(&sp->NOTARIZED_DESTTXID,1,sizeof(sp->NOTARIZED_DESTTXID),fp) != sizeof(sp->NOTARIZED_DESTTXID) )
468 errs++;
469 komodo_eventadd_notarized(sp,symbol,height,dest,sp->NOTARIZED_HASH,sp->NOTARIZED_DESTTXID,sp->NOTARIZED_HEIGHT);
470 }
671187dd 471 }
47f47733 472 fflush(fp);
bafc61f3 473 }
474}
475
20dfaa77 476int32_t komodo_voutupdate(int32_t *isratificationp,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,int32_t notarized,uint64_t signedmask,uint32_t timestamp)
1390456b 477{
c96e160a 478 static uint256 zero; static FILE *signedfp;
ff5cd12f 479 CBlockIndex *pindex; int32_t opretlen,nid,k,len = 0; uint256 kmdtxid,desttxid; uint8_t crypto777[33]; struct komodo_state *sp; char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN];
2df2f193 480 if ( (sp= komodo_stateptr(symbol,dest)) == 0 )
481 return(-1);
9c406099 482 if ( scriptlen == 35 && scriptbuf[0] == 33 && scriptbuf[34] == 0xac )
1390456b 483 {
0ef85dd0 484 if ( i == 0 && j == 0 && memcmp(NOTARY_PUBKEY33,scriptbuf+1,33) == 0 && NOTARY_PUBKEY33[0] != 0 )
9152feb5 485 {
ba37a6b9 486 printf("%s KOMODO_LASTMINED.%d -> %d\n",ASSETCHAINS_SYMBOL,KOMODO_LASTMINED,height);
8ee93080 487 prevKOMODO_LASTMINED = KOMODO_LASTMINED;
9152feb5 488 KOMODO_LASTMINED = height;
489 }
c23dd601 490 decode_hex(crypto777,33,(char *)CRYPTO777_PUBSECPSTR);
986d3459 491 /*for (k=0; k<33; k++)
e1be360e 492 printf("%02x",crypto777[k]);
493 printf(" crypto777 ");
494 for (k=0; k<scriptlen; k++)
495 printf("%02x",scriptbuf[k]);
986d3459 496 printf(" <- script ht.%d i.%d j.%d cmp.%d\n",height,i,j,memcmp(crypto777,scriptbuf+1,33));*/
1390456b 497 if ( memcmp(crypto777,scriptbuf+1,33) == 0 )
498 {
499 *specialtxp = 1;
b7f942c8 500 //printf(">>>>>>>> ");
1390456b 501 }
20dfaa77 502 else if ( komodo_chosennotary(&nid,height,scriptbuf + 1,timestamp) >= 0 )
1390456b 503 {
84e843cd 504 //printf("found notary.k%d\n",k);
505 if ( notaryid < 64 )
1390456b 506 {
84e843cd 507 if ( notaryid < 0 )
508 {
a5f315c7 509 notaryid = nid;
84e843cd 510 *voutmaskp |= (1LL << j);
511 }
a5f315c7 512 else if ( notaryid != nid )
84e843cd 513 {
b7f942c8 514 //for (i=0; i<33; i++)
515 // printf("%02x",scriptbuf[i+1]);
516 //printf(" %s mismatch notaryid.%d k.%d\n",ASSETCHAINS_SYMBOL,notaryid,nid);
84e843cd 517 notaryid = 64;
518 *voutmaskp = 0;
519 }
520 else *voutmaskp |= (1LL << j);
1390456b 521 }
1390456b 522 }
523 }
844a6138 524 if ( scriptbuf[len++] == 0x6a )
1390456b 525 {
526 if ( (opretlen= scriptbuf[len++]) == 0x4c )
527 opretlen = scriptbuf[len++];
528 else if ( opretlen == 0x4d )
529 {
530 opretlen = scriptbuf[len++];
508b0d3c 531 opretlen += (scriptbuf[len++] << 8);
1390456b 532 }
34c68daa 533 if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 )
0b27cefa 534 printf("[%s] notarized.%d notarizedht.%d sp.Nht %d sp.ht %d opretlen.%d (%c %c %c)\n",ASSETCHAINS_SYMBOL,notarized,*notarizedheightp,sp->NOTARIZED_HEIGHT,sp->CURRENT_HEIGHT,opretlen,scriptbuf[len+32*2+4],scriptbuf[len+32*2+4+1],scriptbuf[len+32*2+4+2]);
a6400079 535 if ( j == 1 && opretlen >= 32*2+4 && strcmp(ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,(char *)&scriptbuf[len+32*2+4]) == 0 )
1390456b 536 {
4a41b0b2 537 len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&kmdtxid);
dbaf1154 538 len += iguana_rwnum(0,&scriptbuf[len],sizeof(*notarizedheightp),(uint8_t *)notarizedheightp);
3eea72f2 539 len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&desttxid);
ecc47f43 540 if ( notarized != 0 && IsInitialBlockDownload() == 0 && ((pindex= mapBlockIndex[srchash]) == 0 || pindex->nHeight != *notarizedheightp) )
ff5cd12f 541 {
ecc47f43 542 fprintf(stderr,"%s possible FORK detected. notarized.%d %s not in this chain! last notarization %d -> rewindtarget.%d\n",ASSETCHAINS_SYMBOL,*notarizedheightp,srchash.ToString().c_str(),sp->NOTARIZED_HEIGHT,sp->NOTARIZED_HEIGHT);
ff5cd12f 543 notarized = 0;
544 }
42af20bb 545 if ( notarized != 0 && *notarizedheightp > sp->NOTARIZED_HEIGHT && *notarizedheightp < height && (height < sp->CURRENT_HEIGHT-1000 || komodo_verifynotarization(ASSETCHAINS_SYMBOL[0]==0?(char *)"KMD":ASSETCHAINS_SYMBOL,(char *)(ASSETCHAINS_SYMBOL[0] == 0 ? "BTC" : "KMD"),height,*notarizedheightp,kmdtxid,desttxid) == 0) )
1390456b 546 {
c75c18fc 547 sp->NOTARIZED_HEIGHT = *notarizedheightp;
548 sp->NOTARIZED_HASH = kmdtxid;
549 sp->NOTARIZED_DESTTXID = desttxid;
e155dbe9 550 komodo_stateupdate(height,0,0,0,zero,0,0,0,0,0,0,0,0,0,0);
3237fdd4 551 len += 4;
7c18529b 552 if ( ASSETCHAINS_SYMBOL[0] != 0 )
2c1ea235 553 printf("[%s] ht.%d NOTARIZED.%d %s.%s %sTXID.%s lens.(%d %d)\n",ASSETCHAINS_SYMBOL,height,*notarizedheightp,ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,kmdtxid.ToString().c_str(),ASSETCHAINS_SYMBOL[0]==0?"BTC":"KMD",desttxid.ToString().c_str(),opretlen,len);
dbaf1154 554 if ( ASSETCHAINS_SYMBOL[0] == 0 )
06d1a655 555 {
f1d6fb9b 556 if ( signedfp == 0 )
557 {
558 char fname[512];
559 komodo_statefname(fname,ASSETCHAINS_SYMBOL,(char *)"signedmasks");
560 if ( (signedfp= fopen(fname,"rb+")) == 0 )
561 signedfp = fopen(fname,"wb");
562 else fseek(signedfp,0,SEEK_END);
563 }
564 if ( signedfp != 0 )
565 {
566 fwrite(&height,1,sizeof(height),signedfp);
567 fwrite(&signedmask,1,sizeof(signedmask),signedfp);
568 fflush(signedfp);
569 }
dbaf1154 570 if ( opretlen > len && scriptbuf[len] == 'A' )
571 {
2962d925 572 //for (i=0; i<opretlen-len; i++)
573 // printf("%02x",scriptbuf[len+i]);
574 //printf(" Found extradata.[%d] %d - %d\n",opretlen-len,opretlen,len);
c83633f8 575 komodo_stateupdate(height,0,0,0,txhash,0,0,0,0,0,0,value,&scriptbuf[len],opretlen-len+4+3+(scriptbuf[1] == 0x4d),j);
dbaf1154 576 }
06d1a655 577 }
cd586654 578 } else if ( height >= KOMODO_MAINNET_START )
579 printf("notarized.%d %llx reject ht.%d NOTARIZED.%d prev.%d %s.%s DESTTXID.%s (%s)\n",notarized,(long long)signedmask,height,*notarizedheightp,sp->NOTARIZED_HEIGHT,ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,kmdtxid.ToString().c_str(),desttxid.ToString().c_str(),(char *)&scriptbuf[len]);
1390456b 580 }
babdc001 581 else if ( i == 0 && j == 1 && opretlen == 149 )
d42d3348 582 {
76b9b8b8 583 if ( notaryid >= 0 && notaryid < 64 )
d42d3348 584 komodo_paxpricefeed(height,&scriptbuf[len],opretlen);
585 }
eb406ebd 586 else
587 {
cd586654 588 //int32_t k; for (k=0; k<scriptlen; k++)
589 // printf("%02x",scriptbuf[k]);
590 //printf(" <- script ht.%d i.%d j.%d value %.8f %s\n",height,i,j,dstr(value),ASSETCHAINS_SYMBOL);
6dba48ec 591 if ( opretlen >= 32*2+4 && strcmp(ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,(char *)&scriptbuf[len+32*2+4]) == 0 )
592 {
5a286a6f 593 for (k=0; k<32; k++)
594 if ( scriptbuf[len+k] != 0 )
595 break;
596 if ( k == 32 )
6dba48ec 597 {
598 *isratificationp = 1;
599 printf("ISRATIFICATION (%s)\n",(char *)&scriptbuf[len+32*2+4]);
600 }
601 }
8f3aa743 602
c9e4d982 603 if ( *isratificationp == 0 && (signedmask != 0 || (scriptbuf[len] != 'X' && scriptbuf[len] != 'A')) ) // && scriptbuf[len] != 'I')
e155dbe9 604 komodo_stateupdate(height,0,0,0,txhash,0,0,0,0,0,0,value,&scriptbuf[len],opretlen,j);
eb406ebd 605 }
1390456b 606 }
607 return(notaryid);
608}
609
58033467 610/*int32_t komodo_isratify(int32_t isspecial,int32_t numvalid)
f38345e9 611{
755ead98 612 if ( isspecial != 0 && numvalid >= KOMODO_MINRATIFY )
f38345e9 613 return(1);
614 else return(0);
58033467 615}*/
f38345e9 616
617// Special tx have vout[0] -> CRYPTO777
755ead98 618// with more than KOMODO_MINRATIFY pay2pubkey outputs -> ratify
f38345e9 619// if all outputs to notary -> notary utxo
620// if txi == 0 && 2 outputs and 2nd OP_RETURN, len == 32*2+4 -> notarized, 1st byte 'P' -> pricefeed
420d7311 621// OP_RETURN: 'D' -> deposit, 'W' -> withdraw
ab918767 622
6f3cb4d0 623int32_t gettxout_scriptPubKey(uint8_t *scriptPubKey,int32_t maxsize,uint256 txid,int32_t n);
624
625int32_t komodo_notarycmp(uint8_t *scriptPubKey,int32_t scriptlen,uint8_t pubkeys[64][33],int32_t numnotaries,uint8_t rmd160[20])
626{
627 int32_t i;
628 if ( scriptlen == 25 && memcmp(&scriptPubKey[3],rmd160,20) == 0 )
629 return(0);
630 else if ( scriptlen == 35 )
631 {
632 for (i=0; i<numnotaries; i++)
633 if ( memcmp(&scriptPubKey[1],pubkeys[i],33) == 0 )
634 return(i);
635 }
636 return(-1);
637}
f38345e9 638
651989c7 639void komodo_connectblock(CBlockIndex *pindex,CBlock& block)
50027f06 640{
a7f0d3e4 641 static int32_t hwmheight;
7c130297 642 uint64_t signedmask,voutmask; char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; struct komodo_state *sp;
ab918767 643 uint8_t scriptbuf[4096],pubkeys[64][33],rmd160[20],scriptPubKey[35]; uint256 kmdtxid,zero,btctxid,txhash;
ea365a71 644 int32_t i,j,k,numnotaries,notarized,scriptlen,isratification,nid,numvalid,specialtx,notarizedheight,notaryid,len,numvouts,numvins,height,txn_count;
878d3961 645 memset(&zero,0,sizeof(zero));
c93dc546 646 komodo_init(pindex->nHeight);
d7227bf6 647 KOMODO_INITDONE = (uint32_t)time(NULL);
ab918767 648 if ( (sp= komodo_stateptr(symbol,dest)) == 0 )
3df53390 649 {
650 fprintf(stderr,"unexpected null komodostateptr.[%s]\n",ASSETCHAINS_SYMBOL);
ab918767 651 return;
3df53390 652 }
e0440cc3 653 //fprintf(stderr,"%s connect.%d\n",ASSETCHAINS_SYMBOL,pindex->nHeight);
20dfaa77 654 numnotaries = komodo_notaries(pubkeys,pindex->nHeight,pindex->GetBlockTime());
6f3cb4d0 655 calc_rmd160_sha256(rmd160,pubkeys[0],33);
a7f0d3e4 656 if ( pindex->nHeight > hwmheight )
657 hwmheight = pindex->nHeight;
658 else
659 {
174cae41 660 if ( pindex->nHeight != hwmheight )
661 printf("%s hwmheight.%d vs pindex->nHeight.%d t.%u reorg.%d\n",ASSETCHAINS_SYMBOL,hwmheight,pindex->nHeight,(uint32_t)pindex->nTime,hwmheight-pindex->nHeight);
ab918767 662 komodo_event_rewind(sp,symbol,pindex->nHeight);
e155dbe9 663 komodo_stateupdate(pindex->nHeight,0,0,0,zero,0,0,0,0,-pindex->nHeight,pindex->nTime,0,0,0,0);
a7f0d3e4 664 }
c75c18fc 665 komodo_currentheight_set(chainActive.Tip()->nHeight);
68916cc6 666 if ( pindex != 0 )
b501ded2 667 {
656eddcd 668 height = pindex->nHeight;
01cc012f 669 txn_count = block.vtx.size();
670 for (i=0; i<txn_count; i++)
dc64de68 671 {
352f8081 672 txhash = block.vtx[i].GetHash();
01cc012f 673 numvouts = block.vtx[i].vout.size();
352f8081 674 notaryid = -1;
ea365a71 675 voutmask = specialtx = notarizedheight = isratification = notarized = 0;
517b1691 676 signedmask = (height < 91400) ? 1 : 0;
ea365a71 677 numvins = block.vtx[i].vin.size();
678 for (j=0; j<numvins; j++)
679 {
69383c9f 680 if ( i == 0 && j == 0 )
681 continue;
ea365a71 682 if ( (scriptlen= gettxout_scriptPubKey(scriptPubKey,sizeof(scriptPubKey),block.vtx[i].vin[j].prevout.hash,block.vtx[i].vin[j].prevout.n)) > 0 )
683 {
684 if ( (k= komodo_notarycmp(scriptPubKey,scriptlen,pubkeys,numnotaries,rmd160)) >= 0 )
685 signedmask |= (1LL << k);
c7918614 686 else if ( 0 && numvins >= 17 )
bb1963ca 687 {
688 int32_t k;
689 for (k=0; k<scriptlen; k++)
690 printf("%02x",scriptPubKey[k]);
57d9cfcc 691 printf(" scriptPubKey doesnt match any notary vini.%d of %d\n",j,numvins);
bb1963ca 692 }
693 } else printf("cant get scriptPubKey for ht.%d txi.%d vin.%d\n",height,i,j);
ea365a71 694 }
e6d7eca6 695 numvalid = bitweight(signedmask);
ee5e8026 696 if ( (((height < 90000 || (signedmask & 1) != 0) && numvalid >= KOMODO_MINRATIFY) ||
697 (numvalid >= KOMODO_MINRATIFY && ASSETCHAINS_SYMBOL[0] != 0) ||
698 numvalid > (numnotaries/5)) )
ea365a71 699 {
f1d6fb9b 700 if ( ASSETCHAINS_SYMBOL[0] != 0 )
701 {
702 static FILE *signedfp;
703 if ( signedfp == 0 )
704 {
705 char fname[512];
706 komodo_statefname(fname,ASSETCHAINS_SYMBOL,(char *)"signedmasks");
707 if ( (signedfp= fopen(fname,"rb+")) == 0 )
708 signedfp = fopen(fname,"wb");
709 else fseek(signedfp,0,SEEK_END);
710 }
711 if ( signedfp != 0 )
712 {
713 fwrite(&height,1,sizeof(height),signedfp);
714 fwrite(&signedmask,1,sizeof(signedmask),signedfp);
715 fflush(signedfp);
716 }
1132e845 717 printf("[%s] ht.%d txi.%d signedmask.%llx numvins.%d numvouts.%d <<<<<<<<<<< notarized\n",ASSETCHAINS_SYMBOL,height,i,(long long)signedmask,numvins,numvouts);
f1d6fb9b 718 }
ea365a71 719 notarized = 1;
720 }
e8b7db1a 721 if ( NOTARY_PUBKEY33[0] != 0 && ASSETCHAINS_SYMBOL[0] == 0 )
9e5fc6d7 722 printf("(tx.%d: ",i);
01cc012f 723 for (j=0; j<numvouts; j++)
dc64de68 724 {
081ab21c 725 /*if ( i == 0 && j == 0 )
6615cec9 726 {
727 uint8_t *script = (uint8_t *)block.vtx[0].vout[numvouts-1].scriptPubKey.data();
728 if ( numvouts <= 2 || script[0] != 0x6a )
729 {
730 if ( numvouts == 2 && block.vtx[0].vout[1].nValue != 0 )
731 {
732 fprintf(stderr,"ht.%d numvouts.%d value %.8f\n",height,numvouts,dstr(block.vtx[0].vout[1].nValue));
49508d3c 733 if ( height >= 235300 && block.vtx[0].vout[1].nValue >= 100000*COIN )
6615cec9 734 block.vtx[0].vout[1].nValue = 0;
735 break;
736 }
737 }
081ab21c 738 }*/
e8b7db1a 739 if ( NOTARY_PUBKEY33[0] != 0 && ASSETCHAINS_SYMBOL[0] == 0 )
9e5fc6d7 740 printf("%.8f ",dstr(block.vtx[i].vout[j].nValue));
1390456b 741 len = block.vtx[i].vout[j].scriptPubKey.size();
97561034 742 if ( len >= sizeof(uint32_t) && len <= sizeof(scriptbuf) )
01cc012f 743 {
189d9dee 744#ifdef KOMODO_ZCASH
484f8777 745 memcpy(scriptbuf,block.vtx[i].vout[j].scriptPubKey.data(),len);
189d9dee 746#else
747 memcpy(scriptbuf,(uint8_t *)&block.vtx[i].vout[j].scriptPubKey[0],len);
748#endif
20dfaa77 749 notaryid = komodo_voutupdate(&isratification,notaryid,scriptbuf,len,height,txhash,i,j,&voutmask,&specialtx,&notarizedheight,(uint64_t)block.vtx[i].vout[j].nValue,notarized,signedmask,(uint32_t)chainActive.Tip()->GetBlockTime());
a01acef4 750 if ( 0 && i > 0 )
e69a0833 751 {
752 for (k=0; k<len; k++)
753 printf("%02x",scriptbuf[k]);
a8832194 754 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 755 }
01cc012f 756 }
352f8081 757 }
e8b7db1a 758 if ( NOTARY_PUBKEY33[0] != 0 && ASSETCHAINS_SYMBOL[0] == 0 )
9e5fc6d7 759 printf(") ");
05c1e522 760 if ( 0 && ASSETCHAINS_SYMBOL[0] == 0 )
0b27cefa 761 printf("[%s] ht.%d txi.%d signedmask.%llx numvins.%d numvouts.%d notarized.%d special.%d isratification.%d\n",ASSETCHAINS_SYMBOL,height,i,(long long)signedmask,numvins,numvouts,notarized,specialtx,isratification);
ea365a71 762 if ( notarized != 0 && (notarizedheight != 0 || specialtx != 0) )
1390456b 763 {
b338ea90 764 if ( isratification != 0 )
765 {
766 printf("%s NOTARY SIGNED.%llx numvins.%d ht.%d txi.%d notaryht.%d specialtx.%d\n",ASSETCHAINS_SYMBOL,(long long)signedmask,numvins,height,i,notarizedheight,specialtx);
767 printf("ht.%d specialtx.%d isratification.%d numvouts.%d signed.%llx numnotaries.%d\n",height,specialtx,isratification,numvouts,(long long)signedmask,numnotaries);
768 }
d2a115d8 769 if ( specialtx != 0 && isratification != 0 && numvouts > 2 )
84e843cd 770 {
29e69b85 771 numvalid = 0;
dd7b22ad 772 memset(pubkeys,0,sizeof(pubkeys));
6dba48ec 773 for (j=1; j<numvouts-1; j++)
84e843cd 774 {
775 len = block.vtx[i].vout[j].scriptPubKey.size();
0554de3c 776 if ( len >= sizeof(uint32_t) && len <= sizeof(scriptbuf) )
84e843cd 777 {
189d9dee 778#ifdef KOMODO_ZCASH
484f8777 779 memcpy(scriptbuf,block.vtx[i].vout[j].scriptPubKey.data(),len);
189d9dee 780#else
781 memcpy(scriptbuf,(uint8_t *)&block.vtx[i].vout[j].scriptPubKey[0],len);
782#endif
84e843cd 783 if ( len == 35 && scriptbuf[0] == 33 && scriptbuf[34] == 0xac )
784 {
29e69b85 785 memcpy(pubkeys[numvalid++],scriptbuf+1,33);
e7f99312 786 for (k=0; k<33; k++)
84e843cd 787 printf("%02x",scriptbuf[k+1]);
788 printf(" <- new notary.[%d]\n",j-1);
789 }
790 }
791 }
aa114a60 792 if ( ((signedmask & 1) != 0 && numvalid >= KOMODO_MINRATIFY) || bitweight(signedmask) > (numnotaries/3) )
d8ce705a 793 {
794 memset(&txhash,0,sizeof(txhash));
e155dbe9 795 komodo_stateupdate(height,pubkeys,numvalid,0,txhash,0,0,0,0,0,0,0,0,0,0);
f9d034d4 796 printf("RATIFIED! >>>>>>>>>> new notaries.%d newheight.%d from height.%d\n",numvalid,(((height+KOMODO_ELECTION_GAP/2)/KOMODO_ELECTION_GAP)+1)*KOMODO_ELECTION_GAP,height);
6423c8a9 797 } else printf("signedmask.%llx numvalid.%d wt.%d numnotaries.%d\n",(long long)signedmask,numvalid,bitweight(signedmask),numnotaries);
84e843cd 798 }
a96439f5 799 }
656eddcd 800 }
e8b7db1a 801 if ( NOTARY_PUBKEY33[0] != 0 && ASSETCHAINS_SYMBOL[0] == 0 )
ac93bb3e 802 printf("%s ht.%d\n",ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL,height);
e155dbe9 803 if ( pindex->nHeight == hwmheight )
8afdc8e7 804 komodo_stateupdate(height,0,0,0,zero,0,0,0,0,height,(uint32_t)pindex->nTime,0,0,0,0);
3df53390 805 } else fprintf(stderr,"komodo_connectblock: unexpected null pindex\n");
17899df4 806 //KOMODO_INITDONE = (uint32_t)time(NULL);
dd42fd9b 807 //fprintf(stderr,"%s end connect.%d\n",ASSETCHAINS_SYMBOL,pindex->nHeight);
3d35aa5b 808}
809
0f24f245 810
fcd36118 811#endif
This page took 0.423559 seconds and 4 git commands to generate.