|
|
@ -301,7 +301,7 @@ cJSON *iguana_voutjson(struct iguana_info *coin,struct iguana_msgvout *vout,int3 |
|
|
|
return(json); |
|
|
|
} |
|
|
|
|
|
|
|
bits256 bitcoin_sigtxid(struct iguana_info *coin,uint8_t *serialized,int32_t maxlen,struct iguana_msgtx *msgtx,int32_t vini,uint8_t *spendscript,int32_t spendlen,int32_t hashtype,char *vpnstr) |
|
|
|
bits256 bitcoin_sigtxid(struct iguana_info *coin,uint8_t *serialized,int32_t maxlen,struct iguana_msgtx *msgtx,int32_t vini,uint8_t *spendscript,int32_t spendlen,int32_t hashtype,char *vpnstr,int32_t suppress_pubkeys) |
|
|
|
{ |
|
|
|
int32_t i,len; bits256 sigtxid,txid,revsigtxid; struct iguana_msgtx dest; |
|
|
|
dest = *msgtx; |
|
|
@ -326,7 +326,7 @@ bits256 bitcoin_sigtxid(struct iguana_info *coin,uint8_t *serialized,int32_t max |
|
|
|
dest.vins[i].p2shlen = 0; |
|
|
|
dest.vins[i].redeemscript = 0; |
|
|
|
} |
|
|
|
len = iguana_rwmsgtx(coin,1,0,serialized,maxlen,&dest,&txid,vpnstr,0,0,0); |
|
|
|
len = iguana_rwmsgtx(coin,1,0,serialized,maxlen,&dest,&txid,vpnstr,0,0,0,suppress_pubkeys); |
|
|
|
if ( len > 0 ) |
|
|
|
{ |
|
|
|
len += iguana_rwnum(1,&serialized[len],sizeof(hashtype),&hashtype); |
|
|
@ -338,7 +338,7 @@ bits256 bitcoin_sigtxid(struct iguana_info *coin,uint8_t *serialized,int32_t max |
|
|
|
return(sigtxid); |
|
|
|
} |
|
|
|
|
|
|
|
int32_t iguana_rwmsgtx(struct iguana_info *coin,int32_t rwflag,cJSON *json,uint8_t *serialized,int32_t maxsize,struct iguana_msgtx *msg,bits256 *txidp,char *vpnstr,uint8_t *extraspace,int32_t extralen,cJSON *vins) |
|
|
|
int32_t iguana_rwmsgtx(struct iguana_info *coin,int32_t rwflag,cJSON *json,uint8_t *serialized,int32_t maxsize,struct iguana_msgtx *msg,bits256 *txidp,char *vpnstr,uint8_t *extraspace,int32_t extralen,cJSON *vins,int32_t suppress_pubkeys) |
|
|
|
{ |
|
|
|
int32_t i,n,len = 0,extraused=0; uint8_t *txstart = serialized,*sigser=0; char txidstr[65]; cJSON *array=0; bits256 sigtxid; |
|
|
|
len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->version),&msg->version); |
|
|
@ -393,7 +393,7 @@ int32_t iguana_rwmsgtx(struct iguana_info *coin,int32_t rwflag,cJSON *json,uint8 |
|
|
|
{ |
|
|
|
//set spendscript here
|
|
|
|
printf("vini.%d spendscript.%p spendlen.%d (%s)\n",i,msg->vins[i].spendscript,msg->vins[i].spendlen,jprint(jitem(vins,i),0)); |
|
|
|
sigtxid = bitcoin_sigtxid(coin,sigser,maxsize*2,msg,i,msg->vins[i].spendscript,msg->vins[i].spendlen,SIGHASH_ALL,vpnstr); |
|
|
|
sigtxid = bitcoin_sigtxid(coin,sigser,maxsize*2,msg,i,msg->vins[i].spendscript,msg->vins[i].spendlen,SIGHASH_ALL,vpnstr,suppress_pubkeys); |
|
|
|
} else memset(sigtxid.bytes,0,sizeof(sigtxid)); |
|
|
|
jaddi(array,iguana_vinjson(coin,&msg->vins[i],sigtxid)); |
|
|
|
} |
|
|
@ -522,7 +522,7 @@ bits256 iguana_parsetxobj(struct supernet_info *myinfo,struct iguana_info *coin, |
|
|
|
msg->lock_time = jint(txobj,"locktime"); |
|
|
|
msg->txid = jbits256(txobj,"txid"); |
|
|
|
*txstartp = len; |
|
|
|
if ( (msg->allocsize= iguana_rwmsgtx(coin,1,0,&serialized[len],maxsize-len,msg,&txid,vpnstr,0,0,0)) < 0 ) |
|
|
|
if ( (msg->allocsize= iguana_rwmsgtx(coin,1,0,&serialized[len],maxsize-len,msg,&txid,vpnstr,0,0,0,V->suppress_pubkeys)) < 0 ) |
|
|
|
{ |
|
|
|
memset(txid.bytes,0,sizeof(txid)); |
|
|
|
printf("error parsing txobj\n"); |
|
|
@ -532,13 +532,13 @@ bits256 iguana_parsetxobj(struct supernet_info *myinfo,struct iguana_info *coin, |
|
|
|
return(txid); |
|
|
|
} |
|
|
|
|
|
|
|
char *iguana_rawtxbytes(struct iguana_info *coin,cJSON *json,struct iguana_msgtx *msgtx) |
|
|
|
char *iguana_rawtxbytes(struct iguana_info *coin,cJSON *json,struct iguana_msgtx *msgtx,int32_t suppress_pubkeys) |
|
|
|
{ |
|
|
|
int32_t n; char *txbytes = 0,vpnstr[64]; uint8_t *serialized; |
|
|
|
serialized = malloc(IGUANA_MAXPACKETSIZE); |
|
|
|
vpnstr[0] = 0; |
|
|
|
//char str[65]; printf("%d of %d: %s\n",i,msg.txn_count,bits256_str(str,tx.txid));
|
|
|
|
if ( (n= iguana_rwmsgtx(coin,1,json,serialized,IGUANA_MAXPACKETSIZE,msgtx,&msgtx->txid,vpnstr,0,0,0)) > 0 ) |
|
|
|
if ( (n= iguana_rwmsgtx(coin,1,json,serialized,IGUANA_MAXPACKETSIZE,msgtx,&msgtx->txid,vpnstr,0,0,0,suppress_pubkeys)) > 0 ) |
|
|
|
{ |
|
|
|
txbytes = malloc(n*2+1); |
|
|
|
init_hexbytes_noT(txbytes,serialized,n); |
|
|
@ -566,7 +566,7 @@ char *bitcoin_json2hex(struct supernet_info *myinfo,struct iguana_info *coin,bit |
|
|
|
return(txbytes); |
|
|
|
} |
|
|
|
|
|
|
|
cJSON *bitcoin_data2json(struct iguana_info *coin,bits256 *txidp,struct iguana_msgtx *msgtx,uint8_t *extraspace,int32_t extralen,uint8_t *serialized,int32_t len,cJSON *vins) |
|
|
|
cJSON *bitcoin_data2json(struct iguana_info *coin,bits256 *txidp,struct iguana_msgtx *msgtx,uint8_t *extraspace,int32_t extralen,uint8_t *serialized,int32_t len,cJSON *vins,int32_t suppress_pubkeys) |
|
|
|
{ |
|
|
|
int32_t n; char vpnstr[64]; struct iguana_msgtx M; cJSON *txobj; |
|
|
|
if ( coin == 0 || serialized == 0 ) |
|
|
@ -577,7 +577,7 @@ cJSON *bitcoin_data2json(struct iguana_info *coin,bits256 *txidp,struct iguana_m |
|
|
|
memset(msgtx,0,sizeof(M)); |
|
|
|
vpnstr[0] = 0; |
|
|
|
memset(txidp,0,sizeof(*txidp)); |
|
|
|
if ( (n= iguana_rwmsgtx(coin,0,txobj,serialized,len,msgtx,txidp,vpnstr,extraspace,extralen,vins)) <= 0 ) |
|
|
|
if ( (n= iguana_rwmsgtx(coin,0,txobj,serialized,len,msgtx,txidp,vpnstr,extraspace,extralen,vins,suppress_pubkeys)) <= 0 ) |
|
|
|
{ |
|
|
|
free_json(txobj); |
|
|
|
txobj = cJSON_CreateObject(); |
|
|
@ -587,7 +587,7 @@ cJSON *bitcoin_data2json(struct iguana_info *coin,bits256 *txidp,struct iguana_m |
|
|
|
return(txobj); |
|
|
|
} |
|
|
|
|
|
|
|
cJSON *bitcoin_hex2json(struct iguana_info *coin,bits256 *txidp,struct iguana_msgtx *msgtx,char *txbytes,uint8_t *extraspace,int32_t extralen,uint8_t *origserialized,cJSON *vins) |
|
|
|
cJSON *bitcoin_hex2json(struct iguana_info *coin,bits256 *txidp,struct iguana_msgtx *msgtx,char *txbytes,uint8_t *extraspace,int32_t extralen,uint8_t *origserialized,cJSON *vins,int32_t suppress_pubkeys) |
|
|
|
{ |
|
|
|
int32_t len; uint8_t *serialized; cJSON *txobj; |
|
|
|
if ( coin == 0 || txbytes == 0 ) |
|
|
@ -596,7 +596,7 @@ cJSON *bitcoin_hex2json(struct iguana_info *coin,bits256 *txidp,struct iguana_ms |
|
|
|
if ( (serialized= origserialized) == 0 ) |
|
|
|
serialized = calloc(1,len); |
|
|
|
decode_hex(serialized,len,txbytes); |
|
|
|
txobj = bitcoin_data2json(coin,txidp,msgtx,extraspace,extralen,serialized,len,vins); |
|
|
|
txobj = bitcoin_data2json(coin,txidp,msgtx,extraspace,extralen,serialized,len,vins,suppress_pubkeys); |
|
|
|
if ( serialized != origserialized ) |
|
|
|
free(serialized); |
|
|
|
return(txobj); |
|
|
@ -666,7 +666,7 @@ int32_t iguana_msgtx_Vset(struct iguana_info *coin,uint8_t *serialized,int32_t m |
|
|
|
return(len); |
|
|
|
} |
|
|
|
|
|
|
|
int32_t bitcoin_verifyvins(struct iguana_info *coin,bits256 *signedtxidp,char **signedtx,struct iguana_msgtx *msgtx,uint8_t *serialized,int32_t maxlen,struct vin_info *V,int32_t sighash,int32_t signtx) |
|
|
|
int32_t bitcoin_verifyvins(struct iguana_info *coin,bits256 *signedtxidp,char **signedtx,struct iguana_msgtx *msgtx,uint8_t *serialized,int32_t maxlen,struct vin_info *V,int32_t sighash,int32_t signtx,int32_t suppress_pubkeys) |
|
|
|
{ |
|
|
|
bits256 sigtxid; uint8_t *sig; struct vin_info *vp; char vpnstr[64]; int32_t complete=0,plen,j,vini=0,flag=0,siglen,numvouts,numsigs; |
|
|
|
numvouts = msgtx->tx_out; |
|
|
@ -675,7 +675,7 @@ int32_t bitcoin_verifyvins(struct iguana_info *coin,bits256 *signedtxidp,char ** |
|
|
|
memset(signedtxidp,0,sizeof(*signedtxidp)); |
|
|
|
for (vini=0; vini<msgtx->tx_in; vini++) |
|
|
|
{ |
|
|
|
sigtxid = bitcoin_sigtxid(coin,serialized,maxlen,msgtx,vini,msgtx->vins[vini].spendscript,msgtx->vins[vini].spendlen,sighash,vpnstr); |
|
|
|
sigtxid = bitcoin_sigtxid(coin,serialized,maxlen,msgtx,vini,msgtx->vins[vini].spendscript,msgtx->vins[vini].spendlen,sighash,vpnstr,suppress_pubkeys); |
|
|
|
if ( bits256_nonz(sigtxid) != 0 ) |
|
|
|
{ |
|
|
|
vp = &V[vini]; |
|
|
@ -728,7 +728,7 @@ int32_t bitcoin_verifyvins(struct iguana_info *coin,bits256 *signedtxidp,char ** |
|
|
|
} |
|
|
|
iguana_msgtx_Vset(coin,serialized,maxlen,msgtx,V); |
|
|
|
cJSON *txobj = cJSON_CreateObject(); |
|
|
|
*signedtx = iguana_rawtxbytes(coin,txobj,msgtx); |
|
|
|
*signedtx = iguana_rawtxbytes(coin,txobj,msgtx,suppress_pubkeys); |
|
|
|
//printf("SIGNEDTX.(%s)\n",jprint(txobj,1));
|
|
|
|
*signedtxidp = msgtx->txid; |
|
|
|
return(complete); |
|
|
@ -1072,7 +1072,7 @@ P2SH_SPENDAPI(iguana,spendmsig,activecoin,vintxid,vinvout,destaddress,destamount |
|
|
|
bitcoin_txinput(active,txobj,vintxid,vinvout,0xffffffff,spendscript,spendlen,V.p2shscript,V.p2shlen,pubkeyptrs,N); |
|
|
|
bitcoin_address(msigaddr,active->chain->p2shtype,V.p2shscript,V.p2shlen); |
|
|
|
retjson = cJSON_CreateObject(); |
|
|
|
if ( bitcoin_verifyvins(active,&signedtxid,&signedtx,&msgtx,serialized,sizeof(serialized),&V,SIGHASH_ALL,1) == 0 ) |
|
|
|
if ( bitcoin_verifyvins(active,&signedtxid,&signedtx,&msgtx,serialized,sizeof(serialized),&V,SIGHASH_ALL,1,V.suppress_pubkeys) == 0 ) |
|
|
|
{ |
|
|
|
jaddstr(retjson,"result","msigtx"); |
|
|
|
if ( signedtx != 0 ) |
|
|
@ -1096,7 +1096,7 @@ int32_t iguana_signrawtransaction(struct supernet_info *myinfo,struct iguana_inf |
|
|
|
extraspace = malloc(extralen); |
|
|
|
memset(msgtx,0,sizeof(*msgtx)); |
|
|
|
decode_hex(serialized,len,rawtx); |
|
|
|
if ( (txobj= bitcoin_hex2json(coin,&txid,msgtx,rawtx,extraspace,extralen,serialized4,vins)) != 0 ) |
|
|
|
if ( (txobj= bitcoin_hex2json(coin,&txid,msgtx,rawtx,extraspace,extralen,serialized4,vins,V->suppress_pubkeys)) != 0 ) |
|
|
|
{ |
|
|
|
printf("txobj.(%s)\n",jprint(txobj,0)); |
|
|
|
if ( 0 && (checkstr= bitcoin_json2hex(myinfo,coin,&txid,txobj,V)) != 0 ) |
|
|
@ -1116,7 +1116,7 @@ int32_t iguana_signrawtransaction(struct supernet_info *myinfo,struct iguana_inf |
|
|
|
if ( (numinputs= cJSON_GetArraySize(vins)) > 0 ) |
|
|
|
{ |
|
|
|
memset(msgtx,0,sizeof(*msgtx)); |
|
|
|
if ( iguana_rwmsgtx(coin,0,0,serialized,maxsize,msgtx,&txid,"",extraspace,65536,vins) > 0 && numinputs == msgtx->tx_in ) |
|
|
|
if ( iguana_rwmsgtx(coin,0,0,serialized,maxsize,msgtx,&txid,"",extraspace,65536,vins,V->suppress_pubkeys) > 0 && numinputs == msgtx->tx_in ) |
|
|
|
{ |
|
|
|
if ( (n= cJSON_GetArraySize(privkeys)) > 0 ) |
|
|
|
{ |
|
|
@ -1131,7 +1131,7 @@ int32_t iguana_signrawtransaction(struct supernet_info *myinfo,struct iguana_inf |
|
|
|
} |
|
|
|
} |
|
|
|
finalized = iguana_vininfo_create(myinfo,coin,serialized2,maxsize,msgtx,vins,numinputs,V); |
|
|
|
if ( (complete= bitcoin_verifyvins(coin,signedtxidp,&signedtx,msgtx,serialized3,maxsize,V,SIGHASH_ALL,1)) > 0 && signedtx != 0 ) |
|
|
|
if ( (complete= bitcoin_verifyvins(coin,signedtxidp,&signedtx,msgtx,serialized3,maxsize,V,SIGHASH_ALL,1,V->suppress_pubkeys)) > 0 && signedtx != 0 ) |
|
|
|
{ |
|
|
|
int32_t tmp; |
|
|
|
if ( (tmp= iguana_interpreter(coin,0,iguana_lockval(finalized,jint(txobj,"locktime")),V,numinputs)) < 0 ) |
|
|
|