jl777 8 years ago
parent
commit
a651896ca0
  1. 2
      basilisk/basilisk_swap.c
  2. 2
      iguana/exchanges/bitcoin.c
  3. 17
      iguana/iguana777.c
  4. 25
      iguana/iguana_interpreter.c
  5. 6
      iguana/iguana_payments.c
  6. 6
      iguana/iguana_scripts.c
  7. 146
      iguana/iguana_sign.c
  8. 2
      iguana/iguana_wallet.c
  9. 2
      includes/iguana_structs.h

2
basilisk/basilisk_swap.c

@ -897,7 +897,7 @@ struct basilisk_swap *bitcoin_swapinit(struct supernet_info *myinfo,struct basil
basilisk_rawtx_setparms("alicepayment",myinfo,swap,&swap->alicepayment,swap->alicecoin,swap->aliceconfirms,0,swap->alicesatoshis,2,0);
basilisk_rawtx_setparms("bobspend",myinfo,swap,&swap->bobspend,swap->alicecoin,swap->aliceconfirms,2,swap->alicesatoshis-swap->alicecoin->txfee,1,bobpub33);
swap->bobspend.suppress_pubkeys = 0;
swap->bobspend.suppress_pubkeys = 1;
basilisk_rawtx_setparms("alicereclaim",myinfo,swap,&swap->alicereclaim,swap->alicecoin,swap->aliceconfirms,2,swap->alicesatoshis-swap->alicecoin->txfee,1,alicepub33);
swap->alicereclaim.suppress_pubkeys = 1;
return(swap);

2
iguana/exchanges/bitcoin.c

@ -331,7 +331,7 @@ cJSON *bitcoin_vout(uint64_t satoshis,char *paymentscriptstr)
skey = cJSON_CreateObject();
jaddstr(skey,"hex",paymentscriptstr);
//printf("addoutput.(%s %s)\n",hexstr,jprint(skey,0));
jadd(item,"scriptPubkey",skey);
jadd(item,"scriptPubKey",skey);
return(item);
}

17
iguana/iguana777.c

@ -880,21 +880,26 @@ void iguana_coinloop(void *arg)
if ( coin->started == 0 && coin->active != 0 )
{
iguana_callcoinstart(myinfo,coin);
if ( strcmp("BTC",coin->symbol) == 0 )
if ( strcmp("BTCD",coin->symbol) == 0 )
{
char *txstr = "0100000001d378ebd1b0c230b4d078288cf95fe28d7b3032d28c47de22ed6140d845dcb01f00000000d147304402204dd322834ff15cf1526dae3940521bb504b365b194515725d9c0f81dfbeae68d02205fb8fd269e3f2ddf7d0a17b056d2904ce572b8f22edeb39cd4c209fcf5244645011d74c7e7d8a2041be600e74708276d79ff001e754269b6e868ccf517f87f3d004c674c6763040cd6e557b175210326af93b75917b4903d7acdf8e2a560357ce18b7615cc7de02ade4f62861a57dfac67a9149c41c06aac6a7fcfd29eef87c4a633b9126b8b09882102a9669e63ef1ab04913615c2f3887ea3584f81e5f08feee9535b19ab3739d8afdac68ffffffff01127b0000000000001976a914b7128d2ee837cf03e30a2c0e3e0181f7b9669bb688ac00000000";
cJSON *txobj = cJSON_Parse("{\"version\":1,\"locktime\":1474666158,\"vin\":[{\"userdata\":\"51\",\"txid\":\"fc97c3675c83c09723e0b14292ddec73820cb7352166ace4fe81ed62568315f2\",\"vout\":0,\"scriptPubKey\":{\"hex\":\"a914b7a2e599edb55d3f78ebcbfd49e82dd9a12adc2487\"},\"suppress\":1,\"sequence\":0,\"redeemScript\":\"6304ae9ee557b1752102a9669e63ef1ab04913615c2f3887ea3584f81e5f08feee9535b19ab3739d8afdac67a914adfad35d6646a0514011ba6ab53462319b651f96882103225046c9947222ab04acdefe2ed5dec4dcb593c5e6ae58e2c61c7ace14d81b70ac68\"}],\"vout\":[{\"satoshis\":\"36042\",\"scriptPubkey\":{\"hex\":\"76a914b7128d2ee837cf03e30a2c0e3e0181f7b9669bb688ac\"}}]}");
cJSON *txobj4 = cJSON_Parse("{\"version\":1,\"locktime\":0,\"timestamp\":1474721847,\"vin\":[{\"txid\":\"a18e779a1daf22e9c427dc01dea0c268345a6b619da2eb7cdefd692719bdafdc\",\"vout\":0,\"scriptPubKey\":{\"hex\":\"a9149a8254cc4499a340209e7ca699fe6a096f79b31087\"},\"suppress\":1,\"redeemScript\":\"522102f563272bd62384d1813c1d30e774e6da6efa5822178a3ab64d6f3ed9e4cfb77e210387edb0a5895e772788c3e010b46c6145a0bafe862f098d6b74dc2f443408827b52ae\"}],\"vout\":[{\"satoshis\":\"9990000\",\"scriptPubkey\":{\"hex\":\"76a9148ee61a3161993f4f7b7081259bf5f3322d65d3f888ac\"}}]}");
cJSON *privkeys = cJSON_Parse("[\"UwqPATeGVau5GeevspxCsvjnusCrEkU8To8NKLv91GU4mbZCQKeT\", \"Uu4AEVHrgFv4trDfj24kDTgKhaEdDkV7sNpH8MgTKTxEATF9YEcv\"]");
cJSON *txobj2 = cJSON_Parse("{\"version\":1,\"locktime\":0,\"vin\":[{\"userdata\":\"20491d74c7e7d8a2041be600e74708276d79ff001e754269b6e868ccf517f87f3d00\",\"txid\":\"1fb0dc45d84061ed22de478cd232307b8de25ff98c2878d0b430c2b0d1eb78d3\",\"vout\":0,\"scriptPubKey\":{\"hex\":\"a9144bf88c2ce8b9a40e3863bf1d4a5fb443d3e1bfe487\"},\"suppress\":1,\"redeemScript\":\"63040cd6e557b175210326af93b75917b4903d7acdf8e2a560357ce18b7615cc7de02ade4f62861a57dfac67a9149c41c06aac6a7fcfd29eef87c4a633b9126b8b09882102a9669e63ef1ab04913615c2f3887ea3584f81e5f08feee9535b19ab3739d8afdac68\"}],\"vout\":[{\"satoshis\":\"31506\",\"scriptPubkey\":{\"hex\":\"76a914b7128d2ee837cf03e30a2c0e3e0181f7b9669bb688ac\"}}]}");
cJSON *txobj3 = cJSON_Parse("{\"version\":1,\"timestamp\":1474672690,\"vin\":[{\"sequence\":4294967214,\"txid\":\"119ec1a65f530c751e53b4af0505e960cf47680859c5f3ee3981ebe883207186\",\"vout\":0,\"scriptSig\":{\"hex\":\"483045022100880a1e3eafade4d4a24dd0bde2f31178d43978beacd63da1ee54760e0651f3b2022061dd05a66b65dc40fb729d95d2205dbf054ceb0bc4eb55c42088d0684a4c5a6701483045022100b4498798fc3a61de0b6df83ea4f6b67f89c5683124c2a3a981bd070826d7d1590220121d73d362b796583baa73c8c78eb851f78dc8f1cc75cb5bb3dfb14d6b843742012102ed1e99e73093c70c6156bce5954cb3e04215405ac06aa525ff942b74b8416efc2103a013a5f01afb3f0f00a657bb76fb30fd38437c80b52d9248b50738c96902e78747522102ed1e99e73093c70c6156bce5954cb3e04215405ac06aa525ff942b74b8416efc2103a013a5f01afb3f0f00a657bb76fb30fd38437c80b52d9248b50738c96902e78752ae\",\"asm\":\"3045022100880a1e3eafade4d4a24dd0bde2f31178d43978beacd63da1ee54760e0651f3b2022061dd05a66b65dc40fb729d95d2205dbf054ceb0bc4eb55c42088d0684a4c5a6701 3045022100b4498798fc3a61de0b6df83ea4f6b67f89c5683124c2a3a981bd070826d7d1590220121d73d362b796583baa73c8c78eb851f78dc8f1cc75cb5bb3dfb14d6b84374201 02ed1e99e73093c70c6156bce5954cb3e04215405ac06aa525ff942b74b8416efc 03a013a5f01afb3f0f00a657bb76fb30fd38437c80b52d9248b50738c96902e787 522102ed1e99e73093c70c6156bce5954cb3e04215405ac06aa525ff942b74b8416efc2103a013a5f01afb3f0f00a657bb76fb30fd38437c80b52d9248b50738c96902e78752ae\"}}],\"numvins\":1}");
struct vin_info V[3]; bits256 txid,checktxid; uint8_t *extraspace; struct iguana_info *coin = iguana_coinfind("BTCD");
struct vin_info V[3]; int32_t completed; char *signedtx; bits256 txid,signedtxid,checktxid; uint8_t *extraspace; struct iguana_info *coin = iguana_coinfind("BTCD");
memset(V,0,sizeof(V));
char *txbytes = bitcoin_json2hex(myinfo,coin,&txid,txobj3,V);
cJSON *tx = txobj4;
char *txbytes = bitcoin_json2hex(myinfo,coin,&txid,tx,V);
printf("rawtx.(%s)\n",txbytes);
extraspace = calloc(1,65536);
txobj = bitcoin_hex2json(coin,coin->blocks.hwmchain.height,&checktxid,0,txbytes,extraspace,65536,0,jobj(txobj2,"vin"),1);
printf("TXOBJ.(%s)\n",jprint(txobj,0));
txobj = bitcoin_hex2json(coin,coin->blocks.hwmchain.height,&checktxid,0,txbytes,extraspace,65536,0,jobj(tx,"vin"),1);
printf("\nTXOBJ.(%s)\n\n",jprint(txobj,0));
if ( (signedtx= iguana_signrawtx(myinfo,coin,1000000,&signedtxid,&completed,jobj(tx,"vin"),txbytes,privkeys,V)) != 0 )
printf("signedtx.(%s)\n",signedtx);
free(extraspace);
//getchar();
getchar();
}
}
now = (uint32_t)time(NULL);

25
iguana/iguana_interpreter.c

@ -501,12 +501,12 @@ static int32_t iguana_pushdata(struct iguana_interpreter *stacks,int64_t num64,u
//printf("PUSH.(%lld %p %d)\n",(long long)num64,numbuf,numlen);
if ( stacks->maxstackdepth > 0 )
{
/*if ( numbuf != 0 )
if ( numbuf != 0 )
{
int32_t i; for (i=0; i<numlen; i++)
printf("%02x",numbuf[i]);
} else printf("%lld",(long long)num64);
printf(" PUSHDATA len.%d\n",numlen);*/
printf(" PUSHDATA len.%d\n",numlen);
if ( stacks->stackdepth < stacks->maxstackdepth )
{
if ( stacks->logarray != 0 )
@ -785,6 +785,7 @@ int32_t iguana_checkmultisig(struct iguana_info *coin,struct iguana_interpreter
printf("iguana_checkmultisig n.%d != N.%d\n",n,N);
return(0);
}
printf("n.%d stackdepth.%d\n",n,stacks->stackdepth);
for (i=0; i<N; i++)
{
if ( stacks->stackdepth <= 0 )
@ -793,9 +794,9 @@ int32_t iguana_checkmultisig(struct iguana_info *coin,struct iguana_interpreter
if ( len == bitcoin_pubkeylen(pubkeys[i]) )
{
numsigners++;
//for (j=0; j<33; j++)
// printf("%02x",pubkeys[i][j]);
//printf(" <- pubkey.[%d]\n",i);
for (j=0; j<33; j++)
printf("%02x",pubkeys[i][j]);
printf(" <- pubkey.[%d]\n",i);
}
else
{
@ -809,6 +810,8 @@ int32_t iguana_checkmultisig(struct iguana_info *coin,struct iguana_interpreter
if ( stacks->stackdepth <= 0 )
return(0);
m = (int32_t)iguana_num(iguana_pop(stacks));
printf("m.%d stackdepth.%d\n",m,stacks->stackdepth);
if ( m != M )
{
printf("iguana_checkmultisig m.%d != M.%d\n",m,M);
@ -821,13 +824,13 @@ int32_t iguana_checkmultisig(struct iguana_info *coin,struct iguana_interpreter
siglens[i] = iguana_databuf(sigs[i],iguana_pop(stacks));
if ( siglens[i] <= 0 || siglens[i] > 74 )
break;
//for (j=0; j<siglens[i]; j++)
// printf("%02x",sigs[i][j]);
//printf(" <- sigs[%d]\n",i);
for (j=0; j<siglens[i]; j++)
printf("%02x",sigs[i][j]);
printf(" <- sigs[%d]\n",i);
}
if ( i == numsigners )
{
//char str[65]; printf("sigtxid.(%s)\n",bits256_str(str,txhash2));
char str[65]; printf("sigtxid.(%s)\n",bits256_str(str,txhash2));
if ( stacks->stackdepth > 0 )
iguana_pop(stacks); // for backward compatibility
j = numsigners-1;
@ -1018,7 +1021,7 @@ int32_t bitcoin_assembler(struct iguana_info *coin,cJSON *logarray,uint8_t scrip
free(stacks);
return(-1);
}
//printf("pushdata siglen.%d depth.%d\n",V->signers[i].siglen,stacks->stackdepth);
printf("pushdata siglen.%d depth.%d\n",V->signers[i].siglen,stacks->stackdepth);
}
}
for (i=0; i<V->N; i++)
@ -1029,7 +1032,7 @@ int32_t bitcoin_assembler(struct iguana_info *coin,cJSON *logarray,uint8_t scrip
if ( V->suppress_pubkeys == 0 && (V->spendscript[0] != plen || V->spendscript[V->spendlen - 1] != IGUANA_OP_CHECKSIG || bitcoin_pubkeylen(&V->spendscript[1]) <= 0) )
{
iguana_pushdata(stacks,0,V->signers[i].pubkey,plen);
//printf(">>>>>>>>> suppress.%d pushdata plen.%d depth.%d\n",V->suppress_pubkeys,plen,stacks->stackdepth);
printf(">>>>>>>>> suppress.%d pushdata [%02x %02x] plen.%d depth.%d\n",V->suppress_pubkeys,V->signers[i].pubkey[0],V->signers[i].pubkey[1],plen,stacks->stackdepth);
} // else printf("<<<<<<<<<< skip pubkey push %d script[0].%d spendlen.%d depth.%d\n",plen,V->spendscript[0],V->spendlen,stacks->stackdepth);
}
}

6
iguana/iguana_payments.c

@ -1153,12 +1153,12 @@ cJSON *iguana_createvins(struct supernet_info *myinfo,struct iguana_info *coin,c
jaddbits256(newvin,"txid",txid);
jaddnum(newvin,"vout",vout);
p2shlen = spendlen = 0;
if ( ((str= jstr(item,"scriptPub")) != 0 || (str= jstr(item,"scriptPubkey")) != 0) && is_hexstr(str,(int32_t)strlen(str)) > 0 )
if ( ((str= jstr(item,"scriptPub")) != 0 || (str= jstr(item,"scriptPubKey")) != 0) && is_hexstr(str,(int32_t)strlen(str)) > 0 )
{
spendlen = (int32_t)strlen(str) >> 1;
decode_hex(spendscript,spendlen,str);
}
else if ( ((obj= jobj(item,"scriptPub")) != 0 || (obj= jobj(item,"scriptPubkey")) != 0) && (hexstr= jstr(obj,"hex")) != 0 )
else if ( ((obj= jobj(item,"scriptPub")) != 0 || (obj= jobj(item,"scriptPubKey")) != 0) && (hexstr= jstr(obj,"hex")) != 0 )
{
spendlen = (int32_t)strlen(hexstr) >> 1;
decode_hex(spendscript,spendlen,hexstr);
@ -1175,7 +1175,7 @@ cJSON *iguana_createvins(struct supernet_info *myinfo,struct iguana_info *coin,c
if ( spendlen > 0 )
{
init_hexbytes_noT(scriptstr,spendscript,spendlen);
jaddstr(newvin,"scriptPub",scriptstr);
jaddstr(newvin,"scriptPubKey",scriptstr);
}
if ( (str= jstr(item,"redeemScript")) != 0 )
{

6
iguana/iguana_scripts.c

@ -288,8 +288,10 @@ int32_t _iguana_calcrmd160(struct iguana_info *coin,struct vin_info *vp)
{
static uint8_t zero_rmd160[20];
char hexstr[8192]; uint8_t *script,type; int32_t i,n,m,plen;
vp->N = 1;
vp->M = 1;
if ( vp->N == 0 )
vp->N = 1;
if ( vp->M == 0 )
vp->M = 1;
type = IGUANA_SCRIPT_STRANGE;
init_hexbytes_noT(hexstr,vp->spendscript,vp->spendlen);
//char str[65]; printf("script.(%s).%d in %s len.%d plen.%d spendlen.%d cmp.%d\n",hexstr,vp->spendlen,bits256_str(str,vp->vin.prev_hash),vp->spendlen,bitcoin_pubkeylen(&vp->spendscript[1]),vp->spendlen,vp->spendscript[vp->spendlen-1] == SCRIPT_OP_CHECKSIG);

146
iguana/iguana_sign.c

@ -181,6 +181,15 @@ int32_t iguana_parsehexstr(uint8_t **destp,uint16_t *lenp,uint8_t *dest2,int32_t
return(n);
}
int32_t iguana_scriptnum(uint8_t opcode)
{
if ( opcode == 0x00 )
return(0);
else if ( opcode >= 0x51 && opcode < 0x60 )
return(opcode - 0x50);
else return(-1);
}
int32_t iguana_parsevinobj(struct supernet_info *myinfo,struct iguana_info *coin,uint8_t *serialized,int32_t maxsize,struct iguana_msgvin *vin,cJSON *vinobj,struct vin_info *V)
{
struct iguana_outpoint outpt; struct iguana_waddress *waddr; struct iguana_waccount *wacct; uint8_t lastbyte,spendscript[8192]; uint32_t tmp=0; int32_t i,n,starti,spendlen,suppress_pubkeys,siglen,plen,m,endi,rwflag=1,len = 0; char *userdata=0,*pubkeystr,*hexstr = 0,*redeemstr = 0,*spendstr = 0; cJSON *scriptjson = 0,*obj,*pubkeysjson = 0;
@ -198,9 +207,9 @@ int32_t iguana_parsevinobj(struct supernet_info *myinfo,struct iguana_info *coin
vin->prev_vout = jint(vinobj,"vout");
if ( (scriptjson= jobj(vinobj,"scriptSig")) != 0 )
hexstr = jstr(scriptjson,"hex");
if ( ((spendstr= jstr(vinobj,"scriptPub")) == 0 && (spendstr= jstr(vinobj,"scriptPubkey")) == 0) || is_hexstr(spendstr,(int32_t)strlen(spendstr)) <= 0 )
if ( ((spendstr= jstr(vinobj,"scriptPub")) == 0 && (spendstr= jstr(vinobj,"scriptPubKey")) == 0) || is_hexstr(spendstr,(int32_t)strlen(spendstr)) <= 0 )
{
if ( (obj= jobj(vinobj,"scriptPub")) != 0 || (obj= jobj(vinobj,"scriptPubkey")) != 0 )
if ( (obj= jobj(vinobj,"scriptPub")) != 0 || (obj= jobj(vinobj,"scriptPubKey")) != 0 )
{
spendstr = jstr(obj,"hex");
lastbyte = _decode_hex(&spendstr[strlen(spendstr)-2]);
@ -233,7 +242,8 @@ int32_t iguana_parsevinobj(struct supernet_info *myinfo,struct iguana_info *coin
len += iguana_rwnum(rwflag,&serialized[len],sizeof(vin->prev_vout),&vin->prev_vout);
if ( V != 0 )
{
if ( vin->vinscript == 0 )
V->suppress_pubkeys = suppress_pubkeys;
if ( vin->vinscript == 0 && V->spendlen == 0 )
{
if ( iguana_RTunspentindfind(myinfo,coin,&outpt,V->coinaddr,spendscript,&spendlen,&V->amount,&V->height,vin->prev_hash,vin->prev_vout,coin->bundlescount-1,0) == 0 )
{
@ -341,6 +351,11 @@ int32_t iguana_parsevinobj(struct supernet_info *myinfo,struct iguana_info *coin
}
n = iguana_parsehexstr(&vin->redeemscript,&vin->p2shlen,V!=0?V->p2shscript:0,V!=0?&V->p2shlen:0,&serialized[len],redeemstr);
len += n;
if ( vin->redeemscript[vin->p2shlen-1] == SCRIPT_OP_CHECKMULTISIG )
{
V->M = iguana_scriptnum(vin->redeemscript[0]);
V->N = iguana_scriptnum(vin->redeemscript[vin->p2shlen-2]);
}
}
tmp = (len - endi);
if ( tmp < 0x100 )
@ -371,16 +386,21 @@ int32_t iguana_parsevinobj(struct supernet_info *myinfo,struct iguana_info *coin
len += iguana_rwnum(rwflag,&serialized[len],sizeof(vin->sequence),&vin->sequence);
if ( spendstr != 0 )
{
if ( V != 0 )
{
if ( V->spendlen == 0 )
{
V->spendlen = (int32_t)strlen(spendstr) >> 1;
decode_hex(V->spendscript,V->spendlen,spendstr);
}
if ( vin->spendscript == 0 )
vin->spendscript = V->spendscript;
}
if ( vin->spendlen == 0 && vin->spendscript != 0 )
{
vin->spendlen = (int32_t)strlen(spendstr) >> 1;
decode_hex(vin->spendscript,vin->spendlen,spendstr);
}
if ( V != 0 && V->spendlen == 0 )
{
V->spendlen = (int32_t)strlen(spendstr) >> 1;
decode_hex(V->spendscript,V->spendlen,spendstr);
}
//printf("serialized.%p len.%d\n",serialized,len);
//n = iguana_parsehexstr(&vin->spendscript,&vin->spendlen,V!=0?V->spendscript:0,V!=0?&V->spendlen:0,&serialized[len],spendstr);
//len += n;
@ -464,13 +484,17 @@ bits256 bitcoin_sigtxid(struct iguana_info *coin,int32_t height,uint8_t *seriali
{
int32_t i,len; bits256 sigtxid,txid,revsigtxid; struct iguana_msgtx dest;
dest = *msgtx;
dest.vins = calloc(dest.tx_in,sizeof(*dest.vins));
dest.vouts = calloc(dest.tx_out,sizeof(*dest.vouts));
memcpy(dest.vins,msgtx->vins,dest.tx_in * sizeof(*dest.vins));
memcpy(dest.vouts,msgtx->vouts,dest.tx_out * sizeof(*dest.vouts));
memset(sigtxid.bytes,0,sizeof(sigtxid));
if ( hashtype != SIGHASH_ALL )
{
printf("currently only SIGHASH_ALL supported, not %d\n",hashtype);
return(sigtxid);
}
for (i=0; i<msgtx->tx_in; i++)
for (i=0; i<dest.tx_in; i++)
{
if ( i == vini )
{
@ -486,6 +510,9 @@ bits256 bitcoin_sigtxid(struct iguana_info *coin,int32_t height,uint8_t *seriali
dest.vins[i].redeemscript = 0;
}
len = iguana_rwmsgtx(coin,height,1,0,serialized,maxlen,&dest,&txid,vpnstr,0,0,0,suppress_pubkeys);
for (i=0; i<len; i++)
printf("%02x",serialized[i]);
printf(" <- sigtx\n");
if ( len > 0 ) // (dest.tx_in != 1 || bits256_nonz(dest.vins[0].prev_hash) != 0) && dest.vins[0].scriptlen > 0 &&
{
#ifdef BTC2_VERSION
@ -496,22 +523,42 @@ bits256 bitcoin_sigtxid(struct iguana_info *coin,int32_t height,uint8_t *seriali
revsigtxid = bits256_doublesha256(0,serialized,len);
for (i=0; i<sizeof(revsigtxid); i++)
sigtxid.bytes[31-i] = revsigtxid.bytes[i];
//char str[65]; printf("SIGTXID.(%s)\n",bits256_str(str,sigtxid));
char str[65]; printf("SIGTXID.(%s) numvouts.%d\n",bits256_str(str,sigtxid),dest.tx_out);
}
free(dest.vins);
free(dest.vouts);
return(sigtxid);
}
void iguana_vinobjset(struct iguana_msgvin *vin,cJSON *item,uint8_t *spendscript,int32_t maxsize)
{
char *redeemstr,*hexstr; cJSON *sobj;
if ( (redeemstr= jstr(item,"redeemScript")) != 0 && is_hexstr(redeemstr,0) > 0 )
vin->p2shlen = (int32_t)strlen(redeemstr) >> 1;
if ( (sobj= jobj(item,"scriptPubKey")) != 0 && (hexstr= jstr(sobj,"hex")) != 0 && is_hexstr(hexstr,0) > 0 && (vin->spendlen == 0 || vin->spendscript == 0) )
{
vin->spendlen = (int32_t)strlen(hexstr) >> 1;
if ( vin->spendlen < maxsize )
{
if ( vin->spendscript == 0 )
vin->spendscript = spendscript;
decode_hex(vin->spendscript,vin->spendlen,hexstr);
}
}
}
int32_t iguana_rwmsgtx(struct iguana_info *coin,int32_t height,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 spendscript[8192],*txstart = serialized,*sigser=0; char txidstr[65],*redeemstr,*hexstr; cJSON *vin,*sobj,*array=0; bits256 sigtxid;
int32_t i,n,len = 0,extraused=0; uint8_t spendscript[8192],*txstart = serialized,*sigser=0; char txidstr[65]; cJSON *vinarray=0,*voutarray=0; bits256 sigtxid;
len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->version),&msg->version);
if ( json != 0 )
{
jaddnum(json,"version",msg->version);
array = cJSON_CreateArray();
vinarray = cJSON_CreateArray();
voutarray = cJSON_CreateArray();
if ( rwflag == 0 )
sigser = calloc(1,maxsize*2);
//printf("json.%p array.%p sigser.%p\n",json,array,sigser);
//printf("json.%p array.%p sigser.%p\n",json,vinarray,sigser);
}
//printf("version.%d\n",msg->version);
if ( coin->chain->isPoS != 0 )
@ -539,22 +586,12 @@ int32_t iguana_rwmsgtx(struct iguana_info *coin,int32_t height,int32_t rwflag,cJ
for (i=0; i<msg->tx_in; i++)
{
//printf("vin.%d starts offset.%d\n",i,len);
if ( vins != 0 && (vin= jitem(vins,i)) != 0 )
{
if ( (redeemstr= jstr(vin,"redeemScript")) != 0 && is_hexstr(redeemstr,0) > 0 )
msg->vins[i].p2shlen = (int32_t)strlen(redeemstr) >> 1;
if ( (sobj= jobj(vin,"scriptPubkey")) != 0 && (hexstr= jstr(sobj,"hex")) != 0 && is_hexstr(hexstr,0) > 0 && msg->vins[i].spendlen == 0 )
{
msg->vins[i].spendlen = (int32_t)strlen(hexstr) >> 1;
if ( msg->vins[i].spendscript == 0 && msg->vins[i].spendlen < sizeof(spendscript) )
{
msg->vins[i].spendscript = spendscript;
decode_hex(spendscript,msg->vins[i].spendlen,hexstr);
}
}
}
if ( vins != 0 && jitem(vins,i) != 0 )
iguana_vinobjset(&msg->vins[i],jitem(vins,i),spendscript,sizeof(spendscript));
if ( (n= iguana_vinparse(coin,rwflag,&serialized[len],&msg->vins[i])) < 0 )
return(-1);
if ( msg->vins[i].spendscript == spendscript )
msg->vins[i].spendscript = 0;
//printf("vin.%d n.%d len.%d\n",i,n,len);
len += n;
if ( len > maxsize )
@ -562,26 +599,6 @@ int32_t iguana_rwmsgtx(struct iguana_info *coin,int32_t height,int32_t rwflag,cJ
printf("invalid tx_in.%d len.%d vs maxsize.%d\n",msg->tx_in,len,maxsize);
return(-1);
}
if ( array != 0 )
{
if ( sigser != 0 && vins != 0 )
{
//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,height,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));
}
if ( msg->vins[i].spendscript == spendscript )
msg->vins[i].spendscript = 0;
}
if ( array != 0 )
{
if ( sigser != 0 )
free(sigser);
jadd(json,"vin",array);
jaddnum(json,"numvins",msg->tx_in);
array = cJSON_CreateArray();
}
len += iguana_rwvarint32(rwflag,&serialized[len],&msg->tx_out);
if ( rwflag == 0 )
@ -611,13 +628,8 @@ int32_t iguana_rwmsgtx(struct iguana_info *coin,int32_t height,int32_t rwflag,cJ
printf("invalid tx_out.%d len.%d vs maxsize.%d n.%d\n",msg->tx_out,len,maxsize,n);
return(-1);
}
if ( array != 0 )
jaddi(array,iguana_voutjson(coin,&msg->vouts[i],i,*txidp));
}
if ( array != 0 )
{
jadd(json,"vout",array);
jaddnum(json,"numvouts",msg->tx_out);
if ( voutarray != 0 )
jaddi(voutarray,iguana_voutjson(coin,&msg->vouts[i],i,*txidp));
}
len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->lock_time),&msg->lock_time);
//printf("lock_time.%08x len.%d\n",msg->lock_time,len);
@ -641,6 +653,29 @@ int32_t iguana_rwmsgtx(struct iguana_info *coin,int32_t height,int32_t rwflag,cJ
jaddstr(json,"vpnstr",vpnstr);
}
}
if ( sigser != 0 && vinarray != 0 )
{
for (i=0; i<msg->tx_in; i++)
{
if ( vins != 0 && jitem(vins,i) != 0 )
{
iguana_vinobjset(&msg->vins[i],jitem(vins,i),spendscript,sizeof(spendscript));
sigtxid = bitcoin_sigtxid(coin,height,sigser,maxsize*2,msg,i,msg->vins[i].spendscript,msg->vins[i].spendlen,SIGHASH_ALL,vpnstr,suppress_pubkeys);
//printf("after vini.%d vinscript.%p spendscript.%p spendlen.%d (%s)\n",i,msg->vins[i].vinscript,msg->vins[i].spendscript,msg->vins[i].spendlen,jprint(jitem(vins,i),0));
jaddi(vinarray,iguana_vinjson(coin,&msg->vins[i],sigtxid));
if ( msg->vins[i].spendscript == spendscript )
msg->vins[i].spendscript = 0;
}
}
free(sigser);
jadd(json,"vin",vinarray);
jaddnum(json,"numvins",msg->tx_in);
}
if ( voutarray != 0 )
{
jadd(json,"vout",voutarray);
jaddnum(json,"numvouts",msg->tx_out);
}
*txidp = bits256_doublesha256(txidstr,txstart,len);
if ( json != 0 )
{
@ -969,6 +1004,7 @@ int32_t iguana_vininfo_create(struct supernet_info *myinfo,struct iguana_info *c
for (i=0; i<msgtx->tx_in; i++)
{
vp = &V[i];
//printf("VINS.(%s)\n",jprint(jitem(vins,i),0));
len += iguana_parsevinobj(myinfo,coin,&serialized[len],maxsize,&msgtx->vins[i],jitem(vins,i),vp);
if ( msgtx->vins[i].sequence < IGUANA_SEQUENCEID_FINAL )
finalized = 0;
@ -1361,6 +1397,8 @@ int32_t iguana_signrawtransaction(struct supernet_info *myinfo,struct iguana_inf
V->signers[i].privkey = privkey;
if ( bits256_nonz(privkey) != 0 )
iguana_ensure_privkey(myinfo,coin,privkey);
if ( V->suppress_pubkeys == 0 && bitcoin_pubkeylen(V->signers[i].pubkey) <= 0 )
bitcoin_pubkey33(myinfo->ctx,V->signers[i].pubkey,privkey);
}
}
finalized = iguana_vininfo_create(myinfo,coin,serialized2,maxsize,msgtx,vins,numinputs,V);

2
iguana/iguana_wallet.c

@ -957,7 +957,7 @@ cJSON *iguana_privkeysjson(struct supernet_info *myinfo,struct iguana_info *coin
{
if ( (scripthexstr= jstr(item,"spendscript")) == 0 )
{
if ( (scriptobj= jobj(item,"scriptPubkey")) != 0 )
if ( (scriptobj= jobj(item,"scriptPubKey")) != 0 )
scripthexstr = jstr(scriptobj,"hex");
}
if ( scripthexstr != 0 )

2
includes/iguana_structs.h

@ -168,7 +168,7 @@ struct iguana_msgtx
int32_t allocsize,timestamp,numinputs,numoutputs;
int64_t inputsum,outputsum,txfee;
uint8_t *serialized;
}PACKEDSTRUCT;
} PACKEDSTRUCT;
struct iguana_msgjoinsplit
{

Loading…
Cancel
Save