jl777 7 years ago
parent
commit
3473598c88
  1. 44
      iguana/exchanges/LP_commands.c
  2. 47
      iguana/exchanges/LP_nativeDEX.c
  3. 148
      iguana/exchanges/LP_ordermatch.c
  4. 5
      iguana/exchanges/LP_prices.c
  5. 38
      iguana/exchanges/LP_utxo.c

44
iguana/exchanges/LP_commands.c

@ -63,6 +63,8 @@ char *stats_JSON(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,char *r
}
if ( method == 0 )
{
if ( is_cJSON_Array(argjson) != 0 )
printf("RAWARRAY command? %s\n",jprint(argjson,0));
if ( flag == 0 || jobj(argjson,"result") != 0 )
printf("stats_JSON no method: (%s) (%s:%u)\n",jprint(argjson,0),ipaddr,argport);
return(0);
@ -228,7 +230,6 @@ stop()\n\
{
if ( price > SMALLVAL )
{
//LP_signature_add(argjson,base,rel,(uint64_t)price * SATOSHIDEN);
if ( LP_mypriceset(&changed,base,rel,price) < 0 )
return(clonestr("{\"error\":\"couldnt set price\"}"));
//else if ( LP_mypriceset(&changed,rel,base,1./price) < 0 )
@ -238,7 +239,6 @@ stop()\n\
}
else if ( strcmp(method,"autoprice") == 0 )
{
//LP_signature_add(argjson,base,rel,(uint64_t)price * SATOSHIDEN);
if ( LP_autoprice(base,rel,argjson) < 0 )
return(clonestr("{\"error\":\"couldnt set autoprice\"}"));
else return(clonestr("{\"result\":\"success\"}"));
@ -450,29 +450,13 @@ stop()\n\
}
}
if ( strcmp(method,"postprice") == 0 )
{
// LP_checksig
retstr = LP_postedprice(argjson);
}
else if ( strcmp(method,"postutxos") == 0 )
retstr = LP_postedutxos(argjson);
else if ( strcmp(method,"getprices") == 0 )
return(LP_prices());
else if ( strcmp(method,"uitem") == 0 )
{
bits256 txid; int32_t vout,height; uint64_t value; char *coinaddr;
txid = jbits256(argjson,"txid");
vout = jint(argjson,"vout");
height = jint(argjson,"ht");
value = j64bits(argjson,"value");
coinaddr = jstr(argjson,"coinaddr");
if ( coin != 0 && coinaddr != 0 )
{
//char str[65]; printf("uitem %s %s %s/v%d %.8f ht.%d\n",coin,coinaddr,bits256_str(str,txid),vout,dstr(value),height);
LP_address_utxoadd(LP_coinfind(coin),coinaddr,txid,vout,value,height,-1);
}
return(clonestr("{\"result\":\"success\"}"));
}
retstr = LP_uitem_recv(argjson);
else if ( strcmp(method,"orderbook") == 0 )
return(LP_orderbook(base,rel,jint(argjson,"duration")));
else if ( strcmp(method,"listunspent") == 0 )
@ -549,26 +533,8 @@ stop()\n\
return(jprint(LP_pricearray(base,rel,firsttime,juint(argjson,"lasttime"),jint(argjson,"timescale")),1));
}
else if ( strcmp(method,"notify") == 0 )
{
char *rmd160str,*secpstr; bits256 pub; struct LP_pubkeyinfo *pubp;
pub = jbits256(argjson,"pub");
// LP_checksig
if ( bits256_nonz(pub) != 0 && (rmd160str= jstr(argjson,"rmd160")) != 0 && strlen(rmd160str) == 40 )
{
if ( (pubp= LP_pubkeyadd(pub)) != 0 )
{
decode_hex(pubp->rmd160,20,rmd160str);
if ( (secpstr= jstr(argjson,"pubsecp")) != 0 )
{
decode_hex(pubp->pubsecp,sizeof(pubp->pubsecp),secpstr);
//printf("got pubkey.(%s)\n",secpstr);
}
}
//printf("NOTIFIED pub %s rmd160 %s\n",bits256_str(str,pub),rmd160str);
}
retstr = clonestr("{\"result\":\"success\",\"notify\":\"received\"}");
}
if ( IAMLP != 0 )
retstr = LP_notify_recv(argjson);
else if ( IAMLP != 0 )
{
if ( strcmp(method,"broadcast") == 0 )
{

47
iguana/exchanges/LP_nativeDEX.c

@ -19,12 +19,13 @@
// marketmaker
//
// sign critical api calls (pubkey reg, listunspent, orders?)
// process stats.log local file -> map of realtime activity!
// handles <-> pubkeys, deal with offline pubkeys, reputations, bonds etc.
//
// alice only coins GAME UNO BTM ANC: GAME BTCD PPC RDD XZC POT EAC FTC BASH SPR WDC UNO XPM XCN BELA CHC DIME MEC NAUT MED AUR MAX DGC RIC EB3 DOT BTM GEO ANC CANN ICASH WBB SRC PTC ADZ TIPS EQT START EFL FST FJC NYC GCN
// verify portfolio, pricearray, interest to KMD withdraw
// dPoW security -> 4: KMD notarized, 5: BTC notarized
// dPoW security -> 4: KMD notarized, 5: BTC notarized, after next notary elections
#include <stdio.h>
@ -343,48 +344,6 @@ void command_rpcloop(void *myipaddr)
}
}
void LP_smartutxos_push(struct iguana_info *coin)
{
struct LP_peerinfo *peer,*tmp; uint64_t value; bits256 zero,txid; int32_t i,vout,height,n; char *retstr; cJSON *array,*item,*req;
if ( coin->smartaddr[0] == 0 )
return;
if ( (array= LP_address_utxos(coin,coin->smartaddr,1)) != 0 )
{
memset(zero.bytes,0,sizeof(zero));
if ( (n= cJSON_GetArraySize(array)) > 0 )
{
//printf("PUSH %s %s\n",coin->symbol,coin->smartaddr);
for (i=0; i<n; i++)
{
item = jitem(array,i);
txid = jbits256(item,"tx_hash");
vout = jint(item,"tx_pos");
value = j64bits(item,"value");
height = jint(item,"height");
if ( (rand() % 100) == 0 && IAMLP == 0 )
{
HASH_ITER(hh,LP_peerinfos,peer,tmp)
{
if ( (retstr= issue_LP_uitem(peer->ipaddr,peer->port,coin->symbol,coin->smartaddr,txid,vout,height,value)) != 0 )
free(retstr);
}
}
req = cJSON_CreateObject();
jaddstr(req,"method","uitem");
jaddstr(req,"coin",coin->symbol);
jaddstr(req,"coinaddr",coin->smartaddr);
jaddbits256(req,"txid",txid);
jaddnum(req,"vout",vout);
jaddnum(req,"ht",height);
jadd64bits(req,"value",value);
//printf("ADDR_UNSPENTS[] <- %s\n",jprint(req,0));
LP_reserved_msg("","",zero,jprint(req,1));
}
}
free_json(array);
}
}
int32_t LP_utxos_sync(struct LP_peerinfo *peer)
{
int32_t i,j,n=0,m,v,posted=0; bits256 txid; cJSON *array,*item,*item2,*array2,*array3; uint64_t total,total2,metric; struct iguana_info *coin,*ctmp; struct LP_address *ap; char *retstr,*retstr2,*coinaddr;

148
iguana/exchanges/LP_ordermatch.c

@ -219,6 +219,102 @@ char *LP_quotereceived(cJSON *argjson)
} else return(clonestr("{\"error\":\"nullptr\"}"));
}
void LP_smartutxos_push(struct iguana_info *coin)
{
struct LP_peerinfo *peer,*tmp; uint64_t value; bits256 zero,txid; int32_t i,vout,height,n; char *retstr; cJSON *array,*item,*req;
if ( coin->smartaddr[0] == 0 )
return;
if ( (array= LP_address_utxos(coin,coin->smartaddr,1)) != 0 )
{
memset(zero.bytes,0,sizeof(zero));
if ( (n= cJSON_GetArraySize(array)) > 0 )
{
//printf("PUSH %s %s\n",coin->symbol,coin->smartaddr);
for (i=0; i<n; i++)
{
item = jitem(array,i);
txid = jbits256(item,"tx_hash");
vout = jint(item,"tx_pos");
value = j64bits(item,"value");
height = jint(item,"height");
if ( (rand() % 100) == 0 && IAMLP == 0 )
{
HASH_ITER(hh,LP_peerinfos,peer,tmp)
{
if ( (retstr= issue_LP_uitem(peer->ipaddr,peer->port,coin->symbol,coin->smartaddr,txid,vout,height,value)) != 0 )
free(retstr);
}
}
req = cJSON_CreateObject();
jaddstr(req,"method","uitem");
jaddstr(req,"coin",coin->symbol);
jaddstr(req,"coinaddr",coin->smartaddr);
jaddbits256(req,"txid",txid);
jaddnum(req,"vout",vout);
jaddnum(req,"ht",height);
jadd64bits(req,"value",value);
//printf("ADDR_UNSPENTS[] <- %s\n",jprint(req,0));
LP_reserved_msg("","",zero,jprint(req,1));
}
}
free_json(array);
}
}
void LP_postutxos(char *symbol,char *coinaddr)
{
bits256 zero; struct iguana_info *coin; cJSON *array,*reqjson = cJSON_CreateObject();
if ( (coin= LP_coinfind(symbol)) != 0 && (array= LP_address_utxos(coin,coinaddr,1)) != 0 )
{
//printf("LP_postutxos pubsock.%d %s %s\n",pubsock,symbol,coin->smartaddr);
if ( cJSON_GetArraySize(array) == 0 )
free_json(array);
else
{
memset(zero.bytes,0,sizeof(zero));
jaddstr(reqjson,"method","postutxos");
jaddstr(reqjson,"coin",symbol);
jaddstr(reqjson,"coinaddr",coinaddr);
jadd(reqjson,"utxos",array);
//printf("post (%s) -> %d\n",msg,LP_mypubsock);
LP_reserved_msg(symbol,symbol,zero,jprint(reqjson,1));
}
}
}
char *LP_postedutxos(cJSON *argjson)
{
int32_t n; char *symbol,*coinaddr; struct LP_address *ap; struct iguana_info *coin; cJSON *array;
//printf("posted.(%s)\n",jprint(argjson,0));
if ( (coinaddr= jstr(argjson,"coinaddr")) != 0 && (symbol= jstr(argjson,"coin")) != 0 && (coin= LP_coinfind(symbol)) != 0 ) // addsig
{
if ( coin->electrum == 0 || (ap= LP_addressfind(coin,coinaddr)) != 0 )
{
if ( (array= jarray(&n,argjson,"utxos")) != 0 )
LP_unspents_array(coin,coinaddr,array);
}
else if ( (array= electrum_address_listunspent(symbol,coin->electrum,&array,coinaddr,1)) != 0 )
free_json(array);
}
return(clonestr("{\"result\":\"success\"}"));
}
char *LP_uitem_recv(cJSON *argjson)
{
bits256 txid; int32_t vout,height; uint64_t value; char *coinaddr,*symbol;
txid = jbits256(argjson,"txid");
vout = jint(argjson,"vout");
height = jint(argjson,"ht");
value = j64bits(argjson,"value");
coinaddr = jstr(argjson,"coinaddr");
if ( (symbol= jstr(argjson,"coin")) != 0 && coinaddr != 0 )
{
//char str[65]; printf("uitem %s %s %s/v%d %.8f ht.%d\n",coin,coinaddr,bits256_str(str,txid),vout,dstr(value),height);
LP_address_utxoadd(LP_coinfind(symbol),coinaddr,txid,vout,value,height,-1);
}
return(clonestr("{\"result\":\"success\"}"));
}
char *LP_pricepings(void *ctx,char *myipaddr,int32_t pubsock,char *base,char *rel,double price)
{
bits256 zero; cJSON *reqjson = cJSON_CreateObject();
@ -233,6 +329,22 @@ char *LP_pricepings(void *ctx,char *myipaddr,int32_t pubsock,char *base,char *re
return(clonestr("{\"result\":\"success\"}"));
}
char *LP_postedprice(cJSON *argjson)
{
bits256 pubkey; double price; char *base,*rel;
//printf("PRICE POSTED.(%s)\n",jprint(argjson,0));
if ( (base= jstr(argjson,"base")) != 0 && (rel= jstr(argjson,"rel")) != 0 && (price= jdouble(argjson,"price")) > SMALLVAL )
{
pubkey = jbits256(argjson,"pubkey");
if ( bits256_nonz(pubkey) != 0 )
{
LP_pricefeedupdate(pubkey,base,rel,price);
return(clonestr("{\"result\":\"success\"}"));
}
}
return(clonestr("{\"error\":\"missing fields in posted price\"}"));
}
void LP_notify_pubkeys(void *ctx,int32_t pubsock)
{
bits256 zero; char secpstr[67]; cJSON *reqjson = cJSON_CreateObject();
@ -246,6 +358,27 @@ void LP_notify_pubkeys(void *ctx,int32_t pubsock)
LP_reserved_msg("","",zero,jprint(reqjson,1));
}
char *LP_notify_recv(cJSON *argjson)
{
char *rmd160str,*secpstr; bits256 pub; struct LP_pubkeyinfo *pubp;
pub = jbits256(argjson,"pub");
// LP_checksig
if ( bits256_nonz(pub) != 0 && (rmd160str= jstr(argjson,"rmd160")) != 0 && strlen(rmd160str) == 40 )
{
if ( (pubp= LP_pubkeyadd(pub)) != 0 )
{
decode_hex(pubp->rmd160,20,rmd160str);
if ( (secpstr= jstr(argjson,"pubsecp")) != 0 )
{
decode_hex(pubp->pubsecp,sizeof(pubp->pubsecp),secpstr);
//printf("got pubkey.(%s)\n",secpstr);
}
}
//printf("NOTIFIED pub %s rmd160 %s\n",bits256_str(str,pub),rmd160str);
}
return(clonestr("{\"result\":\"success\",\"notify\":\"received\"}"));
}
void LP_listunspent_query(char *symbol,char *coinaddr)
{
bits256 zero; cJSON *reqjson = cJSON_CreateObject();
@ -256,21 +389,6 @@ void LP_listunspent_query(char *symbol,char *coinaddr)
LP_reserved_msg("","",zero,jprint(reqjson,1));
}
char *LP_postedprice(cJSON *argjson)
{
bits256 pubkey; double price; char *base,*rel;
//printf("PRICE POSTED.(%s)\n",jprint(argjson,0));
if ( (base= jstr(argjson,"base")) != 0 && (rel= jstr(argjson,"rel")) != 0 && (price= jdouble(argjson,"price")) > SMALLVAL )
{
pubkey = jbits256(argjson,"pubkey");
if ( bits256_nonz(pubkey) != 0 )
{
LP_pricefeedupdate(pubkey,base,rel,price);
return(clonestr("{\"result\":\"success\"}"));
}
}
return(clonestr("{\"error\":\"missing fields in posted price\"}"));
}
int32_t LP_quote_checkmempool(struct LP_quoteinfo *qp,struct LP_utxoinfo *autxo,struct LP_utxoinfo *butxo)
{

5
iguana/exchanges/LP_prices.c

@ -872,7 +872,7 @@ uint64_t LP_KMDvalue(struct iguana_info *coin,uint64_t balance)
return(KMDvalue);
}
char *LP_pricestr(char *base,char *rel,double origprice)
/*char *LP_pricestr(char *base,char *rel,double origprice)
{
cJSON *retjson; double price = 0.;
if ( base != 0 && base[0] != 0 && rel != 0 && rel[0] != 0 )
@ -884,7 +884,6 @@ char *LP_pricestr(char *base,char *rel,double origprice)
if ( LP_pricevalid(price) > 0 )
{
retjson = cJSON_CreateObject();
// LP_addsig
jaddstr(retjson,"result","success");
jaddstr(retjson,"method","postprice");
jaddbits256(retjson,"pubkey",G.LP_mypub25519);
@ -895,7 +894,7 @@ char *LP_pricestr(char *base,char *rel,double origprice)
jadd(retjson,"quotes",LP_priceinfomatrix(1));
return(jprint(retjson,1));
} else return(clonestr("{\"error\":\"cant find baserel pair\"}"));
}
}*/
void LP_priceupdate(char *base,char *rel,double price,double avebid,double aveask,double highbid,double lowask,double PAXPRICES[32])
{

38
iguana/exchanges/LP_utxo.c

@ -429,27 +429,6 @@ cJSON *LP_address_balance(struct iguana_info *coin,char *coinaddr,int32_t electr
return(retjson);
}
void LP_postutxos(char *symbol,char *coinaddr)
{
bits256 zero; struct iguana_info *coin; cJSON *array,*reqjson = cJSON_CreateObject();
if ( (coin= LP_coinfind(symbol)) != 0 && (array= LP_address_utxos(coin,coinaddr,1)) != 0 )
{
//printf("LP_postutxos pubsock.%d %s %s\n",pubsock,symbol,coin->smartaddr);
if ( cJSON_GetArraySize(array) == 0 )
free_json(array);
else
{
memset(zero.bytes,0,sizeof(zero));
jaddstr(reqjson,"method","postutxos");
jaddstr(reqjson,"coin",symbol);
jaddstr(reqjson,"coinaddr",coinaddr);
jadd(reqjson,"utxos",array);
//printf("post (%s) -> %d\n",msg,LP_mypubsock);
LP_reserved_msg(symbol,symbol,zero,jprint(reqjson,1));
}
}
}
int32_t LP_unspents_array(struct iguana_info *coin,char *coinaddr,cJSON *array)
{
int32_t i,n,v,ht,errs,height,count=0; uint64_t value,val; cJSON *item,*txobj; bits256 txid;
@ -493,23 +472,6 @@ int32_t LP_unspents_array(struct iguana_info *coin,char *coinaddr,cJSON *array)
return(count);
}
char *LP_postedutxos(cJSON *argjson)
{
int32_t n; char *symbol,*coinaddr; struct LP_address *ap; struct iguana_info *coin; cJSON *array;
//printf("posted.(%s)\n",jprint(argjson,0));
if ( (coinaddr= jstr(argjson,"coinaddr")) != 0 && (symbol= jstr(argjson,"coin")) != 0 && (coin= LP_coinfind(symbol)) != 0 ) // addsig
{
if ( coin->electrum == 0 || (ap= LP_addressfind(coin,coinaddr)) != 0 )
{
if ( (array= jarray(&n,argjson,"utxos")) != 0 )
LP_unspents_array(coin,coinaddr,array);
}
else if ( (array= electrum_address_listunspent(symbol,coin->electrum,&array,coinaddr,1)) != 0 )
free_json(array);
}
return(clonestr("{\"result\":\"success\"}"));
}
void LP_utxosetkey(uint8_t *key,bits256 txid,int32_t vout)
{
memcpy(key,txid.bytes,sizeof(txid));

Loading…
Cancel
Save