Browse Source

time lock field

etomic
jl777 8 years ago
parent
commit
bf44f16076
  1. 8
      basilisk/basilisk.c
  2. 55
      basilisk/basilisk_bitcoin.c
  3. 7
      iguana/iguana_scripts.c
  4. 2
      iguana/tests/utxorawtx
  5. 1
      includes/iguana_funcs.h

8
basilisk/basilisk.c

@ -1158,7 +1158,8 @@ TWO_STRINGS(basilisk,refresh,symbol,address)
STRING_ARRAY_OBJ_STRING(basilisk,utxorawtx,symbol,utxos,vals,ignore)
{
char *destaddr,*changeaddr; uint64_t satoshis,txfee; int32_t completed,sendflag;
char *destaddr,*changeaddr; uint64_t satoshis,txfee; int32_t completed,sendflag,timelock;
timelock = jint(vals,"timelock");
sendflag = jint(vals,"sendflag");
satoshis = jdouble(vals,"amount") * SATOSHIDEN;
destaddr = jstr(vals,"destaddr");
@ -1167,9 +1168,12 @@ STRING_ARRAY_OBJ_STRING(basilisk,utxorawtx,symbol,utxos,vals,ignore)
{
if ( (txfee= jdouble(vals,"txfee") * SATOSHIDEN) == 0 )
txfee = coin->txfee;
return(iguana_utxorawtx(myinfo,coin,destaddr,changeaddr,satoshis,txfee,&completed,sendflag,utxos));
return(iguana_utxorawtx(myinfo,coin,timelock,destaddr,changeaddr,satoshis,txfee,&completed,sendflag,utxos));
}
return(clonestr("{\"error\":\"invalid coin or address specified\"}"));
}
int64_t iguana_verifytimelock(struct supernet_info *myinfo,struct iguana_info *coin,uint32_t timelocked,char *destaddr,bits256 txid,int32_t vout)
#include "../includes/iguana_apiundefs.h"

55
basilisk/basilisk_bitcoin.c

@ -580,22 +580,64 @@ char *iguana_utxoduplicates(struct supernet_info *myinfo,struct iguana_info *coi
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;
if ( iguana_addressvalidate(coin,&addrtype,destaddr) < 0 || iguana_addressvalidate(coin,&addrtype,changeaddr) < 0 )
return(clonestr("{\"error\":\"invalid coin address\"}"));
bitcoin_addr2rmd160(&addrtype,rmd160,changeaddr);
if ( addrtype != coin->chain->pubtype )
return(clonestr("{\"error\":\"invalid dest changeaddr type\"}"));
return(clonestr("{\"error\":\"invalid changeaddr type\"}"));
bitcoin_addr2rmd160(&addrtype,rmd160,destaddr);
if ( addrtype != coin->chain->pubtype )
return(clonestr("{\"error\":\"invalid dest address type\"}"));
retjson = cJSON_CreateObject();
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);
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");
}
}
if ( timelock != 0 )
{
jaddnum(retjson,"timelock",timelock);
jaddnum(retjson,"timelocked",timelocked);
}
jaddstr(retjson,"result","success");
if ( *completedp != 0 )
jadd(retjson,"completed",jtrue());

7
iguana/iguana_scripts.c

@ -77,6 +77,13 @@ int32_t bitcoin_checklocktimeverify(uint8_t *script,int32_t n,uint32_t locktime)
return(n);
}
int32_t bitcoin_timelockspend(uint8_t *script,int32_t n,uint8_t rmd160[20],uint32_t timestamp)
{
n = bitcoin_checklocktimeverify(script,n,timestamp);
n = bitcoin_standardspend(script,n,rmd160);
return(n);
}
int32_t bitcoin_MofNspendscript(uint8_t p2sh_rmd160[20],uint8_t *script,int32_t n,const struct vin_info *vp)
{
int32_t i,plen;

2
iguana/tests/utxorawtx

@ -1,2 +1,2 @@
#!/bin/bash
curl --url "http://127.0.0.1:7778" --data "{\"symbol\":\"KMD\",\"agent\":\"basilisk\",\"method\":\"utxorawtx\",\"vals\":{\"changeaddr\":\"RNmvQtThVZAbc1tFEFmKAnJZrc9XqciNog\",\"destaddr\":\"RHfraY22xd9aAuuUJ6Yjb6HFUXh535z6Lg\",\"txfee\":0.00011,\"amount\":0.01,\"sendflag\":0},\"utxos\":[{\"bestblock\":\"000000a7d7b317af7169a156f6b4b9538293da2a3707a69aa3048998a87fbf2c\",\"confirmations\":0,\"value\":1,\"scriptPubKey\":{\"asm\":\"OP_DUP OP_HASH160 b7128d2ee837cf03e30a2c0e3e0181f7b9669bb6 OP_EQUALVERIFY OP_CHECKSIG\",\"hex\":\"76a914b7128d2ee837cf03e30a2c0e3e0181f7b9669bb688ac\",\"reqSigs\":1,\"type\":\"pubkeyhash\",\"addresses\":[\"RRyBxbrAPRUBCUpiJgJZYrkxqrh8x5ta9Z\"]},\"version\":1,\"coinbase\":false,\"randipbits\":3350674129,\"coin\":\"KMD\",\"txid\":\"94e8c4acd20e5d59d9a6a69375c74749b1eba5821d0f218b44c3ce3d8f6989ec\",\"vout\":1,\"amount\":1}]}"
curl --url "http://127.0.0.1:7778" --data "{\"symbol\":\"KMD\",\"agent\":\"basilisk\",\"method\":\"utxorawtx\",\"vals\":{\"timelock\":0,\"changeaddr\":\"RNmvQtThVZAbc1tFEFmKAnJZrc9XqciNog\",\"destaddr\":\"RHfraY22xd9aAuuUJ6Yjb6HFUXh535z6Lg\",\"txfee\":0.00011,\"amount\":0.01,\"sendflag\":0},\"utxos\":[{\"bestblock\":\"000000a7d7b317af7169a156f6b4b9538293da2a3707a69aa3048998a87fbf2c\",\"confirmations\":0,\"value\":0.02,\"scriptPubKey\":{\"asm\":\"OP_DUP OP_HASH160 b7128d2ee837cf03e30a2c0e3e0181f7b9669bb6 OP_EQUALVERIFY OP_CHECKSIG\",\"hex\":\"76a914b7128d2ee837cf03e30a2c0e3e0181f7b9669bb688ac\",\"reqSigs\":1,\"type\":\"pubkeyhash\",\"addresses\":[\"RRyBxbrAPRUBCUpiJgJZYrkxqrh8x5ta9Z\"]},\"version\":1,\"coinbase\":false,\"randipbits\":3350674129,\"coin\":\"KMD\",\"txid\":\"9329814cc4c7a8cabf83627d4228c1a2090e776d669c585d824d912ce2e13b13\",\"vout\":1,\"amount\":0.02}]}"

1
includes/iguana_funcs.h

@ -638,6 +638,7 @@ void libgfshare_init(struct supernet_info *myinfo,uint8_t _logs[256],uint8_t _ex
int32_t init_sharenrs(uint8_t sharenrs[255],uint8_t *orig,int32_t m,int32_t n);
void iguana_schnorr(struct supernet_info *myinfo);
void iguana_fixsecp(struct supernet_info *myinfo);
int32_t bitcoin_timelockspend(uint8_t *script,int32_t n,uint8_t rmd160[20],uint32_t timestamp);
char *iguana_calcutxorawtx(struct supernet_info *myinfo,struct iguana_info *coin,cJSON **vinsp,cJSON *txobj,int64_t satoshis,char *changeaddr,int64_t txfee,cJSON *utxos,char *remoteaddr,struct vin_info *V,int32_t maxmode);

Loading…
Cancel
Save