Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
b8abef30f8
  1. 2
      iguana/iguana.sources
  2. 2
      iguana/iguana777.h
  3. 21
      iguana/iguana_payments.c
  4. 17
      iguana/iguana_sign.c
  5. 2
      iguana/m_unix
  6. 33
      iguana/swaps/iguana_BTCswap.c

2
iguana/iguana.sources

@ -1,2 +1,2 @@
SOURCES := SuperNET.c iguana_bundles.c iguana_stake.c iguana_interpreter.c mini-gmp.c main.c iguana_payments.c iguana_spendvectors.c iguana_sign.c iguana_txidfind.c iguana_realtime.c iguana_volatiles.c peggy_price.c SuperNET_category.c iguana_chains.c iguana_ramchain.c iguana_secp.c pangea_api.c peggy_ramkv.c SuperNET_hexmsg.c iguana_exchanges.c iguana_recv.c pangea_bets.c peggy_serdes.c SuperNET_keys.c iguana_rpc.c pangea_hand.c peggy_tx.c cards777.c iguana_init.c iguana_scripts.c pangea_json.c peggy_txind.c iguana777.c iguana_instantdex.c iguana_tradebots.c pangea_summary.c peggy_update.c iguana_accept.c iguana_json.c iguana_tx.c peggy.c poker.c iguana_bitmap.c iguana_msg.c iguana_unspents.c peggy_accts.c ramchain_api.c iguana_blocks.c iguana_peers.c iguana_wallet.c peggy_consensus.c databases/iguana_DB.c secp256k1/src/secp256k1.c
SOURCES := SuperNET.c iguana_bundles.c iguana_stake.c iguana_interpreter.c mini-gmp.c main.c iguana_payments.c iguana_spendvectors.c iguana_sign.c iguana_txidfind.c iguana_realtime.c iguana_volatiles.c peggy_price.c SuperNET_category.c iguana_chains.c iguana_ramchain.c iguana_secp.c pangea_api.c peggy_ramkv.c SuperNET_hexmsg.c iguana_exchanges.c iguana_recv.c pangea_bets.c peggy_serdes.c SuperNET_keys.c iguana_rpc.c pangea_hand.c peggy_tx.c cards777.c iguana_init.c iguana_scripts.c pangea_json.c peggy_txind.c iguana777.c iguana_instantdex.c iguana_tradebots.c pangea_summary.c peggy_update.c iguana_accept.c iguana_json.c iguana_tx.c peggy.c poker.c iguana_bitmap.c iguana_msg.c iguana_unspents.c peggy_accts.c ramchain_api.c iguana_blocks.c iguana_peers.c iguana_wallet.c peggy_consensus.c secp256k1/src/secp256k1.c

2
iguana/iguana777.h

@ -826,7 +826,7 @@ cJSON *iguana_blockjson(struct iguana_info *coin,struct iguana_block *block,int3
void calc_rmd160_sha256(uint8_t rmd160[20],uint8_t *data,int32_t datalen);
int32_t bitcoin_checklocktimeverify(uint8_t *script,int32_t n,uint32_t locktime);
struct bitcoin_spend *iguana_spendset(struct supernet_info *myinfo,struct iguana_info *coin,int64_t satoshis,int64_t insurance,char *account);
cJSON *bitcoin_hex2json(struct iguana_info *coin,bits256 *txidp,struct iguana_msgtx *msgtx,char *txbytes);
cJSON *bitcoin_hex2json(struct iguana_info *coin,bits256 *txidp,struct iguana_msgtx *msgtx,char *txbytes,uint8_t *extrapace,int32_t extralen);
cJSON *iguana_signtx(struct supernet_info *myinfo,struct iguana_info *coin,bits256 *txidp,char **signedtxp,struct bitcoin_spend *spend,cJSON *txobj,cJSON *vins);
void iguana_addscript(struct iguana_info *coin,cJSON *dest,uint8_t *script,int32_t scriptlen,char *fieldname);

21
iguana/iguana_payments.c

@ -994,7 +994,7 @@ THREE_STRINGS(bitcoinrpc,verifymessage,address,sig,message)
HASH_AND_INT(bitcoinrpc,getrawtransaction,txid,verbose)
{
struct iguana_txid *tx,T; char *txbytes; bits256 checktxid; int32_t len,height; cJSON *retjson,*txobj;
struct iguana_txid *tx,T; char *txbytes; bits256 checktxid; int32_t len,height,extralen=65536; cJSON *retjson,*txobj; uint8_t *extraspace;
if ( remoteaddr != 0 )
return(clonestr("{\"error\":\"no remote\"}"));
if ( (tx= iguana_txidfind(coin,&height,&T,txid,coin->bundlescount-1)) != 0 )
@ -1006,7 +1006,9 @@ HASH_AND_INT(bitcoinrpc,getrawtransaction,txid,verbose)
init_hexbytes_noT(txbytes,coin->blockspace,len);
if ( verbose != 0 )
{
txobj = bitcoin_hex2json(coin,&checktxid,0,txbytes);
extraspace = calloc(1,extralen);
txobj = bitcoin_hex2json(coin,&checktxid,0,txbytes,extraspace,extralen);
free(extraspace);
free(txbytes);
if ( txobj != 0 )
return(jprint(txobj,1));
@ -1048,7 +1050,7 @@ HASH_AND_INT(bitcoinrpc,getrawtransaction,txid,verbose)
STRING_ARG(bitcoinrpc,validaterawtransaction,rawtx)
{
bits256 txid,signedtxid; struct iguana_msgtx msgtx; struct iguana_msgvin vin; cJSON *log,*vins,*txobj,*retjson; char *checkstr,*signedtx; int32_t i,len,maxsize,numinputs,complete; struct vin_info *V; uint8_t *serialized,*serialized2; uint32_t sigsize,pubkeysize,p2shsize,suffixlen;
bits256 txid,signedtxid; struct iguana_msgtx msgtx; struct iguana_msgvin vin; cJSON *log,*vins,*txobj,*retjson; char *checkstr,*signedtx; int32_t i,len,maxsize,numinputs,complete,extralen=65536; struct vin_info *V; uint8_t *serialized,*serialized2,*extraspace; uint32_t sigsize,pubkeysize,p2shsize,suffixlen;
if ( remoteaddr != 0 )
return(clonestr("{\"error\":\"no remote\"}"));
retjson = cJSON_CreateObject();
@ -1057,7 +1059,8 @@ STRING_ARG(bitcoinrpc,validaterawtransaction,rawtx)
if ( (strlen(rawtx) & 1) != 0 )
return(clonestr("{\"error\":\"rawtx hex has odd length\"}"));
memset(&msgtx,0,sizeof(msgtx));
if ( (txobj= bitcoin_hex2json(coin,&txid,&msgtx,rawtx)) != 0 )
extraspace = calloc(1,extralen);
if ( (txobj= bitcoin_hex2json(coin,&txid,&msgtx,rawtx,extraspace,extralen)) != 0 )
{
//printf("txobj.(%s)\n",jprint(txobj,0));
if ( (checkstr= bitcoin_json2hex(myinfo,coin,&txid,txobj,0)) != 0 )
@ -1072,9 +1075,10 @@ STRING_ARG(bitcoinrpc,validaterawtransaction,rawtx)
break;
jaddnum(retjson,"mismatch position",i);
jadd(retjson,"origtx",txobj);
if ( (txobj= bitcoin_hex2json(coin,&txid,&msgtx,checkstr)) != 0 )
if ( (txobj= bitcoin_hex2json(coin,&txid,&msgtx,checkstr,extraspace,extralen)) != 0 )
jadd(retjson,"checktx",txobj);
free(checkstr);
free(extraspace);
return(jprint(retjson,1));
}
free(checkstr);
@ -1111,6 +1115,7 @@ STRING_ARG(bitcoinrpc,validaterawtransaction,rawtx)
}
jaddnum(retjson,"complete",complete);
free(serialized), free(serialized2);
free(extraspace);
}
}
//char str[65]; printf("got txid.(%s)\n",bits256_str(str,txid));
@ -1120,14 +1125,16 @@ STRING_ARG(bitcoinrpc,validaterawtransaction,rawtx)
STRING_ARG(bitcoinrpc,decoderawtransaction,rawtx)
{
cJSON *txobj = 0; bits256 txid;
cJSON *txobj = 0; bits256 txid; uint8_t *extraspace; int32_t extralen = 65536;
if ( remoteaddr != 0 )
return(clonestr("{\"error\":\"no remote\"}"));
if ( rawtx != 0 && rawtx[0] != 0 )
{
if ( (strlen(rawtx) & 1) != 0 )
return(clonestr("{\"error\":\"rawtx hex has odd length\"}"));
txobj = bitcoin_hex2json(coin,&txid,0,rawtx);
extraspace = calloc(1,extralen);
txobj = bitcoin_hex2json(coin,&txid,0,rawtx,extraspace,extralen);
free(extraspace);
//char str[65]; printf("got txid.(%s)\n",bits256_str(str,txid));
}
if ( txobj == 0 )

17
iguana/iguana_sign.c

@ -508,27 +508,25 @@ char *bitcoin_json2hex(struct supernet_info *myinfo,struct iguana_info *coin,bit
return(txbytes);
}
cJSON *bitcoin_hex2json(struct iguana_info *coin,bits256 *txidp,struct iguana_msgtx *msgtx,char *txbytes)
cJSON *bitcoin_hex2json(struct iguana_info *coin,bits256 *txidp,struct iguana_msgtx *msgtx,char *txbytes,uint8_t *extraspace,int32_t extralen)
{
int32_t n,len; char vpnstr[64]; struct iguana_msgtx M; uint8_t *serialized,*extraspace; cJSON *txobj;
int32_t n,len; char vpnstr[64]; struct iguana_msgtx M; uint8_t *serialized; cJSON *txobj;
txobj = cJSON_CreateObject();
if ( msgtx == 0 )
msgtx = &M;
memset(msgtx,0,sizeof(M));
len = (int32_t)strlen(txbytes) >> 1;
serialized = malloc(len);
extraspace = calloc(1,65536);
decode_hex(serialized,len,txbytes);
vpnstr[0] = 0;
memset(txidp,0,sizeof(*txidp));
if ( (n= iguana_rwmsgtx(coin,0,txobj,serialized,len,msgtx,txidp,vpnstr,extraspace,65536)) <= 0 )
if ( (n= iguana_rwmsgtx(coin,0,txobj,serialized,len,msgtx,txidp,vpnstr,extraspace,extralen)) <= 0 )
{
free_json(txobj);
txobj = cJSON_CreateObject();
jaddstr(txobj,"error","couldnt decode transaction");
jaddstr(txobj,"coin",coin->symbol);
}
free(extraspace);
free(serialized);
return(txobj);
}
@ -1036,16 +1034,17 @@ P2SH_SPENDAPI(iguana,spendmsig,activecoin,vintxid,vinvout,destaddress,destamount
int32_t iguana_signrawtransaction(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_msgtx *msgtx,char **signedtxp,bits256 *signedtxidp,struct vin_info *V,int32_t numinputs,char *rawtx,cJSON *vins,cJSON *privkeys)
{
uint8_t *serialized,*serialized2,*serialized3,*extraspace; int32_t i,len,n,maxsize,complete = 0; char *checkstr,*privkeystr,*signedtx = 0; bits256 privkey,txid; cJSON *item; cJSON *txobj = 0;
uint8_t *serialized,*serialized2,*serialized3,*extraspace; int32_t i,len,n,maxsize,complete = 0,extralen = 65536; char *checkstr,*privkeystr,*signedtx = 0; bits256 privkey,txid; cJSON *item; cJSON *txobj = 0;
maxsize = 1000000;
if ( rawtx != 0 && rawtx[0] != 0 && (len= (int32_t)strlen(rawtx)>>1) < maxsize )
{
serialized = malloc(maxsize);
serialized2 = malloc(maxsize);
serialized3 = malloc(maxsize);
extraspace = malloc(extralen);
memset(msgtx,0,sizeof(*msgtx));
decode_hex(serialized,len,rawtx);
if ( (txobj= bitcoin_hex2json(coin,&txid,msgtx,rawtx)) != 0 )
if ( (txobj= bitcoin_hex2json(coin,&txid,msgtx,rawtx,extraspace,extralen)) != 0 )
{
//printf("txobj.(%s)\n",jprint(txobj,0));
if ( (checkstr= bitcoin_json2hex(myinfo,coin,&txid,txobj,0)) != 0 )
@ -1056,6 +1055,7 @@ int32_t iguana_signrawtransaction(struct supernet_info *myinfo,struct iguana_inf
free_json(txobj);
free(checkstr);
free(serialized), free(serialized2), free(serialized3);
free(extraspace);
return(-2);
}
free(checkstr);
@ -1064,7 +1064,6 @@ int32_t iguana_signrawtransaction(struct supernet_info *myinfo,struct iguana_inf
if ( (numinputs= cJSON_GetArraySize(vins)) > 0 )
{
memset(msgtx,0,sizeof(*msgtx));
extraspace = calloc(1,65536);
if ( iguana_rwmsgtx(coin,0,0,serialized,maxsize,msgtx,&txid,"",extraspace,65536) > 0 && numinputs == msgtx->tx_in )
{
if ( (n= cJSON_GetArraySize(privkeys)) > 0 )
@ -1089,8 +1088,8 @@ int32_t iguana_signrawtransaction(struct supernet_info *myinfo,struct iguana_inf
}
}
}
free(extraspace);
}
free(extraspace);
free(serialized), free(serialized2), free(serialized3);
} else return(-1);
if ( txobj != 0 )

2
iguana/m_unix

@ -2,7 +2,7 @@
rm ../agents/iguana *.o
git pull
cd secp256k1; ./m_unix; cd ..
gcc -g -Wno-deprecated -c -O2 *.c databases/iguana_DB.c
gcc -g -Wno-deprecated -c -O2 *.c #databases/iguana_DB.c
gcc -g -Wno-deprecated -c main.c iguana777.c iguana_bundles.c
#gcc -g -o ../agents/iguana *.o ../agents/libcrypto777.a -lcurl -lssl -lcrypto -lpthread -lm #../includes/libsecp256k1.a -lgmp
gcc -g -o ../agents/iguana *.o ../agents/libcrypto777.a -lpthread -lm

33
iguana/swaps/iguana_BTCswap.c

@ -119,12 +119,12 @@ int32_t instantdex_outputinsurance(char *coinaddr,uint8_t addrtype,uint8_t *scri
return(n);
}
void disp_tx(struct supernet_info *myinfo,struct iguana_info *coin,char *str,char *txbytes)
/*void disp_tx(struct supernet_info *myinfo,struct iguana_info *coin,char *str,char *txbytes)
{
cJSON *txobj; bits256 txid;
txobj = bitcoin_hex2json(coin,&txid,0,txbytes);
txobj = bitcoin_hex2json(coin,&txid,0,txbytes,extraspace,extralen);
printf("disp_tx (%s) -> %s.(%s)\n",txbytes,str,jprint(txobj,1));
}
}*/
struct bitcoin_statetx *instantdex_getstatetx(struct bitcoin_swapinfo *swap,char *txname)
{
@ -255,11 +255,12 @@ struct bitcoin_statetx *instantdex_feetx(struct supernet_info *myinfo,struct ins
int32_t instantdex_feetxverify(struct supernet_info *myinfo,struct iguana_info *coin,struct bitcoin_swapinfo *swap,cJSON *argjson)
{
cJSON *txobj; bits256 txid; uint32_t n; int32_t i,retval = -1; int64_t insurance; uint64_t r;
struct iguana_msgtx msgtx; uint8_t script[512]; char coinaddr[64];
cJSON *txobj; bits256 txid; uint32_t n; int32_t i,retval = -1,extralen=65536; int64_t insurance; uint64_t r;
struct iguana_msgtx msgtx; uint8_t script[512],*extraspace=0; char coinaddr[64];
if ( swap->otherfee != 0 )
{
if ( (txobj= bitcoin_hex2json(coin,&txid,&msgtx,swap->otherfee->txbytes)) != 0 )
extraspace = calloc(1,extralen);
if ( (txobj= bitcoin_hex2json(coin,&txid,&msgtx,swap->otherfee->txbytes,extraspace,extralen)) != 0 )
{
r = swap->other.orderid;
if ( strcmp(coin->symbol,"BTC") == 0 )
@ -287,6 +288,8 @@ int32_t instantdex_feetxverify(struct supernet_info *myinfo,struct iguana_info *
free_json(txobj);
} else printf("error converting (%s) txobj\n",swap->otherfee->txbytes);
} else printf("no feetx to verify\n");
if ( extraspace != 0 )
free(extraspace);
return(retval);
}
@ -314,14 +317,15 @@ struct bitcoin_statetx *instantdex_bobtx(struct supernet_info *myinfo,struct bit
int32_t instantdex_paymentverify(struct supernet_info *myinfo,struct iguana_info *coin,struct bitcoin_swapinfo *swap,cJSON *argjson,int32_t depositflag)
{
cJSON *txobj; bits256 txid; uint32_t n,locktime; int32_t i,secretstart,retval = -1; uint64_t x;
struct iguana_msgtx msgtx; uint8_t script[512]; int64_t amount;
cJSON *txobj; bits256 txid; uint32_t n,locktime; int32_t i,secretstart,retval = -1,extralen=65536; uint64_t x;
struct iguana_msgtx msgtx; uint8_t script[512],*extraspace=0; int64_t amount;
if ( coin != 0 && swap->deposit != 0 )
{
amount = swap->BTCsatoshis + depositflag*swap->insurance*100 + swap->coinbtc->chain->txfee;
if ( (n= instantdex_bobscript(script,0,&locktime,&secretstart,swap,depositflag)) <= 0 )
return(retval);
if ( (txobj= bitcoin_hex2json(coin,&txid,&msgtx,swap->deposit->txbytes)) != 0 )
extraspace = calloc(1,extralen);
if ( (txobj= bitcoin_hex2json(coin,&txid,&msgtx,swap->deposit->txbytes,extraspace,extralen)) != 0 )
{
memcpy(&script[secretstart],&msgtx.vouts[0].pk_script[secretstart],20);
printf("locktime.%u amount %.8f satoshis %.8f\n",locktime,dstr(amount),dstr(amount));
@ -348,16 +352,19 @@ int32_t instantdex_paymentverify(struct supernet_info *myinfo,struct iguana_info
free_json(txobj);
}
}
if ( extraspace != 0 )
free(extraspace);
return(retval);
}
int32_t instantdex_altpaymentverify(struct supernet_info *myinfo,struct iguana_info *coin,struct bitcoin_swapinfo *swap,cJSON *argjson)
{
cJSON *txobj; bits256 txid; uint32_t n; int32_t i,retval = -1;
struct iguana_msgtx msgtx; uint8_t script[512]; char *altmsigaddr=0,msigaddr[64];
cJSON *txobj; bits256 txid; uint32_t n; int32_t i,retval = -1,extralen = 65536;
struct iguana_msgtx msgtx; uint8_t script[512],*extraspace=0; char *altmsigaddr=0,msigaddr[64];
if ( swap->altpayment != 0 && (altmsigaddr= jstr(argjson,"altmsigaddr")) != 0 )
{
if ( (txobj= bitcoin_hex2json(coin,&txid,&msgtx,swap->altpayment->txbytes)) != 0 )
extraspace = calloc(1,extralen);
if ( (txobj= bitcoin_hex2json(coin,&txid,&msgtx,swap->altpayment->txbytes,extraspace,extralen)) != 0 )
{
n = instantdex_alicescript(script,0,msigaddr,coin->chain->p2shtype,swap->pubAm,swap->pubBn);
if ( strcmp(msigaddr,altmsigaddr) == 0 && n == msgtx.vouts[0].pk_scriptlen )
@ -380,6 +387,8 @@ int32_t instantdex_altpaymentverify(struct supernet_info *myinfo,struct iguana_i
free_json(txobj);
} else printf("bitcoin_hex2json error\n");
} else printf("no altpayment.%p or no altmsig.%s\n",swap->altpayment,altmsigaddr!=0?altmsigaddr:"");
if ( extraspace != 0 )
free(extraspace);
return(retval);
}

Loading…
Cancel
Save