|
@ -580,22 +580,64 @@ char *iguana_utxoduplicates(struct supernet_info *myinfo,struct iguana_info *coi |
|
|
return(rawtx); |
|
|
return(rawtx); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
char *iguana_utxorawtx(struct supernet_info *myinfo,struct iguana_info *coin,char *destaddr,char *changeaddr,uint64_t satoshis,uint64_t txfee,int32_t *completedp,int32_t sendflag,cJSON *utxos) |
|
|
int64_t iguana_verifytimelock(struct supernet_info *myinfo,struct iguana_info *coin,uint32_t timelocked,char *destaddr,bits256 txid,int32_t vout) |
|
|
{ |
|
|
{ |
|
|
uint8_t script[35],rmd160[20],addrtype; bits256 txid; int32_t spendlen; cJSON *retjson,*txobj=0,*vins=0; char *rawtx=0,*signedtx=0; |
|
|
uint8_t script[35],script2[35],p2shscript[128],rmd160[20],addrtype; char *retstr,*spendscriptstr; int32_t p2shlen,spendlen; cJSON *sobj,*txout=0; int64_t value = 0; |
|
|
|
|
|
bitcoin_addr2rmd160(&addrtype,rmd160,destaddr); |
|
|
|
|
|
if ( addrtype != coin->chain->pubtype ) |
|
|
|
|
|
return(-1); |
|
|
|
|
|
p2shlen = bitcoin_timelockspend(p2shscript,0,rmd160,timelocked); |
|
|
|
|
|
calc_rmd160(0,rmd160,p2shscript,p2shlen); |
|
|
|
|
|
spendlen = bitcoin_p2shspend(script,0,rmd160); |
|
|
|
|
|
if ( coin->FULLNODE != 0 ) |
|
|
|
|
|
txout = dpow_gettxout(myinfo,coin,txid,vout); |
|
|
|
|
|
else if ( (retstr= _dex_gettxout(myinfo,coin->symbol,txid,vout)) != 0 ) |
|
|
|
|
|
{ |
|
|
|
|
|
txout = cJSON_Parse(retstr); |
|
|
|
|
|
free(retstr); |
|
|
|
|
|
} |
|
|
|
|
|
if ( txout != 0 ) |
|
|
|
|
|
{ |
|
|
|
|
|
if ( (sobj= jobj(txout,"scriptPubKey")) != 0 && (spendscriptstr= jstr(sobj,"hex")) == 0 ) |
|
|
|
|
|
{ |
|
|
|
|
|
if ( strlen(spendscriptstr) == spendlen*2 ) |
|
|
|
|
|
{ |
|
|
|
|
|
decode_hex(script2,spendlen,spendscriptstr); |
|
|
|
|
|
if ( memcmp(script,script2,spendlen) != 0 ) |
|
|
|
|
|
return(-2); |
|
|
|
|
|
value = SATOSHIDEN * jdouble(txout,"value"); |
|
|
|
|
|
} else return(-4); |
|
|
|
|
|
} |
|
|
|
|
|
free_json(txout); |
|
|
|
|
|
return(value); |
|
|
|
|
|
} return(-2); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
char *iguana_utxorawtx(struct supernet_info *myinfo,struct iguana_info *coin,int32_t timelock,char *destaddr,char *changeaddr,uint64_t satoshis,uint64_t txfee,int32_t *completedp,int32_t sendflag,cJSON *utxos) |
|
|
|
|
|
{ |
|
|
|
|
|
uint8_t script[35],p2shscript[128],rmd160[20],addrtype; bits256 txid; int32_t p2shlen,spendlen; cJSON *retjson,*txobj=0,*vins=0; char *rawtx=0,*signedtx=0; uint32_t timelocked = 0; |
|
|
*completedp = 0; |
|
|
*completedp = 0; |
|
|
if ( iguana_addressvalidate(coin,&addrtype,destaddr) < 0 || iguana_addressvalidate(coin,&addrtype,changeaddr) < 0 ) |
|
|
if ( iguana_addressvalidate(coin,&addrtype,destaddr) < 0 || iguana_addressvalidate(coin,&addrtype,changeaddr) < 0 ) |
|
|
return(clonestr("{\"error\":\"invalid coin address\"}")); |
|
|
return(clonestr("{\"error\":\"invalid coin address\"}")); |
|
|
bitcoin_addr2rmd160(&addrtype,rmd160,changeaddr); |
|
|
bitcoin_addr2rmd160(&addrtype,rmd160,changeaddr); |
|
|
if ( addrtype != coin->chain->pubtype ) |
|
|
if ( addrtype != coin->chain->pubtype ) |
|
|
return(clonestr("{\"error\":\"invalid dest changeaddr type\"}")); |
|
|
return(clonestr("{\"error\":\"invalid changeaddr type\"}")); |
|
|
bitcoin_addr2rmd160(&addrtype,rmd160,destaddr); |
|
|
bitcoin_addr2rmd160(&addrtype,rmd160,destaddr); |
|
|
if ( addrtype != coin->chain->pubtype ) |
|
|
if ( addrtype != coin->chain->pubtype ) |
|
|
return(clonestr("{\"error\":\"invalid dest address type\"}")); |
|
|
return(clonestr("{\"error\":\"invalid dest address type\"}")); |
|
|
retjson = cJSON_CreateObject(); |
|
|
retjson = cJSON_CreateObject(); |
|
|
if ( (txobj= bitcoin_txcreate(coin->symbol,coin->chain->isPoS,0,1,0)) != 0 ) |
|
|
if ( (txobj= bitcoin_txcreate(coin->symbol,coin->chain->isPoS,0,1,0)) != 0 ) |
|
|
{ |
|
|
{ |
|
|
spendlen = bitcoin_standardspend(script,0,rmd160); |
|
|
if ( timelock == 0 ) |
|
|
|
|
|
spendlen = bitcoin_standardspend(script,0,rmd160); |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
timelocked = (uint32_t)(time(NULL)+timelock); |
|
|
|
|
|
p2shlen = bitcoin_timelockspend(p2shscript,0,rmd160,timelocked); |
|
|
|
|
|
calc_rmd160(0,rmd160,p2shscript,p2shlen); |
|
|
|
|
|
spendlen = bitcoin_p2shspend(script,0,rmd160); |
|
|
|
|
|
printf("timelock.%d spend timelocked %u\n",timelock,timelocked); |
|
|
|
|
|
} |
|
|
bitcoin_txoutput(txobj,script,spendlen,satoshis); |
|
|
bitcoin_txoutput(txobj,script,spendlen,satoshis); |
|
|
if ( (rawtx= iguana_calcutxorawtx(myinfo,coin,&vins,txobj,satoshis,changeaddr,txfee,utxos,"",0,0)) != 0 ) |
|
|
if ( (rawtx= iguana_calcutxorawtx(myinfo,coin,&vins,txobj,satoshis,changeaddr,txfee,utxos,"",0,0)) != 0 ) |
|
|
{ |
|
|
{ |
|
@ -616,6 +658,11 @@ char *iguana_utxorawtx(struct supernet_info *myinfo,struct iguana_info *coin,cha |
|
|
} else printf("error signing raw utxoduplicates tx\n"); |
|
|
} else printf("error signing raw utxoduplicates tx\n"); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
if ( timelock != 0 ) |
|
|
|
|
|
{ |
|
|
|
|
|
jaddnum(retjson,"timelock",timelock); |
|
|
|
|
|
jaddnum(retjson,"timelocked",timelocked); |
|
|
|
|
|
} |
|
|
jaddstr(retjson,"result","success"); |
|
|
jaddstr(retjson,"result","success"); |
|
|
if ( *completedp != 0 ) |
|
|
if ( *completedp != 0 ) |
|
|
jadd(retjson,"completed",jtrue()); |
|
|
jadd(retjson,"completed",jtrue()); |
|
|