Browse Source

splitfunds

dPoW2
jl777 8 years ago
parent
commit
94dd377c0a
  1. 40
      basilisk/basilisk_bitcoin.c
  2. 3
      basilisk/basilisk_swap.c
  3. 2
      iguana/exchanges/bitcoin.c
  4. 7
      iguana/iguana777.c
  5. 22
      iguana/iguana_payments.c
  6. 18
      iguana/iguana_wallet.c
  7. 2
      iguana/tests/decoderawtransaction
  8. 2
      iguana/tests/listunspent
  9. 1
      iguana/tests/splitfunds
  10. 1
      includes/iguana_apideclares.h
  11. 1
      includes/iguana_funcs.h

40
basilisk/basilisk_bitcoin.c

@ -542,6 +542,46 @@ int32_t basilisk_vins_validate(struct supernet_info *myinfo,struct iguana_info *
return(retval);
}
char *iguana_utxoduplicates(struct supernet_info *myinfo,struct iguana_info *coin,bits256 privkey,uint64_t satoshis,int32_t duplicates,int32_t *completedp,bits256 *signedtxidp,int32_t sendflag)
{
uint8_t script[35],pubkey33[33]; int32_t i,spendlen; cJSON *txobj=0,*addresses=0,*vins=0; char *rawtx=0,*signedtx,changeaddr[64];
*completedp = 0;
if ( signedtxidp != 0 )
memset(signedtxidp,0,sizeof(*signedtxidp));
bitcoin_address(changeaddr,coin->chain->pubtype,myinfo->persistent_pubkey33,33);
if ( (txobj= bitcoin_txcreate(coin->chain->isPoS,0,1,0)) != 0 )
{
if ( duplicates <= 0 )
duplicates = 1;
bitcoin_pubkey33(myinfo->ctx,pubkey33,privkey);
spendlen = bitcoin_pubkeyspend(script,0,pubkey33);
for (i=0; i<duplicates; i++)
bitcoin_txoutput(txobj,script,spendlen,satoshis);
addresses = iguana_getaddressesbyaccount(myinfo,coin,"*");
rawtx = iguana_calcrawtx(myinfo,coin,&vins,txobj,satoshis * duplicates,changeaddr,coin->txfee,addresses,0,0,0,0,"127.0.0.1",0);
printf("duplicatesTX.(%s)\n",rawtx);
if ( signedtxidp != 0 )
{
if ( (signedtx= iguana_signrawtx(myinfo,coin,0,signedtxidp,completedp,vins,rawtx,0,0)) != 0 )
{
free(rawtx);
if ( *completedp != 0 && sendflag != 0 )
{
iguana_sendrawtransaction(myinfo,coin,signedtx);
}
rawtx = signedtx;
} else printf("error signing raw utxoduplicates tx\n");
}
}
if ( vins != 0 )
free_json(vins);
if ( txobj != 0 )
free_json(txobj);
if ( addresses != 0 )
free_json(addresses);
return(rawtx);
}
char *basilisk_bitcoinrawtx(struct supernet_info *myinfo,struct iguana_info *coin,char *remoteaddr,uint32_t basilisktag,int32_t timeoutmillis,cJSON *valsobj,struct vin_info *V)
{
uint8_t buf[4096]; int32_t oplen,offset,minconf,spendlen; cJSON *vins,*addresses,*txobj = 0; uint32_t locktime; char *opreturn,*spendscriptstr,*changeaddr,*rawtx = 0; int64_t amount,txfee,burnamount;

3
basilisk/basilisk_swap.c

@ -13,8 +13,9 @@
* *
******************************************************************************/
// Todo: monitor blockchains
// Todo: monitor blockchains, ie complete extracting scriptsig
// mode to autocreate required outputs
// more better LP commands
// included from basilisk.c

2
iguana/exchanges/bitcoin.c

@ -144,7 +144,6 @@ int32_t bitcoin_priv2wif(char *wifstr,bits256 privkey,uint8_t addrtype)
return((int32_t)strlen(wifstr));
}
#ifdef bitcoincancalulatebalances
uint64_t bitcoin_parseunspent(struct iguana_info *coin,struct bitcoin_unspent *unspent,double minconfirms,char *account,cJSON *item)
{
char *hexstr,coinaddr[64];
@ -385,7 +384,6 @@ char *bitcoin_calcrawtx(struct supernet_info *myinfo,struct iguana_info *coin,cJ
printf("need to patch locktime\n");
return(rawtx);
}
#endif
#define EXCHANGE_NAME "bitcoin"
#define UPDATE bitcoin ## _price

7
iguana/iguana777.c

@ -882,12 +882,7 @@ void iguana_coinloop(void *arg)
if ( coin->started == 0 && coin->active != 0 )
{
iguana_callcoinstart(myinfo,coin);
/*if ( strcmp("BTC",coin->symbol) == 0 )
{
uint8_t redeemscript;
n = bitcoin_checklocktimeverify(redeemscript,n,time(NULL)+300);
}
if ( 0 && strcmp("BTC",coin->symbol) == 0 )
/*if ( 0 && strcmp("BTC",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\"}}]}");

22
iguana/iguana_payments.c

@ -354,7 +354,10 @@ char *iguana_calcrawtx(struct supernet_info *myinfo,struct iguana_info *coin,cJS
}
}
if ( vins != 0 && V == 0 )
{
V = calloc(cJSON_GetArraySize(vins),sizeof(*V)), allocflag = 1;
//iguana_vinprivkeys(myinfo,coin,V,vins);
}
rawtx = bitcoin_json2hex(myinfo,coin,&txid,txobj,V);
if ( allocflag != 0 )
free(V);
@ -1356,6 +1359,7 @@ S_A_I_S(bitcoinrpc,sendmany,fromaccount,payments,minconf,comment)
//iguana_unspentset(myinfo,coin);
n = cJSON_GetArraySize(payments);
item = payments->child;
retjson = cJSON_CreateArray();
for (required=i=0; i<n; i++)
{
if ( item != 0 && (coinaddr= item->string) != 0 )
@ -1365,14 +1369,30 @@ S_A_I_S(bitcoinrpc,sendmany,fromaccount,payments,minconf,comment)
printf("(%s %.8f) ",coinaddr,dstr(val));
if ( (str= sendtoaddress(myinfo,coin,remoteaddr,coinaddr,val,coin->txfee,comment,"",minconf,fromaccount)) != 0 )
{
free(str);
jaddistr(retjson,str);
}
required += val;
}
item = item->next;
}
printf("required %.8f\n",dstr(required));
return(jprint(retjson,1));
}
THREE_INTS(iguana,splitfunds,satoshis,duplicates,sendflag)
{
char *rawtx; int32_t completed; cJSON *retjson; bits256 signedtxid;
if ( remoteaddr != 0 )
return(clonestr("{\"error\":\"no remote\"}"));
if ( myinfo->expiration == 0 )
return(clonestr("{\"error\":\"need to unlock wallet\"}"));
retjson = cJSON_CreateObject();
if ( (rawtx= iguana_utxoduplicates(myinfo,coin,myinfo->persistent_priv,satoshis,duplicates,&completed,&signedtxid,sendflag)) != 0 )
{
jaddstr(retjson,"result",rawtx);
jaddbits256(retjson,"txid",signedtxid);
jadd(retjson,"completed",completed != 0 ? jtrue() : jfalse());
} else jaddstr(retjson,"error","couldnt create duplicates tx");
return(jprint(retjson,1));
}

18
iguana/iguana_wallet.c

@ -944,7 +944,7 @@ int64_t oldiguana_waccountbalance(struct supernet_info *myinfo,struct iguana_inf
cJSON *iguana_privkeysjson(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *vins)
{
int32_t i,j,n,numinputs,scriptlen; struct iguana_waddress *waddr; struct iguana_waccount *wacct; char *addresses,*address,*scripthexstr,coinaddr[64]; cJSON *scriptobj,*privkeys,*item; uint8_t spendscript[IGUANA_MAXSCRIPTSIZE];
int32_t i,n,numinputs,scriptlen; struct iguana_waddress *waddr; struct iguana_waccount *wacct; char *addresses,*address,*scripthexstr,coinaddr[64]; cJSON *scriptobj,*privkeys,*item; uint8_t spendscript[IGUANA_MAXSCRIPTSIZE];
privkeys = cJSON_CreateArray();
if ( (numinputs= cJSON_GetArraySize(vins)) > 0 )
{
@ -970,19 +970,17 @@ cJSON *iguana_privkeysjson(struct supernet_info *myinfo,struct iguana_info *coin
//if ( (address= iguana_RTinputaddress(myinfo,coin,coinaddr,&spentpt,jitem(vins,i))) != 0 )
if ( address != 0 )
{
for (j=0; j<n; j++)
{
if ( strcmp(&addresses[64 * j],address) == 0 )
break;
}
if ( j == n )
strcpy(&addresses[64 * n++],address);
strcpy(&addresses[64 * n++],address);
} else printf("cant get address from.(%s)\n",jprint(item,0));
}
for (i=0; i<n; i++)
{
if ( (waddr= iguana_waddresssearch(myinfo,&wacct,&addresses[i * 64])) != 0 )
{
printf("%s ",waddr->wifstr);
jaddistr(privkeys,waddr->wifstr);
}
else printf("cant find waddr for %s\n",&addresses[i*64]);
}
free(addresses);
}
@ -1343,6 +1341,10 @@ TWOSTRINGS_AND_INT(bitcoinrpc,walletpassphrase,password,permanentfile,timeout)
retstr = SuperNET_login(IGUANA_CALLARGS,myinfo->handle,myinfo->secret,myinfo->permanentfile,myinfo->password);
myinfo->expiration = (uint32_t)time(NULL) + timeout;
iguana_walletinitcheck(myinfo,coin);
if ( coin != 0 )
{
bitcoin_address(coin->changeaddr,coin->chain->pubtype,myinfo->persistent_pubkey33,33);
}
//basilisk_unspents_update(myinfo,coin);
return(retstr);
}

2
iguana/tests/decoderawtransaction

@ -1 +1 @@
curl --url "http://127.0.0.1:7778" --data "{\"coin\":\"BTC\",\"method\":\"decoderawtransaction\",\"params\":[\"01000000bee8eb57015ede795f68e677621de3e1155134bad2364caef364de1afea707fee0d663bf11010000001976a9142ad8809cca3878b0f97433b65a0e49799982ccd888acffffffff0210270000000000001976a914ca1e04745e8ca0c60d8c5881531d51bec470743f88ace092f505000000001976a914b7128d2ee837cf03e30a2c0e3e0181f7b9669bb688ac00000000\", 1]}"
curl --url "http://127.0.0.1:7778" --data "{\"coin\":\"BTCD\",\"method\":\"decoderawtransaction\",\"params\":[\"0100000039f0ef57012da7ff408b643b8c40d69eb1265a0dfc1055a2a1a0635c37abb10a03b44a37a00100000000ffffffff06e8030000000000002321020e0f6fe6e0fcdcac541eb728d6fe538a12adff20412b3c8a7fa892b223a47c2face8030000000000002321020e0f6fe6e0fcdcac541eb728d6fe538a12adff20412b3c8a7fa892b223a47c2face8030000000000002321020e0f6fe6e0fcdcac541eb728d6fe538a12adff20412b3c8a7fa892b223a47c2face8030000000000002321020e0f6fe6e0fcdcac541eb728d6fe538a12adff20412b3c8a7fa892b223a47c2face8030000000000002321020e0f6fe6e0fcdcac541eb728d6fe538a12adff20412b3c8a7fa892b223a47c2fac188e2903000000001976a914b7128d2ee837cf03e30a2c0e3e0181f7b9669bb688ac00000000\", 1]}"

2
iguana/tests/listunspent

@ -1 +1 @@
curl --url "http://127.0.0.1:7778" --data "{\"coin\":\"BTC\",\"method\":\"listunspent\",\"params\":[1, 9999999, [\"1E2ac2gxeFR2ir1H3vqETTperWkiXkwy99\"]]}"
curl --url "http://127.0.0.1:7778" --data "{\"coin\":\"BTC\",\"method\":\"listunspent\",\"params\":[1, 9999999, []]}"

1
iguana/tests/splitfunds

@ -0,0 +1 @@
curl --url "http://127.0.0.1:7778" --data "{\"coin\":\"BTC\",\"agent\":\"iguana\",\"method\":\"splitfunds\",\"satoshis\":\"1000\",\"sendflag\":0,\"duplicates\":5}"

1
includes/iguana_apideclares.h

@ -86,6 +86,7 @@ ARRAY_OBJ_INT(bitcoinrpc,createrawtransaction,vins,vouts,locktime);
ZERO_ARGS(iguana,makekeypair);
STRING_ARG(bitcoinrpc,validatepubkey,pubkey);
STRING_ARG(bitcoinrpc,validateaddress,address);
THREE_INTS(iguana,splitfunds,satoshis,duplicates,sendflag);
ZERO_ARGS(bitcoinrpc,walletlock);
TWOSTRINGS_AND_INT(bitcoinrpc,walletpassphrase,password,permanentfile,timeout);

1
includes/iguana_funcs.h

@ -495,6 +495,7 @@ struct exchange_info *exchange_create(char *exchangestr,cJSON *argjson);
int32_t iguana_inv2poll(struct supernet_info *myinfo,struct iguana_info *coin);
struct iguana_bundlereq *iguana_bundlereq(struct iguana_info *coin,struct iguana_peer *addr,int32_t type,uint8_t *data,int32_t datalen);
void instantdex_FSMinit();
char *iguana_utxoduplicates(struct supernet_info *myinfo,struct iguana_info *coin,bits256 privkey,uint64_t satoshis,int32_t duplicates,int32_t *completedp,bits256 *signedtxidp,int32_t sendflag);
int32_t bitcoin_p2shspend(uint8_t *script,int32_t n,uint8_t rmd160[20]);
void iguana_RTunspentslock(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *vins);
char *iguana_calcrawtx(struct supernet_info *myinfo,struct iguana_info *coin,cJSON **vinsp,cJSON *txobj,int64_t satoshis,char *changeaddr,int64_t txfee,cJSON *addresses,int32_t minconf,uint8_t *opreturn,int32_t oplen,int64_t burnamount,char *remoteaddr,struct vin_info *V);

Loading…
Cancel
Save