]>
Commit | Line | Data |
---|---|---|
9b0e1808 | 1 | /****************************************************************************** |
37fed603 | 2 | * Copyright © 2014-2017 The SuperNET Developers. * |
9b0e1808 | 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 | |
aa114a60 | 18 | int32_t pax_fiatstatus(uint64_t *available,uint64_t *deposited,uint64_t *issued,uint64_t *withdrawn,uint64_t *approved,uint64_t *redeemed,char *base) |
3cbfd2b4 | 19 | { |
16c7bf6b | 20 | int32_t baseid; struct komodo_state *sp; int64_t netliability,maxallowed,maxval; |
aa114a60 | 21 | *available = *deposited = *issued = *withdrawn = *approved = *redeemed = 0; |
3cbfd2b4 | 22 | if ( (baseid= komodo_baseid(base)) >= 0 ) |
23 | { | |
24 | if ( (sp= komodo_stateptrget(base)) != 0 ) | |
25 | { | |
26 | *deposited = sp->deposited; | |
27 | *issued = sp->issued; | |
28 | *withdrawn = sp->withdrawn; | |
29 | *approved = sp->approved; | |
30 | *redeemed = sp->redeemed; | |
16c7bf6b | 31 | maxval = sp->approved; |
32 | if ( sp->withdrawn > maxval ) | |
33 | maxval = sp->withdrawn; | |
34 | netliability = (sp->issued - maxval) - sp->shorted; | |
aa114a60 | 35 | maxallowed = komodo_maxallowed(baseid); |
36 | if ( netliability < maxallowed ) | |
37 | *available = (maxallowed - netliability); | |
68025c1c | 38 | //printf("%llu - %llu %s %.8f %.8f %.8f %.8f %.8f\n",(long long)maxallowed,(long long)netliability,base,dstr(*deposited),dstr(*issued),dstr(*withdrawn),dstr(*approved),dstr(*redeemed)); |
3cbfd2b4 | 39 | return(0); |
ee5e5744 | 40 | } else printf("pax_fiatstatus cant get basesp.%s\n",base); |
106a1d04 | 41 | } // else printf("pax_fiatstatus illegal base.%s\n",base); |
3cbfd2b4 | 42 | return(-1); |
43 | } | |
44 | ||
51e5d952 | 45 | void pax_keyset(uint8_t *buf,uint256 txid,uint16_t vout,uint8_t type) |
6210f328 | 46 | { |
51e5d952 | 47 | memcpy(buf,&txid,32); |
48 | memcpy(&buf[32],&vout,2); | |
49 | buf[34] = type; | |
50 | } | |
51 | ||
52 | struct pax_transaction *komodo_paxfind(uint256 txid,uint16_t vout,uint8_t type) | |
53 | { | |
54 | struct pax_transaction *pax; uint8_t buf[35]; | |
6210f328 | 55 | pthread_mutex_lock(&komodo_mutex); |
51e5d952 | 56 | pax_keyset(buf,txid,vout,type); |
57 | HASH_FIND(hh,PAX,buf,sizeof(buf),pax); | |
6210f328 | 58 | pthread_mutex_unlock(&komodo_mutex); |
59 | return(pax); | |
60 | } | |
61 | ||
16cd9f2d | 62 | struct pax_transaction *komodo_paxfinds(uint256 txid,uint16_t vout) |
c5c0e527 | 63 | { |
2aba5e49 | 64 | struct pax_transaction *pax; int32_t i; uint8_t types[] = { 'I', 'D', 'X', 'A', 'W' }; |
16cd9f2d | 65 | for (i=0; i<sizeof(types)/sizeof(*types); i++) |
66 | if ( (pax= komodo_paxfind(txid,vout,types[i])) != 0 ) | |
8dfdb3d0 | 67 | return(pax); |
c5c0e527 | 68 | return(0); |
69 | } | |
70 | ||
51e5d952 | 71 | struct pax_transaction *komodo_paxmark(int32_t height,uint256 txid,uint16_t vout,uint8_t type,int32_t mark) |
6210f328 | 72 | { |
51e5d952 | 73 | struct pax_transaction *pax; uint8_t buf[35]; |
6210f328 | 74 | pthread_mutex_lock(&komodo_mutex); |
51e5d952 | 75 | pax_keyset(buf,txid,vout,type); |
76 | HASH_FIND(hh,PAX,buf,sizeof(buf),pax); | |
2ab43fd2 | 77 | if ( pax == 0 ) |
78 | { | |
79 | pax = (struct pax_transaction *)calloc(1,sizeof(*pax)); | |
80 | pax->txid = txid; | |
81 | pax->vout = vout; | |
51e5d952 | 82 | pax->type = type; |
83 | memcpy(pax->buf,buf,sizeof(pax->buf)); | |
84 | HASH_ADD_KEYPTR(hh,PAX,pax->buf,sizeof(pax->buf),pax); | |
32d525eb | 85 | //printf("ht.%d create pax.%p mark.%d\n",height,pax,mark); |
2ab43fd2 | 86 | } |
6210f328 | 87 | if ( pax != 0 ) |
649a9ebf | 88 | { |
6210f328 | 89 | pax->marked = mark; |
cfd94f88 | 90 | //if ( height > 214700 || pax->height > 214700 ) |
91 | // printf("mark ht.%d %.8f %.8f\n",pax->height,dstr(pax->komodoshis),dstr(pax->fiatoshis)); | |
649a9ebf | 92 | |
93 | } | |
6210f328 | 94 | pthread_mutex_unlock(&komodo_mutex); |
95 | return(pax); | |
96 | } | |
429dabb5 | 97 | |
57f349cb | 98 | void komodo_paxdelete(struct pax_transaction *pax) |
99 | { | |
5720de88 | 100 | return; // breaks when out of order |
57f349cb | 101 | pthread_mutex_lock(&komodo_mutex); |
102 | HASH_DELETE(hh,PAX,pax); | |
103 | pthread_mutex_unlock(&komodo_mutex); | |
104 | } | |
105 | ||
51e5d952 | 106 | void komodo_gateway_deposit(char *coinaddr,uint64_t value,char *symbol,uint64_t fiatoshis,uint8_t *rmd160,uint256 txid,uint16_t vout,uint8_t type,int32_t height,int32_t otherheight,char *source,int32_t approved) // assetchain context |
d43c7a93 | 107 | { |
51e5d952 | 108 | struct pax_transaction *pax; uint8_t buf[35]; int32_t addflag = 0; struct komodo_state *sp; char str[16],dest[16],*s; |
717dfab6 | 109 | //if ( KOMODO_PAX == 0 ) |
110 | // return; | |
4a6d9acb | 111 | //if ( strcmp(symbol,ASSETCHAINS_SYMBOL) != 0 ) |
112 | // return; | |
bffa91b2 | 113 | sp = komodo_stateptr(str,dest); |
d43c7a93 | 114 | pthread_mutex_lock(&komodo_mutex); |
51e5d952 | 115 | pax_keyset(buf,txid,vout,type); |
116 | HASH_FIND(hh,PAX,buf,sizeof(buf),pax); | |
d43c7a93 | 117 | if ( pax == 0 ) |
b2d64a0f | 118 | { |
d43c7a93 | 119 | pax = (struct pax_transaction *)calloc(1,sizeof(*pax)); |
8d52488f | 120 | pax->txid = txid; |
121 | pax->vout = vout; | |
51e5d952 | 122 | pax->type = type; |
123 | memcpy(pax->buf,buf,sizeof(pax->buf)); | |
124 | HASH_ADD_KEYPTR(hh,PAX,pax->buf,sizeof(pax->buf),pax); | |
7961668b | 125 | addflag = 1; |
f3159f77 | 126 | if ( 0 && ASSETCHAINS_SYMBOL[0] == 0 ) |
1fc75a27 | 127 | { |
128 | int32_t i; for (i=0; i<32; i++) | |
129 | printf("%02x",((uint8_t *)&txid)[i]); | |
5ce8bf22 | 130 | printf(" v.%d [%s] kht.%d ht.%d create pax.%p symbol.%s source.%s\n",vout,ASSETCHAINS_SYMBOL,height,otherheight,pax,symbol,source); |
1fc75a27 | 131 | } |
b2d64a0f | 132 | } |
8d52488f | 133 | pthread_mutex_unlock(&komodo_mutex); |
d43c7a93 | 134 | if ( coinaddr != 0 ) |
135 | { | |
136 | strcpy(pax->coinaddr,coinaddr); | |
9ccd3f33 | 137 | if ( value != 0 ) |
138 | pax->komodoshis = value; | |
139 | if ( symbol != 0 ) | |
140 | strcpy(pax->symbol,symbol); | |
cd26c1f3 | 141 | if ( source != 0 ) |
142 | strcpy(pax->source,source); | |
9ccd3f33 | 143 | if ( fiatoshis != 0 ) |
144 | pax->fiatoshis = fiatoshis; | |
145 | if ( rmd160 != 0 ) | |
146 | memcpy(pax->rmd160,rmd160,20); | |
147 | if ( height != 0 ) | |
148 | pax->height = height; | |
149 | if ( otherheight != 0 ) | |
150 | pax->otherheight = otherheight; | |
d43c7a93 | 151 | } |
152 | else | |
153 | { | |
154 | pax->marked = height; | |
bff51d67 | 155 | //printf("pax.%p MARK DEPOSIT ht.%d other.%d\n",pax,height,otherheight); |
d43c7a93 | 156 | } |
d43c7a93 | 157 | } |
158 | ||
7cc6844b | 159 | int32_t komodo_rwapproval(int32_t rwflag,uint8_t *opretbuf,struct pax_transaction *pax) |
160 | { | |
161 | int32_t i,len = 0; | |
ddf827b2 | 162 | if ( rwflag == 1 ) |
163 | { | |
164 | for (i=0; i<32; i++) | |
165 | opretbuf[len++] = ((uint8_t *)&pax->txid)[i]; | |
166 | opretbuf[len++] = pax->vout & 0xff; | |
167 | opretbuf[len++] = (pax->vout >> 8) & 0xff; | |
168 | } | |
169 | else | |
170 | { | |
171 | for (i=0; i<32; i++) | |
a6972662 | 172 | ((uint8_t *)&pax->txid)[i] = opretbuf[len++]; |
bff51d67 | 173 | //for (i=0; i<32; i++) |
174 | // printf("%02x",((uint8_t *)&pax->txid)[31-i]); | |
ddf827b2 | 175 | pax->vout = opretbuf[len++]; |
176 | pax->vout += ((uint32_t)opretbuf[len++] << 8); | |
bff51d67 | 177 | //printf(" txid v.%d\n",pax->vout); |
ddf827b2 | 178 | } |
ad66994d | 179 | len += iguana_rwnum(rwflag,&opretbuf[len],sizeof(pax->komodoshis),&pax->komodoshis); |
ddf827b2 | 180 | len += iguana_rwnum(rwflag,&opretbuf[len],sizeof(pax->fiatoshis),&pax->fiatoshis); |
181 | len += iguana_rwnum(rwflag,&opretbuf[len],sizeof(pax->height),&pax->height); | |
182 | len += iguana_rwnum(rwflag,&opretbuf[len],sizeof(pax->otherheight),&pax->otherheight); | |
183 | if ( rwflag != 0 ) | |
184 | { | |
185 | memcpy(&opretbuf[len],pax->rmd160,20), len += 20; | |
186 | for (i=0; i<4; i++) | |
187 | opretbuf[len++] = pax->source[i]; | |
188 | } | |
189 | else | |
190 | { | |
191 | memcpy(pax->rmd160,&opretbuf[len],20), len += 20; | |
192 | for (i=0; i<4; i++) | |
193 | pax->source[i] = opretbuf[len++]; | |
194 | } | |
7cc6844b | 195 | return(len); |
196 | } | |
197 | ||
b89ab77c | 198 | int32_t komodo_issued_opreturn(char *base,uint256 *txids,uint16_t *vouts,int64_t *values,int64_t *srcvalues,int32_t *kmdheights,int32_t *otherheights,int8_t *baseids,uint8_t *rmd160s,uint8_t *opretbuf,int32_t opretlen,int32_t iskomodo) |
63b289ad | 199 | { |
54661780 | 200 | struct pax_transaction p,*pax; int32_t i,n=0,j,len=0,incr,height,otherheight; uint8_t type,rmd160[20]; uint64_t fiatoshis; char symbol[16]; |
717dfab6 | 201 | //if ( KOMODO_PAX == 0 ) |
202 | // return(0); | |
c83633f8 | 203 | incr = 34 + (iskomodo * (2*sizeof(fiatoshis) + 2*sizeof(height) + 20 + 4)); |
085c4ee4 | 204 | //41e77b91cb68dc2aa02fa88550eae6b6d44db676a7e935337b6d1392d9718f03cb0200305c90660400000000fbcbeb1f000000bde801006201000058e7945ad08ddba1eac9c9b6c8e1e97e8016a2d152 |
8b4d7f27 | 205 | |
206 | // 41e94d736ec69d88c08b5d238abeeca609c02357a8317e0d56c328bcb1c259be5d0200485bc80200000000404b4c000000000059470200b80b000061f22ba7d19fe29ac3baebd839af8b7127d1f9075553440046bb4cc7a3b5cd39dffe7206507a3482a00780e617f68b273cce9817ed69298d02001069ca1b0000000080f0fa02000000005b470200b90b000061f22ba7d19fe29ac3baebd839af8b7127d1f90755 | |
207 | ||
40f3d9cc | 208 | //for (i=0; i<opretlen; i++) |
209 | // printf("%02x",opretbuf[i]); | |
b3183e3e | 210 | //printf(" opretlen.%d (%s)\n",opretlen,base); |
40f3d9cc | 211 | //printf(" opretlen.%d vs %d incr.%d (%d)\n",opretlen,(int32_t)(2*sizeof(fiatoshis) + 2*sizeof(height) + 20 + 2),incr,opretlen/incr); |
c3152c23 | 212 | //if ( ASSETCHAINS_SYMBOL[0] == 0 || strncmp(ASSETCHAINS_SYMBOL,base,strlen(base)) == 0 ) |
63b289ad | 213 | { |
947d956f | 214 | type = opretbuf[0]; |
63b289ad | 215 | opretbuf++, opretlen--; |
e8433f7a | 216 | for (n=0; n<opretlen/incr; n++) |
63b289ad | 217 | { |
05d91eb2 | 218 | if ( iskomodo != 0 ) |
219 | { | |
e8433f7a | 220 | memset(&p,0,sizeof(p)); |
ffec138e | 221 | len += komodo_rwapproval(0,&opretbuf[len],&p); |
b89ab77c | 222 | if ( values != 0 && srcvalues != 0 && kmdheights != 0 && otherheights != 0 && baseids != 0 && rmd160s != 0 ) |
1ed46112 | 223 | { |
63342b19 | 224 | txids[n] = p.txid; |
225 | vouts[n] = p.vout; | |
c65d0868 | 226 | values[n] = (strcmp("KMD",base) == 0) ? p.komodoshis : p.fiatoshis; |
227 | srcvalues[n] = (strcmp("KMD",base) == 0) ? p.fiatoshis : p.komodoshis; | |
a3f1fb69 | 228 | kmdheights[n] = p.height; |
229 | otherheights[n] = p.otherheight; | |
7cc6844b | 230 | memcpy(&rmd160s[n * 20],p.rmd160,20); |
1dbea872 | 231 | baseids[n] = komodo_baseid(p.source); |
109afe64 | 232 | if ( 0 ) |
71c9af7c | 233 | { |
234 | char coinaddr[64]; | |
235 | bitcoin_address(coinaddr,60,&rmd160s[n * 20],20); | |
947d956f | 236 | printf(">>>>>>> %s: (%s) fiat %.8f kmdheight.%d other.%d -> %s %.8f\n",type=='A'?"approvedA":"issuedX",baseids[n]>=0?CURRENCIES[baseids[n]]:"???",dstr(p.fiatoshis),kmdheights[n],otherheights[n],coinaddr,dstr(values[n])); |
71c9af7c | 237 | } |
52e87248 | 238 | } |
05d91eb2 | 239 | } |
7cc6844b | 240 | else |
241 | { | |
5cb9312f | 242 | for (i=0; i<4; i++) |
243 | base[i] = opretbuf[opretlen-4+i]; | |
7cc6844b | 244 | for (j=0; j<32; j++) |
245 | { | |
246 | ((uint8_t *)&txids[n])[j] = opretbuf[len++]; | |
a13467f5 | 247 | //printf("%02x",((uint8_t *)&txids[n])[j]); |
7cc6844b | 248 | } |
249 | vouts[n] = opretbuf[len++]; | |
250 | vouts[n] = (opretbuf[len++] << 8) | vouts[n]; | |
cb3bf8df | 251 | baseids[n] = komodo_baseid(base); |
16cd9f2d | 252 | if ( (pax= komodo_paxfinds(txids[n],vouts[n])) != 0 ) |
54661780 | 253 | { |
c3152c23 | 254 | values[n] = (strcmp("KMD",base) == 0) ? pax->komodoshis : pax->fiatoshis; |
255 | srcvalues[n] = (strcmp("KMD",base) == 0) ? pax->fiatoshis : pax->komodoshis; | |
54661780 | 256 | kmdheights[n] = pax->height; |
257 | otherheights[n] = pax->otherheight; | |
258 | memcpy(&rmd160s[n * 20],pax->rmd160,20); | |
259 | } | |
7cc6844b | 260 | } |
a13467f5 | 261 | //printf(" komodo_issued_opreturn issuedtxid v%d i.%d opretlen.%d\n",vouts[n],n,opretlen); |
63b289ad | 262 | } |
263 | } | |
264 | return(n); | |
265 | } | |
266 | ||
865bd972 | 267 | int32_t komodo_paxcmp(char *symbol,int32_t kmdheight,uint64_t value,uint64_t checkvalue,uint64_t seed) |
268 | { | |
269 | int32_t ratio; | |
270 | if ( seed == 0 && checkvalue != 0 ) | |
271 | { | |
272 | ratio = ((value << 6) / checkvalue); | |
5e9f4470 | 273 | if ( ratio >= 62 && ratio <= 66 ) |
865bd972 | 274 | return(0); |
275 | else | |
276 | { | |
7d935b7e | 277 | if ( kmdheight >= 238000 ) |
865bd972 | 278 | printf("ht.%d ignore mismatched %s value %lld vs checkvalue %lld -> ratio.%d\n",kmdheight,symbol,(long long)value,(long long)checkvalue,ratio); |
279 | return(-1); | |
280 | } | |
281 | } | |
282 | else if ( checkvalue != 0 ) | |
283 | { | |
284 | ratio = ((value << 10) / checkvalue); | |
285 | if ( ratio >= 1023 && ratio <= 1025 ) | |
286 | return(0); | |
287 | } | |
288 | return(value != checkvalue); | |
289 | } | |
290 | ||
f1db88ea | 291 | uint64_t komodo_paxtotal() |
292 | { | |
a73709a3 | 293 | struct pax_transaction *pax,*pax2,*tmp,*tmp2; char symbol[16],dest[16],*str; int32_t i,ht; int64_t checktoshis; uint64_t seed,total = 0; struct komodo_state *basesp; |
717dfab6 | 294 | if ( KOMODO_PASSPORT_INITDONE == 0 ) //KOMODO_PAX == 0 || |
6cd01056 | 295 | return(0); |
48a3cd18 | 296 | if ( komodo_isrealtime(&ht) == 0 ) |
f1db88ea | 297 | return(0); |
ca75995d | 298 | else |
299 | { | |
300 | HASH_ITER(hh,PAX,pax,tmp) | |
301 | { | |
5ccb222a | 302 | if ( pax->marked != 0 ) |
303 | continue; | |
85779087 | 304 | if ( pax->type == 'A' || pax->type == 'D' || pax->type == 'X' ) |
305 | str = pax->symbol; | |
306 | else str = pax->source; | |
307 | basesp = komodo_stateptrget(str); | |
115e6a5c | 308 | if ( basesp != 0 && pax->didstats == 0 ) |
ca75995d | 309 | { |
6e458bf3 | 310 | if ( pax->type == 'I' && (pax2= komodo_paxfind(pax->txid,pax->vout,'D')) != 0 ) |
ca75995d | 311 | { |
3cfd4837 | 312 | if ( pax2->fiatoshis != 0 ) |
313 | { | |
314 | pax->komodoshis = pax2->komodoshis; | |
315 | pax->fiatoshis = pax2->fiatoshis; | |
316 | basesp->issued += pax->fiatoshis; | |
317 | pax->didstats = 1; | |
54f87e10 | 318 | if ( strcmp(str,ASSETCHAINS_SYMBOL) == 0 ) |
319 | printf("########### %p issued %s += %.8f kmdheight.%d %.8f other.%d\n",basesp,str,dstr(pax->fiatoshis),pax->height,dstr(pax->komodoshis),pax->otherheight); | |
c3111e7b | 320 | pax2->marked = pax->height; |
54f87e10 | 321 | pax->marked = pax->height; |
3cfd4837 | 322 | } |
fa81b5ae | 323 | } |
115e6a5c | 324 | else if ( pax->type == 'W' ) |
325 | { | |
431af13e | 326 | //bitcoin_address(coinaddr,addrtype,rmd160,20); |
1bc5fdf8 | 327 | if ( (checktoshis= komodo_paxprice(&seed,pax->height,pax->source,(char *)"KMD",(uint64_t)pax->fiatoshis)) != 0 ) |
328 | { | |
db7becdc | 329 | if ( komodo_paxcmp(pax->source,pax->height,pax->komodoshis,checktoshis,seed) != 0 ) |
772c13de | 330 | { |
1bc5fdf8 | 331 | pax->marked = pax->height; |
60cd57df | 332 | //printf("WITHDRAW.%s mark <- %d %.8f != %.8f\n",pax->source,pax->height,dstr(checktoshis),dstr(pax->komodoshis)); |
772c13de | 333 | } |
1bc5fdf8 | 334 | else if ( pax->validated == 0 ) |
335 | { | |
d4003105 | 336 | pax->validated = pax->komodoshis = checktoshis; |
109afe64 | 337 | //int32_t j; for (j=0; j<32; j++) |
338 | // printf("%02x",((uint8_t *)&pax->txid)[j]); | |
2405bc66 | 339 | //if ( strcmp(str,ASSETCHAINS_SYMBOL) == 0 ) |
109afe64 | 340 | // printf(" v%d %p got WITHDRAW.%s kmd.%d ht.%d %.8f -> %.8f/%.8f\n",pax->vout,pax,pax->source,pax->height,pax->otherheight,dstr(pax->fiatoshis),dstr(pax->komodoshis),dstr(checktoshis)); |
1bc5fdf8 | 341 | } |
342 | } | |
115e6a5c | 343 | } |
ca75995d | 344 | } |
345 | } | |
346 | } | |
ede04b12 | 347 | komodo_stateptr(symbol,dest); |
f1db88ea | 348 | HASH_ITER(hh,PAX,pax,tmp) |
349 | { | |
115e6a5c | 350 | pax->ready = 0; |
16cd9f2d | 351 | if ( 0 && pax->type == 'A' ) |
352 | printf("%p pax.%s <- %s marked.%d %.8f -> %.8f validated.%d approved.%d\n",pax,pax->symbol,pax->source,pax->marked,dstr(pax->komodoshis),dstr(pax->fiatoshis),pax->validated != 0,pax->approved != 0); | |
5ccb222a | 353 | if ( pax->marked != 0 ) |
354 | continue; | |
cfa1fdda | 355 | if ( strcmp(symbol,pax->symbol) == 0 || pax->type == 'A' ) |
f1db88ea | 356 | { |
ede04b12 | 357 | if ( pax->marked == 0 ) |
358 | { | |
359 | if ( komodo_is_issuer() != 0 ) | |
1bc5fdf8 | 360 | { |
0449e3f0 | 361 | if ( pax->validated != 0 && pax->type == 'D' ) |
1bc5fdf8 | 362 | { |
363 | total += pax->fiatoshis; | |
364 | pax->ready = 1; | |
365 | } | |
366 | } | |
371a9c87 | 367 | else if ( pax->approved != 0 && pax->type == 'A' ) |
992c3be5 | 368 | { |
369 | if ( pax->validated != 0 ) | |
02c36c15 | 370 | { |
992c3be5 | 371 | total += pax->komodoshis; |
02c36c15 | 372 | pax->ready = 1; |
373 | } | |
992c3be5 | 374 | else |
375 | { | |
376 | seed = 0; | |
f186b8a1 | 377 | checktoshis = komodo_paxprice(&seed,pax->height,pax->source,(char *)"KMD",(uint64_t)pax->fiatoshis); |
9ae3d21c | 378 | //printf("paxtotal PAX_fiatdest ht.%d price %s %.8f -> KMD %.8f vs %.8f\n",pax->height,pax->symbol,(double)pax->fiatoshis/COIN,(double)pax->komodoshis/COIN,(double)checktoshis/COIN); |
379 | //printf(" v%d %.8f k.%d ht.%d\n",pax->vout,dstr(pax->komodoshis),pax->height,pax->otherheight); | |
6e458bf3 | 380 | if ( seed != 0 && checktoshis != 0 ) |
992c3be5 | 381 | { |
115e6a5c | 382 | if ( checktoshis == pax->komodoshis ) |
992c3be5 | 383 | { |
384 | total += pax->komodoshis; | |
385 | pax->validated = pax->komodoshis; | |
115e6a5c | 386 | pax->ready = 1; |
992c3be5 | 387 | } else pax->marked = pax->height; |
388 | } | |
389 | } | |
390 | } | |
a8ffc9b9 | 391 | if ( 0 && pax->ready != 0 ) |
649a9ebf | 392 | printf("%p (%c) pax.%s marked.%d %.8f -> %.8f validated.%d approved.%d ready.%d ht.%d\n",pax,pax->type,pax->symbol,pax->marked,dstr(pax->komodoshis),dstr(pax->fiatoshis),pax->validated != 0,pax->approved != 0,pax->ready,pax->height); |
ede04b12 | 393 | } |
f1db88ea | 394 | } |
395 | } | |
5481c677 | 396 | //printf("paxtotal %.8f\n",dstr(total)); |
f1db88ea | 397 | return(total); |
398 | } | |
399 | ||
fa1a55cd | 400 | static int _paxorder(const void *a,const void *b) |
f360ea0a | 401 | { |
fa1a55cd | 402 | #define pax_a (*(struct pax_transaction **)a) |
403 | #define pax_b (*(struct pax_transaction **)b) | |
404 | uint64_t aval,bval; | |
d936b97f | 405 | aval = pax_a->fiatoshis + pax_a->komodoshis + pax_a->height; |
406 | bval = pax_b->fiatoshis + pax_b->komodoshis + pax_b->height; | |
fa1a55cd | 407 | if ( bval > aval ) |
408 | return(-1); | |
409 | else if ( bval < aval ) | |
410 | return(1); | |
411 | return(0); | |
412 | #undef pax_a | |
413 | #undef pax_b | |
414 | } | |
415 | ||
416 | int32_t komodo_pending_withdraws(char *opretstr) // todo: enforce deterministic order | |
417 | { | |
6b3eb2c4 | 418 | struct pax_transaction *pax,*pax2,*tmp,*paxes[64]; uint8_t opretbuf[16384]; int32_t i,n,ht,len=0; uint64_t total = 0; |
9aefc81b | 419 | if ( KOMODO_PAX == 0 || KOMODO_PASSPORT_INITDONE == 0 ) |
6cd01056 | 420 | return(0); |
f360ea0a | 421 | if ( komodo_isrealtime(&ht) == 0 || ASSETCHAINS_SYMBOL[0] != 0 ) |
422 | return(0); | |
fa1a55cd | 423 | n = 0; |
f360ea0a | 424 | HASH_ITER(hh,PAX,pax,tmp) |
425 | { | |
f1e6a937 | 426 | if ( pax->type == 'W' ) |
f360ea0a | 427 | { |
6b3eb2c4 | 428 | if ( (pax2= komodo_paxfind(pax->txid,pax->vout,'A')) != 0 ) |
429 | { | |
430 | if ( pax2->approved != 0 ) | |
431 | pax->approved = pax2->approved; | |
432 | } | |
16cd9f2d | 433 | else if ( (pax2= komodo_paxfind(pax->txid,pax->vout,'X')) != 0 ) |
0b262b65 | 434 | pax->approved = pax->height; |
01d3b36a | 435 | //printf("pending_withdraw: pax %s marked.%u approved.%u validated.%llu\n",pax->symbol,pax->marked,pax->approved,(long long)pax->validated); |
7d121b40 | 436 | if ( pax->marked == 0 && pax->approved == 0 && pax->validated != 0 ) //strcmp((char *)"KMD",pax->symbol) == 0 && |
f1e6a937 | 437 | { |
fa1a55cd | 438 | if ( n < sizeof(paxes)/sizeof(*paxes) ) |
ac4eb454 | 439 | { |
fa1a55cd | 440 | paxes[n++] = pax; |
2e575216 | 441 | //int32_t j; for (j=0; j<32; j++) |
442 | // printf("%02x",((uint8_t *)&pax->txid)[j]); | |
443 | //printf(" %s.(kmdht.%d ht.%d marked.%u approved.%d validated %.8f) %.8f\n",pax->source,pax->height,pax->otherheight,pax->marked,pax->approved,dstr(pax->validated),dstr(pax->komodoshis)); | |
ac4eb454 | 444 | } |
f1e6a937 | 445 | } |
f360ea0a | 446 | } |
447 | } | |
fa1a55cd | 448 | opretstr[0] = 0; |
449 | if ( n > 0 ) | |
450 | { | |
451 | opretbuf[len++] = 'A'; | |
452 | qsort(paxes,n,sizeof(*paxes),_paxorder); | |
453 | for (i=0; i<n; i++) | |
454 | { | |
455 | if ( len < (sizeof(opretbuf)>>3)*7 ) | |
456 | len += komodo_rwapproval(1,&opretbuf[len],paxes[i]); | |
457 | } | |
458 | if ( len > 0 ) | |
459 | init_hexbytes_noT(opretstr,opretbuf,len); | |
460 | } | |
132aea8c | 461 | //fprintf(stderr,"komodo_pending_withdraws len.%d PAXTOTAL %.8f\n",len,dstr(komodo_paxtotal())); |
f360ea0a | 462 | return(len); |
463 | } | |
a4c67285 | 464 | |
635dd34d | 465 | int32_t komodo_gateway_deposits(CMutableTransaction *txNew,char *base,int32_t tokomodo) |
429dabb5 | 466 | { |
1bf41050 | 467 | struct pax_transaction *pax,*tmp; char symbol[16],dest[16]; uint8_t *script,opcode,opret[16384],data[16384]; int32_t i,baseid,ht,len=0,opretlen=0,numvouts=1; struct komodo_state *sp; uint64_t available,deposited,issued,withdrawn,approved,redeemed,mask,sum = 0; |
717dfab6 | 468 | if ( KOMODO_PASSPORT_INITDONE == 0 )//KOMODO_PAX == 0 || |
6cd01056 | 469 | return(0); |
76d59c1d | 470 | struct komodo_state *kmdsp = komodo_stateptrget((char *)"KMD"); |
635dd34d | 471 | sp = komodo_stateptr(symbol,dest); |
27bf3c5e | 472 | strcpy(symbol,base); |
b27b2877 | 473 | if ( ASSETCHAINS_SYMBOL[0] != 0 && komodo_baseid(ASSETCHAINS_SYMBOL) < 0 ) |
716fb382 | 474 | return(0); |
429dabb5 | 475 | PENDING_KOMODO_TX = 0; |
b8cceac5 | 476 | for (i=0; i<3; i++) |
477 | { | |
478 | if ( komodo_isrealtime(&ht) != 0 ) | |
479 | break; | |
480 | sleep(1); | |
481 | } | |
482 | if ( i == 3 ) | |
483 | { | |
deba1c48 | 484 | if ( tokomodo == 0 ) |
485 | printf("%s not realtime ht.%d\n",ASSETCHAINS_SYMBOL,ht); | |
b8cceac5 | 486 | return(0); |
487 | } | |
a3f23ee2 | 488 | if ( tokomodo == 0 ) |
48e96ba1 | 489 | { |
77be6cd9 | 490 | opcode = 'I'; |
57f349cb | 491 | } |
492 | else | |
493 | { | |
494 | opcode = 'X'; | |
74d67d42 | 495 | if ( 1 || komodo_paxtotal() == 0 ) |
57f349cb | 496 | return(0); |
497 | } | |
c169f64b | 498 | HASH_ITER(hh,PAX,pax,tmp) |
429dabb5 | 499 | { |
8b4d7f27 | 500 | if ( pax->type != 'D' && pax->type != 'A' ) |
501 | continue; | |
aa114a60 | 502 | { |
503 | #ifdef KOMODO_ASSETCHAINS_WAITNOTARIZE | |
1d474f88 | 504 | if ( pax->height > 236000 ) |
89ede5f3 | 505 | { |
8aed5783 | 506 | if ( kmdsp != 0 && kmdsp->NOTARIZED_HEIGHT >= pax->height ) |
89ede5f3 | 507 | pax->validated = pax->komodoshis; |
508 | else if ( kmdsp->CURRENT_HEIGHT > pax->height+30 ) | |
509 | pax->validated = pax->ready = 0; | |
510 | } | |
511 | else | |
512 | { | |
513 | if ( kmdsp != 0 && (kmdsp->NOTARIZED_HEIGHT >= pax->height || kmdsp->CURRENT_HEIGHT > pax->height+30) ) // assumes same chain as notarize | |
514 | pax->validated = pax->komodoshis; | |
515 | else pax->validated = pax->ready = 0; | |
516 | } | |
13c01d29 | 517 | #else |
518 | pax->validated = pax->komodoshis; | |
aa114a60 | 519 | #endif |
520 | } | |
25d878f4 | 521 | if ( ASSETCHAINS_SYMBOL[0] != 0 && (pax_fiatstatus(&available,&deposited,&issued,&withdrawn,&approved,&redeemed,symbol) != 0 || available < pax->fiatoshis) ) |
1c05f0b5 | 522 | { |
dd36961a | 523 | //if ( pax->height > 214700 || strcmp(ASSETCHAINS_SYMBOL,symbol) == 0 ) |
524 | // printf("miner.[%s]: skip %s %.8f when avail %.8f deposited %.8f, issued %.8f withdrawn %.8f approved %.8f redeemed %.8f\n",ASSETCHAINS_SYMBOL,symbol,dstr(pax->fiatoshis),dstr(available),dstr(deposited),dstr(issued),dstr(withdrawn),dstr(approved),dstr(redeemed)); | |
4502c41e | 525 | continue; |
1c05f0b5 | 526 | } |
274dd7a5 | 527 | /*printf("pax.%s marked.%d %.8f -> %.8f ready.%d validated.%d\n",pax->symbol,pax->marked,dstr(pax->komodoshis),dstr(pax->fiatoshis),pax->ready!=0,pax->validated!=0); |
02c36c15 | 528 | if ( pax->marked != 0 || (pax->type != 'D' && pax->type != 'A') || pax->ready == 0 ) |
a06196fe | 529 | { |
530 | printf("reject 2\n"); | |
e5430f52 | 531 | continue; |
274dd7a5 | 532 | }*/ |
a822a070 | 533 | if ( ASSETCHAINS_SYMBOL[0] != 0 && (strcmp(pax->symbol,symbol) != 0 || pax->validated == 0 || pax->ready == 0) ) |
8bd946ce | 534 | { |
a8ffc9b9 | 535 | if ( strcmp(pax->symbol,ASSETCHAINS_SYMBOL) == 0 ) |
a822a070 | 536 | printf("pax->symbol.%s != %s or null pax->validated %.8f ready.%d ht.(%d %d)\n",pax->symbol,symbol,dstr(pax->validated),pax->ready,kmdsp->CURRENT_HEIGHT,pax->height); |
c495a60a | 537 | pax->marked = pax->height; |
8bd946ce | 538 | continue; |
539 | } | |
fc40c343 | 540 | if ( pax->ready == 0 ) |
541 | continue; | |
582c6afe | 542 | if ( pax->type == 'A' && ASSETCHAINS_SYMBOL[0] == 0 ) |
543 | { | |
76d59c1d | 544 | if ( kmdsp != 0 ) |
582c6afe | 545 | { |
546 | if ( (baseid= komodo_baseid(pax->symbol)) < 0 || ((1LL << baseid) & sp->RTmask) == 0 ) | |
547 | { | |
548 | printf("not RT for (%s) %llx baseid.%d %llx\n",pax->symbol,(long long)sp->RTmask,baseid,(long long)(1LL<<baseid)); | |
549 | continue; | |
550 | } | |
76d59c1d | 551 | } else continue; |
582c6afe | 552 | } |
553 | ||
5481c677 | 554 | //printf("redeem.%d? (%c) %p pax.%s marked.%d %.8f -> %.8f ready.%d validated.%d approved.%d\n",tokomodo,pax->type,pax,pax->symbol,pax->marked,dstr(pax->komodoshis),dstr(pax->fiatoshis),pax->ready!=0,pax->validated!=0,pax->approved!=0); |
49058e97 | 555 | if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 ) |
635dd34d | 556 | printf("pax.%s marked.%d %.8f -> %.8f\n",ASSETCHAINS_SYMBOL,pax->marked,dstr(pax->komodoshis),dstr(pax->fiatoshis)); |
1bf41050 | 557 | if ( opcode == 'I' ) |
558 | { | |
559 | sum += pax->fiatoshis; | |
560 | if ( sum > available ) | |
561 | break; | |
562 | } | |
e5430f52 | 563 | txNew->vout.resize(numvouts+1); |
1fc75a27 | 564 | txNew->vout[numvouts].nValue = (opcode == 'I') ? pax->fiatoshis : pax->komodoshis; |
e5430f52 | 565 | txNew->vout[numvouts].scriptPubKey.resize(25); |
566 | script = (uint8_t *)&txNew->vout[numvouts].scriptPubKey[0]; | |
567 | *script++ = 0x76; | |
568 | *script++ = 0xa9; | |
569 | *script++ = 20; | |
570 | memcpy(script,pax->rmd160,20), script += 20; | |
571 | *script++ = 0x88; | |
572 | *script++ = 0xac; | |
a3f23ee2 | 573 | if ( tokomodo == 0 ) |
16bed6ac | 574 | { |
575 | for (i=0; i<32; i++) | |
16bed6ac | 576 | data[len++] = ((uint8_t *)&pax->txid)[i]; |
16bed6ac | 577 | data[len++] = pax->vout & 0xff; |
578 | data[len++] = (pax->vout >> 8) & 0xff; | |
e5430f52 | 579 | PENDING_KOMODO_TX += pax->fiatoshis; |
16bed6ac | 580 | } |
fbc4209b | 581 | else |
582 | { | |
e0357628 | 583 | len += komodo_rwapproval(1,&data[len],pax); |
fbc4209b | 584 | PENDING_KOMODO_TX += pax->komodoshis; |
1eaffd74 | 585 | printf(" len.%d vout.%u DEPOSIT %.8f <- pax.%s pending ht %d %d %.8f | ",len,pax->vout,(double)txNew->vout[numvouts].nValue/COIN,symbol,pax->height,pax->otherheight,dstr(PENDING_KOMODO_TX)); |
fbc4209b | 586 | } |
c7959ca2 | 587 | if ( numvouts++ >= 64 ) |
e5430f52 | 588 | break; |
429dabb5 | 589 | } |
590 | if ( numvouts > 1 ) | |
591 | { | |
0e3472c1 | 592 | if ( tokomodo != 0 ) |
27bf3c5e | 593 | strcpy(symbol,(char *)"KMD"); |
9ef47e29 | 594 | for (i=0; symbol[i]!=0; i++) |
595 | data[len++] = symbol[i]; | |
a5ad8f02 | 596 | data[len++] = 0; |
16cd9f2d | 597 | for (i=0; i<len; i++) |
598 | printf("%02x",data[i]); | |
599 | printf(" <- data[%d]\n",len); | |
77be6cd9 | 600 | opretlen = komodo_opreturnscript(opret,opcode,data,len); |
50824530 | 601 | txNew->vout.resize(numvouts+1); |
602 | txNew->vout[numvouts].nValue = 0; | |
603 | txNew->vout[numvouts].scriptPubKey.resize(opretlen); | |
604 | script = (uint8_t *)&txNew->vout[numvouts].scriptPubKey[0]; | |
429dabb5 | 605 | memcpy(script,opret,opretlen); |
8b4d7f27 | 606 | for (i=0; i<8; i++) |
607 | printf("%02x",opret[i]); | |
e03bcdd6 | 608 | printf(" <- opret, MINER deposits.%d (%s) vouts.%d %.8f opretlen.%d\n",tokomodo,ASSETCHAINS_SYMBOL,numvouts,dstr(PENDING_KOMODO_TX),opretlen); |
d9a9d562 | 609 | return(1); |
9ef47e29 | 610 | } |
d9a9d562 | 611 | return(0); |
429dabb5 | 612 | } |
613 | ||
5b6fb570 | 614 | const char *banned_txids[] = |
557d9a23 | 615 | { |
6fe17943 | 616 | "78cb4e21245c26b015b888b14c4f5096e18137d2741a6de9734d62b07014dfca", //233559 |
617 | "00697be658e05561febdee1aafe368b821ca33fbb89b7027365e3d77b5dfede5", //234172 | |
618 | "e909465788b32047c472d73e882d79a92b0d550f90be008f76e1edaee6d742ea", //234187 | |
619 | "f56c6873748a327d0b92b8108f8ec8505a2843a541b1926022883678fb24f9dc", //234188 | |
620 | "abf08be07d8f5b3a433ddcca7ef539e79a3571632efd6d0294ec0492442a0204", //234213 | |
621 | "3b854b996cc982fba8c06e76cf507ae7eed52ab92663f4c0d7d10b3ed879c3b0", //234367 | |
622 | "fa9e474c2cda3cb4127881a40eb3f682feaba3f3328307d518589024a6032cc4", //234635 | |
623 | "ca746fa13e0113c4c0969937ea2c66de036d20274efad4ce114f6b699f1bc0f3", //234662 | |
624 | "43ce88438de4973f21b1388ffe66e68fda592da38c6ef939be10bb1b86387041", //234697 | |
625 | "0aeb748de82f209cd5ff7d3a06f65543904c4c17387c9d87c65fd44b14ad8f8c", //234899 | |
626 | "bbd3a3d9b14730991e1066bd7c626ca270acac4127131afe25f877a5a886eb25", //235252 | |
627 | "fa9943525f2e6c32cbc243294b08187e314d83a2870830180380c3c12a9fd33c", //235253 | |
628 | "a01671c8775328a41304e31a6693bbd35e9acbab28ab117f729eaba9cb769461", //235265 | |
629 | "2ef49d2d27946ad7c5d5e4ab5c089696762ff04e855f8ab48e83bdf0cc68726d", //235295 | |
630 | "c85dcffb16d5a45bd239021ad33443414d60224760f11d535ae2063e5709efee", //235296 | |
c2123afe | 631 | // all vouts banned |
14aa6cc0 | 632 | "c4ea1462c207547cd6fb6a4155ca6d042b22170d29801a465db5c09fec55b19d", //246748 |
c2123afe | 633 | "305dc96d8bc23a69d3db955e03a6a87c1832673470c32fe25473a46cc473c7d1", //247204 |
c7a3aca6 | 634 | }; |
635 | ||
c2123afe | 636 | int32_t komodo_bannedset(int32_t *indallvoutsp,uint256 *array,int32_t max) |
c7a3aca6 | 637 | { |
638 | int32_t i; | |
c2123afe | 639 | if ( sizeof(banned_txids)/sizeof(*banned_txids) > max ) |
640 | { | |
641 | fprintf(stderr,"komodo_bannedset: buffer too small %ld vs %d\n",sizeof(banned_txids)/sizeof(*banned_txids),max); | |
642 | exit(-1); | |
643 | } | |
081ab21c | 644 | for (i=0; i<sizeof(banned_txids)/sizeof(*banned_txids); i++) |
645 | array[i] = uint256S(banned_txids[i]); | |
abdf25c8 | 646 | *indallvoutsp = i-2; |
464fe491 | 647 | return(i); |
c7a3aca6 | 648 | } |
649 | ||
db2b1957 | 650 | void komodo_passport_iteration(); |
651 | ||
c7a3aca6 | 652 | int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above block is valid pax pricing |
653 | { | |
c2123afe | 654 | static uint256 array[64]; static int32_t numbanned,indallvouts; |
ab0442fc | 655 | int32_t i,j,k,n,ht,baseid,txn_count,activation,num,opretlen,offset=1,errs=0,matched=0,kmdheights[64],otherheights[64]; uint256 hash,txids[64]; char symbol[16],base[16]; uint16_t vouts[64]; int8_t baseids[64]; uint8_t *script,opcode,rmd160s[64*20]; uint64_t total,available,deposited,issued,withdrawn,approved,redeemed; int64_t values[64],srcvalues[64]; struct pax_transaction *pax; struct komodo_state *sp; |
656 | activation = 235300; | |
c7a3aca6 | 657 | if ( *(int32_t *)&array[0] == 0 ) |
c2123afe | 658 | numbanned = komodo_bannedset(&indallvouts,array,(int32_t)(sizeof(array)/sizeof(*array))); |
1ed46112 | 659 | memset(baseids,0xff,sizeof(baseids)); |
660 | memset(values,0,sizeof(values)); | |
b89ab77c | 661 | memset(srcvalues,0,sizeof(srcvalues)); |
f360ea0a | 662 | memset(rmd160s,0,sizeof(rmd160s)); |
1ed46112 | 663 | memset(kmdheights,0,sizeof(kmdheights)); |
664 | memset(otherheights,0,sizeof(otherheights)); | |
c7a3aca6 | 665 | txn_count = block.vtx.size(); |
7f6ddefd | 666 | if ( ASSETCHAINS_SYMBOL[0] == 0 ) |
c7a3aca6 | 667 | { |
7f6ddefd | 668 | for (i=0; i<txn_count; i++) |
c7a3aca6 | 669 | { |
7f6ddefd | 670 | n = block.vtx[i].vin.size(); |
671 | for (j=0; j<n; j++) | |
c7a3aca6 | 672 | { |
c2123afe | 673 | for (k=0; k<numbanned; k++) |
081ab21c | 674 | { |
464fe491 | 675 | if ( block.vtx[i].vin[j].prevout.hash == array[k] && (block.vtx[i].vin[j].prevout.n == 1 || k >= indallvouts) ) |
7f6ddefd | 676 | { |
677 | printf("banned tx.%d being used at ht.%d txi.%d vini.%d\n",k,height,i,j); | |
678 | return(-1); | |
679 | } | |
081ab21c | 680 | } |
c7a3aca6 | 681 | } |
682 | } | |
683 | } | |
684 | n = block.vtx[0].vout.size(); | |
685 | script = (uint8_t *)block.vtx[0].vout[n-1].scriptPubKey.data(); | |
12d47153 | 686 | if ( n <= 2 || script[0] != 0x6a ) |
d083ecd5 | 687 | { |
7bf32ee2 | 688 | int64_t val,prevtotal = 0; int32_t overflow = 0; |
6c8cc7ee | 689 | total = 0; |
690 | for (i=1; i<n; i++) | |
7bf32ee2 | 691 | { |
692 | if ( (val= block.vtx[0].vout[i].nValue) < 0 || val >= MAX_MONEY ) | |
693 | { | |
694 | overflow = 1; | |
695 | break; | |
696 | } | |
697 | total += val; | |
698 | if ( total < prevtotal || (val != 0 && total == prevtotal) ) | |
699 | { | |
700 | overflow = 1; | |
701 | break; | |
702 | } | |
703 | prevtotal = total; | |
704 | } | |
f0279d99 | 705 | if ( ASSETCHAINS_SYMBOL[0] == 0 ) |
d083ecd5 | 706 | { |
f0279d99 | 707 | if ( overflow != 0 || total > COIN/10 ) |
708 | { | |
709 | //fprintf(stderr,">>>>>>>> <<<<<<<<<< ht.%d illegal nonz output %.8f n.%d\n",height,dstr(block.vtx[0].vout[1].nValue),n); | |
ab0442fc | 710 | if ( height >= activation ) |
f0279d99 | 711 | return(-1); |
712 | } | |
713 | } | |
714 | else | |
715 | { | |
716 | if ( overflow != 0 || total > 0 ) | |
d083ecd5 | 717 | return(-1); |
718 | } | |
12d47153 | 719 | return(0); |
d083ecd5 | 720 | } |
c7a3aca6 | 721 | //fprintf(stderr,"ht.%d n.%d nValue %.8f (%d %d %d)\n",height,n,dstr(block.vtx[0].vout[1].nValue),KOMODO_PAX,komodo_isrealtime(&ht),KOMODO_PASSPORT_INITDONE); |
12d47153 | 722 | offset += komodo_scriptitemlen(&opretlen,&script[offset]); |
77be6cd9 | 723 | if ( ASSETCHAINS_SYMBOL[0] == 0 ) |
724 | { | |
725 | opcode = 'X'; | |
74d67d42 | 726 | if ( height >= 235300 ) |
727 | return(-1); | |
09a235e1 | 728 | strcpy(symbol,(char *)"KMD"); |
e3051943 | 729 | if ( komodo_isrealtime(&ht) == 0 || KOMODO_PASSPORT_INITDONE == 0 ) // init time already in DB |
730 | return(0); | |
77be6cd9 | 731 | } |
732 | else | |
733 | { | |
734 | strcpy(symbol,ASSETCHAINS_SYMBOL); | |
735 | opcode = 'I'; | |
22e2f9b1 | 736 | if ( (baseid= komodo_baseid(symbol)) < 0 ) |
716fb382 | 737 | { |
c7a3aca6 | 738 | if ( block.vtx[0].vout.size() != 1 ) |
716fb382 | 739 | { |
740 | printf("%s has more than one coinbase?\n",symbol); | |
741 | return(-1); | |
742 | } | |
743 | return(0); | |
744 | } | |
4b6b337e | 745 | while ( KOMODO_PASSPORT_INITDONE == 0 ) |
1e1893d8 | 746 | komodo_passport_iteration(); |
0e0c816c | 747 | // grandfathering preexisting |
f64cbe8d | 748 | if ( height < 777 ) |
8f2acb17 | 749 | return(0); |
f81f6075 | 750 | if ( baseid == USD ) // 6820 in balance calcs |
9b072ed5 | 751 | { |
f0279d99 | 752 | if ( height <= 6821 || height <= 2000 || height == 2968 || height == 2960 || height == 2649 || height == 3275 || height == 3282 || height == 3328 || height == 3468 ) |
22e2f9b1 | 753 | return(0); |
9b072ed5 | 754 | } |
9d334465 | 755 | else if ( baseid == EUR ) |
756 | { | |
0a2584e6 | 757 | if ( height < 1200 || height == 1408 || height == 1111 || height == 1094 || height == 1092 || height == 1080 || height == 1053 || height == 1005 || height == 822 || height == 821 || height == 810 || height == 797 || height == 790 || height == 787 || height == 785 || height == 1313 || height == 1288 || height == 1263 || height == 1262 || height <= 211 || height == 210 || height == 188 || height == 185 || height == 182 || height == 181 || height == 171 || height == 170 || height == 169 || height == 168 || height == 167 || height == 166 || height == 165 || height == 164 || height == 163 || height == 162 ) |
9d334465 | 758 | return(0); |
759 | } | |
760 | else if ( baseid == JPY ) | |
761 | { | |
02999b6d | 762 | if ( height == 1038 || height == 1039 || height == 1040 || height == 1041 || height == 1014 || height == 998 || height == 973 || height == 139 || height == 971 || height == 141 || height == 816 || height == 814 || height == 803 || height == 142 || height == 782 || height == 145 || height == 181 || height == 186 || height == 192 || height == 190 || height == 189 || height == 255 || height == 218 || height == 233 || height == 259 || height == 278 || height == 361 || height == 367 || height == 733 || height == 688 || height == 468 ) |
9d334465 | 763 | return(0); |
764 | } | |
765 | else if ( baseid == GBP ) | |
766 | { | |
02999b6d | 767 | if ( height == 1025 || height == 1026 || height == 1027 || height == 1028 || height == 997 || height == 970 || height == 953 || height == 951 || height == 803 || height == 800 || height == 786 || height == 123 || height == 771 || height == 137 || height == 139 || height == 140 || height == 146 || height == 194 || height == 200 || height == 202 || height == 203 || height == 205 || height == 210 || height == 216 || height == 271 || height == 233 || height == 294 ) |
9d334465 | 768 | return(0); |
769 | } | |
770 | else if ( baseid == AUD ) | |
771 | { | |
18457475 | 772 | if ( height == 1012 || height == 1013 || height == 1014 || height == 985 || height == 958 || height == 936 || height == 933 || height == 790 || height == 788 || height == 778 || height == 124 || height == 777 || height == 122 || height == 140 || height == 142 || height == 143 || height == 186 || height == 196 || height == 198 || height == 201 || height == 210 || height == 192 ) |
9d334465 | 773 | return(0); |
774 | } | |
775 | else if ( baseid == CAD ) | |
776 | { | |
f17ad8c9 | 777 | if ( height < 1000 || height == 836 || height == 781 || height == 779 || height == 798 || height == 794 || height == 1181 || height == 1179 || height == 1159 || height == 1134 || height == 1132 || height == 121 || height == 970 || height == 119 || height == 299 || height == 302 || height == 303 || height == 306 || height == 308 || height == 355 || height == 362 || height == 367 || height == 363 || height == 364 || height == 380 || height == 373 || height == 390 || height == 437 || height == 777 ) |
9d334465 | 778 | return(0); |
779 | } | |
780 | else if ( baseid == CHF ) | |
781 | { | |
18457475 | 782 | if ( height == 987 || height == 988 || height == 989 || height == 960 || height == 931 || height == 914 || height == 122 || height == 912 || height == 141 || height == 780 || height == 145 || height == 777 || height == 151 || height == 775 || height == 765 || height == 195 || height == 764 || height == 737 || height == 194 || height == 193 || height == 198 || height == 207 || height == 216 || height == 227 || height == 256 || height == 260 || height == 276 || height == 289 || height == 292 || height == 349 ) |
9d334465 | 783 | return(0); |
784 | } | |
785 | else if ( baseid == NZD ) | |
786 | { | |
f17ad8c9 | 787 | if ( height < 1000 || height == 787 || height == 786 || height == 784 || height == 785 || height == 777 || height == 1113 || height == 1083 || height == 1067 || height == 265 || height == 1064 || height == 920 || height == 913 || height == 124 || height == 911 || height == 903 || height == 900 || height == 879 || height == 122 || height == 266 || height == 269 || height == 270 || height == 278 || height == 307 || height == 318 || height == 322 || height == 335 || height == 395 || height == 406 || height == 314 ) |
9d334465 | 788 | return(0); |
789 | } | |
790 | else if ( baseid == CNY ) | |
791 | { | |
18457475 | 792 | if ( height == 987 || height == 988 || height == 989 || height == 982 || height == 957 || height == 931 || height == 119 || height == 929 || height == 134 || height == 782 || height == 137 || height == 775 || height == 143 || height == 772 || height == 186 || height == 763 || height == 761 || height == 734 || height == 183 || height == 190 || height == 192 || height == 211 || height == 203 || height == 226 || height == 263 || height == 264 || height == 277 || height == 342 || height == 613 || height == 525 ) |
9d334465 | 793 | return(0); |
794 | } | |
795 | else if ( baseid == RUB ) | |
796 | { | |
18457475 | 797 | if ( height == 819 || height == 812 || height == 810 || height == 802 || height == 801 || height == 1074 || height == 1040 || height == 1014 || height == 163 || height == 1013 || height == 877 || height == 867 || height == 863 || height == 834 || height == 158 || height == 126 || height == 106 || height == 105 || height == 174 || height == 175 || height == 176 || height == 177 || height == 181 || height == 183 || height == 184 || height == 187 ) |
9d334465 | 798 | return(0); |
799 | } | |
800 | else if ( baseid == MXN ) | |
801 | { | |
18457475 | 802 | if ( height == 1079 || height == 1080 || height == 1081 || height == 1069 || height == 1048 || height == 1028 || height == 121 || height == 1027 || height == 146 || height == 894 || height == 891 || height == 148 || height == 882 || height == 879 || height == 151 || height == 856 || height == 158 || height == 822 || height == 197 || height == 203 || height == 207 || height == 209 || height == 213 || height == 217 || height == 218 || height == 226 || height == 283 || height == 302 || height == 319 || height == 318 || height == 569 ) |
9d334465 | 803 | return(0); |
804 | } | |
805 | else if ( baseid == BRL ) | |
806 | { | |
18457475 | 807 | if ( height == 1003 || height == 1004 || height == 1005 || height == 972 || height == 943 || height == 922 || height == 118 || height == 920 || height == 145 || height == 787 || height == 783 || height == 147 || height == 781 || height == 774 || height == 148 || height == 771 || height == 154 || height == 751 || height == 156 || height == 188 || height == 193 || height == 195 || height == 199 || height == 203 || height == 225 || height == 230 || height == 262 || height == 266 || height == 284 || height == 300 || height == 640 ) |
9d334465 | 808 | return(0); |
809 | } | |
810 | else if ( baseid == INR ) | |
811 | { | |
18457475 | 812 | if ( height == 998 || height == 999 || height == 1000 || height == 788 || height == 786 || height == 775 || height == 753 || height == 125 || height == 153 || height == 155 || height == 159 || height == 204 || height == 206 || height == 211 || height == 217 || height == 220 || height == 229 || height == 265 || height == 292 || height == 300 ) |
9d334465 | 813 | return(0); |
814 | } | |
815 | else if ( baseid == PLN ) | |
816 | { | |
18457475 | 817 | if ( height == 1029 || height == 1030 || height == 1031 || height == 1009 || height == 984 || height == 960 || height == 959 || height == 798 || height == 794 || height == 792 || height == 782 || height == 775 || height == 755 || height == 122 || height == 120 || height == 158 || height == 160 || height == 163 || height == 225 || height == 217 || height == 219 || height == 229 || height == 234 || height == 286 || height == 231 || height == 292 ) |
9d334465 | 818 | return(0); |
819 | } | |
820 | else if ( baseid == HKD ) | |
821 | { | |
18457475 | 822 | if ( height == 1013 || height == 1014 || height == 1015 || height == 1002 || height == 979 || height == 947 || height == 123 || height == 946 || height == 153 || height == 811 || height == 808 || height == 806 || height == 155 || height == 795 || height == 157 || height == 773 || height == 205 || height == 208 || height == 210 || height == 211 || height == 215 || height == 221 || height == 231 || height == 255 || height == 273 || height == 293 || height == 310 || height == 654 ) |
9d334465 | 823 | return(0); |
824 | } | |
825 | else if ( baseid == TRY ) | |
826 | { | |
18457475 | 827 | if ( height == 1022 || height == 1023 || height == 1051 || height == 991 || height == 974 || height == 949 || height == 141 || height == 948 || height == 783 || height == 153 || height == 781 || height == 779 || height == 776 || height == 768 || height == 765 || height == 121 || height == 142 || height == 144 || height == 143 || height == 149 || height == 204 || height == 210 || height == 216 || height == 229 || height == 280 || height == 145 ) |
9d334465 | 828 | return(0); |
829 | } | |
830 | else if ( baseid == NOK ) | |
831 | { | |
18457475 | 832 | if ( height == 987 || height == 988 || height == 989 || height == 962 || height == 911 || height == 907 || height == 125 || height == 765 || height == 150 || height == 762 || height == 760 || height == 753 || height == 152 || height == 751 || height == 151 || height == 154 || height == 160 || height == 195 || height == 203 || height == 207 || height == 211 || height == 220 || height == 236 || height == 253 || height == 278 || height == 283 ) |
9d334465 | 833 | return(0); |
834 | } | |
835 | else if ( baseid == ZAR ) | |
836 | { | |
18457475 | 837 | if ( height == 979 || height == 980 || height == 981 || height == 956 || height == 937 || height == 906 || height == 905 || height == 122 || height == 756 || height == 754 || height == 752 || height == 749 || height == 742 || height == 739 || height == 120 || height == 151 || height == 153 || height == 157 || height == 159 || height == 206 || height == 213 || height == 216 || height == 222 || height == 277 || height == 287 || height == 215 ) |
9d334465 | 838 | return(0); |
839 | } | |
840 | else if ( baseid == SEK ) | |
841 | { | |
18457475 | 842 | if ( height == 960 || height == 961 || height == 962 || height == 943 || height == 925 || height == 896 || height == 147 || height == 894 || height == 759 || height == 751 || height == 749 || height == 742 || height == 740 || height == 716 || height == 123 || height == 148 || height == 150 || height == 151 || height == 157 || height == 199 || height == 200 || height == 201 || height == 206 || height == 256 || height == 257 || height == 268 ) |
9d334465 | 843 | return(0); |
844 | } | |
845 | else if ( baseid == CZK ) | |
846 | { | |
18457475 | 847 | if ( height == 1084 || height == 1085 || height == 1086 || height == 778 || height == 1079 || height == 1054 || height == 1032 || height == 121 || height == 1030 || height == 182 || height == 876 || height == 873 || height == 871 || height == 184 || height == 862 || height == 185 || height == 861 || height == 186 || height == 838 || height == 238 || height == 242 || height == 246 || height == 248 || height == 250 || height == 251 || height == 256 || height == 282 || height == 322 || height == 343 || height == 433 || height == 323 || height == 276 ) |
9d334465 | 848 | return(0); |
849 | } | |
850 | else if ( baseid == HUF ) | |
851 | { | |
73dc8390 | 852 | if ( height < 2200 || height == 1531 || height == 1528 || height == 1530 || height == 1451 || height == 1448 || height == 1442 || height == 1418 || height == 1407 || height == 1406 || height == 1392 || height == 1391 || height == 1387 || height == 1383 || height == 1335 || height == 1337 || height == 1338 || height == 1649 || height == 2378 || height == 2376 || height == 2371 || height == 1330 || height == 2326 || height == 1344 || height == 2305 || height == 2304 || height == 2171 || height == 2168 || height == 2166 || height == 2156 || height == 2135 || height == 1343 || height == 1342 || height == 1341 || height == 1340 || height == 1339 || height == 1336 || height == 1334 || height == 1333 || height == 1346 || height == 1400 || height == 1525 || height == 1509 ) |
9d334465 | 853 | return(0); |
854 | } | |
855 | else if ( baseid == DKK ) | |
856 | { | |
0a2584e6 | 857 | if ( height == 1241 || height == 945 || height == 898 || height == 894 || height == 892 || height == 866 || height == 857 || height == 853 || height == 834 || height == 812 || height == 792 || height == 784 || height == 778 || height == 783 || height == 1214 || height == 1186 || height == 1158 || height == 126 || height == 1156 || height == 329 || height == 1021 || height == 1016 || height == 1014 || height == 333 || height == 1003 || height == 1002 || height == 978 || height == 332 || height == 337 || height == 381 || height == 390 || height == 386 || height == 401 || height == 389 || height == 396 || height == 428 || height == 473 || height == 490 || height == 493 ) |
9d334465 | 858 | return(0); |
859 | } | |
860 | else if ( baseid == ILS ) | |
861 | { | |
18457475 | 862 | if ( height == 1017 || height == 1018 || height == 1019 || height == 1010 || height == 985 || height == 954 || height == 120 || height == 952 || height == 143 || height == 819 || height == 817 || height == 808 || height == 145 || height == 786 || height == 155 || height == 753 || height == 151 || height == 149 || height == 199 || height == 193 || height == 201 || height == 209 || height == 284 || height == 305 || height == 676 || height == 702 || height == 406 ) |
9d334465 | 863 | return(0); |
864 | } | |
865 | else if ( baseid == MYR ) | |
866 | { | |
18457475 | 867 | if ( height == 1020 || height == 1021 || height == 1022 || height == 1015 || height == 984 || height == 950 || height == 949 || height == 823 || height == 820 || height == 818 || height == 812 || height == 809 || height == 126 || height == 789 || height == 144 || height == 746 || height == 146 || height == 147 || height == 148 || height == 150 || height == 205 || height == 210 || height == 215 || height == 219 || height == 222 || height == 290 || height == 242 || height == 312 ) |
9d334465 | 868 | return(0); |
869 | } | |
870 | else if ( baseid == PHP ) | |
871 | { | |
f19fb8d2 | 872 | if ( height == 859 || height == 817 || height == 812 || height == 811 || height == 792 || height == 779 || height == 778 || height == 781 || height == 1154 || height == 1114 || height == 1077 || height == 1076 || height == 931 || height == 927 || height == 925 || height == 918 || height == 891 || height == 127 || height == 125 || height == 272 || height == 275 || height == 276 || height == 278 || height == 328 || height == 330 || height == 335 || height == 344 || height == 315 ) |
9d334465 | 873 | return(0); |
874 | } | |
875 | else if ( baseid == KRW ) | |
876 | { | |
18457475 | 877 | if ( height == 1021 || height == 1022 || height == 1023 || height == 1010 || height == 950 || height == 916 || height == 138 || height == 914 || height == 140 || height == 785 || height == 782 || height == 781 || height == 142 || height == 775 || height == 148 || height == 772 || height == 751 || height == 147 || height == 146 || height == 159 || height == 175 || height == 181 || height == 184 || height == 186 || height == 188 || height == 196 || height == 209 || height == 238 ) |
9d334465 | 878 | return(0); |
879 | } | |
880 | else if ( baseid == RON ) | |
881 | { | |
18457475 | 882 | if ( height == 1008 || height == 1009 || height == 1010 || height == 1003 || height == 973 || height == 940 || height == 939 || height == 806 || height == 802 || height == 800 || height == 793 || height == 789 || height == 768 || height == 123 || height == 141 || height == 143 || height == 144 || height == 150 || height == 197 || height == 200 || height == 202 || height == 217 || height == 240 || height == 276 ) |
9d334465 | 883 | return(0); |
884 | } | |
885 | else if ( baseid == SGD ) | |
886 | { | |
18457475 | 887 | if ( height == 1016 || height == 1017 || height == 1018 || height == 1010 || height == 984 || height == 951 || height == 950 || height == 801 || height == 798 || height == 792 || height == 788 || height == 122 || height == 769 || height == 120 || height == 158 || height == 160 || height == 164 || height == 169 || height == 229 || height == 234 || height == 246 || height == 297 || height == 299 || height == 316 || height == 233 ) |
9d334465 | 888 | return(0); |
889 | } | |
890 | else if ( baseid == THB ) | |
891 | { | |
18457475 | 892 | if ( height == 977 || height == 978 || height == 968 || height == 933 || height == 898 || height == 897 || height == 788 || height == 786 || height == 779 || height == 777 || height == 757 || height == 119 || height == 140 || height == 142 || height == 146 || height == 152 || height == 196 || height == 200 || height == 214 || height == 260 || height == 263 ) |
9d334465 | 893 | return(0); |
894 | } | |
895 | else if ( baseid == BGN ) | |
896 | { | |
18457475 | 897 | if ( height == 1044 || height == 1045 || height == 1046 || height == 1030 || height == 995 || height == 960 || height == 959 || height == 830 || height == 822 || height == 819 || height == 810 || height == 809 || height == 781 || height == 124 || height == 122 || height == 189 || height == 193 || height == 200 || height == 194 || height == 250 || height == 256 || height == 260 || height == 280 ) |
9d334465 | 898 | return(0); |
899 | } | |
900 | else if ( baseid == HRK ) | |
901 | { | |
18457475 | 902 | if ( height == 1027 || height == 1028 || height == 1029 || height == 1022 || height == 999 || height == 969 || height == 967 || height == 832 || height == 829 || height == 827 || height == 817 || height == 792 || height == 754 || height == 125 || height == 123 || height == 184 || height == 186 || height == 187 || height == 227 || height == 230 || height == 235 || height == 240 || height == 242 || height == 261 || height == 336 ) |
9d334465 | 903 | return(0); |
904 | } | |
905 | else if ( baseid == IDR ) | |
906 | { | |
18457475 | 907 | if ( height == 836 || height == 1036 || height == 837 || height == 720 || height == 715 || height == 714 || height == 696 || height == 695 || height == 694 || height == 693 || height == 119 || height == 689 || height == 120 || height == 669 || height == 123 || height == 662 || height == 122 || height == 634 || height == 121 || height == 609 || height == 124 || height == 174 || height == 603 || height == 595 || height == 166 || height == 176 || height == 589 || height == 172 || height == 587 || height == 179 || height == 239 || height == 175 || height == 245 || height == 260 ) |
9d334465 | 908 | return(0); |
909 | } | |
77be6cd9 | 910 | } |
c7a3aca6 | 911 | if ( script[offset] == opcode && opretlen < block.vtx[0].vout[n-1].scriptPubKey.size() ) |
557d9a23 | 912 | { |
b89ab77c | 913 | if ( (num= komodo_issued_opreturn(base,txids,vouts,values,srcvalues,kmdheights,otherheights,baseids,rmd160s,&script[offset],opretlen,opcode == 'X')) > 0 ) |
557d9a23 | 914 | { |
915 | for (i=1; i<n-1; i++) | |
916 | { | |
fe348242 | 917 | if ( (sp= komodo_stateptrget(CURRENCIES[baseids[i-1]])) != 0 && (sp->RTmask & (1LL << baseids[i-1])) == 0 ) |
b8cceac5 | 918 | { |
4fb9b706 | 919 | /*printf("skip checkdeposit.%s not RT %llx\n",CURRENCIES[baseids[i-1]],(long long)sp->RTmask); |
920 | matched++; | |
921 | continue;*/ | |
b8cceac5 | 922 | } |
16cd9f2d | 923 | if ( (pax= komodo_paxfinds(txids[i-1],vouts[i-1])) != 0 ) // finds... make sure right one |
5a2c5b6f | 924 | { |
ca75995d | 925 | pax->type = opcode; |
16cd9f2d | 926 | if ( opcode == 'I' && (pax_fiatstatus(&available,&deposited,&issued,&withdrawn,&approved,&redeemed,symbol) != 0 || available < pax->fiatoshis) ) |
1c05f0b5 | 927 | { |
0e0c816c | 928 | printf("checkdeposit.[%s.%d]: skip %s %.8f when avail %.8f deposited %.8f, issued %.8f withdrawn %.8f approved %.8f redeemed %.8f\n",ASSETCHAINS_SYMBOL,height,symbol,dstr(pax->fiatoshis),dstr(available),dstr(deposited),dstr(issued),dstr(withdrawn),dstr(approved),dstr(redeemed)); |
951bb1bb | 929 | return(-1); |
1c05f0b5 | 930 | } |
951bb1bb | 931 | if ( pax->fiatoshis == block.vtx[0].vout[i].nValue ) |
f10b8e2e | 932 | { |
84e0ca8e | 933 | matched++; |
02c36c15 | 934 | if ( pax->marked != 0 && height >= 80820 ) |
73585700 | 935 | { |
4a6d9acb | 936 | printf(">>>>>>>>>>> %c errs.%d i.%d match %.8f vs %.8f paxmarked.%d kht.%d ht.%d [%s].%d\n",opcode,errs,i,dstr(opcode == 'I' ? pax->fiatoshis : pax->komodoshis),dstr(block.vtx[0].vout[i].nValue),pax->marked,pax->height,pax->otherheight,ASSETCHAINS_SYMBOL,height); |
4eb7c730 | 937 | } |
938 | else | |
939 | { | |
4eb7c730 | 940 | } |
1af0ebce | 941 | if ( strcmp(ASSETCHAINS_SYMBOL,CURRENCIES[baseids[i-1]]) == 0 ) |
048846d7 | 942 | printf("check deposit validates %s.%d [%d] %.8f -> %.8f (%.8f %.8f %.8f)\n",CURRENCIES[baseids[i-1]],height,i,dstr(srcvalues[i-1]),dstr(values[i-1]),dstr(pax->komodoshis),dstr(pax->fiatoshis),dstr(block.vtx[0].vout[i].nValue)); |
f10b8e2e | 943 | } |
89a2e527 | 944 | else if ( strcmp(ASSETCHAINS_SYMBOL,CURRENCIES[baseids[i-1]]) == 0 ) |
f10b8e2e | 945 | { |
1c05f0b5 | 946 | for (j=0; j<32; j++) |
947 | printf("%02x",((uint8_t *)&txids[i-1])[j]); | |
6e3d5db8 | 948 | printf(" cant paxfind %c txid [%d]\n",opcode,height); |
4a6d9acb | 949 | printf(">>>>>>>>>>> %c errs.%d i.%d match %.8f vs %.8f pax.%p [%s] ht.%d\n",opcode,errs,i,dstr(opcode == 'I' ? pax->fiatoshis : pax->komodoshis),dstr(block.vtx[0].vout[i].nValue),pax,ASSETCHAINS_SYMBOL,height); |
cb9c5fd3 | 950 | return(-1); |
f10b8e2e | 951 | } |
5a2c5b6f | 952 | } |
8de77430 | 953 | else //if ( kmdheights[i-1] > 0 && otherheights[i-1] > 0 ) |
cb040aa1 | 954 | { |
c7a3aca6 | 955 | hash = block.GetHash(); |
1c05f0b5 | 956 | for (j=0; j<32; j++) |
957 | printf("%02x",((uint8_t *)&hash)[j]); | |
2eceb04b | 958 | printf(" kht.%d ht.%d %.8f %.8f blockhash couldnt find vout.[%d] ht.%d %s for [%s]\n",kmdheights[i-1],otherheights[i-1],dstr(values[i-1]),dstr(srcvalues[i]),i,height,ASSETCHAINS_SYMBOL,CURRENCIES[baseids[i-1]]); |
88908338 | 959 | if ( ASSETCHAINS_SYMBOL[0] != 0 || height >= activation ) |
960 | return(-1); | |
cb040aa1 | 961 | } |
557d9a23 | 962 | } |
283168fd | 963 | if ( ASSETCHAINS_SYMBOL[0] == 0 ) |
81041ab2 | 964 | { |
283168fd | 965 | if ( height > 0 && (height < chainActive.Tip()->nHeight || (height >= chainActive.Tip()->nHeight && komodo_isrealtime(&ht) != 0)) && matched != num ) |
52b2e68d | 966 | { |
5641c3d2 | 967 | printf("WOULD REJECT %s: ht.%d (%c) matched.%d vs num.%d tip.%d isRT.%d\n",symbol,height,opcode,matched,num,(int32_t)chainActive.Tip()->nHeight,komodo_isrealtime(&ht)); |
968 | // can easily happen depending on order of loading | |
969 | if ( height > 200000 ) | |
970 | { | |
971 | printf("REJECT: ht.%d (%c) matched.%d vs num.%d\n",height,opcode,matched,num); | |
972 | return(-1); | |
973 | } | |
4fb9b706 | 974 | } |
5641c3d2 | 975 | } |
976 | else | |
977 | { | |
4df419cd | 978 | if ( height > 0 && (height < chainActive.Tip()->nHeight || (height >= chainActive.Tip()->nHeight && komodo_isrealtime(&ht) != 0)) && matched != num ) |
5641c3d2 | 979 | { |
02999b6d | 980 | printf("REJECT %s: ht.%d (%c) matched.%d vs num.%d tip.%d isRT.%d\n",symbol,height,opcode,matched,num,(int32_t)chainActive.Tip()->nHeight,komodo_isrealtime(&ht)); |
981 | return(-1); | |
52b2e68d | 982 | } |
81041ab2 | 983 | } |
557d9a23 | 984 | } |
22c10675 | 985 | else |
986 | { | |
5eaffe75 | 987 | for (i=0; i<n; i++) |
988 | printf("%.8f ",dstr(block.vtx[0].vout[i].nValue)); | |
989 | printf("no opreturn entries to check ht.%d %s\n",height,ASSETCHAINS_SYMBOL); | |
88908338 | 990 | if ( ASSETCHAINS_SYMBOL[0] != 0 || height >= activation ) |
ab0442fc | 991 | return(-1); |
22c10675 | 992 | } |
b98053e2 | 993 | //printf("opretlen.%d num.%d\n",opretlen,num); |
22c10675 | 994 | } |
995 | else | |
996 | { | |
9a762d0e | 997 | for (i=0; i<opretlen&&i<100; i++) |
db82494f | 998 | printf("%02x",script[i]); |
9a762d0e | 999 | printf(" height.%d checkdeposit n.%d [%02x] [%c] %d len.%d ",height,n,script[0],script[offset],script[offset],opretlen); |
3788126c | 1000 | printf("not proper vout with opreturn format %s ht.%d\n",ASSETCHAINS_SYMBOL,height); |
22c10675 | 1001 | return(-1); |
1002 | } | |
557d9a23 | 1003 | return(0); |
1004 | } | |
1005 | ||
cd26c1f3 | 1006 | const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int32_t opretlen,uint256 txid,uint16_t vout,char *source) |
429dabb5 | 1007 | { |
16cd9f2d | 1008 | uint8_t rmd160[20],rmd160s[64*20],addrtype,shortflag,pubkey33[33]; int32_t didstats,i,j,n,kvheight,len,tokomodo,kmdheight,otherheights[64],kmdheights[64]; int8_t baseids[64]; char base[4],coinaddr[64],destaddr[64]; uint256 txids[64]; uint16_t vouts[64]; uint64_t convtoshis,seed; int64_t fee,fiatoshis,komodoshis,checktoshis,values[64],srcvalues[64]; struct pax_transaction *pax,*pax2; struct komodo_state *basesp; double diff; |
1ed46112 | 1009 | const char *typestr = "unknown"; |
088b1fa8 | 1010 | if ( ASSETCHAINS_SYMBOL[0] != 0 && komodo_baseid(ASSETCHAINS_SYMBOL) < 0 && opretbuf[0] != 'K' ) |
894c570b | 1011 | { |
b27b2877 | 1012 | //printf("komodo_opreturn skip %s\n",ASSETCHAINS_SYMBOL); |
716fb382 | 1013 | return("assetchain"); |
894c570b | 1014 | } |
46222318 | 1015 | //else if ( KOMODO_PAX == 0 ) |
1016 | // return("nopax"); | |
1ed46112 | 1017 | memset(baseids,0xff,sizeof(baseids)); |
1018 | memset(values,0,sizeof(values)); | |
06cfcf31 | 1019 | memset(srcvalues,0,sizeof(srcvalues)); |
f360ea0a | 1020 | memset(rmd160s,0,sizeof(rmd160s)); |
1ed46112 | 1021 | memset(kmdheights,0,sizeof(kmdheights)); |
1022 | memset(otherheights,0,sizeof(otherheights)); | |
9596e284 | 1023 | tokomodo = (komodo_is_issuer() == 0); |
ab6e81ec | 1024 | if ( opretbuf[0] == 'K' && opretlen != 40 ) |
15d0fbd4 | 1025 | { |
6b5cfbb4 | 1026 | komodo_kvupdate(opretbuf,opretlen,value); |
15d0fbd4 | 1027 | } |
1028 | else if ( opretbuf[0] == 'D' ) | |
64bb0834 | 1029 | { |
9596e284 | 1030 | tokomodo = 0; |
05a37d87 | 1031 | if ( opretlen == 38 ) // any KMD tx |
64bb0834 | 1032 | { |
05a37d87 | 1033 | iguana_rwnum(0,&opretbuf[34],sizeof(kmdheight),&kmdheight); |
abdd8672 | 1034 | memset(base,0,sizeof(base)); |
1035 | PAX_pubkey(0,&opretbuf[1],&addrtype,rmd160,base,&shortflag,&fiatoshis); | |
abdd8672 | 1036 | bitcoin_address(coinaddr,addrtype,rmd160,20); |
81a991e4 | 1037 | checktoshis = PAX_fiatdest(&seed,tokomodo,destaddr,pubkey33,coinaddr,kmdheight,base,fiatoshis); |
abdd8672 | 1038 | typestr = "deposit"; |
b2e010ee | 1039 | if ( strcmp(base,ASSETCHAINS_SYMBOL) == 0 && (kmdheight > 195000 || kmdheight <= height) ) |
6e576848 | 1040 | { |
f5e3cdfa | 1041 | didstats = 0; |
16cd9f2d | 1042 | if ( 0 && kmdheight > 214700 && strcmp(base,ASSETCHAINS_SYMBOL) == 0 ) |
8f261c33 | 1043 | { |
16cd9f2d | 1044 | printf("(%s) (%s) kmdheight.%d vs height.%d check %.8f vs %.8f tokomodo.%d %d seed.%llx\n",ASSETCHAINS_SYMBOL,base,kmdheight,height,dstr(checktoshis),dstr(value),komodo_is_issuer(),strncmp(ASSETCHAINS_SYMBOL,base,strlen(base)) == 0,(long long)seed); |
8f261c33 | 1045 | for (i=0; i<32; i++) |
1046 | printf("%02x",((uint8_t *)&txid)[i]); | |
1047 | printf(" <- txid.v%u ",vout); | |
1048 | for (i=0; i<33; i++) | |
1049 | printf("%02x",pubkey33[i]); | |
1050 | printf(" checkpubkey check %.8f v %.8f dest.(%s) kmdheight.%d height.%d\n",dstr(checktoshis),dstr(value),destaddr,kmdheight,height); | |
1051 | } | |
41b528bb | 1052 | if ( komodo_paxcmp(base,kmdheight,value,checktoshis,kmdheight < 225000 ? seed : 0) == 0 ) |
05a37d87 | 1053 | { |
b915be35 | 1054 | if ( (pax= komodo_paxfind(txid,vout,'D')) == 0 ) |
05a37d87 | 1055 | { |
c98b3a08 | 1056 | if ( (basesp= komodo_stateptrget(base)) != 0 ) |
05a37d87 | 1057 | { |
c98b3a08 | 1058 | basesp->deposited += fiatoshis; |
22a31d52 | 1059 | didstats = 1; |
a13467f5 | 1060 | if ( 0 && strcmp(base,ASSETCHAINS_SYMBOL) == 0 ) |
0398360f | 1061 | printf("########### %p deposited %s += %.8f kmdheight.%d %.8f\n",basesp,base,dstr(fiatoshis),kmdheight,dstr(value)); |
c72ee808 | 1062 | } else printf("cant get stateptr.(%s)\n",base); |
4d4194d3 | 1063 | komodo_gateway_deposit(coinaddr,value,base,fiatoshis,rmd160,txid,vout,'D',kmdheight,height,(char *)"KMD",0); |
3f9cad6d | 1064 | } |
51e5d952 | 1065 | if ( (pax= komodo_paxfind(txid,vout,'D')) != 0 ) |
3f9cad6d | 1066 | { |
8bd946ce | 1067 | pax->height = kmdheight; |
1068 | pax->validated = value; | |
88dff0d3 | 1069 | pax->komodoshis = value; |
1070 | pax->fiatoshis = fiatoshis; | |
22a31d52 | 1071 | if ( didstats == 0 && pax->didstats == 0 ) |
3f9cad6d | 1072 | { |
ca75995d | 1073 | if ( (basesp= komodo_stateptrget(base)) != 0 ) |
1074 | { | |
1075 | basesp->deposited += fiatoshis; | |
22a31d52 | 1076 | didstats = 1; |
a13467f5 | 1077 | if ( 0 && strcmp(base,ASSETCHAINS_SYMBOL) == 0 ) |
c0d7dda6 | 1078 | printf("########### %p depositedB %s += %.8f/%.8f kmdheight.%d/%d %.8f/%.8f\n",basesp,base,dstr(fiatoshis),dstr(pax->fiatoshis),kmdheight,pax->height,dstr(value),dstr(pax->komodoshis)); |
ca75995d | 1079 | } |
4dabad2c | 1080 | } // |
51e5d952 | 1081 | if ( didstats != 0 ) |
1082 | pax->didstats = 1; | |
eb706ef8 | 1083 | if ( (pax2= komodo_paxfind(txid,vout,'I')) != 0 ) |
7ddc4ef7 | 1084 | { |
1085 | pax2->fiatoshis = pax->fiatoshis; | |
1086 | pax2->komodoshis = pax->komodoshis; | |
7ddc4ef7 | 1087 | pax->marked = pax2->marked = pax->height; |
da02b3be | 1088 | pax2->height = pax->height = height; |
c0955f71 | 1089 | if ( pax2->didstats == 0 ) |
25623352 | 1090 | { |
bde7e5ef | 1091 | if ( (basesp= komodo_stateptrget(base)) != 0 ) |
1092 | { | |
1093 | basesp->issued += pax2->fiatoshis; | |
1094 | pax2->didstats = 1; | |
82315b7d | 1095 | if ( 1 && strcmp(base,"USD") == 0 ) |
1096 | printf("########### %p issueda %s += %.8f kmdheight.%d %.8f other.%d [%d]\n",basesp,base,dstr(pax2->fiatoshis),pax2->height,dstr(pax2->komodoshis),pax2->otherheight,height); | |
bde7e5ef | 1097 | } |
25623352 | 1098 | } |
7ddc4ef7 | 1099 | } |
3f9cad6d | 1100 | } |
eb928486 | 1101 | } |
d6cc943d | 1102 | else |
1103 | { | |
1104 | if ( (pax= komodo_paxfind(txid,vout,'D')) != 0 ) | |
1105 | pax->marked = checktoshis; | |
1106 | if ( kmdheight > 238000 && (kmdheight > 214700 || strcmp(base,ASSETCHAINS_SYMBOL) == 0) ) //seed != 0 && | |
1107 | printf("pax %s deposit %.8f rejected kmdheight.%d %.8f KMD check %.8f seed.%llu\n",base,dstr(fiatoshis),kmdheight,dstr(value),dstr(checktoshis),(long long)seed); | |
1108 | } | |
182dcdec | 1109 | } //else printf("paxdeposit height.%d vs kmdheight.%d\n",height,kmdheight); |
64bb0834 | 1110 | } |
1111 | } | |
36b8ed99 | 1112 | else if ( opretbuf[0] == 'I' ) |
1113 | { | |
1114 | tokomodo = 0; | |
7b078158 | 1115 | if ( strncmp((char *)"KMD",(char *)&opretbuf[opretlen-4],3) != 0 && strncmp(ASSETCHAINS_SYMBOL,(char *)&opretbuf[opretlen-4],3) == 0 ) |
36b8ed99 | 1116 | { |
1117 | if ( (n= komodo_issued_opreturn(base,txids,vouts,values,srcvalues,kmdheights,otherheights,baseids,rmd160s,opretbuf,opretlen,0)) > 0 ) | |
1118 | { | |
1119 | for (i=0; i<n; i++) | |
1120 | { | |
1121 | if ( baseids[i] < 0 ) | |
1122 | { | |
1123 | printf("%d of %d illegal baseid.%d\n",i,n,baseids[i]); | |
1124 | continue; | |
1125 | } | |
1126 | bitcoin_address(coinaddr,60,&rmd160s[i*20],20); | |
e2879b92 | 1127 | komodo_gateway_deposit(coinaddr,0,ASSETCHAINS_SYMBOL,0,0,txids[i],vouts[i],'I',height,0,CURRENCIES[baseids[i]],0); |
36b8ed99 | 1128 | komodo_paxmark(height,txids[i],vouts[i],'I',height); |
1129 | if ( (pax= komodo_paxfind(txids[i],vouts[i],'I')) != 0 ) | |
1130 | { | |
1131 | pax->type = opretbuf[0]; | |
1132 | strcpy(pax->source,(char *)&opretbuf[opretlen-4]); | |
a6a33512 | 1133 | if ( (pax2= komodo_paxfind(txids[i],vouts[i],'D')) != 0 && pax2->fiatoshis != 0 && pax2->komodoshis != 0 ) |
36b8ed99 | 1134 | { |
1135 | // realtime path? | |
1136 | pax->fiatoshis = pax2->fiatoshis; | |
1137 | pax->komodoshis = pax2->komodoshis; | |
1138 | pax->marked = pax2->marked = pax2->height; | |
5b62b979 | 1139 | if ( pax->didstats == 0 ) |
36b8ed99 | 1140 | { |
1141 | if ( (basesp= komodo_stateptrget(CURRENCIES[baseids[i]])) != 0 ) | |
1142 | { | |
1143 | basesp->issued += pax->fiatoshis; | |
1144 | pax->didstats = 1; | |
39863e30 | 1145 | pax->height = pax2->height; |
1146 | pax->otherheight = height; | |
82315b7d | 1147 | if ( 1 && strcmp(CURRENCIES[baseids[i]],"USD") == 0 ) |
1148 | printf("########### %p issuedb %s += %.8f kmdheight.%d %.8f other.%d [%d]\n",basesp,CURRENCIES[baseids[i]],dstr(pax->fiatoshis),pax->height,dstr(pax->komodoshis),pax->otherheight,height); | |
36b8ed99 | 1149 | } |
1150 | } | |
1151 | } | |
1152 | } | |
57f349cb | 1153 | if ( (pax= komodo_paxmark(height,txids[i],vouts[i],'I',height)) != 0 ) |
1154 | komodo_paxdelete(pax); | |
1155 | if ( (pax= komodo_paxmark(height,txids[i],vouts[i],'D',height)) != 0 ) | |
1156 | komodo_paxdelete(pax); | |
36b8ed99 | 1157 | } |
174cae41 | 1158 | } //else printf("opreturn none issued?\n"); |
36b8ed99 | 1159 | } |
36b8ed99 | 1160 | } |
7b078158 | 1161 | else if ( height < 236000 && opretbuf[0] == 'W' && strncmp(ASSETCHAINS_SYMBOL,(char *)&opretbuf[opretlen-4],3) == 0 )//&& opretlen >= 38 ) |
01d9ed2f | 1162 | { |
bc653eee | 1163 | if ( komodo_baseid((char *)&opretbuf[opretlen-4]) >= 0 && strcmp(ASSETCHAINS_SYMBOL,(char *)&opretbuf[opretlen-4]) == 0 ) |
8b4d7f27 | 1164 | { |
1165 | for (i=0; i<opretlen; i++) | |
1166 | printf("%02x",opretbuf[i]); | |
d594eaa4 | 1167 | printf(" [%s] reject obsolete withdraw request.%s\n",ASSETCHAINS_SYMBOL,(char *)&opretbuf[opretlen-4]); |
217eb34f | 1168 | return(typestr); |
8b4d7f27 | 1169 | } |
9596e284 | 1170 | tokomodo = 1; |
01d9ed2f | 1171 | iguana_rwnum(0,&opretbuf[34],sizeof(kmdheight),&kmdheight); |
1172 | memset(base,0,sizeof(base)); | |
c3d94aec | 1173 | PAX_pubkey(0,&opretbuf[1],&addrtype,rmd160,base,&shortflag,&komodoshis); |
01d9ed2f | 1174 | bitcoin_address(coinaddr,addrtype,rmd160,20); |
c3d94aec | 1175 | checktoshis = PAX_fiatdest(&seed,tokomodo,destaddr,pubkey33,coinaddr,kmdheight,base,value); |
01d9ed2f | 1176 | typestr = "withdraw"; |
8b4d7f27 | 1177 | //printf(" [%s] WITHDRAW %s.height.%d vs height.%d check %.8f/%.8f vs %.8f tokomodo.%d %d seed.%llx -> (%s) len.%d\n",ASSETCHAINS_SYMBOL,base,kmdheight,height,dstr(checktoshis),dstr(komodoshis),dstr(value),komodo_is_issuer(),strncmp(ASSETCHAINS_SYMBOL,base,strlen(base)) == 0,(long long)seed,coinaddr,opretlen); |
f5e3cdfa | 1178 | didstats = 0; |
a39d7b21 | 1179 | //if ( komodo_paxcmp(base,kmdheight,komodoshis,checktoshis,seed) == 0 ) |
01d9ed2f | 1180 | { |
51e5d952 | 1181 | if ( value != 0 && ((pax= komodo_paxfind(txid,vout,'W')) == 0 || pax->didstats == 0) ) |
0b556992 | 1182 | { |
0126d891 | 1183 | if ( (basesp= komodo_stateptrget(base)) != 0 ) |
1184 | { | |
1185 | basesp->withdrawn += value; | |
1186 | didstats = 1; | |
dd36961a | 1187 | if ( 0 && strcmp(base,ASSETCHAINS_SYMBOL) == 0 ) |
5b489b55 | 1188 | printf("########### %p withdrawn %s += %.8f check %.8f\n",basesp,base,dstr(value),dstr(checktoshis)); |
0126d891 | 1189 | } |
57f349cb | 1190 | if ( 0 && strcmp(base,"RUB") == 0 && (pax == 0 || pax->approved == 0) ) |
4718923d | 1191 | printf("notarize %s %.8f -> %.8f kmd.%d other.%d\n",ASSETCHAINS_SYMBOL,dstr(value),dstr(komodoshis),kmdheight,height); |
ea365a71 | 1192 | } |
115e6a5c | 1193 | komodo_gateway_deposit(coinaddr,0,(char *)"KMD",value,rmd160,txid,vout,'W',kmdheight,height,source,0); |
51e5d952 | 1194 | if ( (pax= komodo_paxfind(txid,vout,'W')) != 0 ) |
daeecf95 | 1195 | { |
1196 | pax->type = opretbuf[0]; | |
1ac3f9ef | 1197 | strcpy(pax->source,base); |
1198 | strcpy(pax->symbol,"KMD"); | |
daeecf95 | 1199 | pax->height = kmdheight; |
1200 | pax->otherheight = height; | |
1e22f865 | 1201 | pax->komodoshis = komodoshis; |
daeecf95 | 1202 | } |
a39d7b21 | 1203 | } // else printf("withdraw %s paxcmp ht.%d %d error value %.8f -> %.8f vs %.8f\n",base,kmdheight,height,dstr(value),dstr(komodoshis),dstr(checktoshis)); |
1204 | // need to allocate pax | |
a4c67285 | 1205 | } |
b2e010ee | 1206 | else if ( height < 236000 && tokomodo != 0 && opretbuf[0] == 'A' && ASSETCHAINS_SYMBOL[0] == 0 ) |
a4c67285 | 1207 | { |
9596e284 | 1208 | tokomodo = 1; |
109afe64 | 1209 | if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 ) |
826bfe51 | 1210 | { |
1211 | for (i=0; i<opretlen; i++) | |
1212 | printf("%02x",opretbuf[i]); | |
40f3d9cc | 1213 | printf(" opret[%c] else path tokomodo.%d ht.%d before %.8f opretlen.%d\n",opretbuf[0],tokomodo,height,dstr(komodo_paxtotal()),opretlen); |
826bfe51 | 1214 | } |
b89ab77c | 1215 | if ( (n= komodo_issued_opreturn(base,txids,vouts,values,srcvalues,kmdheights,otherheights,baseids,rmd160s,opretbuf,opretlen,1)) > 0 ) |
a4c67285 | 1216 | { |
1217 | for (i=0; i<n; i++) | |
1218 | { | |
885643be | 1219 | //for (j=0; j<32; j++) |
1220 | // printf("%02x",((uint8_t *)&txids[i])[j]); | |
1221 | //printf(" v%d %.8f %.8f k.%d ht.%d base.%d\n",vouts[i],dstr(values[i]),dstr(srcvalues[i]),kmdheights[i],otherheights[i],baseids[i]); | |
b89ab77c | 1222 | if ( baseids[i] < 0 ) |
8e7b40d9 | 1223 | { |
afdb28f3 | 1224 | for (i=0; i<opretlen; i++) |
1225 | printf("%02x",opretbuf[i]); | |
1226 | printf(" opret[%c] else path tokomodo.%d ht.%d before %.8f opretlen.%d\n",opretbuf[0],tokomodo,height,dstr(komodo_paxtotal()),opretlen); | |
8952ee9d | 1227 | //printf("baseids[%d] %d\n",i,baseids[i]); |
afdb28f3 | 1228 | if ( (pax= komodo_paxfind(txids[i],vouts[i],'W')) != 0 || (pax= komodo_paxfind(txids[i],vouts[i],'X')) != 0 ) |
51752631 | 1229 | { |
1230 | baseids[i] = komodo_baseid(pax->symbol); | |
1231 | printf("override neg1 with (%s)\n",pax->symbol); | |
1232 | } | |
1233 | if ( baseids[i] < 0 ) | |
1234 | continue; | |
8e7b40d9 | 1235 | } |
f5e3cdfa | 1236 | didstats = 0; |
0cc6ad81 | 1237 | seed = 0; |
d515094d | 1238 | checktoshis = komodo_paxprice(&seed,kmdheights[i],CURRENCIES[baseids[i]],(char *)"KMD",(uint64_t)values[i]); |
8b4d7f27 | 1239 | //printf("PAX_fiatdest ht.%d price %s %.8f -> KMD %.8f vs %.8f\n",kmdheights[i],CURRENCIES[baseids[i]],(double)values[i]/COIN,(double)srcvalues[i]/COIN,(double)checktoshis/COIN); |
371a9c87 | 1240 | if ( srcvalues[i] == checktoshis ) |
a4c67285 | 1241 | { |
36a4e92c | 1242 | if ( (pax= komodo_paxfind(txids[i],vouts[i],'A')) == 0 ) |
0fa85cc3 | 1243 | { |
371a9c87 | 1244 | bitcoin_address(coinaddr,60,&rmd160s[i*20],20); |
5481c677 | 1245 | komodo_gateway_deposit(coinaddr,srcvalues[i],CURRENCIES[baseids[i]],values[i],&rmd160s[i*20],txids[i],vouts[i],'A',kmdheights[i],otherheights[i],CURRENCIES[baseids[i]],kmdheights[i]); |
371a9c87 | 1246 | if ( (pax= komodo_paxfind(txids[i],vouts[i],'A')) == 0 ) |
1247 | printf("unexpected null pax for approve\n"); | |
1248 | else pax->validated = checktoshis; | |
1249 | if ( (pax2= komodo_paxfind(txids[i],vouts[i],'W')) != 0 ) | |
1250 | pax2->approved = kmdheights[i]; | |
7aadf9a9 | 1251 | komodo_paxmark(height,txids[i],vouts[i],'W',height); |
371a9c87 | 1252 | //komodo_paxmark(height,txids[i],vouts[i],'A',height); |
bca09689 | 1253 | if ( values[i] != 0 && (basesp= komodo_stateptrget(CURRENCIES[baseids[i]])) != 0 ) |
371a9c87 | 1254 | { |
5481c677 | 1255 | basesp->approved += values[i]; |
371a9c87 | 1256 | didstats = 1; |
d01c0463 | 1257 | //printf("pax.%p ########### %p approved %s += %.8f -> %.8f/%.8f kht.%d %d\n",pax,basesp,CURRENCIES[baseids[i]],dstr(values[i]),dstr(srcvalues[i]),dstr(checktoshis),kmdheights[i],otherheights[i]); |
371a9c87 | 1258 | } |
1259 | //printf(" i.%d (%s) <- %.8f ADDFLAG APPROVED\n",i,coinaddr,dstr(values[i])); | |
0fa85cc3 | 1260 | } |
371a9c87 | 1261 | else if ( pax->didstats == 0 && srcvalues[i] != 0 ) |
3f9cad6d | 1262 | { |
371a9c87 | 1263 | if ( (basesp= komodo_stateptrget(CURRENCIES[baseids[i]])) != 0 ) |
1264 | { | |
5481c677 | 1265 | basesp->approved += values[i]; |
371a9c87 | 1266 | didstats = 1; |
d01c0463 | 1267 | //printf("pax.%p ########### %p approved %s += %.8f -> %.8f/%.8f kht.%d %d\n",pax,basesp,CURRENCIES[baseids[i]],dstr(values[i]),dstr(srcvalues[i]),dstr(checktoshis),kmdheights[i],otherheights[i]); |
371a9c87 | 1268 | } |
1269 | } //else printf(" i.%d of n.%d pax.%p baseids[] %d\n",i,n,pax,baseids[i]); | |
1270 | if ( (pax= komodo_paxfind(txids[i],vouts[i],'A')) != 0 ) | |
1271 | { | |
1272 | pax->type = opretbuf[0]; | |
1273 | pax->approved = kmdheights[i]; | |
1274 | pax->validated = checktoshis; | |
1275 | if ( didstats != 0 ) | |
1276 | pax->didstats = 1; | |
7ad9ed4d | 1277 | //if ( strcmp(CURRENCIES[baseids[i]],ASSETCHAINS_SYMBOL) == 0 ) |
5481c677 | 1278 | //printf(" i.%d approved.%d <<<<<<<<<<<<< APPROVED %p\n",i,kmdheights[i],pax); |
371a9c87 | 1279 | } |
06d1a655 | 1280 | } |
ea365a71 | 1281 | } |
dd278be2 | 1282 | } //else printf("n.%d from opreturns\n",n); |
bff51d67 | 1283 | //printf("extra.[%d] after %.8f\n",n,dstr(komodo_paxtotal())); |
01d9ed2f | 1284 | } |
b2e010ee | 1285 | else if ( height < 236000 && opretbuf[0] == 'X' && ASSETCHAINS_SYMBOL[0] == 0 ) |
ca3c6549 | 1286 | { |
9596e284 | 1287 | tokomodo = 1; |
c65d0868 | 1288 | if ( (n= komodo_issued_opreturn(base,txids,vouts,values,srcvalues,kmdheights,otherheights,baseids,rmd160s,opretbuf,opretlen,1)) > 0 ) |
4c58b338 | 1289 | { |
1290 | for (i=0; i<n; i++) | |
1291 | { | |
3f9cad6d | 1292 | if ( baseids[i] < 0 ) |
1293 | continue; | |
4c58b338 | 1294 | bitcoin_address(coinaddr,60,&rmd160s[i*20],20); |
51e5d952 | 1295 | komodo_gateway_deposit(coinaddr,0,0,0,0,txids[i],vouts[i],'X',height,0,(char *)"KMD",0); |
aa114a60 | 1296 | komodo_paxmark(height,txids[i],vouts[i],'W',height); |
1297 | komodo_paxmark(height,txids[i],vouts[i],'A',height); | |
1298 | komodo_paxmark(height,txids[i],vouts[i],'X',height); | |
51e5d952 | 1299 | if ( (pax= komodo_paxfind(txids[i],vouts[i],'X')) != 0 ) |
ca75995d | 1300 | { |
1301 | pax->type = opretbuf[0]; | |
6276f755 | 1302 | if ( height < 121842 ) // fields got switched around due to legacy issues and approves |
2ee39fae | 1303 | value = srcvalues[i]; |
1304 | else value = values[i]; | |
1305 | if ( baseids[i] >= 0 && value != 0 && (basesp= komodo_stateptrget(CURRENCIES[baseids[i]])) != 0 ) | |
c6eca157 | 1306 | { |
2ee39fae | 1307 | basesp->redeemed += value; |
546672f5 | 1308 | pax->didstats = 1; |
dff9ec91 | 1309 | if ( strcmp(CURRENCIES[baseids[i]],ASSETCHAINS_SYMBOL) == 0 ) |
e62f7114 | 1310 | printf("ht.%d %.8f ########### %p redeemed %s += %.8f %.8f kht.%d ht.%d\n",height,dstr(value),basesp,CURRENCIES[baseids[i]],dstr(value),dstr(srcvalues[i]),kmdheights[i],otherheights[i]); |
c6eca157 | 1311 | } |
ca75995d | 1312 | } |
57f349cb | 1313 | if ( (pax= komodo_paxmark(height,txids[i],vouts[i],'W',height)) != 0 ) |
1314 | komodo_paxdelete(pax); | |
1315 | if ( (pax= komodo_paxmark(height,txids[i],vouts[i],'A',height)) != 0 ) | |
1316 | komodo_paxdelete(pax); | |
1317 | if ( (pax= komodo_paxmark(height,txids[i],vouts[i],'X',height)) != 0 ) | |
1318 | komodo_paxdelete(pax); | |
4c58b338 | 1319 | } |
dff4ef45 | 1320 | } //else printf("komodo_issued_opreturn returned %d\n",n); |
ca3c6549 | 1321 | } |
64bb0834 | 1322 | return(typestr); |
1323 | } | |
1324 | ||
30d79208 | 1325 | void komodo_passport_iteration() |
ab918767 | 1326 | { |
d9d08bc4 | 1327 | static long lastpos[34]; static char userpass[33][1024]; static uint32_t lasttime; |
02999b6d | 1328 | int32_t maxseconds = 30; |
430d3c77 | 1329 | FILE *fp; int32_t baseid,n,ht,isrealtime,expired,refid,blocks,longest; struct komodo_state *sp,*refsp; char *retstr,fname[512],*base,symbol[16],dest[16]; uint32_t buf[3],starttime; cJSON *infoobj,*result; uint64_t RTmask = 0; |
2a15e8ea | 1330 | //printf("PASSPORT.(%s)\n",ASSETCHAINS_SYMBOL); |
430d3c77 | 1331 | expired = 0; |
17899df4 | 1332 | while ( KOMODO_INITDONE == 0 ) |
1333 | { | |
e40060c2 | 1334 | fprintf(stderr,"[%s] PASSPORT iteration waiting for KOMODO_INITDONE\n",ASSETCHAINS_SYMBOL); |
17899df4 | 1335 | sleep(3); |
1336 | } | |
635dd34d | 1337 | refsp = komodo_stateptr(symbol,dest); |
ab918767 | 1338 | if ( ASSETCHAINS_SYMBOL[0] == 0 ) |
67cd296f | 1339 | refid = 33; |
b307682f | 1340 | else |
716fb382 | 1341 | { |
b307682f | 1342 | refid = komodo_baseid(ASSETCHAINS_SYMBOL)+1; // illegal base -> baseid.-1 -> 0 |
1343 | if ( refid == 0 ) | |
1344 | { | |
1345 | KOMODO_PASSPORT_INITDONE = 1; | |
1346 | return; | |
1347 | } | |
716fb382 | 1348 | } |
717dfab6 | 1349 | /*if ( KOMODO_PAX == 0 ) |
6cd01056 | 1350 | { |
1351 | KOMODO_PASSPORT_INITDONE = 1; | |
1352 | return; | |
717dfab6 | 1353 | }*/ |
ba37a6b9 | 1354 | starttime = (uint32_t)time(NULL); |
d9d08bc4 | 1355 | if ( starttime == lasttime ) |
7f6ddefd | 1356 | { |
1357 | usleep(1000); | |
d9d08bc4 | 1358 | return; |
7f6ddefd | 1359 | } |
d9d08bc4 | 1360 | lasttime = starttime; |
49058e97 | 1361 | //printf("PASSPORT %s refid.%d\n",ASSETCHAINS_SYMBOL,refid); |
959782f9 | 1362 | for (baseid=32; baseid>=0; baseid--) |
b2e010ee | 1363 | { |
e22dcc1e | 1364 | if ( time(NULL) >= starttime+maxseconds ) |
588bc897 | 1365 | break; |
ecf6256c | 1366 | sp = 0; |
1367 | isrealtime = 0; | |
f789edde | 1368 | base = (char *)CURRENCIES[baseid]; |
95a6016d | 1369 | if ( baseid+1 != refid ) |
ab918767 | 1370 | { |
25f7ef8c | 1371 | if ( baseid == 32 || ASSETCHAINS_SYMBOL[0] == 0 ) |
ab918767 | 1372 | { |
b2e010ee | 1373 | komodo_statefname(fname,baseid<32?base:(char *)"",(char *)"komodostate"); |
1374 | komodo_nameset(symbol,dest,base); | |
1375 | sp = komodo_stateptrget(symbol); | |
1376 | n = 0; | |
1377 | if ( (fp= fopen(fname,"rb")) != 0 && sp != 0 ) | |
ab918767 | 1378 | { |
b2e010ee | 1379 | fseek(fp,0,SEEK_END); |
1380 | if ( ftell(fp) > lastpos[baseid] ) | |
ba37a6b9 | 1381 | { |
b028bc48 | 1382 | if ( ASSETCHAINS_SYMBOL[0] != 0 ) |
b6d301be | 1383 | printf("%s passport refid.%d %s fname.(%s) base.%s %ld %ld\n",ASSETCHAINS_SYMBOL,refid,symbol,fname,base,ftell(fp),lastpos[baseid]); |
b2e010ee | 1384 | fseek(fp,lastpos[baseid],SEEK_SET); |
1385 | while ( komodo_parsestatefile(sp,fp,symbol,dest) >= 0 && n < 1000 ) | |
ba37a6b9 | 1386 | { |
b2e010ee | 1387 | if ( n == 999 ) |
430d3c77 | 1388 | { |
b2e010ee | 1389 | if ( time(NULL) < starttime+maxseconds ) |
1390 | n = 0; | |
1391 | else | |
1392 | { | |
1393 | //printf("expire passport loop %s -> %s at %ld\n",ASSETCHAINS_SYMBOL,base,lastpos[baseid]); | |
1394 | expired++; | |
1395 | } | |
430d3c77 | 1396 | } |
b2e010ee | 1397 | n++; |
ba37a6b9 | 1398 | } |
b2e010ee | 1399 | lastpos[baseid] = ftell(fp); |
65f47ad9 | 1400 | if ( lastpos[baseid] == 0 && strcmp(symbol,"KMD") == 0 ) |
b2e010ee | 1401 | printf("from.(%s) lastpos[%s] %ld isrt.%d\n",ASSETCHAINS_SYMBOL,CURRENCIES[baseid],lastpos[baseid],komodo_isrealtime(&ht)); |
1402 | } //else fprintf(stderr,"%s.%ld ",CURRENCIES[baseid],ftell(fp)); | |
1403 | fclose(fp); | |
e7fa1876 | 1404 | } //else printf("error.(%s) %p\n",fname,sp); |
b2e010ee | 1405 | komodo_statefname(fname,baseid<32?base:(char *)"",(char *)"realtime"); |
1406 | if ( (fp= fopen(fname,"rb")) != 0 ) | |
a7ef556c | 1407 | { |
b2e010ee | 1408 | if ( fread(buf,1,sizeof(buf),fp) == sizeof(buf) ) |
6eb41a2f | 1409 | { |
b2e010ee | 1410 | sp->CURRENT_HEIGHT = buf[0]; |
1411 | if ( buf[0] != 0 && buf[0] >= buf[1] && buf[2] > time(NULL)-300 ) | |
1412 | { | |
1413 | isrealtime = 1; | |
1414 | RTmask |= (1LL << baseid); | |
1415 | memcpy(refsp->RTbufs[baseid+1],buf,sizeof(refsp->RTbufs[baseid+1])); | |
9d334465 | 1416 | } else if ( KOMODO_PAX != 0 && (time(NULL)-buf[2]) > 1800 && ASSETCHAINS_SYMBOL[0] != 0 ) |
b2e010ee | 1417 | fprintf(stderr,"[%s]: %s not RT %u %u %d\n",ASSETCHAINS_SYMBOL,base,buf[0],buf[1],(int32_t)(time(NULL)-buf[2])); |
1418 | } //else fprintf(stderr,"%s size error RT\n",base); | |
1419 | fclose(fp); | |
1420 | } //else fprintf(stderr,"%s open error RT\n",base); | |
1421 | } | |
a7ef556c | 1422 | } |
6238a204 | 1423 | else |
a7ef556c | 1424 | { |
1425 | komodo_statefname(fname,baseid<32?base:(char *)"",(char *)"realtime"); | |
1426 | if ( (fp= fopen(fname,"wb")) != 0 ) | |
1427 | { | |
30376a70 | 1428 | buf[0] = (uint32_t)chainActive.Tip()->nHeight; |
a7ef556c | 1429 | buf[1] = (uint32_t)komodo_longestchain(); |
1430 | if ( buf[0] != 0 && buf[0] == buf[1] ) | |
6eb41a2f | 1431 | { |
a7ef556c | 1432 | buf[2] = (uint32_t)time(NULL); |
582c6afe | 1433 | RTmask |= (1LL << baseid); |
635dd34d | 1434 | memcpy(refsp->RTbufs[baseid+1],buf,sizeof(refsp->RTbufs[baseid+1])); |
1435 | if ( refid != 0 ) | |
1436 | memcpy(refsp->RTbufs[0],buf,sizeof(refsp->RTbufs[0])); | |
6eb41a2f | 1437 | } |
a7ef556c | 1438 | if ( fwrite(buf,1,sizeof(buf),fp) != sizeof(buf) ) |
1439 | fprintf(stderr,"[%s] %s error writing realtime\n",ASSETCHAINS_SYMBOL,base); | |
1440 | fclose(fp); | |
f789edde | 1441 | } else fprintf(stderr,"%s create error RT\n",base); |
ecf6256c | 1442 | } |
f1db88ea | 1443 | if ( sp != 0 && isrealtime == 0 ) |
1444 | refsp->RTbufs[0][2] = 0; | |
52f1d788 | 1445 | } |
6238a204 | 1446 | komodo_paxtotal(); |
635dd34d | 1447 | refsp->RTmask = RTmask; |
430d3c77 | 1448 | if ( expired == 0 && KOMODO_PASSPORT_INITDONE == 0 ) |
1449 | { | |
1450 | KOMODO_PASSPORT_INITDONE = 1; | |
1451 | printf("done PASSPORT %s refid.%d\n",ASSETCHAINS_SYMBOL,refid); | |
1452 | } | |
ab918767 | 1453 | } |
ab918767 | 1454 |