diff --git a/iguana/SuperNET_keys.c b/iguana/SuperNET_keys.c index 9eadf21f0..13d4c4684 100755 --- a/iguana/SuperNET_keys.c +++ b/iguana/SuperNET_keys.c @@ -178,7 +178,7 @@ int32_t SuperNET_savejsonfile(struct supernet_info *myinfo,char *finalfname,bits { if ( (ciphered= SuperNET_cipher(0,0,json,0,privkey,destpubkey,confstr)) != 0 ) { - printf("ciphered.save (%s) <- (%s)\n",destfname,confstr); + //printf("ciphered.save (%s) <- (%s)\n",destfname,confstr); if ( (fp= fopen(destfname,"wb")) != 0 ) { if ( fwrite(ciphered,1,strlen(ciphered)+1,fp) == strlen(ciphered)+1 ) @@ -203,7 +203,9 @@ int32_t SuperNET_savejsonfile(struct supernet_info *myinfo,char *finalfname,bits { char oldfname[1024]; int64_t fsize,dsize; if ( (fsize= OS_filesize(finalfname)) > (dsize= OS_filesize(destfname)) ) - printf("skip replacing (%s) since new one is smaller %lld vs %lld\n",finalfname,(long long)fsize,(long long)dsize); + { + //printf("skip replacing (%s) since new one is smaller %lld vs %lld\n",finalfname,(long long)fsize,(long long)dsize); + } else { strcpy(oldfname,finalfname), strcat(oldfname,".old"); diff --git a/iguana/iguana_notary.c b/iguana/iguana_notary.c index a42820818..2e5f66f0a 100755 --- a/iguana/iguana_notary.c +++ b/iguana/iguana_notary.c @@ -489,7 +489,7 @@ STRING_AND_INT(dpow,fundnotaries,symbol,numblocks) { if ( (val= vals[j]) > 0. ) { - bitcoin_address(coinaddr,0,pubkeys[j],33); + bitcoin_address(coinaddr,0,pubkeys[j],33); // fixed sprintf(cmd,"bitcoin-cli sendtoaddress %s %f\n",coinaddr,val); if ( sendflag != 0 && system(cmd) != 0 ) printf("ERROR with (%s)\n",cmd); diff --git a/iguana/iguana_payments.c b/iguana/iguana_payments.c index a0e7c1f76..3d0301f9b 100755 --- a/iguana/iguana_payments.c +++ b/iguana/iguana_payments.c @@ -280,6 +280,9 @@ char *iguana_signrawtx(struct supernet_info *myinfo,struct iguana_info *coin,int if ( iguana_signrawtransaction(myinfo,coin,height,&msgtx,&signedtx,signedtxidp,V,numinputs,rawtx,vins,privkeys) > 0 ) *completedp = 1; else printf("signrawtransaction incomplete\n"); + //for (i=0; idirty = 0; } else printf("iguana_payloadupdate error\n"); } else printf("error parsing decryptstr\n"); diff --git a/iguana/iguana_scripts.c b/iguana/iguana_scripts.c index 1eac905f3..a0cb4a07a 100755 --- a/iguana/iguana_scripts.c +++ b/iguana/iguana_scripts.c @@ -483,7 +483,7 @@ int32_t bitcoin_scriptget(struct iguana_info *coin,int32_t *hashtypep,uint32_t * char asmstr[IGUANA_MAXSCRIPTSIZE*3]; int32_t j,n,siglen,plen; uint8_t *p2shscript; j = n = 0; *userdatap = 0; - *userdatalenp = *pubkeysizep = 0; + *userdatalenp = *pubkeysizep = *sigsizep = 0; *hashtypep = SIGHASH_ALL; while ( (siglen= scriptsig[n]) >= 70 && siglen <= 73 && n+siglen < len && j < 16 ) { diff --git a/iguana/iguana_sign.c b/iguana/iguana_sign.c index ca59d58c8..0db61aef4 100755 --- a/iguana/iguana_sign.c +++ b/iguana/iguana_sign.c @@ -546,6 +546,8 @@ void iguana_vinobjset(struct iguana_msgvin *vin,cJSON *item,uint8_t *spendscript { vin->p2shlen = (int32_t)strlen(redeemstr) >> 1; vin->spendlen = vin->p2shlen; + vin->redeemscript = calloc(1,vin->p2shlen); + decode_hex(vin->redeemscript,vin->p2shlen,redeemstr); hexstr = redeemstr; //printf("VINOBJSET.(%s)\n",redeemstr); } @@ -883,7 +885,7 @@ int32_t iguana_msgtx_Vset(struct iguana_info *coin,uint8_t *serialized,int32_t m if ( redeemscript != 0 && p2shlen > 33 && redeemscript[p2shlen - 1] == SCRIPT_OP_CHECKMULTISIG ) { need_op0 = 1; - printf("found multisig redeemscript\n"); + //printf("found multisig redeemscript\n"); } msgtx->vins[vini].vinscript = script = &serialized[len]; msgtx->vins[vini].vinscript[0] = 0; @@ -1001,20 +1003,21 @@ int32_t bitcoin_verifyvins(struct iguana_info *coin,int32_t height,bits256 *sign } if ( bitcoin_verify(coin->ctx,sig,siglen-1,sigtxid,vp->signers[j].pubkey,bitcoin_pubkeylen(vp->signers[j].pubkey)) < 0 ) { - - printf("SIG.%d.%d ERROR siglen.%d\n",vini,j,siglen); + int32_t k; for (k=0; ksigners[j].pubkey); k++) + printf("%02x",vp->signers[j].pubkey[k]); + printf(" SIG.%d.%d ERROR siglen.%d\n",vini,j,siglen); } else { flag++; numsigs++; - /*int32_t z; + int32_t z; for (z=0; zsigners[j].pubkey[z]); - printf(" <- pub, SIG.%d.%d VERIFIED numsigs.%d vs M.%d\n",vini,j,numsigs,vp->M);*/ + printf(" <- pub, SIG.%d.%d VERIFIED numsigs.%d vs M.%d\n",vini,j,numsigs,vp->M); } } if ( numsigs >= vp->M ) @@ -1401,9 +1404,9 @@ P2SH_SPENDAPI(iguana,spendmsig,activecoin,vintxid,vinvout,destaddress,destamount return(jprint(retjson,1)); } -int32_t iguana_signrawtransaction(struct supernet_info *myinfo,struct iguana_info *coin,int32_t height,struct iguana_msgtx *msgtx,char **signedtxp,bits256 *signedtxidp,struct vin_info *V,int32_t numinputs,char *rawtx,cJSON *vins,cJSON *privkeys) +int32_t iguana_signrawtransaction(struct supernet_info *myinfo,struct iguana_info *coin,int32_t height,struct iguana_msgtx *msgtx,char **signedtxp,bits256 *signedtxidp,struct vin_info *V,int32_t numinputs,char *rawtx,cJSON *vins,cJSON *privkeysjson) { - uint8_t *serialized,*serialized2,*serialized3,*serialized4,*extraspace; int32_t finalized,i,len,n,maxsize,complete = 0,extralen = 65536; char *checkstr,*privkeystr,*signedtx = 0; bits256 privkey,txid; cJSON *item; cJSON *txobj = 0; + uint8_t *serialized,*serialized2,*serialized3,*serialized4,*extraspace,pubkeys[64][33]; int32_t finalized,i,len,n,maxsize,complete = 0,extralen = 65536; char *checkstr,*privkeystr,*signedtx = 0; bits256 privkeys[64],privkey,txid; cJSON *item; cJSON *txobj = 0; maxsize = 1000000; if ( rawtx != 0 && rawtx[0] != 0 && (len= (int32_t)strlen(rawtx)>>1) < maxsize ) { @@ -1441,27 +1444,81 @@ int32_t iguana_signrawtransaction(struct supernet_info *myinfo,struct iguana_inf memset(msgtx,0,sizeof(*msgtx)); if ( iguana_rwmsgtx(coin,height,0,0,serialized,maxsize,msgtx,&txid,"",extraspace,65536,vins,V->suppress_pubkeys) > 0 && numinputs == msgtx->tx_in ) { - if ( (n= cJSON_GetArraySize(privkeys)) > 0 ) + memset(pubkeys,0,sizeof(pubkeys)); + memset(privkeys,0,sizeof(privkeys)); + if ( (n= cJSON_GetArraySize(privkeysjson)) > 0 ) { for (i=0; iN ) - V->signers[i].privkey = privkey; - if ( i < numinputs ) - V[i].signers[0].privkey = privkey; + privkeys[i] = privkey = iguana_str2priv(myinfo,coin,privkeystr); + bitcoin_pubkey33(myinfo->ctx,pubkeys[i],privkey); if ( bits256_nonz(privkey) != 0 ) iguana_ensure_privkey(myinfo,coin,privkey); - if ( V->suppress_pubkeys == 0 && bitcoin_pubkeylen(V->signers[i].pubkey) <= 0 ) + } + } + for (i=0; itx_in; i++) + { + if ( msgtx->vins[i].p2shlen != 0 ) + { + char coinaddr[64]; uint32_t userdatalen,sigsize,pubkeysize; uint8_t *userdata; int32_t j,k,hashtype,type,flag; struct vin_info mvin,mainvin; bits256 zero; + coinaddr[0] = 0; + sigsize = 0; + flag = (msgtx->vins[i].vinscript[0] == 0); + type = bitcoin_scriptget(coin,&hashtype,&sigsize,&pubkeysize,&userdata,&userdatalen,&mainvin,msgtx->vins[i].vinscript+flag,msgtx->vins[i].scriptlen-flag,0); + if ( flag != 0 && pubkeysize == 33 ) // jl777: need to generalize this { - bitcoin_pubkey33(myinfo->ctx,V->signers[i].pubkey,privkey); - if ( i < numinputs ) - memcpy(V[i].signers[0].pubkey,V->signers[i].pubkey,bitcoin_pubkeylen(V->signers[i].pubkey)); + for (k=0; kvins[i].redeemscript != 0 ) + { + //for (j=0; jvins[i].p2shlen; j++) + // printf("%02x",msgtx->vins[i].redeemscript[j]); + bitcoin_address(coinaddr,coin->chain->p2shtype,msgtx->vins[i].redeemscript,msgtx->vins[i].p2shlen); + type = iguana_calcrmd160(coin,0,&mvin,msgtx->vins[i].redeemscript,msgtx->vins[i].p2shlen,zero,0,01); + for (j=0; jsuppress_pubkeys == 0 ) + { + memcpy(V[i].signers[j].pubkey,mvin.signers[j].pubkey,33); + } + if ( flag != 0 && pubkeysize == 33 && mainvin.signers[0].siglen != 0 ) // jl777: need to generalize + { + if ( memcmp(mvin.signers[j].pubkey,mainvin.signers[0].pubkey,33) == 0 ) + { + memcpy(V[i].signers[j].sig,mainvin.signers[0].sig,mainvin.signers[0].siglen); + V[i].signers[j].siglen = mainvin.signers[j].siglen; + printf("[%d].signer[%d] <- from mainvin.[0]\n",i,j); + } + } + for (k=0; ksuppress_pubkeys == 0 ) + memcpy(V[i].signers[j].pubkey,pubkeys[k],33); + printf("%s -> V[%d].signer.[%d] <- privkey.%d\n",mvin.signers[j].coinaddr,i,j,k); + break; + } + } + } + printf("type.%d p2sh.[%d] -> %s M.%d N.%d\n",type,i,mvin.coinaddr,mvin.M,mvin.N); + } + } + if ( i < V->N ) + V->signers[i].privkey = privkey; + if ( i < numinputs ) + V[i].signers[0].privkey = privkey; + if ( V->suppress_pubkeys == 0 && bitcoin_pubkeylen(V->signers[i].pubkey) <= 0 ) + { + if ( i < numinputs ) + memcpy(V[i].signers[0].pubkey,V->signers[i].pubkey,bitcoin_pubkeylen(V->signers[i].pubkey)); } } finalized = iguana_vininfo_create(myinfo,coin,serialized2,maxsize,msgtx,vins,numinputs,V); @@ -1516,6 +1573,9 @@ STRING_ARRAY_OBJ_STRING(bitcoinrpc,signrawtransaction,rawtx,vins,privkeys,sighas else if ( complete == -1 ) jaddstr(retjson,"error",uselessbitcoin_error != 0 ? "-22" : "couldnt load serialized tx or mismatched numinputs"); free(V); + //for (i=0; i 0 ) { - printf("waddrvalidate: need to manually setaccount to fix mismatch (%s:%s) <- (%s:%s)\n",checkwacct != 0 ? checkwacct->account : "",checkwaddr != 0 ? checkwaddr->coinaddr : "",wacct != 0 ? wacct->account : "",waddr->coinaddr); + //printf("waddrvalidate: need to manually setaccount to fix mismatch (%s:%s) <- (%s:%s)\n",checkwacct != 0 ? checkwacct->account : "",checkwaddr != 0 ? checkwaddr->coinaddr : "",wacct != 0 ? wacct->account : "",waddr->coinaddr); } } if ( waddr->scriptlen > 0 ) @@ -883,7 +883,7 @@ void iguana_walletinitcheck(struct supernet_info *myinfo,struct iguana_info *coi { iguana_waddressadd(myinfo,coin,wacct,&waddr,0); printf("(%s) ",waddr.coinaddr); - } else printf("walletinitcheck: error waddresscalc\n"); + } //else printf("walletinitcheck: error waddresscalc\n"); } } } diff --git a/iguana/tests/sign b/iguana/tests/sign index 2ededcbf6..20795f150 100755 --- a/iguana/tests/sign +++ b/iguana/tests/sign @@ -1,3 +1,2 @@ #!/bin/bash -#!/bin/bash -curl --url "http://127.0.0.1:7778" --data "{\"coin\":\"BTC\",\"method\":\"signrawtransaction\",\"params\":[\"0100000008571ec5afd602f294f3eb95adb83da8894399f9de1a72ed85afc913393afbf3f13000000000ffffffffa20dc04e8a4cc6c619f0857e5a24b527db7ab473a0cd051632a3429841c798680700000000ffffffffeb1bcb46fcbdf97d28be1350254d010d1581a0dc0b7115034b1a23d9f14d7b700400000000ffffffffce3cba6588e17a889264daf868582a46853313a4bff8e64bd048a259eb8f2f140700000000ffffffff54505b1507c71de8cdf6c58ad8c2c6864a48681de2326b60f3d3506f8464d33b0000000000ffffffffbcf7cc97c0e064ac8c3839f46bd6c884edb390625c4975f16864376417f1ce5c0700000000ffffffffc011a2d208bb03f88c9c13a9ebeb9041149d72d26121cf4378ced82df462c8ea0400000000fffffffffb1be8356069642320d9f9b4c4d10ce1ebad59f89b78310988ae5abd34a2253d0100000000ffffffff0c70170000000000002321020e46e79a2a8d12b9b5d12c7a91adb4e454edfae43c0a0cb805427d2ac7613fd9ac7017000000000000232103b7621b44118017a16043f19b30cc8a4cfe068ac4e42417bae16ba460c80f3828ac7017000000000000232102ebfc784a4ba768aad88d44d1045d240d47b26e248cafaf1c5169a42d7a61d344ac7017000000000000232103750cf30d739cd7632f77c1c02812dd7a7181628b0558058d4755838117e05339ac701700000000000023210394f3529d2e8cc69ffa7a2b55f3761e7be978fa1896ef4c55dc9c275e77e5bf5eac701700000000000023210243c1eeb3777af47187d542e5f8c84f0ac4b05cf5a7ad77faa8cb6d2d56db7823ac7017000000000000232102bb298844175640a34e908ffdfa2839f77aba3d5edadefee16beb107826e00063ac7017000000000000232102fa88e549b4b871498f892e527a5d57287916809f8cc3163f641d71c535e8df5aac70170000000000002321032f799e370f06476793a122fcd623db7804898fe5aef5572095cfee6353df34bfac7017000000000000232102c06fe5401faff4442ef87b7d1b56c2e5a214166615f9a2f2030c71b0cb067ae8ac70170000000000002321038ac67ca49a8169bcc5de83fe020071095a2c3b2bc4d1c17386977329758956d5ac00000000000000002b6a29000000000000000000000000000000000000000000000000000000000000000000000000524556530000000000\", [{\"txid\":\"6898c7419842a3321605cda073b47adb27b5245a7e85f019c6c64c8a4ec00da2\",\"vout\":7,\"scriptPubKey\":\"2103750cf30d739cd7632f77c1c02812dd7a7181628b0558058d4755838117e05339ac\"}, {\"txid\":\"707b4df1d9231a4b0315710bdca081150d014d255013be287df9bdfc46cb1beb\",\"vout\":4,\"scriptPubKey\":\"210394f3529d2e8cc69ffa7a2b55f3761e7be978fa1896ef4c55dc9c275e77e5bf5eac\"}, {\"txid\":\"142f8feb59a248d04be6f8bfa4133385462a5868f8da6492887ae18865ba3cce\",\"vout\":7,\"scriptPubKey\":\"210243c1eeb3777af47187d542e5f8c84f0ac4b05cf5a7ad77faa8cb6d2d56db7823ac\"}, {\"txid\":\"3bd364846f50d3f3606b32e21d68484a86c6c2d88ac5f6cde81dc707155b5054\",\"vout\":0,\"scriptPubKey\":\"2102bb298844175640a34e908ffdfa2839f77aba3d5edadefee16beb107826e00063ac\"}, {\"txid\":\"5ccef11764376468f175495c6290b3ed84c8d66bf439388cac64e0c097ccf7bc\",\"vout\":7,\"scriptPubKey\":\"2102fa88e549b4b871498f892e527a5d57287916809f8cc3163f641d71c535e8df5aac\"}, {\"txid\":\"eac862f42dd8ce7843cf2161d2729d144190ebeba9139c8cf803bb08d2a211c0\",\"vout\":4,\"scriptPubKey\":\"21032f799e370f06476793a122fcd623db7804898fe5aef5572095cfee6353df34bfac\"}, {\"txid\":\"3d25a234bd5aae880931789bf859adebe10cd1c4b4f9d9202364696035e81bfb\",\"vout\":1,\"scriptPubKey\":\"2102c06fe5401faff4442ef87b7d1b56c2e5a214166615f9a2f2030c71b0cb067ae8ac\"}] ]}" +curl --url "http://127.0.0.1:7778" --data "{\"coin\":\"SHARK\",\"method\":\"signrawtransaction\",\"params\":[\"0100000001f0c3007d723b5e88148a0e8be405148aa0b4f1ced247cec6d61f25e3bfa49f7401000000d700483045022100ce9478bcb42c784423961746a524a2579ab1c6be5e63d5ed52ccf7383f77a458022014254cd3a8524de7a3e290a17a959f00b3d55f6b2c248bb7d0138b0fa9b011430121020a4b45aeeaea23cbe3cd288a399c8a42ba567bdd4841819569a54e8ef3a597434c695221035c7ceb91140df541a12c7cbe245ec9bc53a09771e37e480c485e8fbd69fb76fd21020a4b45aeeaea23cbe3cd288a399c8a42ba567bdd4841819569a54e8ef3a597432102e505c7e3480a643e23dd7b77687751b901404d8eea9c8d0d5a4c6af12b42172553aeffffffff0470170000000000001976a9148ca6e1a181cac5c0ea1e37fd50140c8ed81b8c6988ac60361e00000000001976a914d092ccfc3da5dc4279cb328e39e7a9903395946e88ac10270000000000001976a9147f9878c75123115a00000000000000000000000088ac00127a00000000001976a914ccf0d9a519f21e939893ed3a39f2c5e9d31ec24988ac00000000\", [{\"txid\":\"749fa4bfe3251fd6c6ce47d2cef1b4a08a1405e48b0e8a14885e3b727d00c3f0\",\"vout\":1,\"scriptPubKey\":\"a914ccf0d9a519f21e939893ed3a39f2c5e9d31ec24987\",\"redeemScript\":\"5221035c7ceb91140df541a12c7cbe245ec9bc53a09771e37e480c485e8fbd69fb76fd21020a4b45aeeaea23cbe3cd288a399c8a42ba567bdd4841819569a54e8ef3a597432102e505c7e3480a643e23dd7b77687751b901404d8eea9c8d0d5a4c6af12b42172553ae\"}], [\"UurweRHDBr4BSdMJuiXkgcnueawCNBXNw2e4zQ7TT75TieeG4auT\"], \"ALL\"] }"