diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 216a902d8..2a45899ba 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -35,7 +35,7 @@ char *LP_numutxos() char *stats_JSON(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,char *remoteaddr,uint16_t port) // from rpc port { char *method,*ipaddr,*userpass,*base,*rel,*coin,*retstr = 0; uint16_t argport=0,pushport,subport; int32_t changed,otherpeers,flag = 0; struct LP_peerinfo *peer; cJSON *retjson,*reqjson = 0; struct iguana_info *ptr; -//printf("stats_JSON(%s)\n",jprint(argjson,0)); + //printf("stats_JSON(%s)\n",jprint(argjson,0)); method = jstr(argjson,"method"); if ( (ipaddr= jstr(argjson,"ipaddr")) != 0 && (argport= juint(argjson,"port")) != 0 && (method == 0 || strcmp(method,"electrum") != 0) ) { @@ -51,10 +51,10 @@ char *stats_JSON(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,char *r if ( 0 && (otherpeers= jint(argjson,"numpeers")) > peer->numpeers ) peer->numpeers = otherpeers; /*if ( 0 && (othernumutxos= jint(argjson,"numutxos")) > peer->numutxos ) - { - printf("change.(%s) numutxos.%d -> %d mynumutxos.%d\n",peer->ipaddr,peer->numutxos,othernumutxos,LP_mypeer != 0 ? LP_mypeer->numutxos:0); - peer->numutxos = othernumutxos; - }*/ + { + printf("change.(%s) numutxos.%d -> %d mynumutxos.%d\n",peer->ipaddr,peer->numutxos,othernumutxos,LP_mypeer != 0 ? LP_mypeer->numutxos:0); + peer->numutxos = othernumutxos; + }*/ if ( peer->sessionid == 0 ) peer->sessionid = juint(argjson,"session"); //printf("peer.(%s) found (%d %d) (%d %d) (%s)\n",peer->ipaddr,peer->numpeers,peer->numutxos,otherpeers,othernumutxos,jprint(argjson,0)); @@ -70,32 +70,32 @@ char *stats_JSON(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,char *r return(0); } /*if ( strcmp(method,"hello") == 0 ) - { - //printf("got hello from %s:%u\n",ipaddr!=0?ipaddr:"",argport); - return(0); - } - else*/ if ( strcmp(method,"sendmessage") == 0 && jobj(argjson,"userpass") == 0 ) - { - static char *laststr; - char *newstr; bits256 pubkey = jbits256(argjson,"pubkey"); - if ( bits256_nonz(pubkey) == 0 || bits256_cmp(pubkey,G.LP_mypub25519) == 0 ) - { - newstr = jprint(argjson,0); - if ( laststr == 0 || strcmp(laststr,newstr) != 0 ) - { - printf("got message.(%s) from %s:%u\n",newstr,ipaddr!=0?ipaddr:"",argport); - if ( laststr != 0 ) - free(laststr); - laststr = newstr; - LP_gotmessage(argjson); - retstr = clonestr(laststr); - } - } else retstr = clonestr("{\"error\":\"duplicate message\"}"); - } + { + //printf("got hello from %s:%u\n",ipaddr!=0?ipaddr:"",argport); + return(0); + } + else*/ if ( strcmp(method,"sendmessage") == 0 && jobj(argjson,"userpass") == 0 ) + { + static char *laststr; + char *newstr; bits256 pubkey = jbits256(argjson,"pubkey"); + if ( bits256_nonz(pubkey) == 0 || bits256_cmp(pubkey,G.LP_mypub25519) == 0 ) + { + newstr = jprint(argjson,0); + if ( laststr == 0 || strcmp(laststr,newstr) != 0 ) + { + printf("got message.(%s) from %s:%u\n",newstr,ipaddr!=0?ipaddr:"",argport); + if ( laststr != 0 ) + free(laststr); + laststr = newstr; + LP_gotmessage(argjson); + retstr = clonestr(laststr); + } + } else retstr = clonestr("{\"error\":\"duplicate message\"}"); + } //else if ( strcmp(method,"nn_tests") == 0 ) // return(clonestr("{\"result\":\"success\"}")); - else if ( strcmp(method,"help") == 0 ) - return(clonestr("{\"result\":\" \ + else if ( strcmp(method,"help") == 0 ) + return(clonestr("{\"result\":\" \ available localhost RPC commands: \n \ pricearray(base, rel, firsttime=0, lasttime=-1, timescale=60) -> [timestamp, avebid, aveask, highbid, lowask]\n\ setprice(base, rel, price)\n\ @@ -104,6 +104,7 @@ goal(coin=*, val=)\n\ myprice(base, rel)\n\ enable(coin)\n\ disable(coin)\n\ +getrawtransaction(coin, txid)\n\ inventory(coin)\n\ bestfit(rel, relvolume)\n\ lastnonce()\n\ @@ -137,7 +138,7 @@ dividends(coin, height, )\n\ stop()\n\ \"}")); //sell(base, rel, price, basevolume, timeout=10, duration=3600)\n\ - + base = jstr(argjson,"base"); rel = jstr(argjson,"rel"); coin = jstr(argjson,"coin"); @@ -329,6 +330,10 @@ stop()\n\ { return(LP_sendrawtransaction(coin,jstr(argjson,"signedtx"))); } + else if ( strcmp(method,"getrawtransaction") == 0 ) + { + return(jprint(LP_gettx(coin,jbits256(argjson,"txid")),0)); + } else if ( strcmp(method,"withdraw") == 0 ) { if ( (ptr= LP_coinsearch(coin)) != 0 ) @@ -448,6 +453,12 @@ stop()\n\ // end received response // public access, even from http + else if ( strcmp(method,"tradestatus") == 0 ) + { + LP_tradecommand_log(argjson); + printf("GOT TRADESTATUS! %s\n",jprint(argjson,0)); + retstr = clonestr("{\"result\":\"success\"}"); + } else if ( strcmp(method,"balance") == 0 ) { if ( (ptr= LP_coinsearch(jstr(argjson,"coin"))) != 0 ) @@ -543,41 +554,41 @@ stop()\n\ if ( IAMLP != 0 ) { /*if ( strcmp(method,"broadcast") == 0 ) - { - bits256 zero; char *cipherstr; int32_t cipherlen; uint8_t cipher[LP_ENCRYPTED_MAXSIZE]; - if ( (reqjson= LP_dereference(argjson,"broadcast")) != 0 ) - { - Broadcaststr = jprint(reqjson,0); - if ( (cipherstr= jstr(reqjson,"cipher")) != 0 ) - { - cipherlen = (int32_t)strlen(cipherstr) >> 1; - if ( cipherlen <= sizeof(cipher) ) - { - decode_hex(cipher,cipherlen,cipherstr); - LP_queuesend(calc_crc32(0,&cipher[2],cipherlen-2),LP_mypubsock,base,rel,cipher,cipherlen); - } else retstr = clonestr("{\"error\":\"cipher too big\"}"); - } - else - { - memset(zero.bytes,0,sizeof(zero)); -//printf("broadcast.(%s)\n",Broadcaststr); - LP_reserved_msg(base!=0?base:jstr(argjson,"coin"),rel,zero,jprint(reqjson,0)); - } - retstr = clonestr("{\"result\":\"success\"}"); - } else retstr = clonestr("{\"error\":\"couldnt dereference sendmessage\"}"); - } - else*/ if ( strcmp(method,"psock") == 0 ) - { - if ( myipaddr == 0 || myipaddr[0] == 0 || strcmp(myipaddr,"127.0.0.1") == 0 ) - { - if ( LP_mypeer != 0 ) - myipaddr = LP_mypeer->ipaddr; - else printf("LP_psock dont have actual ipaddr?\n"); - } - if ( jint(argjson,"ispaired") != 0 ) - return(LP_psock(myipaddr,jint(argjson,"ispaired"))); - else return(clonestr("{\"error\":\"you are running an obsolete version, update\"}")); - } + { + bits256 zero; char *cipherstr; int32_t cipherlen; uint8_t cipher[LP_ENCRYPTED_MAXSIZE]; + if ( (reqjson= LP_dereference(argjson,"broadcast")) != 0 ) + { + Broadcaststr = jprint(reqjson,0); + if ( (cipherstr= jstr(reqjson,"cipher")) != 0 ) + { + cipherlen = (int32_t)strlen(cipherstr) >> 1; + if ( cipherlen <= sizeof(cipher) ) + { + decode_hex(cipher,cipherlen,cipherstr); + LP_queuesend(calc_crc32(0,&cipher[2],cipherlen-2),LP_mypubsock,base,rel,cipher,cipherlen); + } else retstr = clonestr("{\"error\":\"cipher too big\"}"); + } + else + { + memset(zero.bytes,0,sizeof(zero)); + //printf("broadcast.(%s)\n",Broadcaststr); + LP_reserved_msg(base!=0?base:jstr(argjson,"coin"),rel,zero,jprint(reqjson,0)); + } + retstr = clonestr("{\"result\":\"success\"}"); + } else retstr = clonestr("{\"error\":\"couldnt dereference sendmessage\"}"); + } + else*/ if ( strcmp(method,"psock") == 0 ) + { + if ( myipaddr == 0 || myipaddr[0] == 0 || strcmp(myipaddr,"127.0.0.1") == 0 ) + { + if ( LP_mypeer != 0 ) + myipaddr = LP_mypeer->ipaddr; + else printf("LP_psock dont have actual ipaddr?\n"); + } + if ( jint(argjson,"ispaired") != 0 ) + return(LP_psock(myipaddr,jint(argjson,"ispaired"))); + else return(clonestr("{\"error\":\"you are running an obsolete version, update\"}")); + } } else { diff --git a/iguana/exchanges/LP_remember.c b/iguana/exchanges/LP_remember.c index 778da68f4..c0887eea8 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -1107,9 +1107,11 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti sprintf(fname,"%s/SWAPS/%u-%u.finished",GLOBAL_DBDIR,rswap.requestid,rswap.quoteid), OS_compatible_path(fname); if ( (fp= fopen(fname,"wb")) != 0 ) { + jaddstr(item,"method","tradestatus"); itemstr = jprint(item,0); fprintf(fp,"%s\n",itemstr); - free(itemstr); + LP_reserved_msg(rswap.src,rswap.dest,zero,clonestr(itemstr)); + LP_broadcast_message(LP_mypubsock,rswap.src,rswap.dest,zero,itemstr); fclose(fp); } } diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index 830dae61b..880d5e9ba 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -250,7 +250,7 @@ bits256 LP_utxos_sighash(uint32_t timestamp,uint8_t *pubsecp,bits256 pubkey,bits int32_t LP_utxos_sigcheck(uint32_t timestamp,char *sigstr,char *pubsecpstr,bits256 pubkey,bits256 utxoshash) { - static void *ctx; int32_t retval=-1; uint8_t pub33[33],pubsecp[33],sig[65]; bits256 sighash; + static void *ctx; int32_t retval=-1; uint8_t pub33[33],pubsecp[33],sig[65]; bits256 sighash; char str[65]; if ( ctx == 0 ) ctx = bitcoin_ctx(); if ( sigstr != 0 && pubsecpstr != 0 && strlen(sigstr) == 65*2 && strlen(pubsecpstr) == 33 *2 ) @@ -261,7 +261,9 @@ int32_t LP_utxos_sigcheck(uint32_t timestamp,char *sigstr,char *pubsecpstr,bits2 retval = bitcoin_recoververify(ctx,"utxos",sig,sighash,pub33,0); if ( memcmp(pub33,pubsecp,33) != 0 || retval != 0 ) { - printf("LP_utxos_sigcheck failure, probably from node with older version\n"); + static uint32_t counter; + if ( counter++ < 100 ) + printf("LP_utxos_sigcheck failure, probably from %s with older version\n",bits256_str(str,pubkey)); retval = -1; } else retval = 0; } diff --git a/iguana/exchanges/getrawtransaction b/iguana/exchanges/getrawtransaction new file mode 100755 index 000000000..c9d042c65 --- /dev/null +++ b/iguana/exchanges/getrawtransaction @@ -0,0 +1,3 @@ +#!/bin/bash +source userpass +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"getrawtransaction\",\"coin\":\"KMD\",\"txid\":\"107a2683abbfa9188f78e17d3bcba66ece5bd7cbe105ab5bbaae79364159e84d\"}"