]>
Commit | Line | Data |
---|---|---|
9b0e1808 | 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 | ||
f38345e9 | 16 | // paxdeposit equivalent in reverse makes opreturn and KMD does the same in reverse |
f38345e9 | 17 | |
77be6cd9 | 18 | uint64_t komodo_paxtotal() |
53c47c90 | 19 | { |
e5430f52 | 20 | struct pax_transaction *pax,*tmp; uint64_t total = 0; |
c169f64b | 21 | HASH_ITER(hh,PAX,pax,tmp) |
22 | { | |
23 | if ( pax->marked == 0 ) | |
24 | { | |
25 | if ( komodo_is_issuer() != 0 ) | |
26 | total += pax->fiatoshis; | |
27 | else total += pax->komodoshis; | |
28 | } | |
29 | } | |
53c47c90 | 30 | return(total); |
2ab43fd2 | 31 | } |
32 | ||
6210f328 | 33 | struct pax_transaction *komodo_paxfind(struct pax_transaction *space,uint256 txid,uint16_t vout) |
34 | { | |
35 | struct pax_transaction *pax; | |
36 | pthread_mutex_lock(&komodo_mutex); | |
37 | HASH_FIND(hh,PAX,&txid,sizeof(txid),pax); | |
38 | if ( pax != 0 ) | |
39 | memcpy(space,pax,sizeof(*pax)); | |
40 | pthread_mutex_unlock(&komodo_mutex); | |
41 | return(pax); | |
42 | } | |
43 | ||
b5bf65f5 | 44 | struct pax_transaction *komodo_paxmark(int32_t height,struct pax_transaction *space,uint256 txid,uint16_t vout,int32_t mark) |
6210f328 | 45 | { |
46 | struct pax_transaction *pax; | |
47 | pthread_mutex_lock(&komodo_mutex); | |
48 | HASH_FIND(hh,PAX,&txid,sizeof(txid),pax); | |
2ab43fd2 | 49 | if ( pax == 0 ) |
50 | { | |
51 | pax = (struct pax_transaction *)calloc(1,sizeof(*pax)); | |
52 | pax->txid = txid; | |
53 | pax->vout = vout; | |
54 | HASH_ADD_KEYPTR(hh,PAX,&pax->txid,sizeof(pax->txid),pax); | |
32d525eb | 55 | //printf("ht.%d create pax.%p mark.%d\n",height,pax,mark); |
2ab43fd2 | 56 | } |
6210f328 | 57 | if ( pax != 0 ) |
58 | { | |
59 | pax->marked = mark; | |
f1e6bb01 | 60 | //int32_t i; for (i=0; i<32; i++) |
61 | // printf("%02x",((uint8_t *)&txid)[i]); | |
62 | //printf(" paxmark.ht %d vout%d\n",mark,vout); | |
6210f328 | 63 | memcpy(space,pax,sizeof(*pax)); |
64 | } | |
65 | pthread_mutex_unlock(&komodo_mutex); | |
66 | return(pax); | |
67 | } | |
429dabb5 | 68 | |
1fc75a27 | 69 | void komodo_gateway_deposit(char *coinaddr,uint64_t value,int32_t shortflag,char *symbol,uint64_t fiatoshis,uint8_t *rmd160,uint256 txid,uint16_t vout,int32_t height,int32_t otherheight) // assetchain context |
d43c7a93 | 70 | { |
b2d64a0f | 71 | struct pax_transaction *pax; int32_t addflag = 0; |
d43c7a93 | 72 | pthread_mutex_lock(&komodo_mutex); |
73 | HASH_FIND(hh,PAX,&txid,sizeof(txid),pax); | |
74 | if ( pax == 0 ) | |
b2d64a0f | 75 | { |
d43c7a93 | 76 | pax = (struct pax_transaction *)calloc(1,sizeof(*pax)); |
8d52488f | 77 | pax->txid = txid; |
78 | pax->vout = vout; | |
79 | HASH_ADD_KEYPTR(hh,PAX,&pax->txid,sizeof(pax->txid),pax); | |
7961668b | 80 | addflag = 1; |
1fc75a27 | 81 | if ( ASSETCHAINS_SYMBOL[0] == 0 ) |
82 | { | |
83 | int32_t i; for (i=0; i<32; i++) | |
84 | printf("%02x",((uint8_t *)&txid)[i]); | |
85 | printf(" v.%d [%s] kht.%d ht.%d create pax.%p\n",vout,ASSETCHAINS_SYMBOL,height,otherheight,pax); | |
86 | } | |
b2d64a0f | 87 | } |
8d52488f | 88 | pthread_mutex_unlock(&komodo_mutex); |
d43c7a93 | 89 | if ( coinaddr != 0 ) |
90 | { | |
91 | strcpy(pax->coinaddr,coinaddr); | |
92 | pax->komodoshis = value; | |
93 | pax->shortflag = shortflag; | |
94 | strcpy(pax->symbol,symbol); | |
95 | pax->fiatoshis = fiatoshis; | |
96 | memcpy(pax->rmd160,rmd160,20); | |
97 | pax->height = height; | |
1fc75a27 | 98 | pax->otherheight = otherheight; |
d43c7a93 | 99 | if ( pax->marked == 0 ) |
7961668b | 100 | { |
101 | if ( addflag != 0 ) | |
00cf544e | 102 | printf("[%s] addflag.%d ADD DEPOSIT %s %.8f -> %s TO PAX ht.%d otherht.%d total %.8f\n",ASSETCHAINS_SYMBOL,addflag,symbol,dstr(fiatoshis),coinaddr,height,otherheight,dstr(komodo_paxtotal())); |
7961668b | 103 | } |
0dca8d4c | 104 | //else printf("%p MARKED.%d DEPOSIT %s %.8f -> %s TO PAX ht.%d otherht.%d\n",pax,pax->marked,symbol,dstr(fiatoshis),coinaddr,height,otherheight); |
d43c7a93 | 105 | } |
106 | else | |
107 | { | |
108 | pax->marked = height; | |
1fc75a27 | 109 | printf("pax.%p MARK DEPOSIT ht.%d other.%d\n",pax,height,otherheight); |
d43c7a93 | 110 | } |
d43c7a93 | 111 | } |
112 | ||
ab918767 | 113 | int32_t komodo_issued_opreturn(char *base,uint256 *txids,uint16_t *vouts,uint8_t *opretbuf,int32_t opretlen,int32_t iskomodo) |
63b289ad | 114 | { |
e2c35fcd | 115 | int32_t i,n=0,j,len; |
63b289ad | 116 | for (i=0; i<4; i++) |
117 | base[i] = opretbuf[opretlen-4+i]; | |
0e3472c1 | 118 | if ( ASSETCHAINS_SYMBOL[0] == 0 || strncmp(ASSETCHAINS_SYMBOL,base,strlen(base)) == 0 ) // shortflag |
63b289ad | 119 | { |
120 | opretbuf++, opretlen--; | |
121 | for (n=len=0; n<opretlen/34; n++) | |
122 | { | |
123 | for (j=0; j<32; j++) | |
124 | { | |
125 | ((uint8_t *)&txids[n])[j] = opretbuf[len++]; | |
1938746c | 126 | //printf("%02x",((uint8_t *)&txids[n])[j]); |
63b289ad | 127 | } |
128 | vouts[n] = opretbuf[len++]; | |
129 | vouts[n] = (opretbuf[len++] << 8) | vouts[n]; | |
1938746c | 130 | //printf(" issuedtxid v%d i.%d opretlen.%d\n",vouts[n],n,opretlen); |
05d91eb2 | 131 | if ( iskomodo != 0 ) |
132 | { | |
133 | uint64_t fiatoshis; int32_t height,otherheight,shortflag; char symbol[16]; | |
134 | len += iguana_rwnum(0,&opretbuf[len],sizeof(fiatoshis),&fiatoshis); | |
135 | len += iguana_rwnum(0,&opretbuf[len],sizeof(height),&height); | |
136 | len += iguana_rwnum(0,&opretbuf[len],sizeof(otherheight),&otherheight); | |
137 | if ( opretbuf[len] == '-' ) | |
138 | shortflag = 1, len++; | |
139 | else shortflag = 0; | |
140 | for (i=0; opretbuf[len+i]!=0&&i<3; i++) | |
141 | symbol[i] = opretbuf[len+i]; | |
142 | symbol[i] = 0; | |
ab918767 | 143 | printf(">>>>>>> iskomodo X: (%s) fiat %.8f kmdheight.%d other.%d\n",symbol,dstr(fiatoshis),height,otherheight); |
05d91eb2 | 144 | } |
63b289ad | 145 | } |
146 | } | |
147 | return(n); | |
148 | } | |
149 | ||
635dd34d | 150 | int32_t komodo_gateway_deposits(CMutableTransaction *txNew,char *base,int32_t tokomodo) |
429dabb5 | 151 | { |
48e96ba1 | 152 | struct pax_transaction *pax,*tmp; char symbol[16],dest[16]; uint8_t *script,opcode,opret[10000],data[10000]; int32_t i,baseid,len=0,opretlen=0,numvouts=1; struct komodo_state *sp; uint64_t mask; |
635dd34d | 153 | sp = komodo_stateptr(symbol,dest); |
27bf3c5e | 154 | strcpy(symbol,base); |
429dabb5 | 155 | PENDING_KOMODO_TX = 0; |
a3f23ee2 | 156 | if ( tokomodo == 0 ) |
48e96ba1 | 157 | { |
77be6cd9 | 158 | opcode = 'I'; |
48e96ba1 | 159 | if ( (baseid= komodo_baseid(base)) < 0 ) |
160 | return(0); | |
161 | mask = (1LL << 32) | (1LL << (baseid+1)); | |
162 | if ( (sp->RTmask & mask) != mask ) | |
163 | { | |
164 | printf("%s not RT mask.%llx vs RTmask.%llx\n",ASSETCHAINS_SYMBOL,(long long)mask,(long long)sp->RTmask); | |
165 | return(0); | |
166 | } | |
167 | } | |
77be6cd9 | 168 | else opcode = 'X'; |
c169f64b | 169 | HASH_ITER(hh,PAX,pax,tmp) |
429dabb5 | 170 | { |
635dd34d | 171 | printf("pax.%s marked.%d %.8f -> %.8f\n",pax->symbol,pax->marked,dstr(pax->komodoshis),dstr(pax->fiatoshis)); |
172 | if ( pax->marked != 0 || strcmp(pax->symbol,ASSETCHAINS_SYMBOL) != 0 ) | |
e5430f52 | 173 | continue; |
7ca711ba | 174 | if ( ASSETCHAINS_SYMBOL[0] != 0 ) |
635dd34d | 175 | printf("pax.%s marked.%d %.8f -> %.8f\n",ASSETCHAINS_SYMBOL,pax->marked,dstr(pax->komodoshis),dstr(pax->fiatoshis)); |
e5430f52 | 176 | txNew->vout.resize(numvouts+1); |
1fc75a27 | 177 | txNew->vout[numvouts].nValue = (opcode == 'I') ? pax->fiatoshis : pax->komodoshis; |
e5430f52 | 178 | txNew->vout[numvouts].scriptPubKey.resize(25); |
179 | script = (uint8_t *)&txNew->vout[numvouts].scriptPubKey[0]; | |
180 | *script++ = 0x76; | |
181 | *script++ = 0xa9; | |
182 | *script++ = 20; | |
183 | memcpy(script,pax->rmd160,20), script += 20; | |
184 | *script++ = 0x88; | |
185 | *script++ = 0xac; | |
186 | for (i=0; i<32; i++) | |
187 | { | |
1938746c | 188 | //printf("%02x",((uint8_t *)&pax->txid)[i]); |
e5430f52 | 189 | data[len++] = ((uint8_t *)&pax->txid)[i]; |
429dabb5 | 190 | } |
e5430f52 | 191 | data[len++] = pax->vout & 0xff; |
192 | data[len++] = (pax->vout >> 8) & 0xff; | |
a3f23ee2 | 193 | if ( tokomodo == 0 ) |
e5430f52 | 194 | PENDING_KOMODO_TX += pax->fiatoshis; |
fbc4209b | 195 | else |
196 | { | |
1fc75a27 | 197 | //[{"prev_hash":"5d5c9a49489b558de9e84f991f996dedaae6b9d0f157f82b2fec64662476d5cf","prev_vout":2,"EUR":0.10000000,"fiat":"EUR","kmdheight":57930,"height":153,"KMD":0.78329000,"address":"RDhEGYScNQYetCyG75Kf8Fg61UWPdwc1C5","rmd160":"306c507eea639e7220b3069ed9f49f3bc97eaca1"}] |
198 | len += iguana_rwnum(1,&data[len],sizeof(pax->fiatoshis),&pax->fiatoshis); | |
199 | len += iguana_rwnum(1,&data[len],sizeof(pax->height),&pax->height); | |
200 | len += iguana_rwnum(1,&data[len],sizeof(pax->otherheight),&pax->otherheight); | |
635dd34d | 201 | for (i=0; pax->symbol[i]!=0&&i<3; i++) // must be 3 letter currency |
1fc75a27 | 202 | data[len++] = pax->symbol[i]; |
203 | data[len++] = 0; | |
fbc4209b | 204 | PENDING_KOMODO_TX += pax->komodoshis; |
05d91eb2 | 205 | printf(" vout.%u DEPOSIT %.8f <- pax.%s pending %.8f | ",pax->vout,(double)txNew->vout[numvouts].nValue/COIN,symbol,dstr(PENDING_KOMODO_TX)); |
fbc4209b | 206 | } |
e5430f52 | 207 | if ( numvouts++ >= 64 ) |
208 | break; | |
429dabb5 | 209 | } |
210 | if ( numvouts > 1 ) | |
211 | { | |
0e3472c1 | 212 | if ( tokomodo != 0 ) |
27bf3c5e | 213 | strcpy(symbol,(char *)"KMD"); |
9ef47e29 | 214 | for (i=0; symbol[i]!=0; i++) |
215 | data[len++] = symbol[i]; | |
a5ad8f02 | 216 | data[len++] = 0; |
77be6cd9 | 217 | opretlen = komodo_opreturnscript(opret,opcode,data,len); |
50824530 | 218 | txNew->vout.resize(numvouts+1); |
219 | txNew->vout[numvouts].nValue = 0; | |
220 | txNew->vout[numvouts].scriptPubKey.resize(opretlen); | |
221 | script = (uint8_t *)&txNew->vout[numvouts].scriptPubKey[0]; | |
429dabb5 | 222 | memcpy(script,opret,opretlen); |
23d955d4 | 223 | printf("MINER deposits.%d (%s) vouts.%d %.8f opretlen.%d\n",tokomodo,ASSETCHAINS_SYMBOL,numvouts,dstr(PENDING_KOMODO_TX),opretlen); |
d9a9d562 | 224 | return(1); |
9ef47e29 | 225 | } |
d9a9d562 | 226 | return(0); |
429dabb5 | 227 | } |
228 | ||
8f64a3a9 | 229 | int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above block is valid pax pricing |
557d9a23 | 230 | { |
ab918767 | 231 | int32_t i,j,n,num,opretlen,offset=1,errs=0,matched=0; uint256 hash,txids[64]; char symbol[16],base[16]; uint16_t vouts[64]; uint8_t *script,opcode; struct pax_transaction *pax,space; |
557d9a23 | 232 | n = block.vtx[0].vout.size(); |
233 | script = (uint8_t *)block.vtx[0].vout[n-1].scriptPubKey.data(); | |
12d47153 | 234 | if ( n <= 2 || script[0] != 0x6a ) |
235 | return(0); | |
236 | offset += komodo_scriptitemlen(&opretlen,&script[offset]); | |
77be6cd9 | 237 | if ( ASSETCHAINS_SYMBOL[0] == 0 ) |
238 | { | |
85de2861 | 239 | //for (i=0; i<opretlen; i++) |
240 | // printf("%02x",script[i]); | |
241 | //printf(" height.%d checkdeposit n.%d [%02x] [%c] %d vs %d\n",height,n,script[0],script[offset],script[offset],'X'); | |
77be6cd9 | 242 | opcode = 'X'; |
243 | strcpy(symbol,"KMD"); | |
244 | } | |
245 | else | |
246 | { | |
247 | strcpy(symbol,ASSETCHAINS_SYMBOL); | |
248 | opcode = 'I'; | |
249 | } | |
250 | if ( script[offset] == opcode && opretlen < block.vtx[0].vout[n-1].scriptPubKey.size() ) | |
557d9a23 | 251 | { |
ab918767 | 252 | if ( (num= komodo_issued_opreturn(base,txids,vouts,&script[offset],opretlen,opcode == 'X')) > 0 ) |
557d9a23 | 253 | { |
254 | for (i=1; i<n-1; i++) | |
255 | { | |
f10b8e2e | 256 | if ( (pax= komodo_paxfind(&space,txids[i-1],vouts[i-1])) != 0 ) |
5a2c5b6f | 257 | { |
f10b8e2e | 258 | if ( ((opcode == 'I' && pax->fiatoshis == block.vtx[0].vout[i].nValue) || (opcode == 'X' && pax->komodoshis == block.vtx[0].vout[i].nValue)) ) |
259 | { | |
260 | if ( pax->marked != 0 ) | |
261 | errs++; | |
262 | else matched++; | |
98ecae42 | 263 | if ( 0 && opcode == 'X' ) |
05d91eb2 | 264 | printf("errs.%d i.%d match %.8f == %.8f\n",errs,i,dstr(pax != 0 ? pax->fiatoshis:-1),dstr(block.vtx[0].vout[i].nValue)); |
f10b8e2e | 265 | } |
266 | else | |
267 | { | |
268 | hash = block.GetHash(); | |
05d91eb2 | 269 | if ( opcode == 'X' ) |
270 | { | |
271 | for (j=0; j<32; j++) | |
272 | printf("%02x",((uint8_t *)&hash)[j]); | |
273 | printf(" ht.%d blockhash couldnt find vout.[%d]\n",height,i); | |
c246f72f | 274 | // validate amount! via fiat chain |
05d91eb2 | 275 | } |
f10b8e2e | 276 | } |
5a2c5b6f | 277 | } |
cb040aa1 | 278 | else |
279 | { | |
05d91eb2 | 280 | if ( opcode == 'X' ) |
281 | { | |
ce94767e | 282 | matched++; |
05d91eb2 | 283 | for (j=0; j<32; j++) |
284 | printf("%02x",((uint8_t *)&txids[i-1])[j]); | |
285 | printf(" cant paxfind txid\n"); | |
c246f72f | 286 | // validate amount! via fiat chain |
ce94767e | 287 | } else if ( opcode == 'I' ) |
288 | matched++; | |
cb040aa1 | 289 | } |
f6b5fa43 | 290 | komodo_paxmark(height,&space,txids[i-1],vouts[i-1],height); |
557d9a23 | 291 | } |
81041ab2 | 292 | if ( matched != num ) |
293 | { | |
0dca8d4c | 294 | // can easily happen depending on order of loading |
ce94767e | 295 | if ( height > 60000 ) |
296 | printf("WARNING: ht.%d (%c) matched.%d vs num.%d\n",height,opcode,matched,num); | |
81041ab2 | 297 | } |
557d9a23 | 298 | } |
b98053e2 | 299 | //printf("opretlen.%d num.%d\n",opretlen,num); |
557d9a23 | 300 | } |
301 | return(0); | |
302 | } | |
303 | ||
429dabb5 | 304 | const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int32_t opretlen,uint256 txid,uint16_t vout) |
305 | { | |
99b921bb | 306 | uint8_t rmd160[20],addrtype,shortflag,pubkey33[33]; int32_t i,j,n,len,tokomodo,kmdheight; char base[4],coinaddr[64],destaddr[64]; struct pax_transaction space; uint256 txids[64]; uint16_t vouts[64]; double diff; uint64_t seed; int64_t fiatoshis,checktoshis; const char *typestr = "unknown"; |
95db8239 | 307 | tokomodo = (komodo_is_issuer() == 0); |
1938746c | 308 | if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 ) |
ad7b6271 | 309 | { |
310 | for (i=0; i<opretlen; i++) | |
311 | printf("%02x",opretbuf[i]); | |
312 | printf(" opret[%c] else path tokomodo.%d ht.%d\n",opretbuf[0],tokomodo,height); | |
313 | } | |
0a611c1e | 314 | if ( opretbuf[0] == 'D' ) |
64bb0834 | 315 | { |
05a37d87 | 316 | if ( opretlen == 38 ) // any KMD tx |
64bb0834 | 317 | { |
05a37d87 | 318 | iguana_rwnum(0,&opretbuf[34],sizeof(kmdheight),&kmdheight); |
abdd8672 | 319 | memset(base,0,sizeof(base)); |
320 | PAX_pubkey(0,&opretbuf[1],&addrtype,rmd160,base,&shortflag,&fiatoshis); | |
321 | if ( fiatoshis < 0 ) | |
322 | fiatoshis = -fiatoshis; | |
323 | bitcoin_address(coinaddr,addrtype,rmd160,20); | |
324 | checktoshis = PAX_fiatdest(&seed,tokomodo,destaddr,pubkey33,coinaddr,kmdheight,base,fiatoshis); | |
325 | typestr = "deposit"; | |
15b7788a | 326 | printf("kmdheight.%d vs height.%d check %.8f vs %.8f tokomodo.%d %d seed.%llx\n",kmdheight,height,dstr(checktoshis),dstr(value),komodo_is_issuer(),strncmp(ASSETCHAINS_SYMBOL,base,strlen(base)) == 0,(long long)seed); |
327 | diff = ((double)value / checktoshis) - 1.; | |
328 | if ( diff < 0. ) | |
329 | diff = -diff; | |
05a37d87 | 330 | if ( kmdheight <= height ) |
6e576848 | 331 | { |
ab918767 | 332 | if ( tokomodo == 0 && strncmp(ASSETCHAINS_SYMBOL,base,strlen(base)) == 0 ) |
05a37d87 | 333 | { |
ab918767 | 334 | for (i=0; i<32; i++) |
335 | printf("%02x",((uint8_t *)&txid)[i]); | |
336 | printf(" <- txid.v%u ",vout); | |
337 | for (i=0; i<33; i++) | |
338 | printf("%02x",pubkey33[i]); | |
339 | printf(" checkpubkey check %.8f v %.8f dest.(%s) kmdheight.%d height.%d\n",dstr(checktoshis),dstr(value),destaddr,kmdheight,height); | |
340 | if ( value >= checktoshis || (seed == 0 && diff < .01) ) | |
05a37d87 | 341 | { |
ab918767 | 342 | if ( komodo_paxfind(&space,txid,vout) == 0 ) |
05a37d87 | 343 | { |
ab918767 | 344 | komodo_gateway_deposit(coinaddr,value,shortflag,base,fiatoshis,rmd160,txid,vout,kmdheight,height); |
345 | } else printf("duplicate deposit\n"); | |
755ead98 | 346 | } |
8e3430ee | 347 | } |
8bc1bcad | 348 | } |
64bb0834 | 349 | } |
350 | } | |
402d5759 | 351 | else if ( strncmp((char *)"KMD",(char *)&opretbuf[opretlen-4],3) != 0 ) |
429dabb5 | 352 | { |
755ead98 | 353 | if ( tokomodo == 0 && opretbuf[0] == 'I' ) // assetchain coinbase |
429dabb5 | 354 | { |
76984d2e | 355 | if ( (n= komodo_issued_opreturn(base,txids,vouts,opretbuf,opretlen,0)) > 0 ) |
429dabb5 | 356 | { |
63b289ad | 357 | for (i=0; i<n; i++) |
ec35af90 | 358 | { |
1938746c | 359 | //for (j=0; j<32; j++) |
360 | // printf("%02x",((uint8_t *)&txids[i])[j]); | |
b5bf65f5 | 361 | if ( komodo_paxmark(height,&space,txids[i],vouts[i],height) == 0 ) |
31e168df | 362 | { |
1fc75a27 | 363 | komodo_gateway_deposit(0,0,0,0,0,0,txids[i],vouts[i],height,0); |
31e168df | 364 | } |
f6b5fa43 | 365 | else |
366 | { | |
1938746c | 367 | //printf(" duplicate issuedtxid v%d i.%d of n.%d opretlen.%d\n",vouts[i],i,n,opretlen); |
f6b5fa43 | 368 | } |
ec35af90 | 369 | } |
429dabb5 | 370 | } |
429dabb5 | 371 | } |
0920fed9 | 372 | else if ( tokomodo != 0 && opretbuf[0] == 'X' ) |
9ef47e29 | 373 | { |
374 | // verify and update limits | |
375 | } | |
429dabb5 | 376 | } |
64bb0834 | 377 | return(typestr); |
378 | } | |
379 | ||
44a80e60 | 380 | int32_t komodo_longestchain(); |
ab918767 | 381 | |
30d79208 | 382 | void komodo_passport_iteration() |
ab918767 | 383 | { |
635dd34d | 384 | static long lastpos[34]; static char userpass[33][1024]; |
385 | FILE *fp; int32_t baseid,isrealtime,refid,blocks,longest; struct komodo_state *sp,*refsp; char *retstr,fname[512],*base,symbol[16],dest[16]; uint32_t buf[3]; cJSON *infoobj,*result; uint64_t RTmask = 0; | |
386 | refsp = komodo_stateptr(symbol,dest); | |
ab918767 | 387 | if ( ASSETCHAINS_SYMBOL[0] == 0 ) |
67cd296f | 388 | refid = 33; |
635dd34d | 389 | else refid = komodo_baseid(ASSETCHAINS_SYMBOL)+1; // illegal base -> baseid.-1 -> 0 |
3085016b | 390 | //printf("PASSPORT %s refid.%d\n",ASSETCHAINS_SYMBOL,refid); |
52f1d788 | 391 | for (baseid=0; baseid<=32; baseid++) |
ab918767 | 392 | { |
ecf6256c | 393 | sp = 0; |
394 | isrealtime = 0; | |
f789edde | 395 | base = (char *)CURRENCIES[baseid]; |
95a6016d | 396 | if ( baseid+1 != refid ) |
ab918767 | 397 | { |
055db9b6 | 398 | komodo_statefname(fname,baseid<32?base:(char *)"",(char *)"komodostate"); |
52f1d788 | 399 | komodo_nameset(symbol,dest,base); |
30376a70 | 400 | //port = komodo_port(base,10,&magic) + 1; |
52f1d788 | 401 | if ( (fp= fopen(fname,"rb")) != 0 && (sp= komodo_stateptrget(symbol)) != 0 ) |
ab918767 | 402 | { |
a8f4e85e | 403 | //printf("refid.%d %s fname.(%s) base.%s\n",refid,symbol,fname,base); |
52f1d788 | 404 | fseek(fp,0,SEEK_END); |
405 | if ( ftell(fp) > lastpos[baseid] ) | |
ab918767 | 406 | { |
52f1d788 | 407 | fseek(fp,lastpos[baseid],SEEK_SET); |
408 | while ( komodo_parsestatefile(sp,fp,symbol,dest) >= 0 ) | |
409 | ; | |
410 | lastpos[baseid] = ftell(fp); | |
a9bb99d2 | 411 | //printf("from.(%s) lastpos[%s] %ld\n",ASSETCHAINS_SYMBOL,CURRENCIES[baseid],lastpos[baseid]); |
52f1d788 | 412 | } //else fprintf(stderr,"%s.%ld ",CURRENCIES[baseid],ftell(fp)); |
413 | fclose(fp); | |
ecf6256c | 414 | } |
a7ef556c | 415 | komodo_statefname(fname,baseid<32?base:(char *)"",(char *)"realtime"); |
416 | if ( (fp= fopen(fname,"rb")) != 0 ) | |
417 | { | |
418 | if ( fread(buf,1,sizeof(buf),fp) == sizeof(buf) ) | |
419 | { | |
fe0210c0 | 420 | if ( buf[0] != 0 && buf[0] == buf[1] && buf[2] > time(NULL)-60 ) |
6eb41a2f | 421 | { |
a7ef556c | 422 | isrealtime = 1; |
6eb41a2f | 423 | RTmask |= (1LL << baseid); |
635dd34d | 424 | memcpy(refsp->RTbufs[baseid+1],buf,sizeof(refsp->RTbufs[baseid+1])); |
140fccf8 | 425 | } //else fprintf(stderr,"%s not RT\n",base); |
209dc96c | 426 | } else fprintf(stderr,"%s size error RT\n",base); |
a7ef556c | 427 | fclose(fp); |
209dc96c | 428 | } else fprintf(stderr,"%s open error RT\n",base); |
a7ef556c | 429 | } |
635dd34d | 430 | else |
a7ef556c | 431 | { |
432 | komodo_statefname(fname,baseid<32?base:(char *)"",(char *)"realtime"); | |
433 | if ( (fp= fopen(fname,"wb")) != 0 ) | |
434 | { | |
30376a70 | 435 | buf[0] = (uint32_t)chainActive.Tip()->nHeight; |
a7ef556c | 436 | buf[1] = (uint32_t)komodo_longestchain(); |
437 | if ( buf[0] != 0 && buf[0] == buf[1] ) | |
6eb41a2f | 438 | { |
a7ef556c | 439 | buf[2] = (uint32_t)time(NULL); |
6eb41a2f | 440 | RTmask |= (1LL << baseid); |
635dd34d | 441 | memcpy(refsp->RTbufs[baseid+1],buf,sizeof(refsp->RTbufs[baseid+1])); |
442 | if ( refid != 0 ) | |
443 | memcpy(refsp->RTbufs[0],buf,sizeof(refsp->RTbufs[0])); | |
6eb41a2f | 444 | } |
a7ef556c | 445 | if ( fwrite(buf,1,sizeof(buf),fp) != sizeof(buf) ) |
446 | fprintf(stderr,"[%s] %s error writing realtime\n",ASSETCHAINS_SYMBOL,base); | |
447 | fclose(fp); | |
f789edde | 448 | } else fprintf(stderr,"%s create error RT\n",base); |
ecf6256c | 449 | } |
ecf6256c | 450 | if ( sp != 0 ) |
451 | sp->KOMODO_REALTIME = isrealtime * (uint32_t)time(NULL); | |
52f1d788 | 452 | } |
635dd34d | 453 | refsp->RTmask = RTmask; |
ab918767 | 454 | } |
ab918767 | 455 |