Skip to content

Commit

Permalink
Merge pull request #22 from artemii235/etomic
Browse files Browse the repository at this point in the history
Etomic
  • Loading branch information
artemii235 authored Apr 9, 2018
2 parents bcae8cf + d453503 commit 4f23d88
Show file tree
Hide file tree
Showing 22 changed files with 192 additions and 114 deletions.
7 changes: 6 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ cache:
- marketmaker_depends

after_build:
- 7z a mm-win.zip .\build_win64_release\iguana\exchanges\Release\marketmaker-mainnet.exe .\marketmaker_depends\curl\build_msvc_2015_win64\lib\Release\libcurl.dll .\marketmaker_depends\nanomsg\build_msvc_2015_win64\Release\nanomsg.dll
- '7z a mm-win.zip
.\build_win64_release\iguana\exchanges\Release\marketmaker-mainnet.exe
.\marketmaker_depends\curl\build_msvc_2015_win64\lib\Release\libcurl.dll
.\marketmaker_depends\nanomsg\build_msvc_2015_win64\Release\nanomsg.dll
"C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\redist\\x64\\Microsoft.VC140.CRT\\msvcp140.dll"
"C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\redist\\x64\\Microsoft.VC140.CRT\\vcruntime140.dll"'

artifacts:
- path: mm-win.zip
Expand Down
2 changes: 1 addition & 1 deletion iguana/exchanges/LP_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ struct LP_transaction *LP_create_transaction(struct iguana_info *coin,bits256 tx
for (i=0; i<numvouts; i++)
{
vout = jitem(vouts,i);
tx->outpoints[i].value = LP_value_extract(vout,0);
tx->outpoints[i].value = LP_value_extract(vout,0,txid);
tx->outpoints[i].interest = SATOSHIDEN * jdouble(vout,"interest");
LP_destaddr(tx->outpoints[i].coinaddr,vout);
//printf("from transaction init %s %s %s/v%d <- %.8f\n",coin->symbol,tx->outpoints[i].coinaddr,bits256_str(str,txid),i,dstr(tx->outpoints[i].value));
Expand Down
6 changes: 3 additions & 3 deletions iguana/exchanges/LP_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\
}*/
else if ( strcmp(method,"recentswaps") == 0 )
{
return(LP_recent_swaps(jint(argjson,"limit")));
return(LP_recent_swaps(jint(argjson,"limit"),0));
}
else if ( strcmp(method,"stop") == 0 )
{
Expand Down Expand Up @@ -500,7 +500,7 @@ jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\
} else vol = jdouble(argjson,"relvolume");
if ( price > SMALLVAL )
{
return(LP_autobuy(ctx,fomo,myipaddr,pubsock,base,rel,price,vol,jint(argjson,"timeout"),jint(argjson,"duration"),jstr(argjson,"gui"),juint(argjson,"nonce"),jbits256(argjson,"destpubkey"),0));
return(LP_autobuy(ctx,fomo,myipaddr,pubsock,base,rel,price,vol,jint(argjson,"timeout"),jint(argjson,"duration"),jstr(argjson,"gui"),juint(argjson,"nonce"),jbits256(argjson,"destpubkey"),0,jstr(argjson,"uuid")));
} else return(clonestr("{\"error\":\"no price set\"}"));
}
else if ( strcmp(method,"sell") == 0 )
Expand All @@ -514,7 +514,7 @@ jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\
} else vol = jdouble(argjson,"basevolume");
if ( price > SMALLVAL )
{
return(LP_autobuy(ctx,fomo,myipaddr,pubsock,rel,base,1./price,vol,jint(argjson,"timeout"),jint(argjson,"duration"),jstr(argjson,"gui"),juint(argjson,"nonce"),jbits256(argjson,"destpubkey"),0));
return(LP_autobuy(ctx,fomo,myipaddr,pubsock,rel,base,1./price,vol,jint(argjson,"timeout"),jint(argjson,"duration"),jstr(argjson,"gui"),juint(argjson,"nonce"),jbits256(argjson,"destpubkey"),0,jstr(argjson,"uuid")));
} else return(clonestr("{\"error\":\"no price set\"}"));
}
}
Expand Down
12 changes: 6 additions & 6 deletions iguana/exchanges/LP_include.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ voind dontprintf(char *formatstr,...) {}

#define LP_MAJOR_VERSION "0"
#define LP_MINOR_VERSION "1"
#define LP_BUILD_NUMBER "27772"
#define LP_BUILD_NUMBER "27774"
#define LP_BARTERDEX_VERSION 1
#define LP_MAGICBITS 1

Expand Down Expand Up @@ -276,7 +276,7 @@ struct LP_swap_remember
uint32_t finishtime,tradeid,requestid,quoteid,plocktime,dlocktime,expiration,state,otherstate;
int32_t iambob,finishedflag,origfinishedflag,Predeemlen,Dredeemlen,sentflags[sizeof(txnames)/sizeof(*txnames)];
uint8_t secretAm[20],secretAm256[32],secretBn[20],secretBn256[32],Predeemscript[1024],Dredeemscript[1024],pubkey33[33],other33[33];
char Agui[65],Bgui[65],gui[65],src[65],dest[65],bobtomic[128],alicetomic[128],etomicsrc[65],etomicdest[65],destaddr[64],Adestaddr[64],Sdestaddr[64],alicepaymentaddr[64],bobpaymentaddr[64],bobdepositaddr[64],alicecoin[65],bobcoin[65],*txbytes[sizeof(txnames)/sizeof(*txnames)],bobDepositEthTx[75],bobPaymentEthTx[75],alicePaymentEthTx[75];
char uuidstr[65],Agui[65],Bgui[65],gui[65],src[65],dest[65],bobtomic[128],alicetomic[128],etomicsrc[65],etomicdest[65],destaddr[64],Adestaddr[64],Sdestaddr[64],alicepaymentaddr[64],bobpaymentaddr[64],bobdepositaddr[64],alicecoin[65],bobcoin[65],*txbytes[sizeof(txnames)/sizeof(*txnames)],bobDepositEthTx[75],bobPaymentEthTx[75],alicePaymentEthTx[75];
};

struct LP_outpoint
Expand Down Expand Up @@ -379,7 +379,7 @@ struct LP_quoteinfo
uint64_t satoshis,txfee,destsatoshis,desttxfee,aliceid;
uint32_t timestamp,quotetime,tradeid;
int32_t vout,vout2,destvout,feevout,pair;
char srccoin[65],coinaddr[64],destcoin[65],destaddr[64],gui[64],etomicsrc[65],etomicdest[65];
char srccoin[65],coinaddr[64],destcoin[65],destaddr[64],gui[64],etomicsrc[65],etomicdest[65],uuidstr[65];
};

struct LP_endpoint { int32_t pair; char ipaddr[64]; uint16_t port; };
Expand All @@ -397,7 +397,7 @@ struct basilisk_swap
struct basilisk_rawtx bobdeposit,bobpayment,alicepayment,myfee,otherfee,aliceclaim,alicespend,bobreclaim,bobspend,bobrefund,alicereclaim;
bits256 privkeys[INSTANTDEX_DECKSIZE];
//struct basilisk_swapmessage *messages; int32_t nummessages,sentflag;
char Bdeposit[64],Bpayment[64];
char Bdeposit[64],Bpayment[64],uuidstr[65];
uint64_t aliceid,otherdeck[INSTANTDEX_DECKSIZE][2],deck[INSTANTDEX_DECKSIZE][2];
uint8_t persistent_pubkey33[33],persistent_other33[33],changermd160[20],pad[15],verifybuf[100000];
};
Expand Down Expand Up @@ -479,7 +479,7 @@ int32_t LP_rawtx_spendscript(struct basilisk_swap *swap,int32_t height,struct ba
void LP_quotesinit(char *base,char *rel);
int32_t LP_forward(void *ctx,char *myipaddr,int32_t pubsock,bits256 pubkey,char *jsonstr,int32_t freeflag);
struct LP_peerinfo *LP_peerfind(uint32_t ipbits,uint16_t port);
uint64_t LP_value_extract(cJSON *obj,int32_t addinterest);
uint64_t LP_value_extract(cJSON *obj,int32_t addinterest,bits256 txid);
int32_t LP_swap_getcoinaddr(char *symbol,char *coinaddr,bits256 txid,int32_t vout);
char *LP_command_process(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,uint8_t *data,int32_t datalen,int32_t stats_JSONonly);
int64_t LP_kmdvalue(char *symbol,int64_t satoshis);
Expand All @@ -490,7 +490,7 @@ int32_t LP_pullsock_check(void *ctx,char **retstrp,char *myipaddr,int32_t pubsoc
int64_t LP_listunspent_parseitem(struct iguana_info *coin,bits256 *txidp,int32_t *voutp,int32_t *heightp,cJSON *item);
void LP_unspents_cache(char *symbol,char *addr,char *arraystr,int32_t updatedflag);
uint16_t LP_psock_get(char *connectaddr,char *publicaddr,int32_t ispaired,int32_t cmdchannel,char *ipaddr);
void LP_failedmsg(uint32_t requestid,uint32_t quoteid,double val);
void LP_failedmsg(uint32_t requestid,uint32_t quoteid,double val,char *uuidstr);
//void LP_utxo_clientpublish(struct LP_utxoinfo *utxo);
//int32_t LP_coinbus(uint16_t coin_busport);
int32_t LP_nanomsg_recvs(void *ctx);
Expand Down
50 changes: 39 additions & 11 deletions iguana/exchanges/LP_instantdex.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,34 @@ void LP_instantdex_deposituniq(FILE *fp,bits256 txid)

void LP_instantdex_filescreate(char *coinaddr)
{
char fname[512]; FILE *fp; bits256 txid; int32_t i,n; cJSON *array,*newarray,*txobj;
char fname[512]; FILE *fp; bits256 txid; int32_t i,j,n; cJSON *array,*newarray,*txobj;
sprintf(fname,"%s/deposits.%s",GLOBAL_DBDIR,coinaddr), OS_compatible_path(fname);
if ( (fp= fopen(fname,"rb")) == 0 )
{
if ( (fp= fopen(fname,"wb+")) != 0 )
{
//printf("created %s\n",fname);
for (i=0; i<2; i++)
{
if ( (array= LP_instantdex_txids(i,coinaddr)) != 0 )
{
if ( (n= cJSON_GetArraySize(array)) > 0 )
{
for (j=0; j<n; j++)
{
txid = jbits256i(array,j);
//char str[65]; printf("j.%d of %d: %s\n",j,n,bits256_str(str,txid));
LP_instantdex_deposituniq(fp,txid);
fflush(fp);
}
}
//printf("i.%d n.%d\n",i,n);
free_json(array);
}
}
fclose(fp);
} else printf("couldnt create %s\n",fname);
} else fclose(fp);
if ( (fp= fopen(fname,"rb")) != 0 )
{
array = cJSON_CreateArray();
Expand All @@ -94,7 +120,7 @@ void LP_instantdex_filescreate(char *coinaddr)
{
fseek(fp,sizeof(txid) * i,SEEK_SET);
if ( fread(&txid,1,sizeof(txid),fp) != sizeof(txid) )
printf("error reating %s\n",fname);
printf("error creating %s\n",fname);
jaddibits256(array,txid);
if ( (txobj= LP_gettxout("KMD",coinaddr,txid,0)) != 0 )
free_json(txobj);
Expand Down Expand Up @@ -312,7 +338,7 @@ char *LP_unlockedspend(void *ctx,char *symbol,bits256 utxotxid)
{
vout0 = jitem(vouts,0);
LP_destaddr(vinaddr,vout0);
satoshis = LP_value_extract(vout0,0);
satoshis = LP_value_extract(vout0,0,utxotxid);
opret = jitem(vouts,numvouts - 1);
jaddstr(retjson,"result","success");
jaddbits256(retjson,"lockedtxid",utxotxid);
Expand Down Expand Up @@ -396,20 +422,20 @@ char *LP_timelock(char *symbol,uint32_t duration,char *destaddr,uint64_t satoshi

int32_t LP_claim_submit(void *ctx,cJSON *txids,int64_t *sump,struct iguana_info *coin,bits256 utxotxid)
{
uint8_t redeemscript[512]; bits256 claimtxid; cJSON *txjson,*vout0,*vout1,*vout2,*vouts,*item; int32_t numvouts; char str[65],vinaddr[64],destaddr[64],checkaddr[64]; int32_t j,utxovout,flagi = 0,redeemlen,weeki,iter; int64_t weeksatoshis,satoshis; uint32_t expiration,claimtime;
uint8_t redeemscript[512]; bits256 claimtxid; cJSON *txjson,*vout0,*vout1,*vout2,*vouts,*item; int32_t numvouts; char str[65],vinaddr[64],destaddr[64],checkaddr[64]; int32_t j,utxovout,flagi = 0,redeemlen,weeki,iter; int64_t weeksatoshis,satoshis,interest; uint32_t expiration,claimtime;
if ( (txjson= LP_gettx("LP_claim_submit",coin->symbol,utxotxid,1)) != 0 )
{
if ( (vouts= jarray(&numvouts,txjson,"vout")) != 0 && numvouts >= 3 )
{
vout0 = jitem(vouts,0);
LP_destaddr(vinaddr,vout0);
satoshis = LP_value_extract(vout0,1);
satoshis = LP_value_extract(vout0,1,utxotxid);
vout2 = jitem(vouts,2);
LP_destaddr(destaddr,vout2);
if ( strcmp(destaddr,coin->smartaddr) == 0 )
{
vout1 = jitem(vouts,1);
weeksatoshis = LP_value_extract(vout1,0);
weeksatoshis = LP_value_extract(vout1,0,utxotxid);
weeki = (int32_t)(weeksatoshis % 10000);
for (iter=0; iter<2; iter++)
for (j=-168; j<=168; j++)
Expand All @@ -425,10 +451,12 @@ int32_t LP_claim_submit(void *ctx,cJSON *txids,int64_t *sump,struct iguana_info
//claimtime = LP_claimtime(coin,expiration);
item = cJSON_CreateObject();
jaddbits256(item,"txid",utxotxid);
jaddnum(item,"deposit",dstr(LP_value_extract(vout0,0)));
jaddnum(item,"deposit",dstr(LP_value_extract(vout0,0,utxotxid)));
if ( coin->electrum == 0 )
jaddnum(item,"interest",dstr(satoshis)-dstr(LP_value_extract(vout0,0)));
else jaddnum(item,"interest",dstr(LP_komodo_interest(utxotxid,satoshis)));
interest = dstr(satoshis) - dstr(LP_value_extract(vout0,0,utxotxid));
else interest = dstr(LP_komodo_interest(utxotxid,satoshis));
jaddnum(item,"interest",interest);
//printf("%.8f %.8f %.8f\n",dstr(satoshis),dstr(LP_value_extract(vout0,0,utxotxid)),dstr(LP_komodo_interest(utxotxid,satoshis)));
if ( claimtime <= expiration )
{
printf("iter.%d j.%d claimtime.%u vs %u, wait %d seconds to %s claim %.8f\n",iter,j,claimtime,expiration,(int32_t)expiration-claimtime,bits256_str(str,utxotxid),dstr(satoshis));
Expand Down Expand Up @@ -526,10 +554,10 @@ int64_t LP_instantdex_creditcalc(struct iguana_info *coin,int32_t dispflag,bits2
}
else
{
amount64 = LP_value_extract(jitem(vouts,1),0);
amount64 = LP_value_extract(jitem(vouts,1),0,txid);
weeki = (amount64 % 10000);
item = jitem(vouts,0);
satoshis = LP_value_extract(item,0);
satoshis = LP_value_extract(item,0,txid);
//char str[65]; printf("%s %s funded %.8f weeki.%d (%s)\n",bits256_str(str,txid),destaddr,dstr(satoshis),weeki,jprint(item,0));
if ( LP_destaddr(p2shaddr,item) == 0 )
{
Expand Down
6 changes: 4 additions & 2 deletions iguana/exchanges/LP_mmjson.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
int32_t MM_numfields;
char *MM_fields[] =
{
"timestamp", "getdPoW", "dPoW", "aliceid", "src", "base", "basevol", "dest", "rel", "relvol", "price", "requestid", "quoteid", "finished", "expired", "bobdeposit", "alicepayment", "bobpayment", "paymentspent", "Apaymentspent", "depositspent", "ind", "method", "swapstatus", "method2", "gettradestatus", "coin", "rmd160", "pub", "pubsecp", "sig", "session", "notify", "pubkey", "price64", "credits", "utxocoin", "n", "bal", "min", "max", "postprice", "notarized", "notarizedhash", "notarizationtxid", "wantnotify", "isLP", "gui", "nogui", "tradeid", "address", "txid", "vout", "srchash", "txfee", "quotetime", "satoshis", "desthash", "txid2", "vout2", "destaddr", "desttxid", "destvout", "feetxid", "feevout", "desttxfee", "destsatoshis", "pending", "reserved", "broadcast", "ismine", "simplegui", "request", "proof", "connect", "expiration", "iambob", "Bgui", "", "Agui", "bob", "srcamount", "bobtxfee", "alice", "destamount", "alicetxfee", "sentflags", "values", "result", "success", "status", "finishtime", "tradestatus", "pair", "connected", "warning", "critical", "endcritical", "cli", "etomic", "bobtomic", "alicetomic", "etomicsrc", "etomicdest"
"timestamp", "getdPoW", "dPoW", "aliceid", "src", "base", "basevol", "dest", "rel", "relvol", "price", "requestid", "quoteid", "finished", "expired", "bobdeposit", "alicepayment", "bobpayment", "paymentspent", "Apaymentspent", "depositspent", "ind", "method", "swapstatus", "method2", "gettradestatus", "coin", "rmd160", "pub", "pubsecp", "sig", "session", "notify", "pubkey", "price64", "credits", "utxocoin", "n", "bal", "min", "max", "postprice", "notarized", "notarizedhash", "notarizationtxid", "wantnotify", "isLP", "gui", "nogui", "tradeid", "address", "txid", "vout", "srchash", "txfee", "quotetime", "satoshis", "desthash", "txid2", "vout2", "destaddr", "desttxid", "destvout", "feetxid", "feevout", "desttxfee", "destsatoshis", "pending", "reserved", "broadcast", "ismine", "simplegui", "request", "proof", "connect", "expiration", "iambob", "Bgui", "", "Agui", "bob", "srcamount", "bobtxfee", "alice", "destamount", "alicetxfee", "sentflags", "values", "result", "success", "status", "finishtime", "tradestatus", "pair", "connected", "warning", "critical", "endcritical", "cli", "etomic", "bobtomic", "alicetomic", "etomicsrc", "etomicdest", "hyperdex", "uuid"
};
#define MMJSON_BOUNDARY ((int32_t)(sizeof(MM_fields)/sizeof(*MM_fields)))

Expand Down Expand Up @@ -581,7 +581,9 @@ int32_t MMJSON_encode(uint8_t *linebuf,char *line)
s = jfieldname(ptr);
if ( (ind= mmfind(s)) < 0 )
{
printf("missing field.(%s) add to MM_fields[]\n",s);
static uint32_t counter;
if ( counter++ < 3 )
printf("missing field.(%s) add to MM_fields[]\n",s);
linebuf[k++] = MMJSON_STRING;
memcpy(&linebuf[k],s,strlen(s)+1);
k += (int32_t)strlen(s) + 1;
Expand Down
6 changes: 6 additions & 0 deletions iguana/exchanges/LP_nativeDEX.c
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ void command_rpcloop(void *ctx)

void LP_coinsloop(void *_coins)
{
static int32_t didfilescreate;
struct LP_address *ap=0; struct LP_transaction *tx; cJSON *retjson; struct LP_address_utxo *up,*tmp; struct iguana_info *coin,*ctmp; char str[65]; struct electrum_info *ep,*backupep=0; bits256 zero; int32_t notarized,oldht,j,nonz; char *coins = _coins;
if ( strcmp("BTC",coins) == 0 )
{
Expand Down Expand Up @@ -564,6 +565,11 @@ void LP_coinsloop(void *_coins)
//printf("%s has no smartaddress??\n",coin->symbol);
continue;
}
if ( didfilescreate == 0 && strcmp("KMD",coin->symbol) == 0 )
{
LP_instantdex_filescreate(coin->smartaddr);
didfilescreate = 1;
}
memset(&zero,0,sizeof(zero));
if ( coin->inactive != 0 )
continue;
Expand Down
Loading

0 comments on commit 4f23d88

Please sign in to comment.