Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
2ae172f172
  1. 14
      iguana/SuperNET.h
  2. 25
      iguana/exchanges/bitcoin.c
  3. 14
      iguana/exchanges/bitcoin.h
  4. 4
      iguana/iguana777.h
  5. 8
      iguana/iguana_json.c
  6. 2
      iguana/iguana_rpc.c
  7. 37
      iguana/ramchain_api.c
  8. 2
      includes/iguana_apideclares.h
  9. 2
      includes/iguana_apidefs.h
  10. 1
      includes/iguana_apiundefs.h

14
iguana/SuperNET.h

@ -132,20 +132,6 @@ struct category_msg { struct queueitem DL; struct tai t; uint64_t remoteipbits;
struct exchange_quote { uint64_t satoshis,orderid,offerNXT,exchangebits; double price,volume; uint32_t timestamp,val; };
struct bitcoin_unspent
{
bits256 txid,privkeys[16]; uint64_t value; int32_t vout,spendlen; uint32_t sequence;
uint8_t addrtype,rmd160[20],spendscript[2048];
};
struct bitcoin_spend
{
char changeaddr[64]; uint8_t change160[20];
int32_t numinputs;
int64_t txfee,input_satoshis,satoshis,change;
struct bitcoin_unspent inputs[];
};
void expand_epbits(char *endpoint,struct endpoint epbits);
struct endpoint calc_epbits(char *transport,uint32_t ipbits,uint16_t port,int32_t type);

25
iguana/exchanges/bitcoin.c

@ -877,8 +877,8 @@ int32_t bitcoin_verifytx(struct iguana_info *coin,bits256 *signedtxidp,char **si
char *bitcoin_json2hex(struct iguana_info *coin,bits256 *txidp,cJSON *txjson)
{
int32_t txstart; uint8_t *serialized; struct iguana_msgtx msgtx; char *txbytes = 0;
serialized = malloc(IGUANA_MAXPACKETSIZE);
*txidp = iguana_parsetxobj(coin,&txstart,serialized,IGUANA_MAXPACKETSIZE,&msgtx,txjson);
serialized = malloc(IGUANA_MAXPACKETSIZE*1.5);
*txidp = iguana_parsetxobj(coin,&txstart,serialized,IGUANA_MAXPACKETSIZE*1.5,&msgtx,txjson);
if ( msgtx.allocsize > 0 )
{
txbytes = malloc(msgtx.allocsize*2 + 1);
@ -913,7 +913,7 @@ cJSON *bitcoin_hex2json(struct iguana_info *coin,bits256 *txidp,struct iguana_ms
return(txobj);
}
cJSON *bitcoin_createtx(struct iguana_info *coin,int32_t locktime)
cJSON *bitcoin_createtx(struct iguana_info *coin,uint32_t locktime)
{
cJSON *json = cJSON_CreateObject();
if ( locktime == 0 )
@ -951,16 +951,22 @@ cJSON *bitcoin_addoutput(struct iguana_info *coin,cJSON *txobj,uint8_t *payments
return(txobj);
}
cJSON *bitcoin_addinput(struct iguana_info *coin,cJSON *txobj,bits256 txid,int32_t vout,uint32_t sequence,uint8_t *script,int32_t scriptlen)
cJSON *bitcoin_addinput(struct iguana_info *coin,cJSON *txobj,bits256 txid,int32_t vout,uint32_t sequenceid,uint8_t *script,int32_t scriptlen,uint8_t *redeemscript,int32_t p2shlen)
{
cJSON *item,*vins;
cJSON *item,*vins; char p2shscriptstr[IGUANA_MAXSCRIPTSIZE*2+1];
vins = jduplicate(jobj(txobj,"vin"));
jdelete(txobj,"vin");
item = cJSON_CreateObject();
if ( script != 0 && scriptlen > 0 )
iguana_addscript(coin,item,script,scriptlen,"scriptPubKey");
if ( redeemscript != 0 && p2shlen > 0 )
{
init_hexbytes_noT(p2shscriptstr,redeemscript,p2shlen);
jaddstr(item,"redeemScript",p2shscriptstr);
}
jaddbits256(item,"txid",txid);
jaddnum(item,"vout",vout);
jaddnum(item,"sequence",sequence);
jaddnum(item,"sequenceid",sequenceid);
jaddi(vins,item);
jadd(txobj,"vin",vins);
//printf("addvin -> (%s)\n",jprint(txobj,0));
@ -1055,7 +1061,7 @@ void iguana_addinputs(struct iguana_info *coin,struct bitcoin_spend *spend,cJSON
for (i=0; i<spend->numinputs; i++)
{
spend->inputs[i].sequence = sequence;
bitcoin_addinput(coin,txobj,spend->inputs[i].txid,spend->inputs[i].vout,spend->inputs[i].sequence,spend->inputs[i].spendscript,spend->inputs[i].spendlen);
bitcoin_addinput(coin,txobj,spend->inputs[i].txid,spend->inputs[i].vout,spend->inputs[i].sequence,spend->inputs[i].spendscript,spend->inputs[i].spendlen,spend->inputs[i].p2shscript,spend->inputs[i].p2shlen);
}
}
@ -1567,7 +1573,7 @@ int32_t bitcoin_txaddspend(struct iguana_info *coin,cJSON *txobj,char *destaddre
P2SH_SPENDAPI(iguana,spendmsig,activecoin,vintxid,vinvout,destaddress,destamount,destaddress2,destamount2,M,N,pubA,wifA,pubB,wifB,pubC,wifC)
{
struct vin_info V; uint8_t p2sh_rmd160[20],serialized[2096];
struct vin_info V; uint8_t p2sh_rmd160[20],serialized[2096],spendscript[32]; int32_t spendlen;
char msigaddr[64],*retstr; cJSON *retjson,*txobj; struct iguana_info *active;
bits256 signedtxid; char *signedtx;
struct iguana_msgtx msgtx;
@ -1589,7 +1595,8 @@ P2SH_SPENDAPI(iguana,spendmsig,activecoin,vintxid,vinvout,destaddress,destamount
return(retstr);
V.M = M, V.N = N, V.type = IGUANA_SCRIPT_P2SH;
V.p2shlen = bitcoin_MofNspendscript(p2sh_rmd160,V.p2shscript,0,&V);
bitcoin_addinput(active,txobj,vintxid,vinvout,0xffffffff,V.p2shscript,V.p2shlen);
spendlen = bitcoin_p2shspend(spendscript,0,p2sh_rmd160);
bitcoin_addinput(active,txobj,vintxid,vinvout,0xffffffff,spendscript,spendlen,V.p2shscript,V.p2shlen);
bitcoin_address(msigaddr,active->chain->p2shtype,V.p2shscript,V.p2shlen);
retjson = cJSON_CreateObject();
if ( bitcoin_verifyvins(active,&signedtxid,&signedtx,&msgtx,serialized,sizeof(serialized),&V,0) == 0 )

14
iguana/exchanges/bitcoin.h

@ -63,6 +63,20 @@
struct bp_key { EC_KEY *k; };
struct bitcoin_unspent
{
bits256 txid,privkeys[16]; uint64_t value; int32_t vout,spendlen,p2shlen; uint32_t sequence;
uint8_t addrtype,rmd160[20],pubkey[65],spendscript[IGUANA_MAXSCRIPTSIZE],p2shscript[IGUANA_MAXSCRIPTSIZE];
};
struct bitcoin_spend
{
char changeaddr[64]; uint8_t change160[20];
int32_t numinputs;
int64_t txfee,input_satoshis,satoshis,change;
struct bitcoin_unspent inputs[];
};
int32_t bitcoin_validaddress(struct iguana_info *coin,char *coinaddr);
int32_t bitcoin_cltvscript(uint8_t p2shtype,char *ps2h_coinaddr,uint8_t p2sh_rmd160[20],uint8_t *script,int32_t n,char *senderaddr,char *otheraddr,uint8_t secret160[20],uint32_t locktime);
int32_t bitcoin_addr2rmd160(uint8_t *addrtypep,uint8_t rmd160[20],char *coinaddr);

4
iguana/iguana777.h

@ -803,10 +803,10 @@ 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 *iguana_signtx(struct iguana_info *coin,bits256 *txidp,char **signedtxp,struct bitcoin_spend *spend,cJSON *txobj);
cJSON *bitcoin_createtx(struct iguana_info *coin,int32_t locktime);
cJSON *bitcoin_createtx(struct iguana_info *coin,uint32_t locktime);
cJSON *bitcoin_addoutput(struct iguana_info *coin,cJSON *txobj,uint8_t *paymentscript,int32_t len,uint64_t satoshis);
int32_t bitcoin_changescript(struct iguana_info *coin,uint8_t *changescript,int32_t n,uint64_t *changep,char *changeaddr,uint64_t inputsatoshis,uint64_t satoshis,uint64_t txfee);
cJSON *bitcoin_addinput(struct iguana_info *coin,cJSON *txobj,bits256 txid,int32_t vout,uint32_t sequence,uint8_t *script,int32_t scriptlen);
cJSON *bitcoin_addinput(struct iguana_info *coin,cJSON *txobj,bits256 txid,int32_t vout,uint32_t sequence,uint8_t *script,int32_t scriptlen,uint8_t *redeemscript,int32_t p2shlen);
int32_t bitcoin_verifytx(struct iguana_info *coin,bits256 *signedtxidp,char **signedtx,char *rawtxstr,struct vin_info *V);
char *bitcoin_json2hex(struct iguana_info *coin,bits256 *txidp,cJSON *txjson);
int32_t bitcoin_addr2rmd160(uint8_t *addrtypep,uint8_t rmd160[20],char *coinaddr);

8
iguana/iguana_json.c

@ -119,6 +119,7 @@ cJSON *SuperNET_helpjson()
#define IGUANA_HELP_64A(agent,name,j64,obj) array = helpjson(IGUANA_ARGS,#agent,#name,helparray2(cJSON_CreateArray(),helpitem(#j64,"u64bits"),helpitem(#obj,"array")))
#define IGUANA_HELP_AA(agent,name,obj,obj2) array = helpjson(IGUANA_ARGS,#agent,#name,helparray2(cJSON_CreateArray(),helpitem(#obj,"array"),helpitem(#obj2,"array")))
#define IGUANA_HELP_AOI(agent,name,obj,obj2,val) array = helpjson(IGUANA_ARGS,#agent,#name,helparray3(cJSON_CreateArray(),helpitem(#obj,"array"),helpitem(#obj2,"object"),helpitem(#val,"int")))
#define IGUANA_HELP_D(agent,name,amount) array = helpjson(IGUANA_ARGS,#agent,#name,helparray(cJSON_CreateArray(),helpitem(#amount,"float")))
#define IGUANA_HELP_H(agent,name,hash) array = helpjson(IGUANA_ARGS,#agent,#name,helparray(cJSON_CreateArray(),helpitem(#hash,"hash")))
@ -180,6 +181,7 @@ cJSON *SuperNET_helpjson()
#define TWO_STRINGS_AND_TWO_DOUBLES IGUANA_HELP_SSDD
#define STRING_AND_TWO_DOUBLES IGUANA_HELP_SDD
#define P2SH_SPENDAPI IGUANA_HELP_SHI_SDSD_II_SSSSSS
#define ARRAY_OBJ_INT IGUANA_HELP_AOI
#include "../includes/iguana_apideclares.h"
@ -222,6 +224,10 @@ int32_t agentform(FILE *fp,char *form,int32_t max,char *agent,cJSON *methoditem)
width = 24;
else if ( strcmp(typestr,"u64bits") == 0 )
width = 24;
else if ( strcmp(typestr,"array") == 0 )
width = 64;
else if ( strcmp(typestr,"object") == 0 )
width = 64;
else width = 0;
}
//sprintf(buf,"<input type=\"text\" name=\"%s\"/>",fieldname);
@ -902,6 +908,7 @@ char *SuperNET_parser(struct supernet_info *myinfo,char *agentstr,char *method,c
#define IGUANA_DISPATCH_SDD(agent,name,str,val,val2) else if ( strcmp(#agent,agentstr) == 0 && strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jstr(json,#str),jdouble(json,#val),jdouble(json,#val2)))
#define IGUANA_DISPATCH_SA(agent,name,str,array) else if ( strcmp(#agent,agentstr) == 0 && strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jstr(json,#str),jobj(json,#array)))
#define IGUANA_DISPATCH_SAA(agent,name,str,array,array2) else if ( strcmp(#agent,agentstr) == 0 && strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jstr(json,#str),jobj(json,#array),jobj(json,#array2)))
#define IGUANA_DISPATCH_AOI(agent,name,array,object,val) else if ( strcmp(#agent,agentstr) == 0 && strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jobj(json,#array),jobj(json,#object),juint(json,#val)))
#define IGUANA_DISPATCH_SIII(agent,name,str,val,val2,val3) else if ( strcmp(#agent,agentstr) == 0 && strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jstr(json,#str),juint(json,#val),juint(json,#val2),juint(json,#val3)))
#define IGUANA_DISPATCH_I(agent,name,val) else if ( strcmp(#agent,agentstr) == 0 && strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,juint(json,#val)))
@ -975,6 +982,7 @@ char *SuperNET_parser(struct supernet_info *myinfo,char *agentstr,char *method,c
#define TWO_STRINGS_AND_TWO_DOUBLES IGUANA_DISPATCH_SSDD
#define STRING_AND_TWO_DOUBLES IGUANA_DISPATCH_SDD
#define P2SH_SPENDAPI IGUANA_DISPATCH_SHI_SDSD_II_SSSSSS
#define ARRAY_OBJ_INT IGUANA_DISPATCH_AOI
#include "../includes/iguana_apideclares.h"
//#undef IGUANA_ARGS

2
iguana/iguana_rpc.c

@ -480,7 +480,7 @@ static char *getrawtransaction(RPCARGS)
static char *createrawtransaction(RPCARGS)
{
return(sglue2(0,CALLGLUE,"bitcoinrpc","createrawtransaction","vins",params[0],"vouts",params[1]));
return(sglue3(0,CALLGLUE,"bitcoinrpc","createrawtransaction","vins",params[0],"vouts",params[1],"locktime",params[2]));
}
static char *decoderawtransaction(RPCARGS)

37
iguana/ramchain_api.c

@ -386,9 +386,42 @@ THREE_STRINGS(bitcoinrpc,verifymessage,address,sig,message)
}
// tx
TWO_ARRAYS(bitcoinrpc,createrawtransaction,vins,vouts)
ARRAY_OBJ_INT(bitcoinrpc,createrawtransaction,vins,vouts,locktime)
{
cJSON *retjson = cJSON_CreateObject();
bits256 txid; int32_t vout,scriptlen=0,p2shlen=0,i,n; uint32_t sequenceid; uint8_t script[IGUANA_MAXSCRIPTSIZE],redeemscript[IGUANA_MAXSCRIPTSIZE]; char *str; cJSON *txobj,*item,*retjson = cJSON_CreateObject();
if ( coin != 0 && (txobj= bitcoin_createtx(coin,locktime)) != 0 )
{
if ( (n= cJSON_GetArraySize(vins)) > 0 )
{
for (i=0; i<n; i++)
{
item = jitem(vins,i);
p2shlen = scriptlen = 0;
if ( (str= jstr(item,"scriptPubKey")) != 0 )
{
scriptlen = (int32_t)strlen(str) >> 1;
decode_hex(script,scriptlen,str);
}
if ( (str= jstr(item,"redeemScript")) != 0 )
{
p2shlen = (int32_t)strlen(str) >> 1;
decode_hex(redeemscript,p2shlen,str);
}
vout = jint(item,"vout");
sequenceid = juint(item,"sequenceid");
txid = jbits256(item,"txid");
bitcoin_addinput(coin,txobj,txid,vout,sequenceid,script,scriptlen,redeemscript,p2shlen);
}
}
if ( (n= cJSON_GetArraySize(vouts)) > 0 )
{
for (i=0; i<n; i++)
{
item = jitem(vouts,i);
}
}
}
printf("vins.(%s) vouts.(%s) locktime.%u\n",jprint(vins,0),jprint(vouts,0),locktime);
return(jprint(retjson,1));
}

2
includes/iguana_apideclares.h

@ -26,7 +26,7 @@ HASH_ARG(bitcoinrpc,gettransaction,txid);
STRING_ARG(bitcoinrpc,decodescript,script);
STRING_ARG(bitcoinrpc,decoderawtransaction,rawtx);
TWO_ARRAYS(bitcoinrpc,createrawtransaction,vins,vouts); //
ARRAY_OBJ_INT(bitcoinrpc,createrawtransaction,vins,vouts,locktime); //
STRING_AND_TWOARRAYS(bitcoinrpc,signrawtransaction,rawtx,vins,privkeys); //
STRING_AND_INT(bitcoinrpc,sendrawtransaction,rawtx,allowhighfees); //

2
includes/iguana_apidefs.h

@ -7,6 +7,7 @@
#define IGUANA_CFUNC_SA(agent,name,str,array) char *agent ## _ ## name(IGUANA_ARGS,char *str,cJSON *array)
#define IGUANA_CFUNC_SD(agent,name,str,val) char *agent ## _ ## name(IGUANA_ARGS,char *str,double val)
#define IGUANA_CFUNC_AA(agent,name,array,array2) char *agent ## _ ## name(IGUANA_ARGS,cJSON *array,cJSON *array2)
#define IGUANA_CFUNC_AOI(agent,name,array,object,val) char *agent ## _ ## name(IGUANA_ARGS,cJSON *array,cJSON *object,int32_t val)
#define IGUANA_CFUNC_SAA(agent,name,str,array,array2) char *agent ## _ ## name(IGUANA_ARGS,char *str,cJSON *array,cJSON *array2)
#define IGUANA_CFUNC_64A(agent,name,j64,array) char *agent ## _ ## name(IGUANA_ARGS,uint64_t j64,cJSON *array)
@ -67,6 +68,7 @@
#define STRING_AND_ARRAY IGUANA_CFUNC_SA
#define STRING_AND_TWOARRAYS IGUANA_CFUNC_SAA
#define TWO_ARRAYS IGUANA_CFUNC_AA
#define ARRAY_OBJ_INT IGUANA_CFUNC_AOI
#define INT_AND_ARRAY IGUANA_CFUNC_IA
#define INT_ARRAY_STRING IGUANA_CFUNC_IAS
#define SS_D_I_S IGUANA_CFUNC_SSDIS

1
includes/iguana_apiundefs.h

@ -15,6 +15,7 @@
#undef HASH_AND_INT
#undef HASH_AND_TWOINTS
#undef DOUBLE_ARG
#undef ARRAY_OBJ_INT
#undef STRING_AND_ARRAY
#undef INT_AND_ARRAY
#undef INT_ARRAY_STRING

Loading…
Cancel
Save