|
|
@ -310,7 +310,7 @@ uint64_t get_btcusd() |
|
|
|
|
|
|
|
char *REFCOIN_CLI; |
|
|
|
|
|
|
|
cJSON *get_komodocli(char *refcoin,char **retstrp,char *acname,char *method,char *arg0,char *arg1,char *arg2) |
|
|
|
cJSON *get_komodocli(char *refcoin,char **retstrp,char *acname,char *method,char *arg0,char *arg1,char *arg2,char *arg3) |
|
|
|
{ |
|
|
|
long fsize; cJSON *retjson = 0; char cmdstr[32768],*jsonstr,fname[256]; |
|
|
|
sprintf(fname,"/tmp/oraclefeed.%s",method); |
|
|
@ -318,13 +318,13 @@ cJSON *get_komodocli(char *refcoin,char **retstrp,char *acname,char *method,char |
|
|
|
{ |
|
|
|
if ( refcoin[0] != 0 && strcmp(refcoin,"KMD") != 0 ) |
|
|
|
printf("unexpected: refcoin.(%s) acname.(%s)\n",refcoin,acname); |
|
|
|
sprintf(cmdstr,"./komodo-cli -ac_name=%s %s %s %s %s > %s\n",acname,method,arg0,arg1,arg2,fname); |
|
|
|
sprintf(cmdstr,"./komodo-cli -ac_name=%s %s %s %s %s %s > %s\n",acname,method,arg0,arg1,arg2,arg3,fname); |
|
|
|
} |
|
|
|
else if ( strcmp(refcoin,"KMD") == 0 ) |
|
|
|
sprintf(cmdstr,"./komodo-cli %s %s %s %s > %s\n",method,arg0,arg1,arg2,fname); |
|
|
|
sprintf(cmdstr,"./komodo-cli %s %s %s %s %s > %s\n",method,arg0,arg1,arg2,arg3,fname); |
|
|
|
else if ( REFCOIN_CLI != 0 && REFCOIN_CLI[0] != 0 ) |
|
|
|
{ |
|
|
|
sprintf(cmdstr,"%s %s %s %s %s > %s\n",REFCOIN_CLI,method,arg0,arg1,arg2,fname); |
|
|
|
sprintf(cmdstr,"%s %s %s %s %s %s > %s\n",REFCOIN_CLI,method,arg0,arg1,arg2,arg3,fname); |
|
|
|
printf("ref.(%s) REFCOIN_CLI (%s)\n",refcoin,cmdstr); |
|
|
|
} |
|
|
|
system(cmdstr); |
|
|
@ -345,7 +345,7 @@ bits256 komodobroadcast(char *refcoin,char *acname,cJSON *hexjson) |
|
|
|
memset(txid.bytes,0,sizeof(txid)); |
|
|
|
if ( (hexstr= jstr(hexjson,"hex")) != 0 ) |
|
|
|
{ |
|
|
|
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"sendrawtransaction",hexstr,"","")) != 0 ) |
|
|
|
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"sendrawtransaction",hexstr,"","","")) != 0 ) |
|
|
|
{ |
|
|
|
//fprintf(stderr,"broadcast.(%s)\n",jprint(retjson,0));
|
|
|
|
free_json(retjson); |
|
|
@ -369,7 +369,7 @@ bits256 sendtoaddress(char *refcoin,char *acname,char *destaddr,int64_t satoshis |
|
|
|
char numstr[32],*retstr,str[65]; cJSON *retjson; bits256 txid; |
|
|
|
memset(txid.bytes,0,sizeof(txid)); |
|
|
|
sprintf(numstr,"%.8f",(double)satoshis/SATOSHIDEN); |
|
|
|
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"sendtoaddress",destaddr,numstr,"")) != 0 ) |
|
|
|
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"sendtoaddress",destaddr,numstr,"","")) != 0 ) |
|
|
|
{ |
|
|
|
fprintf(stderr,"unexpected sendrawtransaction json.(%s)\n",jprint(retjson,0)); |
|
|
|
free_json(retjson); |
|
|
@ -390,7 +390,7 @@ bits256 sendtoaddress(char *refcoin,char *acname,char *destaddr,int64_t satoshis |
|
|
|
int32_t get_coinheight(char *refcoin,char *acname) |
|
|
|
{ |
|
|
|
cJSON *retjson; char *retstr; int32_t height=0; |
|
|
|
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"getblockchaininfo","","","")) != 0 ) |
|
|
|
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"getblockchaininfo","","","","")) != 0 ) |
|
|
|
{ |
|
|
|
height = jint(retjson,"blocks"); |
|
|
|
free_json(retjson); |
|
|
@ -408,7 +408,7 @@ bits256 get_coinblockhash(char *refcoin,char *acname,int32_t height) |
|
|
|
cJSON *retjson; char *retstr,heightstr[32]; bits256 hash; |
|
|
|
memset(hash.bytes,0,sizeof(hash)); |
|
|
|
sprintf(heightstr,"%d",height); |
|
|
|
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"getblockhash",heightstr,"","")) != 0 ) |
|
|
|
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"getblockhash",heightstr,"","","")) != 0 ) |
|
|
|
{ |
|
|
|
fprintf(stderr,"unexpected blockhash json.(%s)\n",jprint(retjson,0)); |
|
|
|
free_json(retjson); |
|
|
@ -429,7 +429,7 @@ bits256 get_coinmerkleroot(char *refcoin,char *acname,bits256 blockhash) |
|
|
|
{ |
|
|
|
cJSON *retjson; char *retstr,str[65]; bits256 merkleroot; |
|
|
|
memset(merkleroot.bytes,0,sizeof(merkleroot)); |
|
|
|
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"getblockheader",bits256_str(str,blockhash),"","")) != 0 ) |
|
|
|
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"getblockheader",bits256_str(str,blockhash),"","","")) != 0 ) |
|
|
|
{ |
|
|
|
merkleroot = jbits256(retjson,"merkleroot"); |
|
|
|
//fprintf(stderr,"got merkleroot.(%s)\n",bits256_str(str,merkleroot));
|
|
|
@ -467,7 +467,7 @@ int32_t get_coinheader(char *refcoin,char *acname,bits256 *blockhashp,bits256 *m |
|
|
|
cJSON *get_gatewayspending(char *refcoin,char *acname,char *oraclestxidstr) |
|
|
|
{ |
|
|
|
cJSON *retjson; char *retstr; |
|
|
|
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"gatewayspending",oraclestxidstr,refcoin,"")) != 0 ) |
|
|
|
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"gatewayspending",oraclestxidstr,refcoin,"","")) != 0 ) |
|
|
|
{ |
|
|
|
//printf("pending.(%s)\n",jprint(retjson,0));
|
|
|
|
return(retjson); |
|
|
@ -483,7 +483,7 @@ cJSON *get_gatewayspending(char *refcoin,char *acname,char *oraclestxidstr) |
|
|
|
cJSON *get_rawmempool(char *refcoin,char *acname) |
|
|
|
{ |
|
|
|
cJSON *retjson; char *retstr; |
|
|
|
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"getrawmempool","","","")) != 0 ) |
|
|
|
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"getrawmempool","","","","")) != 0 ) |
|
|
|
{ |
|
|
|
//printf("mempool.(%s)\n",jprint(retjson,0));
|
|
|
|
return(retjson); |
|
|
@ -502,7 +502,7 @@ cJSON *get_addressutxos(char *refcoin,char *acname,char *coinaddr) |
|
|
|
if ( refcoin[0] != 0 && strcmp(refcoin,"KMD") != 0 ) |
|
|
|
printf("warning: assumes %s has addressindex enabled\n",refcoin); |
|
|
|
sprintf(jsonbuf,"{\\\"addresses\\\":[\\\"%s\\\"]}",coinaddr); |
|
|
|
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"getaddressutxos",jsonbuf,"","")) != 0 ) |
|
|
|
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"getaddressutxos",jsonbuf,"","","")) != 0 ) |
|
|
|
{ |
|
|
|
//printf("addressutxos.(%s)\n",jprint(retjson,0));
|
|
|
|
return(retjson); |
|
|
@ -518,7 +518,7 @@ cJSON *get_addressutxos(char *refcoin,char *acname,char *coinaddr) |
|
|
|
cJSON *get_rawtransaction(char *refcoin,char *acname,bits256 txid) |
|
|
|
{ |
|
|
|
cJSON *retjson; char *retstr,str[65]; |
|
|
|
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"getrawtransaction",bits256_str(str,txid),"1","")) != 0 ) |
|
|
|
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"getrawtransaction",bits256_str(str,txid),"1","","")) != 0 ) |
|
|
|
{ |
|
|
|
return(retjson); |
|
|
|
} |
|
|
@ -533,7 +533,7 @@ cJSON *get_rawtransaction(char *refcoin,char *acname,bits256 txid) |
|
|
|
void importaddress(char *refcoin,char *acname,char *depositaddr) |
|
|
|
{ |
|
|
|
cJSON *retjson; char *retstr; |
|
|
|
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"importaddress",depositaddr,"","")) != 0 ) |
|
|
|
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"importaddress",depositaddr,"","","")) != 0 ) |
|
|
|
{ |
|
|
|
printf("importaddress.(%s)\n",jprint(retjson,0)); |
|
|
|
free_json(retjson); |
|
|
@ -585,7 +585,7 @@ char *createmultisig(char *refcoin,char *acname,char *depositaddr,char *signerad |
|
|
|
} |
|
|
|
satoshis -= txfee; |
|
|
|
sprintf(array,"[\"%s\"]",depositaddr); |
|
|
|
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"listunspent","1","99999999",array)) != 0 ) |
|
|
|
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"listunspent","1","99999999",array,"")) != 0 ) |
|
|
|
{ |
|
|
|
//createrawtransaction [{"txid":"id","vout":n},...] {"address":amount,...}
|
|
|
|
if ( (vins= getinputarray(&total,retjson,satoshis)) != 0 ) |
|
|
@ -602,7 +602,7 @@ char *createmultisig(char *refcoin,char *acname,char *depositaddr,char *signerad |
|
|
|
char *argA,*argB; |
|
|
|
argA = jprint(vins,1); |
|
|
|
argB = jprint(vouts,1); |
|
|
|
if ( (retjson2= get_komodocli(refcoin,&txstr,acname,"createrawtransaction",argA,argB,"")) != 0 ) |
|
|
|
if ( (retjson2= get_komodocli(refcoin,&txstr,acname,"createrawtransaction",argA,argB,"","")) != 0 ) |
|
|
|
{ |
|
|
|
printf("createmultisig: unexpected JSON2.(%s)\n",jprint(retjson2,0)); |
|
|
|
free_json(retjson2); |
|
|
@ -626,7 +626,7 @@ char *createmultisig(char *refcoin,char *acname,char *depositaddr,char *signerad |
|
|
|
cJSON *addmultisignature(char *refcoin,char *acname,char *signeraddr,char *rawtx) |
|
|
|
{ |
|
|
|
char *retstr,*hexstr; cJSON *retjson; |
|
|
|
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"signrawtransaction",rawtx,"","")) != 0 ) |
|
|
|
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"signrawtransaction",rawtx,"","","")) != 0 ) |
|
|
|
{ |
|
|
|
if ( jint(retjson,"complete") != 0 ) |
|
|
|
return(retjson); |
|
|
@ -656,7 +656,7 @@ void gatewaysmarkdone(char *refcoin,char *acname,bits256 withtxid,char *coin,bit |
|
|
|
{ |
|
|
|
char str[65],str2[65],*retstr; cJSON *retjson; |
|
|
|
printf("spend %s %s/v2 as marker\n",acname,bits256_str(str,withtxid)); |
|
|
|
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"gatewaysmarkdone",bits256_str(str,withtxid),coin,bits256_str(str2,cointxid))) != 0 ) |
|
|
|
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"gatewaysmarkdone",bits256_str(str,withtxid),coin,bits256_str(str2,cointxid),"")) != 0 ) |
|
|
|
{ |
|
|
|
komodobroadcast(refcoin,acname,retjson); |
|
|
|
free_json(retjson); |
|
|
@ -671,7 +671,7 @@ void gatewaysmarkdone(char *refcoin,char *acname,bits256 withtxid,char *coin,bit |
|
|
|
int32_t get_gatewaysinfo(char *refcoin,char *acname,char *depositaddr,int32_t *Mp,int32_t *Np,char *bindtxidstr,char *coin,char *oraclestr) |
|
|
|
{ |
|
|
|
char *oracle,*retstr,*name,*deposit; cJSON *retjson; |
|
|
|
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"gatewaysinfo",bindtxidstr,"","")) != 0 ) |
|
|
|
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"gatewaysinfo",bindtxidstr,"","","")) != 0 ) |
|
|
|
{ |
|
|
|
if ( (oracle= jstr(retjson,"oracletxid")) != 0 && strcmp(oracle,oraclestr) == 0 ) |
|
|
|
{ |
|
|
@ -933,7 +933,7 @@ int32_t main(int32_t argc,char **argv) |
|
|
|
while ( 1 ) |
|
|
|
{ |
|
|
|
retstr = 0; |
|
|
|
if ( (refcoin[0] == 0 || prevheight < (get_coinheight(refcoin,"") - 10)) && (clijson= get_komodocli("KMD",&retstr,acname,"oraclesinfo",oraclestr,"","")) != 0 ) |
|
|
|
if ( (refcoin[0] == 0 || prevheight < (get_coinheight(refcoin,"") - 10)) && (clijson= get_komodocli("KMD",&retstr,acname,"oraclesinfo",oraclestr,"","","")) != 0 ) |
|
|
|
{ |
|
|
|
if ( refcoin[0] == 0 && jstr(clijson,"name") != 0 ) |
|
|
|
{ |
|
|
@ -960,7 +960,7 @@ int32_t main(int32_t argc,char **argv) |
|
|
|
{ |
|
|
|
if ( (height= get_oracledata(refcoin,"",prevheight,hexstr,sizeof(hexstr),"Ihh")) != 0 ) |
|
|
|
{ |
|
|
|
if ( (clijson2= get_komodocli("KMD",&retstr2,acname,"oraclesdata",oraclestr,hexstr,"")) != 0 ) |
|
|
|
if ( (clijson2= get_komodocli("KMD",&retstr2,acname,"oraclesdata",oraclestr,hexstr,"","")) != 0 ) |
|
|
|
{ |
|
|
|
//printf("data.(%s)\n",jprint(clijson2,0));
|
|
|
|
txid = komodobroadcast("KMD",acname,clijson2); |
|
|
|