From 3287f0ace2cf0595921dc30a18b4854612968353 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 5 Dec 2017 12:05:50 +0400 Subject: [PATCH] Balances --- iguana/exchanges/LP_commands.c | 3 ++ iguana/exchanges/LP_statemachine.c | 15 +++++++++ iguana/exchanges/LP_utxo.c | 49 +++++++++++++++++++----------- iguana/exchanges/balances | 3 ++ iguana/exchanges/install | 2 +- iguana/exchanges/mm.c | 15 +++++++-- 6 files changed, 66 insertions(+), 21 deletions(-) create mode 100755 iguana/exchanges/balances diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index ebac1c7b4..3366a94cf 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -135,6 +135,7 @@ listunspent(coin, address)\n\ setconfirms(coin, numconfirms, maxconfirms=6)\n\ trust(pubkey, trust) # positive to trust, 0 for normal, negative to blacklist\n\ balance(coin, address)\n\ +balances(address)\n\ orderbook(base, rel, duration=3600)\n\ getprices()\n\ getprice(base, rel)\n\ @@ -256,6 +257,8 @@ instantdex_claim()\n\ return(LP_peers()); else if ( strcmp(method,"getcoins") == 0 ) return(jprint(LP_coinsjson(0),1)); + else if ( strcmp(method,"balances") == 0 ) + return(jprint(LP_balances(),1)); else if ( strcmp(method,"notarizations") == 0 ) { if ( (ptr= LP_coinsearch(coin)) != 0 ) diff --git a/iguana/exchanges/LP_statemachine.c b/iguana/exchanges/LP_statemachine.c index 34549ebf7..bb3754605 100644 --- a/iguana/exchanges/LP_statemachine.c +++ b/iguana/exchanges/LP_statemachine.c @@ -3597,6 +3597,21 @@ void LP_price_broadcastloop(void *ctx) break; } return(clonestr("{\"error\":\"no instantdex deposits to claim\"}"));*/ +/*else + { + if ( (array= LP_address_utxos(coin,coinaddr,1)) != 0 ) + { + if ( (n= cJSON_GetArraySize(array)) > 0 ) + { + for (i=0; ielectrum == 0 ) { - memset(zero.bytes,0,sizeof(zero)); if ( (array= LP_listunspent(coin->symbol,coinaddr,zero,zero)) != 0 ) { if ( (n= cJSON_GetArraySize(array)) > 0 ) @@ -596,23 +596,12 @@ cJSON *LP_address_balance(struct iguana_info *coin,char *coinaddr,int32_t electr } else { - //if ( strcmp(coin->smartaddr,coinaddr) == 0 ) - balance = LP_unspents_load(coin->symbol,coinaddr); - /*else + if ( strcmp(coin->smartaddr,coinaddr) != 0 ) { - if ( (array= LP_address_utxos(coin,coinaddr,1)) != 0 ) - { - if ( (n= cJSON_GetArraySize(array)) > 0 ) - { - for (i=0; isymbol,coin->electrum,&retjson,coinaddr,2,zero,zero)) != 0 ) + free_json(retjson); + } + balance = LP_unspents_load(coin->symbol,coinaddr); } retjson = cJSON_CreateObject(); jaddstr(retjson,"result","success"); @@ -627,6 +616,32 @@ cJSON *LP_address_balance(struct iguana_info *coin,char *coinaddr,int32_t electr return(retjson); } +cJSON *LP_balances() +{ + struct iguana_info *coin,*tmp; char *symbol; cJSON *array,*item,*retjson; + array = cJSON_CreateArray(); + HASH_ITER(hh,LP_coins,coin,tmp) + { + if ( (retjson= LP_address_balance(coin,coin->smartaddr,1)) != 0 ) + { + if ( (symbol= jstr(retjson,"coin")) != 0 ) + { + item = cJSON_CreateObject(); + jaddstr(item,"coin",symbol); + jaddnum(item,"balance",jdouble(retjson,"balance")); + if ( strcmp(symbol,"KMD") == 0 ) + { + jaddnum(item,"zcredits",jdouble(retjson,"zcredits")); + jadd(item,"zdebits",jobj(retjson,"zdebits")); + } + jaddi(array,item); + } + free_json(retjson); + } + } + return(array); +} + int32_t LP_unspents_array(struct iguana_info *coin,char *coinaddr,cJSON *array) { int32_t i,n,v,errs,height,count=0; uint64_t value,val; cJSON *item,*txobj; bits256 txid; diff --git a/iguana/exchanges/balances b/iguana/exchanges/balances new file mode 100755 index 000000000..1eb527b8f --- /dev/null +++ b/iguana/exchanges/balances @@ -0,0 +1,3 @@ +#!/bin/bash +source userpass +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"balances\"}" diff --git a/iguana/exchanges/install b/iguana/exchanges/install index b4feab5c9..8518efa3c 100755 --- a/iguana/exchanges/install +++ b/iguana/exchanges/install @@ -1,5 +1,5 @@ #!/bin/bash -cp dynamictrust getcoin kickstart tradesarray claim deposit10 deposit1 invreset sendrawtransaction processfiles stop millis mnzservers bot_buy bot_list bot_statuslist bot_pause bot_resume bot_sell bot_settings bot_status bot_stop guistats pubkeystats pendings coinswaps baserelswaps setpassphrase notarizations getrawtransaction parselog statsdisp m_js trust trusted setconfirms balance listunspent electrum snapshot_balance snapshot_loop secretaddresses dividends snapshot goals goal portfolio autoprice deletemessages getmessages debug buy sell bestfit orderbook client run_osx client_osx run coins disable enable myprice myprices getcoins getpeers getpeersIP getprices help inv setprice status ../dexscripts +cp balances dynamictrust getcoin kickstart tradesarray claim deposit10 deposit1 invreset sendrawtransaction processfiles stop millis mnzservers bot_buy bot_list bot_statuslist bot_pause bot_resume bot_sell bot_settings bot_status bot_stop guistats pubkeystats pendings coinswaps baserelswaps setpassphrase notarizations getrawtransaction parselog statsdisp m_js trust trusted setconfirms balance listunspent electrum snapshot_balance snapshot_loop secretaddresses dividends snapshot goals goal portfolio autoprice deletemessages getmessages debug buy sell bestfit orderbook client run_osx client_osx run coins disable enable myprice myprices getcoins getpeers getpeersIP getprices help inv setprice status ../dexscripts cp coins.json .. cd ../dexscripts #cp ../exchanges/passphrase ../exchanges/userpass . diff --git a/iguana/exchanges/mm.c b/iguana/exchanges/mm.c index ec3aba913..c3ae78957 100644 --- a/iguana/exchanges/mm.c +++ b/iguana/exchanges/mm.c @@ -884,9 +884,18 @@ int main(int argc, const char * argv[]) { uint8_t addrtype,rmd160[20],rmd160b[20]; char coinaddr[64],coinaddr2[64]; bitcoin_addr2rmd160(0,&addrtype,rmd160,(char *)argv[1]); - bitcoin_address(coinaddr,0,60,rmd160,20); - bitcoin_addr2rmd160(0,&addrtype,rmd160b,coinaddr); - bitcoin_address(coinaddr2,0,0,rmd160b,20); + if ( addrtype == 0 ) + { + bitcoin_address(coinaddr,0,60,rmd160,20); + bitcoin_addr2rmd160(0,&addrtype,rmd160b,coinaddr); + bitcoin_address(coinaddr2,0,0,rmd160b,20); + } + else if ( addrtype == 60 ) + { + bitcoin_address(coinaddr,0,0,rmd160,20); + bitcoin_addr2rmd160(0,&addrtype,rmd160b,coinaddr); + bitcoin_address(coinaddr2,0,60,rmd160b,20); + } printf("(%s) -> %s -> %s\n",(char *)argv[1],coinaddr,coinaddr2); if ( strcmp((char *)argv[1],coinaddr2) != 0 ) printf("ERROR\n");