]>
Commit | Line | Data |
---|---|---|
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 |
20 | ||
9499e4de | 21 | #include <stdint.h> |
22 | #include <stdio.h> | |
975b2ddb | 23 | #include <pthread.h> |
88f973c2 | 24 | #include <ctype.h> |
9499e4de | 25 | |
429dabb5 | 26 | void 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 | 27 | void komodo_init(); |
d9d3a941 | 28 | int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *notarized_desttxidp); |
3c0f5d94 | 29 | char *komodo_issuemethod(char *method,char *params,uint16_t port); |
9499e4de | 30 | |
429dabb5 | 31 | int32_t ASSETCHAINS_SHORTFLAG,NOTARIZED_HEIGHT,Num_nutxos,KMDHEIGHT = 40000; |
3b34b59c | 32 | uint256 NOTARIZED_HASH,NOTARIZED_DESTTXID; |
975b2ddb | 33 | pthread_mutex_t komodo_mutex; |
f38345e9 | 34 | char KMDUSERPASS[1024]; uint16_t BITCOIND_PORT = 7771; |
429dabb5 | 35 | uint64_t KOMODO_DEPOSIT,PENDING_KOMODO_TX; |
d2471545 | 36 | |
46beb55e | 37 | #include "komodo_utils.h" |
429dabb5 | 38 | queue_t DepositsQ,PendingsQ; |
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 | 48 | void 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)); | |
151 | } | |
49df008c | 152 | if ( height <= 0 ) |
153 | { | |
154 | printf("early return: stateupdate height.%d\n",height); | |
155 | return; | |
156 | } | |
3eea72f2 | 157 | if ( fp != 0 ) // write out funcid, height, other fields, call side effect function |
bafc61f3 | 158 | { |
2578b002 | 159 | //printf("fpos.%ld ",ftell(fp)); |
4355e769 | 160 | if ( height < 0 ) |
161 | { | |
9997caa0 | 162 | height = -height; |
2578b002 | 163 | //printf("func D[%d] errs.%d\n",height,errs); |
4355e769 | 164 | fputc('D',fp); |
165 | if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) ) | |
166 | errs++; | |
167 | } | |
2b84e06c | 168 | else if ( KMDheight > 0 ) |
169 | { | |
170 | fputc('K',fp); | |
171 | if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) ) | |
172 | errs++; | |
173 | if ( fwrite(&KMDheight,1,sizeof(KMDheight),fp) != sizeof(KMDheight) ) | |
174 | errs++; | |
2578b002 | 175 | //printf("ht.%d K %d\n",height,KMDheight); |
2b84e06c | 176 | } |
01f9cb3d | 177 | else if ( opretbuf != 0 && opretlen > 0 ) |
64bb0834 | 178 | { |
01f9cb3d | 179 | uint16_t olen = opretlen; |
180 | fputc('R',fp); | |
64bb0834 | 181 | if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) ) |
182 | errs++; | |
429dabb5 | 183 | if ( fwrite(&txhash,1,sizeof(txhash),fp) != sizeof(txhash) ) |
184 | errs++; | |
185 | if ( fwrite(&vout,1,sizeof(vout),fp) != sizeof(vout) ) | |
186 | errs++; | |
30df2e00 | 187 | if ( fwrite(&opretvalue,1,sizeof(opretvalue),fp) != sizeof(opretvalue) ) |
33935bd0 | 188 | errs++; |
289dc57b | 189 | if ( fwrite(&olen,1,sizeof(olen),fp) != olen ) |
190 | errs++; | |
01f9cb3d | 191 | if ( fwrite(opretbuf,1,olen,fp) != olen ) |
64bb0834 | 192 | errs++; |
2578b002 | 193 | //printf("ht.%d R opret[%d]\n",height,olen); |
429dabb5 | 194 | komodo_opreturn(height,opretvalue,opretbuf,olen,txhash,numvouts); |
01f9cb3d | 195 | } |
9997caa0 | 196 | else if ( notarypubs != 0 && numnotaries > 0 ) |
bafc61f3 | 197 | { |
2578b002 | 198 | //printf("ht.%d func P[%d] errs.%d\n",height,numnotaries,errs); |
bafc61f3 | 199 | fputc('P',fp); |
c50ec0fb | 200 | if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) ) |
201 | errs++; | |
bafc61f3 | 202 | fputc(numnotaries,fp); |
52ed4002 | 203 | if ( fwrite(notarypubs,33,numnotaries,fp) != numnotaries ) |
204 | errs++; | |
3eea72f2 | 205 | komodo_notarysinit(height,notarypubs,numnotaries); |
bafc61f3 | 206 | } |
671187dd | 207 | else if ( voutmask != 0 && numvouts > 0 ) |
208 | { | |
2578b002 | 209 | //printf("ht.%d func U %d %d errs.%d hashsize.%ld\n",height,numvouts,notaryid,errs,sizeof(txhash)); |
671187dd | 210 | fputc('U',fp); |
c50ec0fb | 211 | if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) ) |
212 | errs++; | |
671187dd | 213 | fputc(numvouts,fp); |
214 | fputc(notaryid,fp); | |
215 | if ( fwrite(&voutmask,1,sizeof(voutmask),fp) != sizeof(voutmask) ) | |
216 | errs++; | |
217 | if ( fwrite(&txhash,1,sizeof(txhash),fp) != sizeof(txhash) ) | |
218 | errs++; | |
3eea72f2 | 219 | komodo_nutxoadd(height,notaryid,txhash,voutmask,numvouts); |
671187dd | 220 | } |
b673d264 | 221 | //#ifdef KOMODO_PAX |
4a41b0b2 | 222 | else if ( pvals != 0 && numpvals > 0 ) |
223 | { | |
bfa5b4f2 | 224 | int32_t i,nonz = 0; |
1bf82154 | 225 | for (i=0; i<32; i++) |
226 | if ( pvals[i] != 0 ) | |
227 | nonz++; | |
228 | if ( nonz >= 32 ) | |
229 | { | |
230 | fputc('V',fp); | |
231 | if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) ) | |
232 | errs++; | |
233 | fputc(numpvals,fp); | |
234 | if ( fwrite(pvals,sizeof(uint32_t),numpvals,fp) != numpvals ) | |
235 | errs++; | |
236 | komodo_pvals(height,pvals,numpvals); | |
2578b002 | 237 | //printf("ht.%d V numpvals[%d]\n",height,numpvals); |
1bf82154 | 238 | } |
ef7a3548 | 239 | //printf("save pvals height.%d numpvals.%d\n",height,numpvals); |
4a41b0b2 | 240 | } |
b673d264 | 241 | //#endif |
6dabcca4 | 242 | else if ( height != 0 ) |
671187dd | 243 | { |
2578b002 | 244 | //printf("ht.%d func N ht.%d errs.%d\n",height,NOTARIZED_HEIGHT,errs); |
671187dd | 245 | fputc('N',fp); |
c50ec0fb | 246 | if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) ) |
247 | errs++; | |
671187dd | 248 | if ( fwrite(&NOTARIZED_HEIGHT,1,sizeof(NOTARIZED_HEIGHT),fp) != sizeof(NOTARIZED_HEIGHT) ) |
249 | errs++; | |
250 | if ( fwrite(&NOTARIZED_HASH,1,sizeof(NOTARIZED_HASH),fp) != sizeof(NOTARIZED_HASH) ) | |
251 | errs++; | |
1e81ccb7 | 252 | if ( fwrite(&NOTARIZED_DESTTXID,1,sizeof(NOTARIZED_DESTTXID),fp) != sizeof(NOTARIZED_DESTTXID) ) |
671187dd | 253 | errs++; |
1e81ccb7 | 254 | komodo_notarized_update(height,NOTARIZED_HEIGHT,NOTARIZED_HASH,NOTARIZED_DESTTXID); |
671187dd | 255 | } |
47f47733 | 256 | fflush(fp); |
bafc61f3 | 257 | } |
258 | } | |
259 | ||
844a6138 | 260 | int32_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 | 261 | { |
0ac1f6fc | 262 | static uint256 zero; int32_t opretlen,nid,k,len = 0; uint256 kmdtxid,desttxid; uint8_t crypto777[33]; |
9c406099 | 263 | if ( scriptlen == 35 && scriptbuf[0] == 33 && scriptbuf[34] == 0xac ) |
1390456b | 264 | { |
c23dd601 | 265 | decode_hex(crypto777,33,(char *)CRYPTO777_PUBSECPSTR); |
986d3459 | 266 | /*for (k=0; k<33; k++) |
e1be360e | 267 | printf("%02x",crypto777[k]); |
268 | printf(" crypto777 "); | |
269 | for (k=0; k<scriptlen; k++) | |
270 | printf("%02x",scriptbuf[k]); | |
986d3459 | 271 | printf(" <- script ht.%d i.%d j.%d cmp.%d\n",height,i,j,memcmp(crypto777,scriptbuf+1,33));*/ |
1390456b | 272 | if ( memcmp(crypto777,scriptbuf+1,33) == 0 ) |
273 | { | |
274 | *specialtxp = 1; | |
275 | printf(">>>>>>>> "); | |
276 | } | |
a5f315c7 | 277 | else if ( komodo_chosennotary(&nid,height,scriptbuf + 1) >= 0 ) |
1390456b | 278 | { |
84e843cd | 279 | //printf("found notary.k%d\n",k); |
280 | if ( notaryid < 64 ) | |
1390456b | 281 | { |
84e843cd | 282 | if ( notaryid < 0 ) |
283 | { | |
a5f315c7 | 284 | notaryid = nid; |
84e843cd | 285 | *voutmaskp |= (1LL << j); |
286 | } | |
a5f315c7 | 287 | else if ( notaryid != nid ) |
84e843cd | 288 | { |
a5f315c7 | 289 | printf("mismatch notaryid.%d k.%d\n",notaryid,nid); |
84e843cd | 290 | notaryid = 64; |
291 | *voutmaskp = 0; | |
292 | } | |
293 | else *voutmaskp |= (1LL << j); | |
1390456b | 294 | } |
1390456b | 295 | } |
296 | } | |
844a6138 | 297 | if ( scriptbuf[len++] == 0x6a ) |
1390456b | 298 | { |
299 | if ( (opretlen= scriptbuf[len++]) == 0x4c ) | |
300 | opretlen = scriptbuf[len++]; | |
301 | else if ( opretlen == 0x4d ) | |
302 | { | |
303 | opretlen = scriptbuf[len++]; | |
304 | opretlen = (opretlen << 8) + scriptbuf[len++]; | |
305 | } | |
429dabb5 | 306 | //for (k=0; k<scriptlen; k++) |
307 | // printf("%02x",scriptbuf[k]); | |
308 | //printf(" <- script ht.%d i.%d j.%d value %.8f\n",height,i,j,dstr(value)); | |
844a6138 | 309 | if ( j == 1 && opretlen >= 32*2+4 && strcmp(KOMODO_SOURCE,(char *)&scriptbuf[len+32*2+4]) == 0 ) |
1390456b | 310 | { |
4a41b0b2 | 311 | len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&kmdtxid); |
312 | len += iguana_rwnum(0,&scriptbuf[len],4,(uint8_t *)notarizedheightp); | |
3eea72f2 | 313 | len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&desttxid); |
bc1d085a | 314 | if ( *notarizedheightp > NOTARIZED_HEIGHT && *notarizedheightp < height ) |
1390456b | 315 | { |
f9d24468 | 316 | printf("ht.%d NOTARIZED.%d KMD.%s BTCTXID.%s (%s)\n",height,*notarizedheightp,kmdtxid.ToString().c_str(),desttxid.ToString().c_str(),(char *)&scriptbuf[len]); |
4a41b0b2 | 317 | NOTARIZED_HEIGHT = *notarizedheightp; |
318 | NOTARIZED_HASH = kmdtxid; | |
1e81ccb7 | 319 | NOTARIZED_DESTTXID = desttxid; |
429dabb5 | 320 | komodo_stateupdate(height,0,0,0,zero,0,0,0,0,0,0,0,0,0); |
f9d24468 | 321 | } else printf("reject ht.%d NOTARIZED.%d %s.%s DESTTXID.%s (%s)\n",height,*notarizedheightp,KOMODO_SOURCE,kmdtxid.ToString().c_str(),desttxid.ToString().c_str(),(char *)&scriptbuf[len]); |
1390456b | 322 | } |
babdc001 | 323 | else if ( i == 0 && j == 1 && opretlen == 149 ) |
0201d1a6 | 324 | komodo_paxpricefeed(height,&scriptbuf[len],opretlen); |
429dabb5 | 325 | else komodo_stateupdate(height,0,0,0,txhash,0,0,0,0,0,value,&scriptbuf[len],opretlen,j); |
1390456b | 326 | } |
327 | return(notaryid); | |
328 | } | |
329 | ||
f38345e9 | 330 | int32_t komodo_isratify(int32_t isspecial,int32_t numvalid) |
331 | { | |
332 | if ( isspecial != 0 && numvalid > 13 ) | |
333 | return(1); | |
334 | else return(0); | |
335 | } | |
336 | ||
337 | // Special tx have vout[0] -> CRYPTO777 | |
338 | // with more than 13 pay2pubkey outputs -> ratify | |
339 | // if all outputs to notary -> notary utxo | |
340 | // if txi == 0 && 2 outputs and 2nd OP_RETURN, len == 32*2+4 -> notarized, 1st byte 'P' -> pricefeed | |
420d7311 | 341 | // OP_RETURN: 'D' -> deposit, 'W' -> withdraw |
f38345e9 | 342 | |
651989c7 | 343 | void komodo_connectblock(CBlockIndex *pindex,CBlock& block) |
50027f06 | 344 | { |
e9595d76 | 345 | uint64_t signedmask,voutmask; |
dd7b22ad | 346 | uint8_t scriptbuf[4096],pubkeys[64][33]; uint256 kmdtxid,btctxid,txhash; |
e9595d76 | 347 | int32_t i,j,k,numvalid,specialtx,notarizedheight,notaryid,len,numvouts,numvins,height,txn_count; |
77117dbe | 348 | komodo_init(); |
9b0e1808 | 349 | #ifdef KOMODO_ISSUER |
350 | komodo_gateway_issuer(); | |
351 | #else | |
f38345e9 | 352 | komodo_gateway_redeemer(); |
9b0e1808 | 353 | #endif |
68916cc6 | 354 | if ( pindex != 0 ) |
b501ded2 | 355 | { |
656eddcd | 356 | height = pindex->nHeight; |
01cc012f | 357 | txn_count = block.vtx.size(); |
358 | for (i=0; i<txn_count; i++) | |
dc64de68 | 359 | { |
352f8081 | 360 | txhash = block.vtx[i].GetHash(); |
01cc012f | 361 | numvouts = block.vtx[i].vout.size(); |
352f8081 | 362 | notaryid = -1; |
1390456b | 363 | voutmask = specialtx = notarizedheight = 0; |
01cc012f | 364 | for (j=0; j<numvouts; j++) |
dc64de68 | 365 | { |
1390456b | 366 | len = block.vtx[i].vout[j].scriptPubKey.size(); |
367 | if ( len <= sizeof(scriptbuf) ) | |
01cc012f | 368 | { |
189d9dee | 369 | #ifdef KOMODO_ZCASH |
484f8777 | 370 | memcpy(scriptbuf,block.vtx[i].vout[j].scriptPubKey.data(),len); |
189d9dee | 371 | #else |
372 | memcpy(scriptbuf,(uint8_t *)&block.vtx[i].vout[j].scriptPubKey[0],len); | |
373 | #endif | |
bfa5b4f2 | 374 | // signedmask is needed here! |
629e8f37 | 375 | notaryid = komodo_voutupdate(notaryid,scriptbuf,len,height,txhash,i,j,&voutmask,&specialtx,¬arizedheight,(uint64_t)block.vtx[i].vout[j].nValue); |
a01acef4 | 376 | if ( 0 && i > 0 ) |
e69a0833 | 377 | { |
378 | for (k=0; k<len; k++) | |
379 | printf("%02x",scriptbuf[k]); | |
a8832194 | 380 | 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 | 381 | } |
01cc012f | 382 | } |
352f8081 | 383 | } |
cf9538e0 | 384 | if ( i != 0 && notaryid >= 0 && notaryid < 64 && voutmask != 0 ) |
3eea72f2 | 385 | { |
429dabb5 | 386 | komodo_stateupdate(height,0,0,notaryid,txhash,voutmask,numvouts,0,0,0,0,0,0,0); |
3eea72f2 | 387 | //komodo_nutxoadd(height,notaryid,txhash,voutmask,numvouts); |
388 | } | |
1390456b | 389 | signedmask = 0; |
390 | numvins = block.vtx[i].vin.size(); | |
5bdebffe | 391 | for (j=0; j<numvins; j++) |
352f8081 | 392 | { |
4355e769 | 393 | if ( (k= komodo_nutxofind(height,block.vtx[i].vin[j].prevout.hash,block.vtx[i].vin[j].prevout.n)) >= 0 ) |
1390456b | 394 | signedmask |= (1LL << k); |
21cc1d3e | 395 | else if ( 0 && signedmask != 0 ) |
bc6fd011 | 396 | 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 | 397 | } |
06f0ed43 | 398 | if ( signedmask != 0 && (notarizedheight != 0 || specialtx != 0) ) |
1390456b | 399 | { |
e69a0833 | 400 | printf("NOTARY SIGNED.%llx numvins.%d ht.%d txi.%d notaryht.%d specialtx.%d\n",(long long)signedmask,numvins,height,i,notarizedheight,specialtx); |
3eea72f2 | 401 | if ( specialtx != 0 && numvouts > 2 && komodo_ratify_threshold(height,signedmask) > 0 ) |
84e843cd | 402 | { |
29e69b85 | 403 | numvalid = 0; |
dd7b22ad | 404 | memset(pubkeys,0,sizeof(pubkeys)); |
84e843cd | 405 | for (j=1; j<numvouts; j++) |
406 | { | |
407 | len = block.vtx[i].vout[j].scriptPubKey.size(); | |
408 | if ( len <= sizeof(scriptbuf) ) | |
409 | { | |
189d9dee | 410 | #ifdef KOMODO_ZCASH |
484f8777 | 411 | memcpy(scriptbuf,block.vtx[i].vout[j].scriptPubKey.data(),len); |
189d9dee | 412 | #else |
413 | memcpy(scriptbuf,(uint8_t *)&block.vtx[i].vout[j].scriptPubKey[0],len); | |
414 | #endif | |
84e843cd | 415 | if ( len == 35 && scriptbuf[0] == 33 && scriptbuf[34] == 0xac ) |
416 | { | |
29e69b85 | 417 | memcpy(pubkeys[numvalid++],scriptbuf+1,33); |
e7f99312 | 418 | for (k=0; k<33; k++) |
84e843cd | 419 | printf("%02x",scriptbuf[k+1]); |
420 | printf(" <- new notary.[%d]\n",j-1); | |
421 | } | |
422 | } | |
423 | } | |
f38345e9 | 424 | if ( komodo_isratify(1,numvalid) > 13 ) |
d8ce705a | 425 | { |
426 | memset(&txhash,0,sizeof(txhash)); | |
429dabb5 | 427 | komodo_stateupdate(height,pubkeys,numvalid,0,txhash,0,0,0,0,0,0,0,0,0); |
d8ce705a | 428 | } |
835c617e | 429 | printf("new notaries.%d newheight.%d from height.%d\n",numvouts-1,KOMODO_PUBKEYS_HEIGHT(height),height); |
84e843cd | 430 | } |
a96439f5 | 431 | } |
656eddcd | 432 | } |
44c4fbbd | 433 | } else printf("komodo_connectblock: unexpected null pindex\n"); |
3d35aa5b | 434 | } |
435 | ||
0f24f245 | 436 | |
fcd36118 | 437 | #endif |