Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
faba4c89a5
  1. 4
      basilisk/basilisk.h
  2. 74
      basilisk/basilisk_swap.c
  3. 4
      iguana/tests/rawtx2

4
basilisk/basilisk.h

@ -52,10 +52,10 @@ struct basilisk_request
struct basilisk_rawtx
{
bits256 txid,actualtxid;
bits256 txid,signedtxid,actualtxid;
struct iguana_info *coin;
uint64_t amount,change,inputsum;
int32_t datalen,vintype,vouttype,numconfirms,spendlen,secretstart;
int32_t datalen,completed,vintype,vouttype,numconfirms,spendlen,secretstart;
uint32_t locktime;
char destaddr[64]; uint8_t addrtype,pubkey33[33],rmd160[20],spendscript[512];
uint8_t *txbytes;

74
basilisk/basilisk_swap.c

@ -117,9 +117,29 @@ int32_t instantdex_pubkeyargs(struct supernet_info *myinfo,struct basilisk_swap
return(n);
}
int32_t basilisk_rawtx_return(struct supernet_info *myinfo,struct basilisk_rawtx *rawtx,cJSON *item,cJSON *privkeyarray,int32_t lockinputs)
{
char *signedtx,*txbytes; cJSON *vins; int32_t retval = -1;
if ( (txbytes= jstr(item,"rawtx")) != 0 && (vins= jobj(item,"vins")) != 0 )
{
if ( (signedtx= iguana_signrawtx(myinfo,rawtx->coin,&rawtx->signedtxid,&rawtx->completed,vins,txbytes,privkeyarray)) != 0 )
{
if ( lockinputs != 0 )
iguana_unspentslock(myinfo,rawtx->coin,vins);
rawtx->datalen = (int32_t)strlen(signedtx) >> 1;
rawtx->txbytes = calloc(1,rawtx->datalen);
decode_hex(rawtx->txbytes,rawtx->datalen,signedtx);
printf("SIGNEDTX.(%s)\n",signedtx);
free(signedtx);
retval = 0;
} else printf("error signrawtx\n"); //do a very short timeout so it finishes via local poll
}
return(retval);
}
int32_t basilisk_rawtx_gen(char *str,struct supernet_info *myinfo,struct basilisk_swap *swap,int32_t lockinputs,struct basilisk_rawtx *rawtx,uint32_t locktime,uint8_t *script,int32_t scriptlen,int64_t txfee,int32_t minconf)
{
struct iguana_waddress *waddr; struct iguana_waccount *wacct; char coinaddr[64],wifstr[64],*txbytes=0,*signedtx,*retstr,scriptstr[1024]; bits256 signedtxid; uint32_t basilisktag; int32_t flag,completed,retval = -1; cJSON *valsobj,*vins=0,*retjson=0,*privkeyarray,*addresses;
struct iguana_waddress *waddr; struct iguana_waccount *wacct; char coinaddr[64],wifstr[64],*retstr,scriptstr[1024]; uint32_t basilisktag; int32_t flag,i,n,retval = -1; cJSON *valsobj,*retarray=0,*privkeyarray,*addresses;
if ( (waddr= iguana_getaccountaddress(myinfo,rawtx->coin,0,0,rawtx->coin->changeaddr,"change")) == 0 )
{
printf("no change addr error\n");
@ -154,33 +174,23 @@ int32_t basilisk_rawtx_gen(char *str,struct supernet_info *myinfo,struct basilis
{
//printf("%s got.(%s)\n",str,retstr);
flag = 0;
if ( (retjson= cJSON_Parse(retstr)) != 0 )
{
if ( (txbytes= jstr(retjson,"rawtx")) != 0 && (vins= jobj(retjson,"vins")) != 0 )
flag = 1;
else printf("missing rawtx.%p or vins.%p (%s)\n",txbytes,vins,retstr);
} else printf("error parsing.(%s)\n",retstr);
if ( txbytes != 0 && vins != 0 )
if ( (retarray= cJSON_Parse(retstr)) != 0 )
{
//printf("vins.(%s)\n",jprint(vins,0));
if ( (signedtx= iguana_signrawtx(myinfo,rawtx->coin,&signedtxid,&completed,vins,txbytes,privkeyarray)) != 0 )
if ( is_cJSON_Array(retarray) != 0 )
{
if ( lockinputs != 0 )
iguana_unspentslock(myinfo,rawtx->coin,vins);
rawtx->datalen = (int32_t)strlen(signedtx) >> 1;
rawtx->txbytes = calloc(1,rawtx->datalen);
decode_hex(rawtx->txbytes,rawtx->datalen,signedtx);
printf("%s %s.%s\n",swap->iambob != 0 ? "BOB" : "ALICE",str,signedtx);
free(signedtx);
retval = 0;
} else printf("error signrawtx\n"); //do a very short timeout so it finishes via local poll
}
if ( retjson != 0 )
free_json(retjson);
n = cJSON_GetArraySize(retarray);
for (i=0; i<n; i++)
{
if ( (retval= basilisk_rawtx_return(myinfo,rawtx,jitem(retarray,i),privkeyarray,lockinputs)) == 0 )
break;
}
} else retval = basilisk_rawtx_return(myinfo,rawtx,retarray,privkeyarray,lockinputs);
free(retarray);
} else printf("error parsing.(%s)\n",retstr);
free(retstr);
} else printf("error creating %s feetx\n",swap->iambob != 0 ? "BOB" : "ALICE");
free_json(privkeyarray);
free_json(valsobj);
//free_json(privkeyarray);
return(retval);
}
@ -266,8 +276,10 @@ struct basilisk_swap *bitcoin_swapinit(struct supernet_info *myinfo,struct basil
swap->bobconfirms = swap->bobcoin->chain->minconfirms;
if ( swap->aliceconfirms == 0 )
swap->aliceconfirms = swap->alicecoin->chain->minconfirms;
swap->bobinsurance = (swap->bobsatoshis / INSTANTDEX_INSURANCEDIV);
swap->aliceinsurance = (swap->alicesatoshis / INSTANTDEX_INSURANCEDIV);
if ( (swap->bobinsurance= (swap->bobsatoshis / INSTANTDEX_INSURANCEDIV)) < 10000 )
swap->bobinsurance = 10000;
if ( (swap->aliceinsurance= (swap->alicesatoshis / INSTANTDEX_INSURANCEDIV)) < 10000 )
swap->aliceinsurance = 10000;
strcpy(swap->bobstr,swap->bobcoin->symbol);
strcpy(swap->alicestr,swap->alicecoin->symbol);
swap->started = (uint32_t)time(NULL);
@ -591,8 +603,16 @@ void basilisk_swaploop(void *_swap)
}
else if ( (swap->statebits & 0x40) == 0 ) // send fee
{
if ( swap->myfee.txbytes != 0 || basilisk_rawtx_gen("myfee",myinfo,swap,1,&swap->myfee,0,swap->myfee.spendscript,swap->myfee.spendlen,swap->myfee.coin->chain->txfee,1) == 0 )
swap->statebits |= basilisk_swapdata_rawtxsend(myinfo,swap,0x80,data,maxlen,&swap->myfee,0x40);
if ( swap->myfee.txbytes == 0 )
{
if ( basilisk_rawtx_gen("myfee",myinfo,swap,1,&swap->myfee,0,swap->myfee.spendscript,swap->myfee.spendlen,swap->myfee.coin->chain->txfee,1) == 0 )
swap->statebits |= basilisk_swapdata_rawtxsend(myinfo,swap,0x80,data,maxlen,&swap->myfee,0x40);
else
{
printf("error creating myfee\n");
break;
}
}
}
else if ( (swap->statebits & 0x80) == 0 ) // wait for fee
{

4
iguana/tests/rawtx2

@ -1 +1,3 @@
curl --url "http://127.0.0.1:7778" --data "{\"coin\":\"BTC\",\"agent\":\"basilisk\",\"method\":\"rawtx\",\"vals\":{\"changeaddr\":\"1FNhoaBYzf7safMBjoCsJYgxtah3K95sep\",\"addresses\":[\"1Hgzt5xsnbfc8UTWqWKSTLRm5bEYHYBoCE\"],\"timeout\":15000,\"satoshis\":\"20000\",\"spendscript\":\"76a914b7128d2ee837cf03e30a2c0e3e0181f7b9669bb688ac\"}}"
curl --url "http://127.0.0.1:7778" --data "{\"coin\":\"BTCD\",\"agent\":\"basilisk\",\"method\":\"rawtx\",\"vals\":{\"changeaddr\":\"RSyKVKNxrSDc1Vwvh4guYb9ZDEpvMFz2rm\",\"addresses\":[\"RRyBxbrAPRUBCUpiJgJZYrkxqrh8x5ta9Z\", \"RPett64qbUvSefiPCyBzQ52Aer9dx32ngd\", \"RGxn8p5QWZXbs58mpRtVRD8aeATVkRq2Rh\", \"RD9HQdpu9Z7Xsvvbh9URdnwYi6RZVMTVAa\", \"RSZzYEEAVnYDnRvfj5oA3yL6vYtm1WmXHJ\", \"RC3k4XRZxrDDMyYFmvBunZCAsNEFepbpRQ\", \"RSyKVKNxrSDc1Vwvh4guYb9ZDEpvMFz2rm\"],\"timeout\":15000,\"satoshis\":\"128700\",\"spendscript\":\"76a914ca1e04745e8ca0c60d8c5881531d51bec470743f88ac\",\"txfee\":\"1000000\",\"burn\":0.00010000}}"
#{"coin":"BTCD","spendscript":"76a914ca1e04745e8ca0c60d8c5881531d51bec470743f88ac","changeaddr":"RSyKVKNxrSDc1Vwvh4guYb9ZDEpvMFz2rm","satoshis":"128700","txfee":"1000000","minconf":1,"locktime":0,"timeout":30000,"burn":0.00010000,"addresses":["RRyBxbrAPRUBCUpiJgJZYrkxqrh8x5ta9Z", "RPett64qbUvSefiPCyBzQ52Aer9dx32ngd", "RGxn8p5QWZXbs58mpRtVRD8aeATVkRq2Rh", "RD9HQdpu9Z7Xsvvbh9URdnwYi6RZVMTVAa", "RSZzYEEAVnYDnRvfj5oA3yL6vYtm1WmXHJ", "RC3k4XRZxrDDMyYFmvBunZCAsNEFepbpRQ", "RSyKVKNxrSDc1Vwvh4guYb9ZDEpvMFz2rm"],"symbol":"BTCD"}

Loading…
Cancel
Save