Browse Source

Test

etomic
jl777 7 years ago
parent
commit
fb475f76e6
  1. 4
      iguana/exchanges/LP_include.h
  2. 61
      iguana/exchanges/LP_rpc.c
  3. 345
      iguana/exchanges/LP_socket.c
  4. 2
      iguana/exchanges/mm.c

4
iguana/exchanges/LP_include.h

@ -187,8 +187,8 @@ struct iguana_info
UT_hash_handle hh;
portable_mutex_t txmutex; struct LP_transaction *transactions; struct LP_address *addresses;
uint64_t txfee;
int32_t longestchain,firstrefht,firstscanht,lastscanht,bussock; uint16_t busport;
uint32_t counter,inactive,lastmempool,lastgetinfo,ratetime;
int32_t longestchain,firstrefht,firstscanht,lastscanht,bussock,height; uint16_t busport;
uint32_t counter,inactive,lastmempool,lastgetinfo,ratetime,heighttime;
uint8_t pubtype,p2shtype,isPoS,wiftype,wiftaddr,taddr,noimportprivkey_flag;
char symbol[16],smartaddr[64],userpass[1024],serverport[128];
// portfolio

61
iguana/exchanges/LP_rpc.c

@ -103,6 +103,13 @@ char *issue_LP_getprices(char *destip,uint16_t destport)
//return(issue_curlt(url,LP_HTTP_TIMEOUT));
}
char *LP_apicall(struct iguana_info *coin,char *method,char *params)
{
if ( coin->electrum != 0 )
return(jprint(electrum_submit(coin->symbol,coin->electrum,0,method,params,LP_HTTP_TIMEOUT),1));
else return(bitcoind_passthru(coin->symbol,coin->serverport,coin->userpass,method,params));
}
cJSON *bitcoin_json(struct iguana_info *coin,char *method,char *params)
{
cJSON *retjson = 0; char *retstr;
@ -113,15 +120,21 @@ cJSON *bitcoin_json(struct iguana_info *coin,char *method,char *params)
//printf("issue.(%s, %s, %s, %s, %s)\n",coin->symbol,coin->serverport,coin->userpass,method,params);
if ( coin->inactive == 0 || strcmp(method,"importprivkey") == 0 || strcmp(method,"validateaddress") == 0 )
{
retstr = bitcoind_passthru(coin->symbol,coin->serverport,coin->userpass,method,params);
if ( retstr != 0 && retstr[0] != 0 )
if ( coin->electrum == 0 )
{
//printf("%s: %s.%s -> (%s)\n",coin->symbol,method,params,retstr);
retjson = cJSON_Parse(retstr);
free(retstr);
retstr = bitcoind_passthru(coin->symbol,coin->serverport,coin->userpass,method,params);
if ( retstr != 0 && retstr[0] != 0 )
{
//printf("%s: %s.%s -> (%s)\n",coin->symbol,method,params,retstr);
retjson = cJSON_Parse(retstr);
free(retstr);
}
}
else
{
retjson = electrum_submit(coin->symbol,coin->electrum,0,method,params,LP_HTTP_TIMEOUT);
printf("electrum %s.%s -> (%s)\n",method,params,jprint(retjson,0));
}
//usleep(100);
//printf("dpow_gettxout.(%s)\n",retstr);
} else retjson = cJSON_Parse("{\"result\":\"disabled\"}");
} else printf("bitcoin_json cant talk to NULL coin\n");
return(retjson);
@ -167,11 +180,17 @@ cJSON *LP_assethbla(char *assetid)
int32_t LP_getheight(struct iguana_info *coin)
{
cJSON *retjson; int32_t height = -1; //struct iguana_info *coin = LP_coinfind(symbol);
if ( (retjson= bitcoin_json(coin,"getinfo","[]")) != 0 )
cJSON *retjson; char *method = "getinfo"; int32_t height = coin->height;
if ( coin->electrum == 0 && time(NULL) > coin->heighttime+60 )
{
height = jint(retjson,"blocks");
free_json(retjson);
if ( strcmp(coin->symbol,"BTC") == 0 )
method = "getblockchaininfo";
if ( (retjson= bitcoin_json(coin,method,"[]")) != 0 )
{
coin->height = height = jint(retjson,"blocks");
free_json(retjson);
coin->heighttime = (uint32_t)time(NULL);
}
}
return(height);
}
@ -315,16 +334,9 @@ int32_t LP_importaddress(char *symbol,char *address)
return(1);
}
char *LP_apicall(struct iguana_info *coin,char *method,char *params)
{
if ( coin->electrum != 0 )
return(jprint(electrum_submit(coin->symbol,coin->electrum,0,method,params,LP_HTTP_TIMEOUT),1));
else return(bitcoind_passthru(coin->symbol,coin->serverport,coin->userpass,method,params));
}
double LP_getestimatedrate(struct iguana_info *coin)
{
char buf[512],*retstr; double rate = 20;
char buf[512],*retstr,*result; cJSON *retjson = 0; double rate = 20;
if ( coin != 0 && (strcmp(coin->symbol,"BTC") == 0 || coin->txfee == 0) )
{
if ( coin->rate != 0. && time(NULL) > coin->ratetime+60 )
@ -332,14 +344,19 @@ double LP_getestimatedrate(struct iguana_info *coin)
sprintf(buf,"[%d]",3);
if ( (retstr= LP_apicall(coin,"estimatefee",buf)) != 0 )
{
if ( retstr[0] != '-' )
if ( (retjson= cJSON_Parse(retstr)) != 0 )
result = jstr(retjson,"result");
else result = retstr;
if ( result[0] != '-' )
{
rate = atof(retstr) / 1024.;
rate = atof(result) / 1024.;
coin->rate = rate;
coin->ratetime = (uint32_t)time(NULL);
printf("estimated rate.(%s) %s -> %.8f\n",coin->symbol,retstr,rate);
printf("estimated rate.(%s) %s -> %.8f\n",coin->symbol,result,rate);
}
free(retstr);
if ( retjson != 0 )
free_json(retjson);
}
} else rate = coin->rate;
} else return((double)coin->txfee / LP_AVETXSIZE);

345
iguana/exchanges/LP_socket.c

@ -243,8 +243,8 @@ int32_t LP_socketrecv(int32_t sock,uint8_t *recvbuf,int32_t maxlen)
struct electrum_info
{
queue_t sendQ,pendingQ;
int32_t bufsize,sock;
uint32_t stratumid,lasttime,pending;
int32_t bufsize,sock,*heightp;
uint32_t stratumid,lasttime,pending,*heighttimep;
char ipaddr[64],symbol[16];
uint16_t port;
uint8_t buf[];
@ -252,6 +252,14 @@ struct electrum_info
int32_t Num_electrums;
// purge timedout
/*
if ( (retjson= electrum_address_listunspent(symbol,ep,0,addr)) != 0 )
you can call it like the above, where symbol is the coin, ep is the electrum server info pointer, the 0 is a callback ptr where 0 means to block till it is done
all the API calls have the same three args
if the callback ptr is &retjson, then on completion it will put the cJSON *ptr into it, so to spawn a bunch of calls you need to call with symbol,ep,&retjsons[i],...
default timeout is set to 2 seconds, not sure if that is enough, on each receive from any server, requests that are timeout are purged (and if a callback set, will just return and "error" timeout JSON
a null value for ep will make it choose a random server for that coin
*/
struct electrum_info *electrum_server(char *symbol,struct electrum_info *ep)
{
@ -295,6 +303,157 @@ struct electrum_info *electrum_server(char *symbol,struct electrum_info *ep)
return(ep);
}
cJSON *electrum_submit(char *symbol,struct electrum_info *ep,cJSON **retjsonp,char *method,char *params,int32_t timeout)
{
// queue id and string and callback
char stratumreq[16384]; struct stritem *sitem; cJSON *retjson = 0;
if ( ep == 0 )
ep = electrum_server(symbol,0);
if ( ep != 0 )
{
sprintf(stratumreq,"{ \"jsonrpc\":\"2.0\", \"id\": %u, \"method\":\"%s\", \"params\": %s }\n",ep->stratumid,method,params);
//printf("stratumreq.(%s)\n",stratumreq);
ep->buf[0] = 0;
sitem = (struct stritem *)queueitem(stratumreq);
sitem->DL.type = ep->stratumid++;
if ( retjsonp != 0 )
sitem->retptrp = (void **)retjsonp;
else sitem->retptrp = (void **)&retjson;
queue_enqueue("sendQ",&ep->sendQ,&sitem->DL);
} else printf("couldnt find electrum server for (%s %s)\n",method,params);
return(retjson);
}
cJSON *electrum_noargs(char *symbol,struct electrum_info *ep,cJSON **retjsonp,char *method,int32_t timeout)
{
return(electrum_submit(symbol,ep,retjsonp,method,"[]",timeout));
}
cJSON *electrum_strarg(char *symbol,struct electrum_info *ep,cJSON **retjsonp,char *method,char *arg,int32_t timeout)
{
char params[16384];
if ( strlen(arg) < sizeof(params) )
{
sprintf(params,"[\"%s\"]",arg);
return(electrum_submit(symbol,ep,retjsonp,method,params,timeout));
} else return(0);
}
cJSON *electrum_intarg(char *symbol,struct electrum_info *ep,cJSON **retjsonp,char *method,int32_t arg,int32_t timeout)
{
char params[64];
sprintf(params,"[\"%d\"]",arg);
return(electrum_submit(symbol,ep,retjsonp,method,params,timeout));
}
cJSON *electrum_hasharg(char *symbol,struct electrum_info *ep,cJSON **retjsonp,char *method,bits256 arg,int32_t timeout)
{
char params[128],str[65];
sprintf(params,"[\"%s\"]",bits256_str(str,arg));
return(electrum_submit(symbol,ep,retjsonp,method,params,timeout));
}
//" "--blockchain.numblocks.subscribe", "--blockchain.address.get_proof", "--blockchain.utxo.get_address",
cJSON *electrum_version(char *symbol,struct electrum_info *ep,cJSON **retjsonp) { return(electrum_noargs(symbol,ep,retjsonp,"server.version",ELECTRUM_TIMEOUT)); }
cJSON *electrum_banner(char *symbol,struct electrum_info *ep,cJSON **retjsonp) { return(electrum_noargs(symbol,ep,retjsonp,"server.banner",ELECTRUM_TIMEOUT)); }
cJSON *electrum_donation(char *symbol,struct electrum_info *ep,cJSON **retjsonp) { return(electrum_noargs(symbol,ep,retjsonp,"server.donation_address",ELECTRUM_TIMEOUT)); }
cJSON *electrum_peers(char *symbol,struct electrum_info *ep,cJSON **retjsonp) { return(electrum_noargs(symbol,ep,retjsonp,"server.peers.subscribe",ELECTRUM_TIMEOUT)); }
cJSON *electrum_features(char *symbol,struct electrum_info *ep,cJSON **retjsonp) { return(electrum_noargs(symbol,ep,retjsonp,"server.features",ELECTRUM_TIMEOUT)); }
cJSON *electrum_headers_subscribe(char *symbol,struct electrum_info *ep,cJSON **retjsonp) { return(electrum_noargs(symbol,ep,retjsonp,"blockchain.headers.subscribe",ELECTRUM_TIMEOUT)); }
cJSON *electrum_script_getbalance(char *symbol,struct electrum_info *ep,cJSON **retjsonp,char *script) { return(electrum_strarg(symbol,ep,retjsonp,"blockchain.scripthash.get_balance",script,ELECTRUM_TIMEOUT)); }
cJSON *electrum_script_gethistory(char *symbol,struct electrum_info *ep,cJSON **retjsonp,char *script) { return(electrum_strarg(symbol,ep,retjsonp,"blockchain.scripthash.get_history",script,ELECTRUM_TIMEOUT)); }
cJSON *electrum_script_getmempool(char *symbol,struct electrum_info *ep,cJSON **retjsonp,char *script) { return(electrum_strarg(symbol,ep,retjsonp,"blockchain.scripthash.get_mempool",script,ELECTRUM_TIMEOUT)); }
cJSON *electrum_script_listunspent(char *symbol,struct electrum_info *ep,cJSON **retjsonp,char *script) { return(electrum_strarg(symbol,ep,retjsonp,"blockchain.scripthash.listunspent",script,ELECTRUM_TIMEOUT)); }
cJSON *electrum_script_subscribe(char *symbol,struct electrum_info *ep,cJSON **retjsonp,char *script) { return(electrum_strarg(symbol,ep,retjsonp,"blockchain.scripthash.subscribe",script,ELECTRUM_TIMEOUT)); }
cJSON *electrum_address_subscribe(char *symbol,struct electrum_info *ep,cJSON **retjsonp,char *addr) { return(electrum_strarg(symbol,ep,retjsonp,"blockchain.address.subscribe",addr,ELECTRUM_TIMEOUT)); }
cJSON *electrum_address_gethistory(char *symbol,struct electrum_info *ep,cJSON **retjsonp,char *addr) { return(electrum_strarg(symbol,ep,retjsonp,"blockchain.address.get_history",addr,ELECTRUM_TIMEOUT)); }
cJSON *electrum_address_getmempool(char *symbol,struct electrum_info *ep,cJSON **retjsonp,char *addr) { return(electrum_strarg(symbol,ep,retjsonp,"blockchain.address.get_mempool",addr,ELECTRUM_TIMEOUT)); }
cJSON *electrum_address_getbalance(char *symbol,struct electrum_info *ep,cJSON **retjsonp,char *addr) { return(electrum_strarg(symbol,ep,retjsonp,"blockchain.address.get_balance",addr,ELECTRUM_TIMEOUT)); }
cJSON *electrum_address_listunspent(char *symbol,struct electrum_info *ep,cJSON **retjsonp,char *addr) { return(electrum_strarg(symbol,ep,retjsonp,"blockchain.address.listunspent",addr,ELECTRUM_TIMEOUT)); }
cJSON *electrum_addpeer(char *symbol,struct electrum_info *ep,cJSON **retjsonp,char *endpoint) { return(electrum_strarg(symbol,ep,retjsonp,"server.add_peer",endpoint,ELECTRUM_TIMEOUT)); }
cJSON *electrum_sendrawtransaction(char *symbol,struct electrum_info *ep,cJSON **retjsonp,char *rawtx) { return(electrum_strarg(symbol,ep,retjsonp,"blockchain.transaction.broadcast",rawtx,ELECTRUM_TIMEOUT)); }
cJSON *electrum_estimatefee(char *symbol,struct electrum_info *ep,cJSON **retjsonp,int32_t numblocks) { return(electrum_intarg(symbol,ep,retjsonp,"blockchain.estimatefee",numblocks,ELECTRUM_TIMEOUT)); }
cJSON *electrum_getheader(char *symbol,struct electrum_info *ep,cJSON **retjsonp,int32_t n) { return(electrum_intarg(symbol,ep,retjsonp,"blockchain.block.get_header",n,ELECTRUM_TIMEOUT)); }
cJSON *electrum_getchunk(char *symbol,struct electrum_info *ep,cJSON **retjsonp,int32_t n) { return(electrum_intarg(symbol,ep,retjsonp,"blockchain.block.get_chunk",n,ELECTRUM_TIMEOUT)); }
cJSON *electrum_transaction(char *symbol,struct electrum_info *ep,cJSON **retjsonp,bits256 txid) { return(electrum_hasharg(symbol,ep,retjsonp,"blockchain.transaction.get",txid,ELECTRUM_TIMEOUT)); }
cJSON *electrum_getmerkle(char *symbol,struct electrum_info *ep,cJSON **retjsonp,bits256 txid,int32_t height)
{
char params[128],str[65];
sprintf(params,"[\"%s\", %d]",bits256_str(str,txid),height);
return(electrum_submit(symbol,ep,retjsonp,"blockchain.transaction.get_merkle",params,ELECTRUM_TIMEOUT));
}
void electrum_test()
{
cJSON *retjson; bits256 hash; struct electrum_info *ep = 0; char *addr,*script,*symbol = "BTC";
while ( Num_electrums == 0 )
{
sleep(1);
printf("Num_electrums %p -> %d\n",&Num_electrums,Num_electrums);
}
printf("found electrum server\n");
if ( (retjson= electrum_version(symbol,ep,0)) != 0 )
printf("electrum_version %s\n",jprint(retjson,1));
if ( (retjson= electrum_banner(symbol,ep,0)) != 0 )
printf("electrum_banner %s\n",jprint(retjson,1));
if ( (retjson= electrum_donation(symbol,ep,0)) != 0 )
printf("electrum_donation %s\n",jprint(retjson,1));
if ( (retjson= electrum_features(symbol,ep,0)) != 0 )
printf("electrum_features %s\n",jprint(retjson,1));
if ( (retjson= electrum_estimatefee(symbol,ep,0,6)) != 0 )
printf("electrum_estimatefee %s\n",jprint(retjson,1));
decode_hex(hash.bytes,sizeof(hash),"0000000000000000005087f8845f9ed0282559017e3c6344106de15e46c07acd");
if ( (retjson= electrum_getheader(symbol,ep,0,3)) != 0 )
printf("electrum_getheader %s\n",jprint(retjson,1));
//if ( (retjson= electrum_getchunk(symbol,ep,0,3)) != 0 )
// printf("electrum_getchunk %s\n",jprint(retjson,1));
decode_hex(hash.bytes,sizeof(hash),"b967a7d55889fe11e993430921574ec6379bc8ce712a652c3fcb66c6be6e925c");
if ( (retjson= electrum_getmerkle(symbol,ep,0,hash,403000)) != 0 )
printf("electrum_getmerkle %s\n",jprint(retjson,1));
if ( (retjson= electrum_transaction(symbol,ep,0,hash)) != 0 )
printf("electrum_transaction %s\n",jprint(retjson,1));
addr = "14NeevLME8UAANiTCVNgvDrynUPk1VcQKb";
if ( (retjson= electrum_address_gethistory(symbol,ep,0,addr)) != 0 )
printf("electrum_address_gethistory %s\n",jprint(retjson,1));
if ( (retjson= electrum_address_getmempool(symbol,ep,0,addr)) != 0 )
printf("electrum_address_getmempool %s\n",jprint(retjson,1));
if ( (retjson= electrum_address_getbalance(symbol,ep,0,addr)) != 0 )
printf("electrum_address_getbalance %s\n",jprint(retjson,1));
if ( (retjson= electrum_address_listunspent(symbol,ep,0,addr)) != 0 )
printf("electrum_address_listunspent %s\n",jprint(retjson,1));
if ( (retjson= electrum_addpeer(symbol,ep,0,"electrum.be:50001")) != 0 )
printf("electrum_addpeer %s\n",jprint(retjson,1));
if ( (retjson= electrum_sendrawtransaction(symbol,ep,0,"0100000001b7e6d69a0fd650926bd5fbe63cc8578d976c25dbdda8dd61db5e05b0de4041fe000000006b483045022100de3ae8f43a2a026bb46f6b09b890861f8aadcb16821f0b01126d70fa9ae134e4022000925a842073484f1056c7fc97399f2bbddb9beb9e49aca76835cdf6e9c91ef3012103cf5ce3233e6d6e22291ebef454edff2b37a714aed685ce94a7eb4f83d8e4254dffffffff014c4eaa0b000000001976a914b598062b55362952720718e7da584a46a27bedee88ac00000000")) != 0 )
printf("electrum_sendrawtransaction %s\n",jprint(retjson,1));
if ( 0 )
{
script = "76a914b598062b55362952720718e7da584a46a27bedee88ac";
if ( (retjson= electrum_script_gethistory(symbol,ep,0,script)) != 0 )
printf("electrum_script_gethistory %s\n",jprint(retjson,1));
if ( (retjson= electrum_script_getmempool(symbol,ep,0,script)) != 0 )
printf("electrum_script_getmempool %s\n",jprint(retjson,1));
if ( (retjson= electrum_script_getbalance(symbol,ep,0,script)) != 0 )
printf("electrum_script_getbalance %s\n",jprint(retjson,1));
if ( (retjson= electrum_script_listunspent(symbol,ep,0,script)) != 0 )
printf("electrum_script_listunspent %s\n",jprint(retjson,1));
if ( (retjson= electrum_script_subscribe(symbol,ep,0,script)) != 0 )
printf("electrum_script_subscribe %s\n",jprint(retjson,1));
}
if ( (retjson= electrum_headers_subscribe(symbol,ep,0)) != 0 )
printf("electrum_headers %s\n",jprint(retjson,1));
if ( (retjson= electrum_peers(symbol,ep,0)) != 0 )
printf("electrum_peers %s\n",jprint(retjson,1));
if ( (retjson= electrum_address_subscribe(symbol,ep,0,addr)) != 0 )
printf("electrum_address_subscribe %s\n",jprint(retjson,1));
}
struct electrum_info *LP_electrum_info(int32_t *alreadyp,char *symbol,char *ipaddr,uint16_t port,int32_t bufsize)
{
struct electrum_info *ep=0; int32_t i; struct stritem *sitem; char name[512],*str = "init string";
@ -337,10 +496,23 @@ struct electrum_info *LP_electrum_info(int32_t *alreadyp,char *symbol,char *ipad
int32_t LP_recvfunc(struct electrum_info *ep,char *str,int32_t len)
{
cJSON *strjson; uint32_t idnum=0; struct stritem *stritem; struct queueitem *item = 0;
cJSON *strjson; char *method; int32_t height; uint32_t idnum=0; struct stritem *stritem; struct queueitem *item = 0;
ep->lasttime = (uint32_t)time(NULL);
if ( (strjson= cJSON_Parse(str)) != 0 )
{
if ( (method= jstr(strjson,"method")) != 0 )
{
if ( strcmp(method,"blockchain.headers.subscribe") == 0 )
{
printf("headers.(%s)\n",jprint(strjson,0));
if ( (height= jint(strjson,"blocks")) > 0 && ep->heightp != 0 && ep->heighttimep != 0 )
{
*(ep->heightp) = height;
*(ep->heighttimep) = (uint32_t)time(NULL);
printf("set height.%d\n",height);
}
}
}
idnum = juint(strjson,"id");
portable_mutex_lock(&ep->pendingQ.mutex);
if ( ep->pendingQ.list != 0 )
@ -387,7 +559,13 @@ int32_t LP_recvfunc(struct electrum_info *ep,char *str,int32_t len)
void LP_dedicatedloop(void *arg)
{
struct pollfd fds; int32_t i,len,flag,timeout = 10; struct stritem *sitem; struct electrum_info *ep = arg;
struct pollfd fds; int32_t i,len,flag,timeout = 10; struct iguana_info *coin; cJSON *retjson; struct stritem *sitem; struct electrum_info *ep = arg;
if ( (coin= LP_coinfind(ep->symbol)) != 0 )
ep->heightp = &coin->height, ep->heighttimep = &coin->heighttime;
if ( (retjson= electrum_headers_subscribe(ep->symbol,ep,0)) != 0 )
{
free_json(retjson);
}
printf("LP_dedicatedloop ep.%p sock.%d for %s:%u num.%d %p\n",ep,ep->sock,ep->ipaddr,ep->port,Num_electrums,&Num_electrums);
while ( ep->sock >= 0 )
{
@ -470,162 +648,3 @@ cJSON *LP_electrumserver(struct iguana_info *coin,char *ipaddr,uint16_t port)
return(retjson);
}
/*
if ( (retjson= electrum_address_listunspent(symbol,ep,0,addr)) != 0 )
you can call it like the above, where symbol is the coin, ep is the electrum server info pointer, the 0 is a callback ptr where 0 means to block till it is done
all the API calls have the same three args
if the callback ptr is &retjson, then on completion it will put the cJSON *ptr into it, so to spawn a bunch of calls you need to call with symbol,ep,&retjsons[i],...
default timeout is set to 2 seconds, not sure if that is enough, on each receive from any server, requests that are timeout are purged (and if a callback set, will just return and "error" timeout JSON
a null value for ep will make it choose a random server for that coin
*/
cJSON *electrum_submit(char *symbol,struct electrum_info *ep,cJSON **retjsonp,char *method,char *params,int32_t timeout)
{
// queue id and string and callback
char stratumreq[16384]; struct stritem *sitem; cJSON *retjson = 0;
if ( ep == 0 )
ep = electrum_server(symbol,0);
if ( ep != 0 )
{
sprintf(stratumreq,"{ \"jsonrpc\":\"2.0\", \"id\": %u, \"method\":\"%s\", \"params\": %s }\n",ep->stratumid,method,params);
//printf("stratumreq.(%s)\n",stratumreq);
ep->buf[0] = 0;
sitem = (struct stritem *)queueitem(stratumreq);
sitem->DL.type = ep->stratumid++;
if ( retjsonp != 0 )
sitem->retptrp = (void **)retjsonp;
else sitem->retptrp = (void **)&retjson;
queue_enqueue("sendQ",&ep->sendQ,&sitem->DL);
} else printf("couldnt find electrum server for (%s %s)\n",method,params);
return(retjson);
}
cJSON *electrum_noargs(char *symbol,struct electrum_info *ep,cJSON **retjsonp,char *method,int32_t timeout)
{
return(electrum_submit(symbol,ep,retjsonp,method,"[]",timeout));
}
cJSON *electrum_strarg(char *symbol,struct electrum_info *ep,cJSON **retjsonp,char *method,char *arg,int32_t timeout)
{
char params[16384];
if ( strlen(arg) < sizeof(params) )
{
sprintf(params,"[\"%s\"]",arg);
return(electrum_submit(symbol,ep,retjsonp,method,params,timeout));
} else return(0);
}
cJSON *electrum_intarg(char *symbol,struct electrum_info *ep,cJSON **retjsonp,char *method,int32_t arg,int32_t timeout)
{
char params[64];
sprintf(params,"[\"%d\"]",arg);
return(electrum_submit(symbol,ep,retjsonp,method,params,timeout));
}
cJSON *electrum_hasharg(char *symbol,struct electrum_info *ep,cJSON **retjsonp,char *method,bits256 arg,int32_t timeout)
{
char params[128],str[65];
sprintf(params,"[\"%s\"]",bits256_str(str,arg));
return(electrum_submit(symbol,ep,retjsonp,method,params,timeout));
}
//" "--blockchain.numblocks.subscribe", "--blockchain.address.get_proof", "--blockchain.utxo.get_address",
cJSON *electrum_version(char *symbol,struct electrum_info *ep,cJSON **retjsonp) { return(electrum_noargs(symbol,ep,retjsonp,"server.version",ELECTRUM_TIMEOUT)); }
cJSON *electrum_banner(char *symbol,struct electrum_info *ep,cJSON **retjsonp) { return(electrum_noargs(symbol,ep,retjsonp,"server.banner",ELECTRUM_TIMEOUT)); }
cJSON *electrum_donation(char *symbol,struct electrum_info *ep,cJSON **retjsonp) { return(electrum_noargs(symbol,ep,retjsonp,"server.donation_address",ELECTRUM_TIMEOUT)); }
cJSON *electrum_peers(char *symbol,struct electrum_info *ep,cJSON **retjsonp) { return(electrum_noargs(symbol,ep,retjsonp,"server.peers.subscribe",ELECTRUM_TIMEOUT)); }
cJSON *electrum_features(char *symbol,struct electrum_info *ep,cJSON **retjsonp) { return(electrum_noargs(symbol,ep,retjsonp,"server.features",ELECTRUM_TIMEOUT)); }
cJSON *electrum_headers_subscribe(char *symbol,struct electrum_info *ep,cJSON **retjsonp) { return(electrum_noargs(symbol,ep,retjsonp,"blockchain.headers.subscribe",ELECTRUM_TIMEOUT)); }
cJSON *electrum_script_getbalance(char *symbol,struct electrum_info *ep,cJSON **retjsonp,char *script) { return(electrum_strarg(symbol,ep,retjsonp,"blockchain.scripthash.get_balance",script,ELECTRUM_TIMEOUT)); }
cJSON *electrum_script_gethistory(char *symbol,struct electrum_info *ep,cJSON **retjsonp,char *script) { return(electrum_strarg(symbol,ep,retjsonp,"blockchain.scripthash.get_history",script,ELECTRUM_TIMEOUT)); }
cJSON *electrum_script_getmempool(char *symbol,struct electrum_info *ep,cJSON **retjsonp,char *script) { return(electrum_strarg(symbol,ep,retjsonp,"blockchain.scripthash.get_mempool",script,ELECTRUM_TIMEOUT)); }
cJSON *electrum_script_listunspent(char *symbol,struct electrum_info *ep,cJSON **retjsonp,char *script) { return(electrum_strarg(symbol,ep,retjsonp,"blockchain.scripthash.listunspent",script,ELECTRUM_TIMEOUT)); }
cJSON *electrum_script_subscribe(char *symbol,struct electrum_info *ep,cJSON **retjsonp,char *script) { return(electrum_strarg(symbol,ep,retjsonp,"blockchain.scripthash.subscribe",script,ELECTRUM_TIMEOUT)); }
cJSON *electrum_address_subscribe(char *symbol,struct electrum_info *ep,cJSON **retjsonp,char *addr) { return(electrum_strarg(symbol,ep,retjsonp,"blockchain.address.subscribe",addr,ELECTRUM_TIMEOUT)); }
cJSON *electrum_address_gethistory(char *symbol,struct electrum_info *ep,cJSON **retjsonp,char *addr) { return(electrum_strarg(symbol,ep,retjsonp,"blockchain.address.get_history",addr,ELECTRUM_TIMEOUT)); }
cJSON *electrum_address_getmempool(char *symbol,struct electrum_info *ep,cJSON **retjsonp,char *addr) { return(electrum_strarg(symbol,ep,retjsonp,"blockchain.address.get_mempool",addr,ELECTRUM_TIMEOUT)); }
cJSON *electrum_address_getbalance(char *symbol,struct electrum_info *ep,cJSON **retjsonp,char *addr) { return(electrum_strarg(symbol,ep,retjsonp,"blockchain.address.get_balance",addr,ELECTRUM_TIMEOUT)); }
cJSON *electrum_address_listunspent(char *symbol,struct electrum_info *ep,cJSON **retjsonp,char *addr) { return(electrum_strarg(symbol,ep,retjsonp,"blockchain.address.listunspent",addr,ELECTRUM_TIMEOUT)); }
cJSON *electrum_addpeer(char *symbol,struct electrum_info *ep,cJSON **retjsonp,char *endpoint) { return(electrum_strarg(symbol,ep,retjsonp,"server.add_peer",endpoint,ELECTRUM_TIMEOUT)); }
cJSON *electrum_sendrawtransaction(char *symbol,struct electrum_info *ep,cJSON **retjsonp,char *rawtx) { return(electrum_strarg(symbol,ep,retjsonp,"blockchain.transaction.broadcast",rawtx,ELECTRUM_TIMEOUT)); }
cJSON *electrum_estimatefee(char *symbol,struct electrum_info *ep,cJSON **retjsonp,int32_t numblocks) { return(electrum_intarg(symbol,ep,retjsonp,"blockchain.estimatefee",numblocks,ELECTRUM_TIMEOUT)); }
cJSON *electrum_getheader(char *symbol,struct electrum_info *ep,cJSON **retjsonp,int32_t n) { return(electrum_intarg(symbol,ep,retjsonp,"blockchain.block.get_header",n,ELECTRUM_TIMEOUT)); }
cJSON *electrum_getchunk(char *symbol,struct electrum_info *ep,cJSON **retjsonp,int32_t n) { return(electrum_intarg(symbol,ep,retjsonp,"blockchain.block.get_chunk",n,ELECTRUM_TIMEOUT)); }
cJSON *electrum_transaction(char *symbol,struct electrum_info *ep,cJSON **retjsonp,bits256 txid) { return(electrum_hasharg(symbol,ep,retjsonp,"blockchain.transaction.get",txid,ELECTRUM_TIMEOUT)); }
cJSON *electrum_getmerkle(char *symbol,struct electrum_info *ep,cJSON **retjsonp,bits256 txid,int32_t height)
{
char params[128],str[65];
sprintf(params,"[\"%s\", %d]",bits256_str(str,txid),height);
return(electrum_submit(symbol,ep,retjsonp,"blockchain.transaction.get_merkle",params,ELECTRUM_TIMEOUT));
}
void electrum_test()
{
cJSON *retjson; bits256 hash; struct electrum_info *ep = 0; char *addr,*script,*symbol = "BTC";
while ( Num_electrums == 0 )
{
sleep(1);
printf("Num_electrums %p -> %d\n",&Num_electrums,Num_electrums);
}
printf("found electrum server\n");
if ( (retjson= electrum_version(symbol,ep,0)) != 0 )
printf("electrum_version %s\n",jprint(retjson,1));
if ( (retjson= electrum_banner(symbol,ep,0)) != 0 )
printf("electrum_banner %s\n",jprint(retjson,1));
if ( (retjson= electrum_donation(symbol,ep,0)) != 0 )
printf("electrum_donation %s\n",jprint(retjson,1));
if ( (retjson= electrum_features(symbol,ep,0)) != 0 )
printf("electrum_features %s\n",jprint(retjson,1));
if ( (retjson= electrum_estimatefee(symbol,ep,0,6)) != 0 )
printf("electrum_estimatefee %s\n",jprint(retjson,1));
decode_hex(hash.bytes,sizeof(hash),"0000000000000000005087f8845f9ed0282559017e3c6344106de15e46c07acd");
if ( (retjson= electrum_getheader(symbol,ep,0,3)) != 0 )
printf("electrum_getheader %s\n",jprint(retjson,1));
//if ( (retjson= electrum_getchunk(symbol,ep,0,3)) != 0 )
// printf("electrum_getchunk %s\n",jprint(retjson,1));
decode_hex(hash.bytes,sizeof(hash),"b967a7d55889fe11e993430921574ec6379bc8ce712a652c3fcb66c6be6e925c");
if ( (retjson= electrum_getmerkle(symbol,ep,0,hash,403000)) != 0 )
printf("electrum_getmerkle %s\n",jprint(retjson,1));
if ( (retjson= electrum_transaction(symbol,ep,0,hash)) != 0 )
printf("electrum_transaction %s\n",jprint(retjson,1));
addr = "14NeevLME8UAANiTCVNgvDrynUPk1VcQKb";
if ( (retjson= electrum_address_gethistory(symbol,ep,0,addr)) != 0 )
printf("electrum_address_gethistory %s\n",jprint(retjson,1));
if ( (retjson= electrum_address_getmempool(symbol,ep,0,addr)) != 0 )
printf("electrum_address_getmempool %s\n",jprint(retjson,1));
if ( (retjson= electrum_address_getbalance(symbol,ep,0,addr)) != 0 )
printf("electrum_address_getbalance %s\n",jprint(retjson,1));
if ( (retjson= electrum_address_listunspent(symbol,ep,0,addr)) != 0 )
printf("electrum_address_listunspent %s\n",jprint(retjson,1));
if ( (retjson= electrum_addpeer(symbol,ep,0,"electrum.be:50001")) != 0 )
printf("electrum_addpeer %s\n",jprint(retjson,1));
if ( (retjson= electrum_sendrawtransaction(symbol,ep,0,"0100000001b7e6d69a0fd650926bd5fbe63cc8578d976c25dbdda8dd61db5e05b0de4041fe000000006b483045022100de3ae8f43a2a026bb46f6b09b890861f8aadcb16821f0b01126d70fa9ae134e4022000925a842073484f1056c7fc97399f2bbddb9beb9e49aca76835cdf6e9c91ef3012103cf5ce3233e6d6e22291ebef454edff2b37a714aed685ce94a7eb4f83d8e4254dffffffff014c4eaa0b000000001976a914b598062b55362952720718e7da584a46a27bedee88ac00000000")) != 0 )
printf("electrum_sendrawtransaction %s\n",jprint(retjson,1));
if ( 0 )
{
script = "76a914b598062b55362952720718e7da584a46a27bedee88ac";
if ( (retjson= electrum_script_gethistory(symbol,ep,0,script)) != 0 )
printf("electrum_script_gethistory %s\n",jprint(retjson,1));
if ( (retjson= electrum_script_getmempool(symbol,ep,0,script)) != 0 )
printf("electrum_script_getmempool %s\n",jprint(retjson,1));
if ( (retjson= electrum_script_getbalance(symbol,ep,0,script)) != 0 )
printf("electrum_script_getbalance %s\n",jprint(retjson,1));
if ( (retjson= electrum_script_listunspent(symbol,ep,0,script)) != 0 )
printf("electrum_script_listunspent %s\n",jprint(retjson,1));
if ( (retjson= electrum_script_subscribe(symbol,ep,0,script)) != 0 )
printf("electrum_script_subscribe %s\n",jprint(retjson,1));
}
if ( (retjson= electrum_headers_subscribe(symbol,ep,0)) != 0 )
printf("electrum_headers %s\n",jprint(retjson,1));
if ( (retjson= electrum_peers(symbol,ep,0)) != 0 )
printf("electrum_peers %s\n",jprint(retjson,1));
if ( (retjson= electrum_address_subscribe(symbol,ep,0,addr)) != 0 )
printf("electrum_address_subscribe %s\n",jprint(retjson,1));
}

2
iguana/exchanges/mm.c

@ -803,7 +803,7 @@ int main(int argc, const char * argv[])
double profitmargin,maxexposure,incrratio,start_rel,start_base,minask,maxbid,incr;
cJSON *retjson,*loginjson; int32_t i,already;
OS_init();
if ( (1) )
if ( (0) )
{
ep = LP_electrum_info(&already,"BTC","88.198.241.196",50001,IGUANA_MAXPACKETSIZE * 10);
if ( ep != 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_dedicatedloop,(void *)ep) != 0 )

Loading…
Cancel
Save