jl777
7 years ago
committed by
GitHub
46 changed files with 4193 additions and 2538 deletions
@ -0,0 +1,2 @@ |
|||
curl --url "http://127.0.0.1:7778" --data "{\"conf\":\"SHARK.conf\",\"path\":\"${HOME#"/"}/.komodo/SHARK\",\"unitval\":\"20\",\"zcash\":1,\"RELAY\":0,\"VALIDATE\":0,\"prefetchlag\":-1,\"poll\":100,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":4,\"endpend\":4,\"services\":129,\"maxpeers\":8,\"newcoin\":\"SHARK\",\"name\":\"SHARK\",\"hasheaders\":1,\"useaddmultisig\":0,\"netmagic\":\"54a5e30c\",\"p2p\":14103,\"rpc\":14104,\"pubval\":60,\"p2shval\":85,\"wifval\":188,\"txfee_satoshis\":\"10000\",\"isPoS\":0,\"minoutput\":10000,\"minconfirms\":2,\"genesishash\":\"027e3758c3a65b12aa1046462b486d0a63bfa1beae327897f56c5cfb7daaae71\",\"protover\":170002,\"genesisblock\":\"0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000000000000000000000000000000000000000000000000000000000000029ab5f490f0f0f200b00000000000000000000000000000000000000000000000000000000000000fd4005000d5ba7cda5d473947263bf194285317179d2b0d307119c2e7cc4bd8ac456f0774bd52b0cd9249be9d40718b6397a4c7bbd8f2b3272fed2823cd2af4bd1632200ba4bf796727d6347b225f670f292343274cc35099466f5fb5f0cd1c105121b28213d15db2ed7bdba490b4cedc69742a57b7c25af24485e523aadbb77a0144fc76f79ef73bd8530d42b9f3b9bed1c135ad1fe152923fafe98f95f76f1615e64c4abb1137f4c31b218ba2782bc15534788dda2cc08a0ee2987c8b27ff41bd4e31cd5fb5643dfe862c9a02ca9f90c8c51a6671d681d04ad47e4b53b1518d4befafefe8cadfb912f3d03051b1efbf1dfe37b56e93a741d8dfd80d576ca250bee55fab1311fc7b3255977558cdda6f7d6f875306e43a14413facdaed2f46093e0ef1e8f8a963e1632dcbeebd8e49fd16b57d49b08f9762de89157c65233f60c8e38a1f503a48c555f8ec45dedecd574a37601323c27be597b956343107f8bd80f3a925afaf30811df83c402116bb9c1e5231c70fff899a7c82f73c902ba54da53cc459b7bf1113db65cc8f6914d3618560ea69abd13658fa7b6af92d374d6eca9529f8bd565166e4fcbf2a8dfb3c9b69539d4d2ee2e9321b85b331925df195915f2757637c2805e1d4131e1ad9ef9bc1bb1c732d8dba4738716d351ab30c996c8657bab39567ee3b29c6d054b711495c0d52e1cd5d8e55b4f0f0325b97369280755b46a02afd54be4ddd9f77c22272b8bbb17ff5118fedbae2564524e797bd28b5f74f7079d532ccc059807989f94d267f47e724b3f1ecfe00ec9e6541c961080d8891251b84b4480bc292f6a180bea089fef5bbda56e1e41390d7c0e85ba0ef530f7177413481a226465a36ef6afe1e2bca69d2078712b3912bba1a99b1fbff0d355d6ffe726d2bb6fbc103c4ac5756e5bee6e47e17424ebcbf1b63d8cb90ce2e40198b4f4198689daea254307e52a25562f4c1455340f0ffeb10f9d8e914775e37d0edca019fb1b9c6ef81255ed86bc51c5391e0591480f66e2d88c5f4fd7277697968656a9b113ab97f874fdd5f2465e5559533e01ba13ef4a8f7a21d02c30c8ded68e8c54603ab9c8084ef6d9eb4e92c75b078539e2ae786ebab6dab73a09e0aa9ac575bcefb29e930ae656e58bcb513f7e3c17e079dce4f05b5dbc18c2a872b22509740ebe6a3903e00ad1abc55076441862643f93606e3dc35e8d9f2caef3ee6be14d513b2e062b21d0061de3bd56881713a1a5c17f5ace05e1ec09da53f99442df175a49bd154aa96e4949decd52fed79ccf7ccbce32941419c314e374e4a396ac553e17b5340336a1a25c22f9e42a243ba5404450b650acfc826a6e432971ace776e15719515e1634ceb9a4a35061b668c74998d3dfb5827f6238ec015377e6f9c94f38108768cf6e5c8b132e0303fb5a200368f845ad9d46343035a6ff94031df8d8309415bb3f6cd5ede9c135fdabcc030599858d803c0f85be7661c88984d88faa3d26fb0e9aac0056a53f1b5d0baed713c853c4a2726869a0a124a8a5bbc0fc0ef80c8ae4cb53636aa02503b86a1eb9836fcc259823e2692d921d88e1ffc1e6cb2bde43939ceb3f32a611686f539f8f7c9f0bf00381f743607d40960f06d347d1cd8ac8a51969c25e37150efdf7aa4c2037a2fd0516fb444525ab157a0ed0a7412b2fa69b217fe397263153782c0f64351fbdf2678fa0dc8569912dcd8e3ccad38f34f23bbbce14c6a26ac24911b308b82c7e43062d180baeac4ba7153858365c72c63dcf5f6a5b08070b730adb017aeae925b7d0439979e2679f45ed2f25a7edcfd2fb77a8794630285ccb0a071f5cce410b46dbf9750b0354aae8b65574501cc69efb5b6a43444074fee116641bb29da56c2b4a7f456991fc92b2\",\"debug\":0,\"seedipaddr\":\"78.47.196.146\"}" |
|||
|
@ -0,0 +1,2 @@ |
|||
curl --url "http://127.0.0.1:7776" --data "{\"conf\":\"SHARK.conf\",\"path\":\"${HOME#"/"}/.komodo/SHARK\",\"unitval\":\"20\",\"zcash\":1,\"RELAY\":-1,\"VALIDATE\":0,\"prefetchlag\":-1,\"poll\":100,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":4,\"endpend\":4,\"services\":129,\"maxpeers\":8,\"newcoin\":\"SHARK\",\"name\":\"SHARK\",\"hasheaders\":1,\"useaddmultisig\":0,\"netmagic\":\"54a5e30c\",\"p2p\":14103,\"rpc\":14104,\"pubval\":60,\"p2shval\":85,\"wifval\":188,\"txfee_satoshis\":\"10000\",\"isPoS\":0,\"minoutput\":10000,\"minconfirms\":2,\"genesishash\":\"027e3758c3a65b12aa1046462b486d0a63bfa1beae327897f56c5cfb7daaae71\",\"protover\":170002,\"genesisblock\":\"0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000000000000000000000000000000000000000000000000000000000000029ab5f490f0f0f200b00000000000000000000000000000000000000000000000000000000000000fd4005000d5ba7cda5d473947263bf194285317179d2b0d307119c2e7cc4bd8ac456f0774bd52b0cd9249be9d40718b6397a4c7bbd8f2b3272fed2823cd2af4bd1632200ba4bf796727d6347b225f670f292343274cc35099466f5fb5f0cd1c105121b28213d15db2ed7bdba490b4cedc69742a57b7c25af24485e523aadbb77a0144fc76f79ef73bd8530d42b9f3b9bed1c135ad1fe152923fafe98f95f76f1615e64c4abb1137f4c31b218ba2782bc15534788dda2cc08a0ee2987c8b27ff41bd4e31cd5fb5643dfe862c9a02ca9f90c8c51a6671d681d04ad47e4b53b1518d4befafefe8cadfb912f3d03051b1efbf1dfe37b56e93a741d8dfd80d576ca250bee55fab1311fc7b3255977558cdda6f7d6f875306e43a14413facdaed2f46093e0ef1e8f8a963e1632dcbeebd8e49fd16b57d49b08f9762de89157c65233f60c8e38a1f503a48c555f8ec45dedecd574a37601323c27be597b956343107f8bd80f3a925afaf30811df83c402116bb9c1e5231c70fff899a7c82f73c902ba54da53cc459b7bf1113db65cc8f6914d3618560ea69abd13658fa7b6af92d374d6eca9529f8bd565166e4fcbf2a8dfb3c9b69539d4d2ee2e9321b85b331925df195915f2757637c2805e1d4131e1ad9ef9bc1bb1c732d8dba4738716d351ab30c996c8657bab39567ee3b29c6d054b711495c0d52e1cd5d8e55b4f0f0325b97369280755b46a02afd54be4ddd9f77c22272b8bbb17ff5118fedbae2564524e797bd28b5f74f7079d532ccc059807989f94d267f47e724b3f1ecfe00ec9e6541c961080d8891251b84b4480bc292f6a180bea089fef5bbda56e1e41390d7c0e85ba0ef530f7177413481a226465a36ef6afe1e2bca69d2078712b3912bba1a99b1fbff0d355d6ffe726d2bb6fbc103c4ac5756e5bee6e47e17424ebcbf1b63d8cb90ce2e40198b4f4198689daea254307e52a25562f4c1455340f0ffeb10f9d8e914775e37d0edca019fb1b9c6ef81255ed86bc51c5391e0591480f66e2d88c5f4fd7277697968656a9b113ab97f874fdd5f2465e5559533e01ba13ef4a8f7a21d02c30c8ded68e8c54603ab9c8084ef6d9eb4e92c75b078539e2ae786ebab6dab73a09e0aa9ac575bcefb29e930ae656e58bcb513f7e3c17e079dce4f05b5dbc18c2a872b22509740ebe6a3903e00ad1abc55076441862643f93606e3dc35e8d9f2caef3ee6be14d513b2e062b21d0061de3bd56881713a1a5c17f5ace05e1ec09da53f99442df175a49bd154aa96e4949decd52fed79ccf7ccbce32941419c314e374e4a396ac553e17b5340336a1a25c22f9e42a243ba5404450b650acfc826a6e432971ace776e15719515e1634ceb9a4a35061b668c74998d3dfb5827f6238ec015377e6f9c94f38108768cf6e5c8b132e0303fb5a200368f845ad9d46343035a6ff94031df8d8309415bb3f6cd5ede9c135fdabcc030599858d803c0f85be7661c88984d88faa3d26fb0e9aac0056a53f1b5d0baed713c853c4a2726869a0a124a8a5bbc0fc0ef80c8ae4cb53636aa02503b86a1eb9836fcc259823e2692d921d88e1ffc1e6cb2bde43939ceb3f32a611686f539f8f7c9f0bf00381f743607d40960f06d347d1cd8ac8a51969c25e37150efdf7aa4c2037a2fd0516fb444525ab157a0ed0a7412b2fa69b217fe397263153782c0f64351fbdf2678fa0dc8569912dcd8e3ccad38f34f23bbbce14c6a26ac24911b308b82c7e43062d180baeac4ba7153858365c72c63dcf5f6a5b08070b730adb017aeae925b7d0439979e2679f45ed2f25a7edcfd2fb77a8794630285ccb0a071f5cce410b46dbf9750b0354aae8b65574501cc69efb5b6a43444074fee116641bb29da56c2b4a7f456991fc92b2\",\"debug\":0,\"seedipaddr\":\"78.47.196.146\"}" |
|||
|
@ -0,0 +1,373 @@ |
|||
|
|||
/******************************************************************************
|
|||
* Copyright © 2014-2017 The SuperNET Developers. * |
|||
* * |
|||
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * |
|||
* the top-level directory of this distribution for the individual copyright * |
|||
* holder information and the developer policies on copyright and licensing. * |
|||
* * |
|||
* Unless otherwise agreed in a custom licensing agreement, no part of the * |
|||
* SuperNET software, including this file may be copied, modified, propagated * |
|||
* or distributed except according to the terms contained in the LICENSE file * |
|||
* * |
|||
* Removal or modification of this copyright notice is prohibited. * |
|||
* * |
|||
******************************************************************************/ |
|||
|
|||
//
|
|||
// LP_instantdex.c
|
|||
// marketmaker
|
|||
//
|
|||
|
|||
void LP_instantdex_txidaddfname(char *fname) |
|||
{ |
|||
sprintf(fname,"%s/instantdex.json",GLOBAL_DBDIR); |
|||
} |
|||
|
|||
cJSON *LP_instantdex_txidaddjson() |
|||
{ |
|||
char *filestr,fname[1024]; long fsize; cJSON *retjson=0; |
|||
LP_instantdex_txidaddfname(fname); |
|||
if ( (filestr= OS_filestr(&fsize,fname)) != 0 ) |
|||
{ |
|||
retjson = cJSON_Parse(filestr); |
|||
free(filestr); |
|||
} |
|||
return(retjson); |
|||
} |
|||
|
|||
void LP_instantdex_txidadd(bits256 txid) |
|||
{ |
|||
cJSON *array; int32_t i,n; char fname[1024],*filestr; FILE *fp; |
|||
if ( (array= LP_instantdex_txidaddjson()) == 0 ) |
|||
array = cJSON_CreateArray(); |
|||
if ( (n= cJSON_GetArraySize(array)) >= 0 ) |
|||
{ |
|||
for (i=0; i<n; i++) |
|||
if ( bits256_cmp(jbits256i(array,i),txid) == 0 ) |
|||
break; |
|||
if ( i == n ) |
|||
{ |
|||
LP_instantdex_txidaddfname(fname); |
|||
char str[65]; printf("add %s -> %s\n",bits256_str(str,txid),fname); |
|||
jaddibits256(array,txid); |
|||
if ( (fp= fopen(fname,"wb")) != 0 ) |
|||
{ |
|||
filestr = jprint(array,0); |
|||
fwrite(filestr,1,strlen(filestr)+1,fp); |
|||
fclose(fp); |
|||
free(filestr); |
|||
} |
|||
} |
|||
} |
|||
if ( array != 0 ) |
|||
free_json(array); |
|||
} |
|||
|
|||
int32_t LP_deposit_addr(char *p2shaddr,uint8_t *script,uint8_t taddr,uint8_t p2shtype,uint32_t timestamp,uint8_t *pubsecp33) |
|||
{ |
|||
uint8_t elsepub33[33],p2sh_rmd160[20]; int32_t n; |
|||
decode_hex(elsepub33,33,BOTS_BONDPUBKEY33); |
|||
n = bitcoin_performancebond(p2sh_rmd160,script,0,timestamp,pubsecp33,elsepub33); |
|||
bitcoin_address(p2shaddr,taddr,p2shtype,script,n); |
|||
return(n); |
|||
} |
|||
|
|||
char *LP_instantdex_deposit(struct iguana_info *coin,int32_t weeks,double amount,int32_t broadcast) |
|||
{ |
|||
char p2shaddr[64],*retstr,*hexstr; uint8_t script[512]; int32_t weeki,scriptlen; cJSON *argjson,*retjson,*array,*item,*obj; uint32_t timestamp; bits256 txid,sendtxid; uint64_t amount64; |
|||
if ( strcmp(coin->symbol,"KMD") != 0 ) |
|||
return(clonestr("{\"error\":\"instantdex deposit must be in KMD\"}")); |
|||
if ( amount < 10.0 ) |
|||
return(clonestr("{\"error\":\"minimum instantdex deposit is 10 KMD\"}")); |
|||
if ( weeks < 0 || weeks > 52 ) |
|||
return(clonestr("{\"error\":\"weeks must be between 0 and 52\"}")); |
|||
if ( weeks > 0 ) |
|||
{ |
|||
timestamp = (uint32_t)time(NULL); |
|||
timestamp /= LP_WEEKMULT; |
|||
timestamp += weeks+1; |
|||
timestamp *= LP_WEEKMULT; |
|||
weeki = (timestamp - LP_FIRSTWEEKTIME) / LP_WEEKMULT; |
|||
if ( weeks >= 10000 ) |
|||
return(clonestr("{\"error\":\"numweeks must be less than 10000\"}")); |
|||
} else timestamp = (uint32_t)time(NULL) + 300, weeki = 0; |
|||
scriptlen = LP_deposit_addr(p2shaddr,script,coin->taddr,coin->p2shtype,timestamp,G.LP_pubsecp); |
|||
argjson = cJSON_CreateObject(); |
|||
array = cJSON_CreateArray(); |
|||
item = cJSON_CreateObject(); |
|||
jaddnum(item,p2shaddr,amount); |
|||
jaddi(array,item); |
|||
item = cJSON_CreateObject(); |
|||
amount64 = (amount * SATOSHIDEN) / 1000; |
|||
amount64 = (amount64 / 10000) * 10000 + weeki; |
|||
jaddnum(item,BOTS_BONDADDRESS,dstr(amount64)); |
|||
jaddi(array,item); |
|||
item = cJSON_CreateObject(); |
|||
jaddnum(item,coin->smartaddr,0.0001); |
|||
jaddi(array,item); |
|||
jadd(argjson,"outputs",array); |
|||
//printf("deposit.(%s)\n",jprint(argjson,0));
|
|||
if ( (retstr= LP_withdraw(coin,argjson)) != 0 ) |
|||
{ |
|||
if ( (retjson= cJSON_Parse(retstr)) != 0 ) |
|||
{ |
|||
if ( jobj(retjson,"result") != 0 ) |
|||
jdelete(retjson,"result"); |
|||
jaddstr(retjson,"address",p2shaddr); |
|||
jaddnum(retjson,"expiration",timestamp); |
|||
jaddnum(retjson,"deposit",amount); |
|||
if ( (obj= jobj(retjson,"complete")) != 0 && is_cJSON_True(obj) != 0 && (hexstr= jstr(retjson,"hex")) != 0 ) |
|||
{ |
|||
txid = jbits256(retjson,"txid"); |
|||
if ( bits256_nonz(txid) != 0 ) |
|||
LP_instantdex_txidadd(txid); |
|||
if ( broadcast != 0 ) |
|||
{ |
|||
if (bits256_nonz(txid) != 0 ) |
|||
{ |
|||
sendtxid = LP_broadcast("deposit","KMD",hexstr,txid); |
|||
if ( bits256_cmp(sendtxid,txid) != 0 ) |
|||
{ |
|||
jaddstr(retjson,"error","broadcast txid mismatch"); |
|||
jaddbits256(retjson,"broadcast",sendtxid); |
|||
free(retstr); |
|||
return(jprint(retjson,1)); |
|||
} |
|||
else |
|||
{ |
|||
jaddstr(retjson,"result","success"); |
|||
jaddbits256(retjson,"broadcast",sendtxid); |
|||
free(retstr); |
|||
return(jprint(retjson,1)); |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
jaddstr(retjson,"error","couldnt broadcast since no txid created"); |
|||
free(retstr); |
|||
return(jprint(retjson,1)); |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
jaddstr(retjson,"result","success"); |
|||
free(retstr); |
|||
return(jprint(retjson,1)); |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
jaddstr(retjson,"error","couldnt create deposit txid"); |
|||
free(retstr); |
|||
return(jprint(retjson,1)); |
|||
} |
|||
free_json(retjson); |
|||
} |
|||
free(retstr); |
|||
} |
|||
return(clonestr("{\"error\":\"error with LP_withdraw for instantdex deposit\"}")); |
|||
} |
|||
|
|||
char *LP_instantdex_claim(struct iguana_info *coin,char *depositaddr,uint32_t expiration) |
|||
{ |
|||
static void *ctx; |
|||
uint8_t redeemscript[512],userdata[64]; char vinaddr[64],str[65],*signedtx=0; uint32_t timestamp,now,redeemlen,claimtime; int32_t i,n,height,utxovout,userdatalen; bits256 signedtxid,utxotxid,sendtxid,zero; int64_t sum,destamount,satoshis; cJSON *array,*item,*txids,*retjson; |
|||
if ( ctx == 0 ) |
|||
ctx = bitcoin_ctx(); |
|||
if ( strcmp(coin->symbol,"KMD") != 0 ) |
|||
return(clonestr("{\"error\":\"instantdex deposit must be in KMD\"}")); |
|||
now = (uint32_t)time(NULL); |
|||
sum = 0; |
|||
txids = cJSON_CreateArray(); |
|||
timestamp = (now / LP_WEEKMULT) * LP_WEEKMULT + LP_WEEKMULT; |
|||
while ( timestamp > LP_FIRSTWEEKTIME ) |
|||
{ |
|||
if ( expiration != 0 ) |
|||
timestamp = expiration; |
|||
else timestamp -= LP_WEEKMULT; |
|||
redeemlen = LP_deposit_addr(vinaddr,redeemscript,coin->taddr,coin->p2shtype,timestamp,G.LP_pubsecp); |
|||
if ( strcmp(depositaddr,vinaddr) == 0 ) |
|||
{ |
|||
claimtime = (uint32_t)time(NULL)-777; |
|||
if ( claimtime <= timestamp ) |
|||
{ |
|||
printf("claimtime.%u vs locktime.%u, need to wait %d seconds\n",claimtime,timestamp,(int32_t)timestamp-claimtime); |
|||
} |
|||
else |
|||
{ |
|||
printf("found %s at timestamp.%u\n",vinaddr,timestamp); |
|||
memset(zero.bytes,0,sizeof(zero)); |
|||
if ( (array= LP_listunspent(coin->symbol,vinaddr,zero,zero)) != 0 ) |
|||
{ |
|||
userdata[0] = 0x51; |
|||
userdatalen = 1; |
|||
utxovout = 0; |
|||
//printf("unspents.(%s)\n",jprint(array,0));
|
|||
if ( (n= cJSON_GetArraySize(array)) > 0 ) |
|||
{ |
|||
for (i=0; i<n; i++) |
|||
{ |
|||
item = jitem(array,i); |
|||
satoshis = LP_listunspent_parseitem(coin,&utxotxid,&utxovout,&height,item); |
|||
printf("satoshis %.8f %s/v%d\n",dstr(satoshis),bits256_str(str,utxotxid),utxovout); |
|||
if ( (signedtx= basilisk_swap_bobtxspend(&signedtxid,10000,"instantdexclaim",coin->symbol,coin->wiftaddr,coin->taddr,coin->pubtype,coin->p2shtype,coin->isPoS,coin->wiftype,ctx,G.LP_privkey,0,redeemscript,redeemlen,userdata,userdatalen,utxotxid,utxovout,coin->smartaddr,G.LP_pubsecp,0,claimtime,&destamount,0,0,vinaddr,1,coin->zcash)) != 0 ) |
|||
{ |
|||
printf("signedtx.(%s)\n",signedtx); |
|||
sendtxid = LP_broadcast("claim","KMD",signedtx,signedtxid); |
|||
if ( bits256_cmp(sendtxid,signedtxid) == 0 ) |
|||
{ |
|||
jaddibits256(txids,sendtxid); |
|||
sum += (satoshis-coin->txfee); |
|||
} |
|||
else printf("error sending %s\n",bits256_str(str,signedtxid)); |
|||
free(signedtx); |
|||
} else printf("error claiming instantdex deposit %s/v%d %.8f\n",bits256_str(str,utxotxid),utxovout,dstr(satoshis)); |
|||
} |
|||
} |
|||
free_json(array); |
|||
retjson = cJSON_CreateObject(); |
|||
jaddstr(retjson,"result","success"); |
|||
jaddnum(retjson,"claimed",dstr(sum)); |
|||
jadd(retjson,"txids",txids); |
|||
return(jprint(retjson,1)); |
|||
} |
|||
} |
|||
} |
|||
if ( expiration != 0 ) |
|||
break; |
|||
} |
|||
return(clonestr("{\"error\":\"no instantdex deposits to claim\"}")); |
|||
} |
|||
|
|||
int64_t LP_instantdex_credit(int32_t dispflag,char *coinaddr,int64_t satoshis,int32_t weeki,char *p2shaddr,bits256 txid) |
|||
{ |
|||
uint32_t timestamp; struct LP_address *ap; struct iguana_info *coin = LP_coinfind("KMD"); |
|||
if ( coin != 0 ) |
|||
{ |
|||
timestamp = LP_FIRSTWEEKTIME + weeki*LP_WEEKMULT; |
|||
if ( time(NULL) < timestamp-60*3600 && (ap= LP_address(coin,coinaddr)) != 0 ) |
|||
{ |
|||
ap->instantdex_credits += satoshis; |
|||
ap->didinstantdex = 1; |
|||
if ( strcmp(coinaddr,coin->smartaddr) == 0 ) |
|||
LP_instantdex_txidadd(txid); |
|||
if ( dispflag != 0 ) |
|||
printf("InstantDEX credit.(%s) %.8f weeki.%d (%s) -> sum %.8f\n",coinaddr,dstr(satoshis),weeki,p2shaddr,dstr(ap->instantdex_credits)); |
|||
return(satoshis); |
|||
} |
|||
} |
|||
return(0); |
|||
} |
|||
|
|||
int64_t LP_instantdex_creditcalc(struct iguana_info *coin,int32_t dispflag,bits256 txid,char *refaddr) |
|||
{ |
|||
cJSON *txjson,*vouts,*txobj,*item; int64_t satoshis=0,amount64; int32_t weeki,numvouts; char destaddr[64],p2shaddr[64]; |
|||
if ( (txjson= LP_gettx(coin->symbol,txid,0)) != 0 ) |
|||
{ |
|||
// vout0 deposit, vout1 botsfee, vout2 smartaddress
|
|||
if ( (vouts= jarray(&numvouts,txjson,"vout")) > 0 && numvouts >= 3 && LP_destaddr(destaddr,jitem(vouts,2)) == 0 ) |
|||
{ |
|||
if ( refaddr != 0 && strcmp(refaddr,destaddr) != 0 ) |
|||
{ |
|||
printf("LP_instantdex_creditcalc for (%s) but deposit sent for (%s)\n",refaddr,destaddr); |
|||
} |
|||
else |
|||
{ |
|||
amount64 = LP_value_extract(jitem(vouts,1),0); |
|||
weeki = (amount64 % 10000); |
|||
item = jitem(vouts,0); |
|||
satoshis = LP_value_extract(item,0); |
|||
//printf("%s funded %.8f weeki.%d\n",destaddr,dstr(satoshis),weeki);
|
|||
if ( LP_destaddr(p2shaddr,item) == 0 ) |
|||
{ |
|||
if ( (txobj= LP_gettxout(coin->symbol,p2shaddr,txid,0)) != 0 ) |
|||
{ |
|||
free_json(txobj); |
|||
LP_instantdex_credit(dispflag,destaddr,satoshis,weeki,p2shaddr,txid); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
free_json(txjson); |
|||
} |
|||
return(satoshis); |
|||
} |
|||
|
|||
#ifdef bruteforce |
|||
void LP_instantdex_deposits(struct iguana_info *coin) |
|||
{ |
|||
static int dispflag = 1; |
|||
cJSON *array,*item; int32_t i,n,height,vout; bits256 txid; struct LP_address *ap,*tmp; |
|||
if ( coin->electrum != 0 )//&& coin->electruminstantdex != 0 )
|
|||
return; |
|||
HASH_ITER(hh,coin->addresses,ap,tmp) |
|||
{ |
|||
ap->instantdex_credits = 0; |
|||
} |
|||
if ( (array= LP_listreceivedbyaddress("KMD",BOTS_BONDADDRESS)) != 0 ) |
|||
{ |
|||
//printf("instantdex.(%s)\n",jprint(array,0));
|
|||
if ( (n= cJSON_GetArraySize(array)) > 0 ) |
|||
{ |
|||
for (i=0; i<n; i++) |
|||
{ |
|||
if ( coin->electrum != 0 ) |
|||
{ |
|||
item = jitem(array,i); |
|||
LP_listunspent_parseitem(coin,&txid,&vout,&height,item); |
|||
} else txid = jbits256i(array,i); |
|||
LP_instantdex_creditcalc(coin,dispflag,txid,0); |
|||
} |
|||
} |
|||
free_json(array); |
|||
} |
|||
dispflag = 0; |
|||
} |
|||
#endif |
|||
|
|||
int64_t LP_dynamictrust(bits256 pubkey,int64_t kmdvalue) |
|||
{ |
|||
struct LP_pubswap *ptr,*tmp; struct LP_swapstats *sp; struct LP_pubkey_info *pubp; struct LP_address *ap; char coinaddr[64]; struct iguana_info *coin; int64_t swaps_kmdvalue = 0; |
|||
if ( (coin= LP_coinfind("KMD")) != 0 && (pubp= LP_pubkeyfind(pubkey)) != 0 ) |
|||
{ |
|||
bitcoin_address(coinaddr,coin->taddr,coin->pubtype,pubp->pubsecp,33); |
|||
if ((ap= LP_address(coin,coinaddr)) != 0 )//&& ap->instantdex_credits >= kmdvalue )
|
|||
{ |
|||
DL_FOREACH_SAFE(pubp->bobswaps,ptr,tmp) |
|||
{ |
|||
if ( (sp= ptr->swap) != 0 && sp->finished == 0 && sp->expired == 0 ) |
|||
swaps_kmdvalue += LP_kmdvalue(sp->Q.srccoin,sp->Q.satoshis); |
|||
} |
|||
DL_FOREACH_SAFE(pubp->aliceswaps,ptr,tmp) |
|||
{ |
|||
if ( (sp= ptr->swap) != 0 && sp->finished == 0 && sp->expired == 0 ) |
|||
swaps_kmdvalue += LP_kmdvalue(sp->Q.destcoin,sp->Q.destsatoshis); |
|||
} |
|||
//printf("%s instantdex_credits %.8f vs (%.8f + current %.8f)\n",coinaddr,dstr(ap->instantdex_credits),dstr(swaps_kmdvalue),dstr(kmdvalue));
|
|||
//if ( ap->instantdex_credits > swaps_kmdvalue+kmdvalue )
|
|||
return(ap->instantdex_credits - (swaps_kmdvalue+kmdvalue)); |
|||
} |
|||
} |
|||
return(0); |
|||
} |
|||
|
|||
int64_t LP_instantdex_proofcheck(char *coinaddr,cJSON *proof,int32_t num) |
|||
{ |
|||
uint8_t rmd160[20],addrtype; int32_t i; int64_t net = 0; char othersmartaddr[64]; struct iguana_info *coin; struct LP_address *ap = 0; |
|||
if ( (coin= LP_coinfind("KMD")) != 0 ) |
|||
{ |
|||
bitcoin_addr2rmd160(0,&addrtype,rmd160,coinaddr); |
|||
bitcoin_address(othersmartaddr,0,60,rmd160,20); |
|||
if ((ap= LP_address(coin,othersmartaddr)) != 0 && (coin->electrum == 0 || ap->didinstantdex == 0) ) |
|||
{ |
|||
ap->instantdex_credits = 0; |
|||
for (i=0; i<num; i++) |
|||
LP_instantdex_creditcalc(coin,1,jbits256i(proof,i),othersmartaddr); |
|||
ap->didinstantdex = 1; |
|||
//if ( ap->instantdex_credits > 0 )
|
|||
printf("validated instantdex %s.[%d] proof.(%s) credits %.8f net %.8f\n",othersmartaddr,num,jprint(proof,0),dstr(ap->instantdex_credits),dstr(net)); |
|||
} else printf("cant find ap.%p or already did %d %.8f\n",ap,ap!=0?ap->didinstantdex:-1,ap!=0?dstr(ap->instantdex_credits):-1); |
|||
} |
|||
return(net); |
|||
} |
File diff suppressed because it is too large
@ -0,0 +1,354 @@ |
|||
|
|||
/******************************************************************************
|
|||
* Copyright © 2014-2017 The SuperNET Developers. * |
|||
* * |
|||
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * |
|||
* the top-level directory of this distribution for the individual copyright * |
|||
* holder information and the developer policies on copyright and licensing. * |
|||
* * |
|||
* Unless otherwise agreed in a custom licensing agreement, no part of the * |
|||
* SuperNET software, including this file may be copied, modified, propagated * |
|||
* or distributed except according to the terms contained in the LICENSE file * |
|||
* * |
|||
* Removal or modification of this copyright notice is prohibited. * |
|||
* * |
|||
******************************************************************************/ |
|||
//
|
|||
// LP_utxos.c
|
|||
// marketmaker
|
|||
//
|
|||
|
|||
int32_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 myprivkey,bits256 mypub) |
|||
{ |
|||
int32_t enable_utxos = 0; |
|||
char *script,destaddr[64]; cJSON *array,*item; bits256 txid,deposittxid,zero; int32_t used,i,flag=0,height,n,cmpflag,iambob,vout,depositvout; uint64_t *values=0,satoshis,txfee,biggerval,value,total = 0; int64_t targetval; //struct LP_utxoinfo *utxo;
|
|||
if ( coin == 0 || (IAMLP == 0 && coin->inactive != 0) ) |
|||
{ |
|||
//printf("coin not active\n");
|
|||
return(0); |
|||
} |
|||
if ( coin->privkeydepth > 0 ) |
|||
return(0); |
|||
coin->privkeydepth++; |
|||
LP_address(coin,coin->smartaddr); |
|||
//if ( coin->inactive == 0 )
|
|||
// LP_listunspent_issue(coin->symbol,coin->smartaddr,0);
|
|||
memset(zero.bytes,0,sizeof(zero)); |
|||
array = LP_listunspent(coin->symbol,coin->smartaddr,zero,zero); |
|||
if ( array != 0 ) |
|||
{ |
|||
txfee = LP_txfeecalc(coin,0,0); |
|||
if ( is_cJSON_Array(array) != 0 && (n= cJSON_GetArraySize(array)) > 0 ) |
|||
{ |
|||
coin->numutxos = n; |
|||
//printf("LP_privkey_init %s %d\n",coin->symbol,n);
|
|||
for (iambob=0; iambob<=1; iambob++) |
|||
{ |
|||
if ( iambob == 0 ) |
|||
values = calloc(n,sizeof(*values)); |
|||
else memset(values,0,n * sizeof(*values)); |
|||
used = 0; |
|||
for (i=0; i<n; i++) |
|||
{ |
|||
item = jitem(array,i); |
|||
value = LP_listunspent_parseitem(coin,&txid,&vout,&height,item); |
|||
satoshis = LP_txvalue(destaddr,coin->symbol,txid,vout); |
|||
if ( satoshis != 0 && satoshis != value ) |
|||
printf("%s %s privkey_init value %.8f vs %.8f (%s) %.8f %.8f\n",coin->symbol,coin->smartaddr,dstr(satoshis),dstr(value),jprint(item,0),jdouble(item,"amount"),jdouble(item,"interest")); |
|||
if ( coin->electrum != 0 || LP_inventory_prevent(iambob,coin->symbol,txid,vout) == 0 )//&& height > 0 )
|
|||
{ |
|||
values[i] = satoshis; |
|||
//flag += LP_address_utxoadd(coin,destaddr,txid,vout,satoshis,height,-1);
|
|||
} else used++; |
|||
} |
|||
//printf("array.%d\n",n);
|
|||
while ( used < n-1 ) |
|||
{ |
|||
//for (i=0; i<n; i++)
|
|||
// printf("%.8f ",dstr(values[i]));
|
|||
//printf("used.%d of n.%d\n",used,n);
|
|||
if ( (i= LP_maxvalue(values,n)) >= 0 ) |
|||
{ |
|||
item = jitem(array,i); |
|||
if ( coin->electrum == 0 ) |
|||
{ |
|||
deposittxid = jbits256(item,"txid"); |
|||
depositvout = juint(item,"vout"); |
|||
script = jstr(item,"scriptPubKey"); |
|||
} |
|||
else |
|||
{ |
|||
deposittxid = jbits256(item,"tx_hash"); |
|||
depositvout = juint(item,"tx_pos"); |
|||
script = coin->smartaddr; |
|||
} |
|||
biggerval = values[i]; |
|||
values[i] = 0, used++; |
|||
if ( iambob == 0 ) |
|||
targetval = (biggerval / 776) + txfee; |
|||
else targetval = (biggerval / 9) * 8 + 2*txfee; |
|||
if ( targetval < txfee*2 ) |
|||
targetval = txfee*2; |
|||
//printf("iambob.%d i.%d deposit %.8f min %.8f target %.8f\n",iambob,i,dstr(biggerval),dstr((1+LP_MINSIZE_TXFEEMULT)*txfee),dstr(targetval));
|
|||
if ( biggerval < (1+LP_MINSIZE_TXFEEMULT)*txfee ) |
|||
continue; |
|||
i = -1; |
|||
if ( iambob != 0 ) |
|||
{ |
|||
if ( (i= LP_nearestvalue(iambob,values,n,targetval)) < 0 ) |
|||
targetval /= 4; |
|||
if ( targetval < txfee*(1+LP_MINSIZE_TXFEEMULT) ) |
|||
continue; |
|||
} |
|||
if ( i >= 0 || (i= LP_nearestvalue(iambob,values,n,targetval)) >= 0 ) |
|||
{ |
|||
//printf("iambob.%d i.%d %.8f target %.8f\n",iambob,i,dstr(biggerval),dstr(targetval));
|
|||
item = jitem(array,i); |
|||
cmpflag = 0; |
|||
if ( coin->electrum == 0 ) |
|||
{ |
|||
txid = jbits256(item,"txid"); |
|||
vout = juint(item,"vout"); |
|||
if ( jstr(item,"scriptPubKey") != 0 && strcmp(script,jstr(item,"scriptPubKey")) == 0 ) |
|||
cmpflag = 1; |
|||
} |
|||
else |
|||
{ |
|||
txid = jbits256(item,"tx_hash"); |
|||
vout = juint(item,"tx_pos"); |
|||
cmpflag = 1; |
|||
} |
|||
if ( cmpflag != 0 ) |
|||
{ |
|||
value = values[i]; |
|||
values[i] = 0, used++; |
|||
/*portable_mutex_lock(&LP_UTXOmutex);
|
|||
if ( iambob != 0 ) |
|||
{ |
|||
if ( (utxo= LP_utxoadd(1,coin->symbol,txid,vout,value,deposittxid,depositvout,biggerval,coin->smartaddr,mypub,LP_gui,G.LP_sessionid,value)) != 0 ) |
|||
{ |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
//printf("call utxoadd\n");
|
|||
if ( (utxo= LP_utxoadd(0,coin->symbol,deposittxid,depositvout,biggerval,txid,vout,value,coin->smartaddr,mypub,LP_gui,G.LP_sessionid,biggerval)) != 0 ) |
|||
{ |
|||
} |
|||
} |
|||
portable_mutex_unlock(&LP_UTXOmutex);*/ |
|||
total += value; |
|||
} // else printf("scriptmismatch.(%s) vs %s\n",script,jprint(item,0));
|
|||
} //else printf("nothing near i.%d\n",i);
|
|||
} else break; |
|||
} |
|||
if ( enable_utxos == 0 ) |
|||
break; |
|||
} |
|||
} |
|||
free_json(array); |
|||
if ( 0 && flag != 0 ) |
|||
LP_postutxos(coin->symbol,coin->smartaddr); |
|||
} |
|||
if ( values != 0 ) |
|||
free(values); |
|||
if ( coin->privkeydepth > 0 ) |
|||
coin->privkeydepth--; |
|||
//printf("privkey.%s %.8f\n",symbol,dstr(total));
|
|||
return(flag); |
|||
} |
|||
|
|||
char *LP_secretaddresses(void *ctx,char *prefix,char *passphrase,int32_t n,uint8_t taddr,uint8_t pubtype) |
|||
{ |
|||
int32_t i; uint8_t tmptype,pubkey33[33],rmd160[20]; char output[777*45],str[65],str2[65],buf[8192],wifstr[128],coinaddr[64]; bits256 checkprivkey,privkey,pubkey; cJSON *retjson; |
|||
retjson = cJSON_CreateObject(); |
|||
if ( prefix == 0 || prefix[0] == 0 ) |
|||
prefix = "secretaddress"; |
|||
if ( passphrase == 0 || passphrase[0] == 0 ) |
|||
passphrase = "password"; |
|||
if ( n <= 0 ) |
|||
n = 16; |
|||
else if ( n > 777 ) |
|||
n = 777; |
|||
conv_NXTpassword(privkey.bytes,pubkey.bytes,(uint8_t *)passphrase,(int32_t)strlen(passphrase)); |
|||
bitcoin_priv2pub(ctx,pubkey33,coinaddr,privkey,taddr,pubtype); |
|||
printf("generator (%s) secrets.[%d] <%s> t.%u p.%u\n",coinaddr,n,passphrase,taddr,pubtype); |
|||
sprintf(output,"\"addresses\":["); |
|||
for (i=0; i<n; i++) |
|||
{ |
|||
sprintf(buf,"%s %s %03d",prefix,passphrase,i); |
|||
conv_NXTpassword(privkey.bytes,pubkey.bytes,(uint8_t *)buf,(int32_t)strlen(buf)); |
|||
bitcoin_priv2pub(ctx,pubkey33,coinaddr,privkey,taddr,pubtype); |
|||
bitcoin_priv2wif(0,wifstr,privkey,188); |
|||
bitcoin_wif2priv(0,&tmptype,&checkprivkey,wifstr); |
|||
bitcoin_addr2rmd160(taddr,&tmptype,rmd160,coinaddr); |
|||
if ( bits256_cmp(checkprivkey,privkey) != 0 ) |
|||
{ |
|||
printf("WIF.(%s) error -> %s vs %s?\n",wifstr,bits256_str(str,privkey),bits256_str(str2,checkprivkey)); |
|||
free_json(retjson); |
|||
return(clonestr("{\"error\":\"couldnt validate wifstr\"}")); |
|||
} |
|||
else if ( tmptype != pubtype ) |
|||
{ |
|||
printf("checktype.%d != pubtype.%d\n",tmptype,pubtype); |
|||
free_json(retjson); |
|||
return(clonestr("{\"error\":\"couldnt validate pubtype\"}")); |
|||
} |
|||
jaddstr(retjson,coinaddr,wifstr); |
|||
sprintf(output+strlen(output),"\\\"%s\\\"%c ",coinaddr,i<n-1?',':' '); |
|||
printf("./komodo-cli jumblr_secret %s\n",coinaddr); |
|||
} |
|||
printf("%s]\n",output); |
|||
return(jprint(retjson,1)); |
|||
} |
|||
|
|||
bits256 LP_privkeycalc(void *ctx,uint8_t *pubkey33,bits256 *pubkeyp,struct iguana_info *coin,char *passphrase,char *wifstr) |
|||
{ |
|||
//static uint32_t counter;
|
|||
bits256 privkey,userpub,zero,userpass,checkkey; char tmpstr[128]; cJSON *retjson; uint8_t tmptype; |
|||
if ( passphrase != 0 && passphrase[0] != 0 ) |
|||
{ |
|||
calc_NXTaddr(G.LP_NXTaddr,userpub.bytes,(uint8_t *)passphrase,(int32_t)strlen(passphrase)); |
|||
conv_NXTpassword(privkey.bytes,pubkeyp->bytes,(uint8_t *)passphrase,(int32_t)strlen(passphrase)); |
|||
//vcalc_sha256(0,checkkey.bytes,(uint8_t *)passphrase,(int32_t)strlen(passphrase));
|
|||
//printf("SHA256.(%s) ",bits256_str(pstr,checkkey));
|
|||
//printf("privkey.(%s)\n",bits256_str(pstr,privkey));
|
|||
} |
|||
else |
|||
{ |
|||
bitcoin_wif2priv(coin->wiftaddr,&tmptype,&privkey,wifstr); |
|||
if ( 0 ) |
|||
{ |
|||
char str[65],str2[65]; |
|||
checkkey = iguana_wif2privkey(wifstr); |
|||
if ( bits256_cmp(checkkey,privkey) != 0 ) |
|||
printf("WIF.(%s) -> %s or %s?\n",wifstr,bits256_str(str,privkey),bits256_str(str2,checkkey)); |
|||
} |
|||
} |
|||
privkey.bytes[0] &= 248, privkey.bytes[31] &= 127, privkey.bytes[31] |= 64; |
|||
bitcoin_priv2pub(ctx,coin->pubkey33,coin->smartaddr,privkey,coin->taddr,coin->pubtype); |
|||
if ( coin->counter == 0 ) |
|||
{ |
|||
coin->counter++; |
|||
memcpy(G.LP_pubsecp,coin->pubkey33,33); |
|||
bitcoin_priv2wif(coin->wiftaddr,tmpstr,privkey,coin->wiftype); |
|||
bitcoin_addr2rmd160(coin->taddr,&tmptype,G.LP_myrmd160,coin->smartaddr); |
|||
LP_privkeyadd(privkey,G.LP_myrmd160); |
|||
G.LP_privkey = privkey; |
|||
if ( 0 && (coin->pubtype != 60 || strcmp(coin->symbol,"KMD") == 0) ) |
|||
printf("%s (%s) %d wif.(%s) (%s)\n",coin->symbol,coin->smartaddr,coin->pubtype,tmpstr,passphrase); |
|||
if ( G.counter++ == 0 ) |
|||
{ |
|||
bitcoin_priv2wif(coin->wiftaddr,G.USERPASS_WIFSTR,privkey,188); |
|||
bitcoin_wif2priv(coin->wiftaddr,&tmptype,&checkkey,G.USERPASS_WIFSTR); |
|||
if ( bits256_cmp(checkkey,privkey) != 0 ) |
|||
{ |
|||
char str[65],str2[65]; |
|||
printf("FATAL ERROR converting USERPASS_WIFSTR %s -> %s != %s\n",G.USERPASS_WIFSTR,bits256_str(str,checkkey),bits256_str(str2,privkey)); |
|||
exit(-1); |
|||
} |
|||
conv_NXTpassword(userpass.bytes,pubkeyp->bytes,(uint8_t *)G.USERPASS_WIFSTR,(int32_t)strlen(G.USERPASS_WIFSTR)); |
|||
userpub = curve25519(userpass,curve25519_basepoint9()); |
|||
printf("userpass.(%s)\n",bits256_str(G.USERPASS,userpub)); |
|||
} |
|||
} |
|||
if ( coin->importedprivkey == 0 && coin->electrum == 0 && coin->userpass[0] != 0 && LP_getheight(coin) > 0 ) |
|||
{ |
|||
memset(zero.bytes,0,sizeof(zero)); |
|||
LP_listunspent_issue(coin->symbol,coin->smartaddr,0,zero,zero); |
|||
if ( (retjson= LP_importprivkey(coin->symbol,tmpstr,coin->smartaddr,-1)) != 0 ) |
|||
{ |
|||
if ( jobj(retjson,"error") != 0 ) |
|||
{ |
|||
printf("cant importprivkey.%s -> (%s), abort session\n",coin->symbol,jprint(retjson,1)); |
|||
exit(-1); |
|||
} |
|||
free_json(retjson); |
|||
} |
|||
coin->importedprivkey = (uint32_t)time(NULL); |
|||
} |
|||
vcalc_sha256(0,checkkey.bytes,privkey.bytes,sizeof(privkey)); |
|||
checkkey.bytes[0] &= 248, checkkey.bytes[31] &= 127, checkkey.bytes[31] |= 64; |
|||
G.LP_mypub25519 = *pubkeyp = curve25519(checkkey,curve25519_basepoint9()); |
|||
G.LP_mypriv25519 = checkkey; |
|||
LP_pubkeyadd(G.LP_mypub25519); |
|||
return(privkey); |
|||
} |
|||
|
|||
void LP_privkey_updates(void *ctx,int32_t pubsock,char *passphrase) |
|||
{ |
|||
struct iguana_info *coin,*tmp; bits256 pubkey,privkey; uint8_t pubkey33[33]; int32_t initonly; |
|||
initonly = (passphrase != 0); |
|||
memset(privkey.bytes,0,sizeof(privkey)); |
|||
memset(pubkey.bytes,0,sizeof(pubkey)); |
|||
//printf("Total coins: %d\n", HASH_COUNT(LP_coins));
|
|||
//int num_iter = 0;
|
|||
HASH_ITER(hh,LP_coins,coin,tmp) |
|||
{ |
|||
//printf("LP_privkey_updates [%02d / %02d]\n", num_iter++, HASH_COUNT(LP_coins));
|
|||
if ( initonly != 0 ) |
|||
{ |
|||
coin->counter = 0; |
|||
memset(coin->smartaddr,0,sizeof(coin->smartaddr)); |
|||
if ( bits256_nonz(privkey) == 0 || coin->smartaddr[0] == 0 ) |
|||
privkey = LP_privkeycalc(ctx,pubkey33,&pubkey,coin,passphrase,""); |
|||
} |
|||
//printf("i.%d of %d\n",i,LP_numcoins);
|
|||
else if ( IAMLP == 0 || coin->inactive == 0 ) |
|||
{ |
|||
//printf("from updates %s\n",coin->symbol);
|
|||
if ( 0 && LP_privkey_init(pubsock,coin,G.LP_privkey,G.LP_mypub25519) == 0 && (LP_rand() % 10) == 0 ) |
|||
{ |
|||
//LP_postutxos(coin->symbol,coin->smartaddr);
|
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
int32_t LP_passphrase_init(char *passphrase,char *gui) |
|||
{ |
|||
static void *ctx; int32_t counter; //iambob,; struct LP_utxoinfo *utxo,*tmp;
|
|||
if ( ctx == 0 ) |
|||
ctx = bitcoin_ctx(); |
|||
if ( G.LP_pendingswaps != 0 ) |
|||
return(-1); |
|||
G.initializing = 1; |
|||
if ( gui == 0 ) |
|||
gui = "cli"; |
|||
counter = G.USERPASS_COUNTER; |
|||
while ( G.waiting == 0 ) |
|||
{ |
|||
printf("waiting for G.waiting\n"); |
|||
sleep(5); |
|||
} |
|||
/*for (iambob=0; iambob<2; iambob++)
|
|||
{ |
|||
if ( G.LP_utxoinfos[iambob] != 0 ) |
|||
{ |
|||
HASH_ITER(hh,G.LP_utxoinfos[iambob],utxo,tmp) |
|||
{ |
|||
HASH_DELETE(hh,G.LP_utxoinfos[iambob],utxo); |
|||
//free(utxo);
|
|||
} |
|||
} |
|||
if ( G.LP_utxoinfos2[iambob] != 0 ) |
|||
{ |
|||
G.LP_utxoinfos2[iambob] = 0; |
|||
//HASH_ITER(hh,G.LP_utxoinfos2[iambob],utxo,tmp)
|
|||
//{
|
|||
// HASH_DELETE(hh,G.LP_utxoinfos2[iambob],utxo);
|
|||
// free(utxo);
|
|||
//}
|
|||
} |
|||
}*/ |
|||
memset(&G,0,sizeof(G)); |
|||
LP_privkey_updates(ctx,LP_mypubsock,passphrase); |
|||
init_hexbytes_noT(G.LP_myrmd160str,G.LP_myrmd160,20); |
|||
G.LP_sessionid = (uint32_t)time(NULL); |
|||
safecopy(G.gui,gui,sizeof(G.gui)); |
|||
G.USERPASS_COUNTER = counter; |
|||
G.initializing = 0; |
|||
return(0); |
|||
} |
|||
|
|||
|
File diff suppressed because it is too large
@ -1,905 +0,0 @@ |
|||
|
|||
/******************************************************************************
|
|||
* Copyright © 2014-2017 The SuperNET Developers. * |
|||
* * |
|||
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * |
|||
* the top-level directory of this distribution for the individual copyright * |
|||
* holder information and the developer policies on copyright and licensing. * |
|||
* * |
|||
* Unless otherwise agreed in a custom licensing agreement, no part of the * |
|||
* SuperNET software, including this file may be copied, modified, propagated * |
|||
* or distributed except according to the terms contained in the LICENSE file * |
|||
* * |
|||
* Removal or modification of this copyright notice is prohibited. * |
|||
* * |
|||
******************************************************************************/ |
|||
//
|
|||
// LP_utxos.c
|
|||
// marketmaker
|
|||
//
|
|||
|
|||
|
|||
int32_t LP_ismine(struct LP_utxoinfo *utxo) |
|||
{ |
|||
if ( utxo != 0 && bits256_cmp(utxo->pubkey,G.LP_mypub25519) == 0 ) |
|||
return(1); |
|||
else return(0); |
|||
} |
|||
|
|||
int32_t LP_isunspent(struct LP_utxoinfo *utxo) |
|||
{ |
|||
struct LP_address_utxo *up; struct _LP_utxoinfo u; struct iguana_info *coin; |
|||
if ( (coin= LP_coinfind(utxo->coin)) == 0 ) |
|||
return(0); |
|||
if ( (up= LP_address_utxofind(coin,utxo->coinaddr,utxo->payment.txid,utxo->payment.vout)) != 0 && up->spendheight > 0 ) |
|||
{ |
|||
utxo->T.spentflag = up->spendheight; |
|||
return(0); |
|||
} |
|||
u = (utxo->iambob != 0) ? utxo->deposit : utxo->fee; |
|||
if ( (up= LP_address_utxofind(coin,utxo->coinaddr,u.txid,u.vout)) != 0 && up->spendheight > 0 ) |
|||
{ |
|||
utxo->T.spentflag = up->spendheight; |
|||
return(0); |
|||
} |
|||
if ( utxo != 0 && utxo->T.spentflag == 0 && LP_isavailable(utxo) > 0 ) |
|||
return(1); |
|||
else return(0); |
|||
} |
|||
|
|||
struct LP_utxoinfo *LP_utxopairfind(int32_t iambob,bits256 txid,int32_t vout,bits256 txid2,int32_t vout2) |
|||
{ |
|||
struct LP_utxoinfo *utxo=0; struct _LP_utxoinfo u; |
|||
if ( (utxo= LP_utxofind(iambob,txid,vout)) != 0 ) |
|||
{ |
|||
u = (iambob != 0) ? utxo->deposit : utxo->fee; |
|||
if (vout2 == u.vout && bits256_cmp(u.txid,txid2) == 0 ) |
|||
return(utxo); |
|||
} |
|||
return(0); |
|||
} |
|||
|
|||
struct LP_utxoinfo *LP_utxofinds(int32_t iambob,bits256 txid,int32_t vout,bits256 txid2,int32_t vout2) |
|||
{ |
|||
struct LP_utxoinfo *utxo; |
|||
if ( (utxo= LP_utxofind(iambob,txid,vout)) != 0 || (utxo= LP_utxofind(iambob,txid2,vout2)) != 0 || (utxo= LP_utxo2find(iambob,txid,vout)) != 0 || (utxo= LP_utxo2find(iambob,txid2,vout2)) != 0 ) |
|||
return(utxo); |
|||
else return(0); |
|||
} |
|||
|
|||
int32_t LP_utxoaddptrs(struct LP_utxoinfo *ptrs[],int32_t n,struct LP_utxoinfo *utxo) |
|||
{ |
|||
int32_t i; |
|||
for (i=0; i<n; i++) |
|||
if ( ptrs[i] == utxo ) |
|||
return(n); |
|||
ptrs[n++] = utxo; |
|||
return(n); |
|||
} |
|||
|
|||
/*uint32_t LP_allocated(bits256 txid,int32_t vout)
|
|||
{ |
|||
struct LP_utxoinfo *utxo; |
|||
if ( (utxo= _LP_utxofind(0,txid,vout)) != 0 && LP_isavailable(utxo) == 0 ) |
|||
{ |
|||
//char str[65]; printf("%s/v%d not available\n",bits256_str(str,txid),vout);
|
|||
return(utxo); |
|||
} |
|||
if ( (utxo= _LP_utxo2find(0,txid,vout)) != 0 && LP_isavailable(utxo) == 0 ) |
|||
{ |
|||
//char str[65]; printf("%s/v%d not available2\n",bits256_str(str,txid),vout);
|
|||
return(utxo); |
|||
} |
|||
if ( (utxo= _LP_utxofind(1,txid,vout)) != 0 && LP_isavailable(utxo) == 0 ) |
|||
{ |
|||
//char str[65]; printf("%s/v%d not available\n",bits256_str(str,txid),vout);
|
|||
return(utxo); |
|||
} |
|||
if ( (utxo= _LP_utxo2find(1,txid,vout)) != 0 && LP_isavailable(utxo) == 0 ) |
|||
{ |
|||
//char str[65]; printf("%s/v%d not available2\n",bits256_str(str,txid),vout);
|
|||
return(utxo); |
|||
} |
|||
return(0); |
|||
} |
|||
|
|||
int32_t LP_isavailable(struct LP_utxoinfo *utxo) |
|||
{ |
|||
if ( time(NULL) > utxo->T.swappending ) |
|||
utxo->T.swappending = 0; |
|||
if ( utxo != 0 && utxo->T.swappending == 0 && utxo->S.swap == 0 ) |
|||
return(1); |
|||
else return(0); |
|||
} |
|||
|
|||
int32_t LP_utxocollisions(struct LP_utxoinfo *ptrs[],struct LP_utxoinfo *refutxo) |
|||
{ |
|||
int32_t iambob,n = 0; struct LP_utxoinfo *utxo; struct _LP_utxoinfo u; |
|||
if ( refutxo == 0 ) |
|||
return(0); |
|||
portable_mutex_lock(&LP_utxomutex); |
|||
for (iambob=0; iambob<=1; iambob++) |
|||
{ |
|||
if ( (utxo= _LP_utxofind(iambob,refutxo->payment.txid,refutxo->payment.vout)) != 0 && utxo != refutxo ) |
|||
n = LP_utxoaddptrs(ptrs,n,utxo); |
|||
if ( (utxo= _LP_utxo2find(iambob,refutxo->payment.txid,refutxo->payment.vout)) != 0 && utxo != refutxo ) |
|||
n = LP_utxoaddptrs(ptrs,n,utxo); |
|||
u = (refutxo->iambob != 0) ? refutxo->deposit : refutxo->fee; |
|||
if ( (utxo= _LP_utxofind(iambob,u.txid,u.vout)) != 0 && utxo != refutxo ) |
|||
n = LP_utxoaddptrs(ptrs,n,utxo); |
|||
if ( (utxo= _LP_utxo2find(iambob,u.txid,u.vout)) != 0 && utxo != refutxo ) |
|||
n = LP_utxoaddptrs(ptrs,n,utxo); |
|||
} |
|||
portable_mutex_unlock(&LP_utxomutex); |
|||
if ( 0 && n > 0 ) |
|||
printf("LP_utxocollisions n.%d\n",n); |
|||
return(n); |
|||
} |
|||
|
|||
int32_t _LP_availableset(struct LP_utxoinfo *utxo) |
|||
{ |
|||
int32_t flag = 0; |
|||
if ( utxo != 0 ) |
|||
{ |
|||
if ( bits256_nonz(utxo->S.otherpubkey) != 0 ) |
|||
flag = 1, memset(&utxo->S.otherpubkey,0,sizeof(utxo->S.otherpubkey)); |
|||
if ( utxo->S.swap != 0 ) |
|||
flag = 1, utxo->S.swap = 0; |
|||
if ( utxo->T.swappending != 0 ) |
|||
flag = 1, utxo->T.swappending = 0; |
|||
return(flag); |
|||
} |
|||
return(0); |
|||
} |
|||
|
|||
void _LP_unavailableset(struct LP_utxoinfo *utxo,bits256 otherpubkey) |
|||
{ |
|||
if ( utxo != 0 ) |
|||
{ |
|||
utxo->T.swappending = (uint32_t)(time(NULL) + LP_RESERVETIME); |
|||
utxo->S.otherpubkey = otherpubkey; |
|||
} |
|||
} |
|||
|
|||
void LP_unavailableset(struct LP_utxoinfo *utxo,bits256 otherpubkey) |
|||
{ |
|||
struct LP_utxoinfo *ptrs[8]; int32_t i,n; struct _LP_utxoinfo u; |
|||
memset(ptrs,0,sizeof(ptrs)); |
|||
if ( (n= LP_utxocollisions(ptrs,utxo)) > 0 ) |
|||
{ |
|||
for (i=0; i<n; i++) |
|||
_LP_unavailableset(ptrs[i],otherpubkey); |
|||
} |
|||
u = (utxo->iambob != 0) ? utxo->deposit : utxo->fee; |
|||
char str[65],str2[65]; printf("UTXO.[%d] RESERVED %s/v%d %s/v%d collisions.%d\n",utxo->iambob,bits256_str(str,utxo->payment.txid),utxo->payment.vout,bits256_str(str2,u.txid),u.vout,n); |
|||
_LP_unavailableset(utxo,otherpubkey); |
|||
} |
|||
|
|||
void LP_availableset(struct LP_utxoinfo *utxo) |
|||
{ |
|||
struct LP_utxoinfo *ptrs[8]; int32_t i,n,count = 0; struct _LP_utxoinfo u; |
|||
if ( utxo != 0 ) |
|||
{ |
|||
memset(ptrs,0,sizeof(ptrs)); |
|||
if ( (n= LP_utxocollisions(ptrs,utxo)) > 0 ) |
|||
{ |
|||
for (i=0; i<n; i++) |
|||
count += _LP_availableset(ptrs[i]); |
|||
} |
|||
count += _LP_availableset(utxo); |
|||
if ( count > 0 ) |
|||
{ |
|||
u = (utxo->iambob != 0) ? utxo->deposit : utxo->fee; |
|||
char str[65],str2[65]; printf("UTXO.[%d] AVAIL %s/v%d %s/v%d collisions.%d\n",utxo->iambob,bits256_str(str,utxo->payment.txid),utxo->payment.vout,bits256_str(str2,u.txid),u.vout,n); |
|||
} |
|||
} |
|||
} |
|||
*/ |
|||
|
|||
cJSON *LP_inventoryjson(cJSON *item,struct LP_utxoinfo *utxo) |
|||
{ |
|||
struct _LP_utxoinfo u; |
|||
//jaddstr(item,"method","oldutxo");
|
|||
if ( utxo == 0 ) |
|||
return(item); |
|||
if ( utxo->gui[0] != 0 ) |
|||
jaddstr(item,"gui",utxo->gui); |
|||
jaddstr(item,"coin",utxo->coin); |
|||
//jaddnum(item,"now",time(NULL));
|
|||
jaddnum(item,"iambob",utxo->iambob); |
|||
jaddstr(item,"address",utxo->coinaddr); |
|||
jaddbits256(item,"txid",utxo->payment.txid); |
|||
jaddnum(item,"vout",utxo->payment.vout); |
|||
jadd64bits(item,"value",utxo->payment.value); |
|||
jadd64bits(item,"satoshis",utxo->S.satoshis); |
|||
u = (utxo->iambob != 0) ? utxo->deposit : utxo->fee; |
|||
if ( bits256_nonz(u.txid) != 0 ) |
|||
{ |
|||
jaddbits256(item,"txid2",u.txid); |
|||
jaddnum(item,"vout2",u.vout); |
|||
jadd64bits(item,"value2",u.value); |
|||
} |
|||
if ( utxo->T.swappending != 0 ) |
|||
jaddnum(item,"pending",utxo->T.swappending); |
|||
if ( utxo->iambob != 0 ) |
|||
{ |
|||
jaddbits256(item,"srchash",utxo->pubkey);//LP_mypub25519);
|
|||
if ( bits256_nonz(utxo->S.otherpubkey) != 0 ) |
|||
jaddbits256(item,"desthash",utxo->S.otherpubkey); |
|||
} |
|||
else |
|||
{ |
|||
jaddbits256(item,"desthash",utxo->pubkey);//LP_mypub25519);
|
|||
if ( bits256_nonz(utxo->S.otherpubkey) != 0 ) |
|||
jaddbits256(item,"srchash",utxo->S.otherpubkey); |
|||
} |
|||
//if ( utxo->S.swap != 0 )
|
|||
// jaddstr(item,"swap","in progress");
|
|||
if ( utxo->T.spentflag != 0 ) |
|||
jaddnum(item,"spent",utxo->T.spentflag); |
|||
jaddnum(item,"session",utxo->T.sessionid); |
|||
return(item); |
|||
} |
|||
|
|||
cJSON *LP_utxojson(struct LP_utxoinfo *utxo) |
|||
{ |
|||
cJSON *item = cJSON_CreateObject(); |
|||
item = LP_inventoryjson(item,utxo); |
|||
jaddbits256(item,"pubkey",utxo->pubkey); |
|||
//jaddnum(item,"profit",utxo->S.profitmargin);
|
|||
jaddstr(item,"base",utxo->coin); |
|||
//jaddstr(item,"script",utxo->spendscript);
|
|||
return(item); |
|||
} |
|||
|
|||
struct LP_utxoinfo *LP_utxo_bestfit(char *symbol,uint64_t destsatoshis) |
|||
{ |
|||
uint64_t srcvalue,srcvalue2; struct LP_utxoinfo *utxo,*tmp,*bestutxo = 0; int32_t bestsize,iambob = 0; |
|||
if ( symbol == 0 || destsatoshis == 0 ) |
|||
{ |
|||
printf("LP_utxo_bestfit error symbol.%p %.8f\n",symbol,dstr(destsatoshis)); |
|||
return(0); |
|||
} |
|||
HASH_ITER(hh,G.LP_utxoinfos[iambob],utxo,tmp) |
|||
{ |
|||
if ( strcmp(symbol,utxo->coin) != 0 ) |
|||
continue; |
|||
if ( LP_isavailable(utxo) > 0 && LP_ismine(utxo) > 0 ) |
|||
{ |
|||
//printf("(%.8f %.8f %.8f)\n",dstr(utxo->payment.value),dstr(utxo->fee.value),dstr(utxo->S.satoshis));
|
|||
//char str[65]; printf("s%u %d [%.8f vs %.8f] check %s.%s avail.%d ismine.%d >= %d\n",utxo->T.spentflag,LP_iseligible(&srcvalue,&srcvalue2,utxo->iambob,symbol,utxo->payment.txid,utxo->payment.vout,utxo->S.satoshis,utxo->fee.txid,utxo->fee.vout),dstr(destsatoshis),dstr(utxo->S.satoshis),utxo->coin,bits256_str(str,utxo->payment.txid),LP_isavailable(utxo) > 0,LP_ismine(utxo) > 0,utxo->S.satoshis >= destsatoshis);
|
|||
bestsize = 0; |
|||
if ( bestutxo == 0 ) |
|||
{ |
|||
if ( utxo->S.satoshis > destsatoshis/LP_MINCLIENTVOL ) |
|||
bestsize = 1; |
|||
} |
|||
else |
|||
{ |
|||
if ( bestutxo->S.satoshis < destsatoshis ) |
|||
{ |
|||
if ( utxo->S.satoshis > destsatoshis ) |
|||
bestsize = 1; |
|||
else if ( utxo->S.satoshis > bestutxo->S.satoshis ) |
|||
bestsize = 1; |
|||
} |
|||
else |
|||
{ |
|||
if ( utxo->S.satoshis > destsatoshis && utxo->S.satoshis < bestutxo->S.satoshis ) |
|||
bestsize = 1; |
|||
} |
|||
} |
|||
if ( bestsize > 0 ) |
|||
{ |
|||
//printf("bestsize.%d %.8f %.8f -> %.8f\n",bestsize,dstr(utxo->payment.value),dstr(utxo->fee.value),dstr(utxo->S.satoshis));
|
|||
if ( LP_iseligible(&srcvalue,&srcvalue2,utxo->iambob,symbol,utxo->payment.txid,utxo->payment.vout,utxo->S.satoshis,utxo->fee.txid,utxo->fee.vout) == 0 ) |
|||
{ |
|||
//if ( utxo->T.spentflag == 0 )
|
|||
// utxo->T.spentflag = (uint32_t)time(NULL);
|
|||
continue; |
|||
} |
|||
bestutxo = utxo; |
|||
} //else printf("skip alice utxo %.8f vs dest %.8f, bestsize.%d %p\n",dstr(utxo->S.satoshis),dstr(destsatoshis),bestsize,bestutxo);
|
|||
} |
|||
} |
|||
return(bestutxo); |
|||
} |
|||
|
|||
void LP_spentnotify(struct LP_utxoinfo *utxo,int32_t selector) |
|||
{ |
|||
if ( utxo == 0 ) |
|||
return; |
|||
utxo->T.spentflag = (uint32_t)time(NULL); |
|||
} |
|||
|
|||
struct LP_utxoinfo *LP_utxoadd(int32_t iambob,char *symbol,bits256 txid,int32_t vout,int64_t value,bits256 txid2,int32_t vout2,int64_t value2,char *coinaddr,bits256 pubkey,char *gui,uint32_t sessionid,uint64_t satoshis) |
|||
{ |
|||
uint64_t val,val2=0,txfee; int32_t spendvini,numconfirms,selector; bits256 spendtxid; struct iguana_info *coin; struct _LP_utxoinfo u; struct LP_utxoinfo *utxo = 0; |
|||
if ( symbol == 0 || symbol[0] == 0 || coinaddr == 0 || coinaddr[0] == 0 || bits256_nonz(txid) == 0 || bits256_nonz(txid2) == 0 || vout < 0 || vout2 < 0 || value <= 0 || value2 <= 0 )//|| sessionid == 0 )
|
|||
{ |
|||
char str[65],str2[65]; printf("REJECT (%s) iambob.%d %s utxoadd.(%.8f %.8f) %s/v%d %s/v%d\n",coinaddr,iambob,symbol,dstr(value),dstr(value2),bits256_str(str,txid),vout,bits256_str(str2,txid2),vout2); |
|||
printf("session.%u addutxo %d %d %d %d %d %d %d %d\n",sessionid,symbol == 0,coinaddr == 0,bits256_nonz(txid) == 0,bits256_nonz(txid2) == 0,vout < 0,vout2 < 0,value <= 0,value2 <= 0); |
|||
return(0); |
|||
} |
|||
if ( (coin= LP_coinfind(symbol)) == 0 || (IAMLP == 0 && coin->inactive != 0) ) |
|||
{ |
|||
//printf("LP_utxoadd reject inactive %s\n",symbol);
|
|||
return(0); |
|||
} |
|||
txfee = LP_txfeecalc(coin,0,0); |
|||
/*if ( iambob != 0 && value2 < 9 * (satoshis >> 3) + 2*txfee ) // big txfee padding
|
|||
{ |
|||
if ( value2 > 2*txfee ) |
|||
tmpsatoshis = (((value2 - 2*txfee) / 9) << 3); |
|||
else |
|||
{ |
|||
printf("value2 %.8f <= 2 * %.8f\n",dstr(value2),dstr(txfee)); |
|||
return(0); |
|||
} |
|||
} else tmpsatoshis = (satoshis - txfee);*/ |
|||
char str[65],str2[65],dispflag = 0;//(iambob == 0);
|
|||
if ( iambob == 0 && bits256_cmp(pubkey,G.LP_mypub25519) != 0 ) |
|||
{ |
|||
printf("trying to add Alice utxo when not mine? %s/v%d\n",bits256_str(str,txid),vout); |
|||
return(0); |
|||
} |
|||
if ( coin->inactive == 0 ) |
|||
{ |
|||
if ( LP_iseligible(&val,&val2,iambob,symbol,txid,vout,satoshis,txid2,vout2) <= 0 ) |
|||
{ |
|||
static uint32_t counter; |
|||
if ( counter++ < 3 ) |
|||
printf("iambob.%d utxoadd %s inactive.%u got ineligible txid value %.8f:%.8f, value2 %.8f:%.8f, tmpsatoshis %.8f\n",iambob,symbol,coin->inactive,dstr(value),dstr(val),dstr(value2),dstr(val2),dstr(satoshis)); |
|||
return(0); |
|||
} |
|||
if ( (numconfirms= LP_numconfirms(symbol,coinaddr,txid,vout,0)) <= 0 ) |
|||
{ |
|||
printf("LP_utxoadd reject numconfirms.%d %s.%s\n",numconfirms,symbol,bits256_str(str,txid)); |
|||
return(0); |
|||
} |
|||
if ( (numconfirms= LP_numconfirms(symbol,coinaddr,txid2,vout2,0)) <= 0 ) |
|||
{ |
|||
printf("LP_utxoadd reject2 numconfirms.%d %s %s/v%d\n",numconfirms,symbol,bits256_str(str,txid2),vout2); |
|||
return(0); |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
val = value; |
|||
val2 = value2; |
|||
} |
|||
dispflag = 0; |
|||
if ( dispflag != 0 ) |
|||
printf("%.8f %.8f %s iambob.%d %s utxoadd.(%.8f %.8f) %s %s\n",dstr(val),dstr(val2),coinaddr,iambob,symbol,dstr(value),dstr(value2),bits256_str(str,txid),bits256_str(str2,txid2)); |
|||
dispflag = 1; |
|||
if ( (utxo= LP_utxofinds(iambob,txid,vout,txid2,vout2)) != 0 ) |
|||
{ |
|||
if ( 0 && LP_ismine(utxo) == 0 ) |
|||
{ |
|||
char str2[65],str3[65]; printf("iambob.%d %s %s utxoadd.(%.8f %.8f) %s %s\n",iambob,bits256_str(str3,pubkey),symbol,dstr(value),dstr(value2),bits256_str(str,txid),bits256_str(str2,txid2)); |
|||
printf("duplicate %.8f %.8f %.8f vs utxo.(%.8f %.8f %.8f)\n",dstr(value),dstr(value2),dstr(satoshis),dstr(utxo->payment.value),dstr(utxo->deposit.value),dstr(utxo->S.satoshis)); |
|||
} |
|||
u = (utxo->iambob != 0) ? utxo->deposit : utxo->fee; |
|||
if ( bits256_cmp(txid,utxo->payment.txid) != 0 || bits256_cmp(txid2,u.txid) != 0 || vout != utxo->payment.vout || value != utxo->payment.value || satoshis != utxo->S.satoshis || vout2 != u.vout || value2 != u.value || strcmp(symbol,utxo->coin) != 0 || strcmp(coinaddr,utxo->coinaddr) != 0 || bits256_cmp(pubkey,utxo->pubkey) != 0 ) |
|||
{ |
|||
utxo->T.errors++; |
|||
char str[65],str2[65],str3[65],str4[65],str5[65],str6[65]; |
|||
if ( utxo->T.spentflag != 0 || LP_txvalue(0,utxo->coin,utxo->payment.txid,utxo->payment.vout) < utxo->payment.value || LP_txvalue(0,utxo->coin,u.txid,u.vout) < u.value ) |
|||
{ |
|||
//if ( utxo->T.spentflag == 0 )
|
|||
// utxo->T.spentflag = (uint32_t)time(NULL);
|
|||
printf("original utxo pair not valid\n"); |
|||
if ( dispflag != 0 ) |
|||
printf("error on subsequent utxo iambob.%d %.8f %.8f add.(%s %s) when.(%s %s) %d %d %d %d %d %d %d %d %d %d pubkeys.(%s vs %s)\n",iambob,dstr(val),dstr(val2),bits256_str(str,txid),bits256_str(str2,txid2),bits256_str(str3,utxo->payment.txid),bits256_str(str4,utxo->deposit.txid),bits256_cmp(txid,utxo->payment.txid) != 0,bits256_cmp(txid2,u.txid) != 0,vout != utxo->payment.vout,satoshis != utxo->S.satoshis,vout2 != u.vout,value2 != u.value,strcmp(symbol,utxo->coin) != 0,strcmp(coinaddr,utxo->coinaddr) != 0,bits256_cmp(pubkey,utxo->pubkey) != 0,value != utxo->payment.value,bits256_str(str5,pubkey),bits256_str(str6,utxo->pubkey)); |
|||
utxo = 0; |
|||
} |
|||
} |
|||
if ( utxo != 0 ) |
|||
{ |
|||
if ( utxo->T.sessionid == 0 ) |
|||
utxo->T.sessionid = sessionid; |
|||
//else if ( profitmargin > SMALLVAL )
|
|||
// utxo->S.profitmargin = profitmargin;
|
|||
utxo->T.lasttime = (uint32_t)time(NULL); |
|||
//printf("return existing utxo[%d] %s %s\n",iambob,bits256_str(str,utxo->payment.txid),bits256_str(str2,iambob != 0 ? utxo->deposit.txid : utxo->fee.txid));
|
|||
return(utxo); |
|||
} |
|||
} |
|||
utxo = calloc(1,sizeof(*utxo)); |
|||
//utxo->S.profitmargin = profitmargin;
|
|||
utxo->pubkey = pubkey; |
|||
safecopy(utxo->gui,gui,sizeof(utxo->gui)); |
|||
safecopy(utxo->coin,symbol,sizeof(utxo->coin)); |
|||
safecopy(utxo->coinaddr,coinaddr,sizeof(utxo->coinaddr)); |
|||
//safecopy(utxo->spendscript,spendscript,sizeof(utxo->spendscript));
|
|||
utxo->payment.txid = txid; |
|||
utxo->payment.vout = vout; |
|||
utxo->payment.value = value; |
|||
utxo->S.satoshis = satoshis; |
|||
if ( (utxo->iambob= iambob) != 0 ) |
|||
{ |
|||
utxo->deposit.txid = txid2; |
|||
utxo->deposit.vout = vout2; |
|||
utxo->deposit.value = value2; |
|||
} |
|||
else |
|||
{ |
|||
utxo->fee.txid = txid2; |
|||
utxo->fee.vout = vout2; |
|||
utxo->fee.value = value2; |
|||
} |
|||
LP_utxosetkey(utxo->key,txid,vout); |
|||
LP_utxosetkey(utxo->key2,txid2,vout2); |
|||
if ( LP_ismine(utxo) > 0 ) |
|||
utxo->T.sessionid = G.LP_sessionid; |
|||
else utxo->T.sessionid = sessionid; |
|||
if ( coin->inactive == 0 && (selector= LP_mempool_vinscan(&spendtxid,&spendvini,symbol,coinaddr,txid,vout,txid2,vout2)) >= 0 ) |
|||
{ |
|||
printf("utxoadd selector.%d spent in mempool %s vini.%d",selector,bits256_str(str,spendtxid),spendvini); |
|||
utxo->T.spentflag = (uint32_t)time(NULL); |
|||
} |
|||
//printf(" %s %.8f %.8f %p addutxo.%d (%s %s) session.%u iambob.%d <<<<<<<<<<<<<<< %.8f\n",symbol,dstr(value),dstr(value2),utxo,LP_ismine(utxo) > 0,bits256_str(str,utxo->payment.txid),bits256_str(str2,iambob != 0 ? utxo->deposit.txid : utxo->fee.txid),utxo->T.sessionid,iambob,dstr(satoshis));
|
|||
portable_mutex_lock(&LP_utxomutex); |
|||
HASH_ADD_KEYPTR(hh,G.LP_utxoinfos[iambob],utxo->key,sizeof(utxo->key),utxo); |
|||
if ( _LP_utxo2find(iambob,txid2,vout2) == 0 ) |
|||
HASH_ADD_KEYPTR(hh2,G.LP_utxoinfos2[iambob],utxo->key2,sizeof(utxo->key2),utxo); |
|||
portable_mutex_unlock(&LP_utxomutex); |
|||
if ( iambob != 0 ) |
|||
{ |
|||
if ( LP_ismine(utxo) > 0 ) |
|||
{ |
|||
//LP_utxo_clientpublish(utxo);
|
|||
if ( LP_mypeer != 0 ) |
|||
utxo->T.lasttime = (uint32_t)time(NULL); |
|||
} |
|||
} |
|||
return(utxo); |
|||
} |
|||
|
|||
int32_t _LP_utxos_remove(bits256 txid,int32_t vout) |
|||
{ |
|||
struct LP_utxoinfo *utxo,*utxo2; int32_t retval = 0,iambob = 1; |
|||
utxo = utxo2 = 0; |
|||
if ( (utxo= _LP_utxofind(iambob,txid,vout)) != 0 ) |
|||
{ |
|||
if ( LP_isavailable(utxo) == 0 ) |
|||
retval = -1; |
|||
else |
|||
{ |
|||
if ( (utxo2= _LP_utxo2find(iambob,txid,vout)) != 0 ) |
|||
{ |
|||
if ( LP_isavailable(utxo) == 0 ) |
|||
retval = -1; |
|||
else |
|||
{ |
|||
_LP_utxo_delete(iambob,utxo); |
|||
_LP_utxo2_delete(iambob,utxo2); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
else if ( (utxo2= _LP_utxo2find(iambob,txid,vout)) != 0 ) |
|||
{ |
|||
if ( LP_isavailable(utxo2) == 0 ) |
|||
retval = -1; |
|||
else _LP_utxo2_delete(iambob,utxo2); |
|||
} |
|||
return(retval); |
|||
} |
|||
|
|||
int32_t LP_utxos_remove(bits256 txid,int32_t vout) |
|||
{ |
|||
int32_t retval; |
|||
portable_mutex_lock(&LP_utxomutex); |
|||
retval = _LP_utxos_remove(txid,vout); |
|||
portable_mutex_unlock(&LP_utxomutex); |
|||
return(retval); |
|||
} |
|||
|
|||
cJSON *LP_inventory(char *symbol) |
|||
{ |
|||
struct LP_utxoinfo *utxo,*tmp; struct _LP_utxoinfo u; char *myipaddr; cJSON *array; uint64_t val,val2; int32_t iambob = 0; struct iguana_info *coin; |
|||
array = cJSON_CreateArray(); |
|||
if ( LP_mypeer != 0 ) |
|||
myipaddr = LP_mypeer->ipaddr; |
|||
else myipaddr = "127.0.0.1"; |
|||
if ( (coin= LP_coinfind(symbol)) != 0 ) |
|||
LP_listunspent_both(symbol,coin->smartaddr,0); |
|||
HASH_ITER(hh,G.LP_utxoinfos[iambob],utxo,tmp) |
|||
{ |
|||
char str[65]; |
|||
//printf("iambob.%d iterate %s\n",iambob,bits256_str(str,LP_mypub25519));
|
|||
if ( LP_isunspent(utxo) != 0 && strcmp(symbol,utxo->coin) == 0 && utxo->iambob == iambob && LP_ismine(utxo) > 0 ) |
|||
{ |
|||
u = (iambob != 0) ? utxo->deposit : utxo->fee; |
|||
if ( LP_iseligible(&val,&val2,iambob,utxo->coin,utxo->payment.txid,utxo->payment.vout,utxo->S.satoshis,u.txid,u.vout) == 0 ) |
|||
{ |
|||
//if ( utxo->T.spentflag == 0 )
|
|||
// utxo->T.spentflag = (uint32_t)time(NULL);
|
|||
//printf("%s %s ineligible %.8f %.8f\n",utxo->coin,bits256_str(str,u.txid),dstr(val),dstr(val2));
|
|||
continue; |
|||
} |
|||
//if ( iambob != 0 )
|
|||
// LP_utxo_clientpublish(utxo);
|
|||
jaddi(array,LP_inventoryjson(cJSON_CreateObject(),utxo)); |
|||
} |
|||
else if ( 0 && LP_ismine(utxo) > 0 && strcmp(symbol,utxo->coin) == 0 ) |
|||
printf("skip %s %s %d %d %d %d\n",utxo->coin,bits256_str(str,utxo->payment.txid),LP_isunspent(utxo) != 0,strcmp(symbol,utxo->coin) == 0,utxo->iambob == iambob,LP_ismine(utxo) > 0); |
|||
} |
|||
return(array); |
|||
} |
|||
|
|||
int32_t LP_maxvalue(uint64_t *values,int32_t n) |
|||
{ |
|||
int32_t i,maxi = -1; uint64_t maxval = 0; |
|||
for (i=0; i<n; i++) |
|||
if ( values[i] > maxval ) |
|||
{ |
|||
maxi = i; |
|||
maxval = values[i]; |
|||
} |
|||
return(maxi); |
|||
} |
|||
|
|||
int32_t LP_nearestvalue(int32_t iambob,uint64_t *values,int32_t n,uint64_t targetval) |
|||
{ |
|||
int32_t i,mini = -1; int64_t dist; uint64_t mindist = (1 << 31); |
|||
for (i=0; i<n; i++) |
|||
{ |
|||
dist = (values[i] - targetval); |
|||
if ( iambob != 0 && dist < 0 && -dist < values[i]/10 ) |
|||
dist = -dist; |
|||
//printf("(%.8f %.8f %.8f).%d ",dstr(values[i]),dstr(dist),dstr(mindist),mini);
|
|||
if ( dist >= 0 && dist < mindist ) |
|||
{ |
|||
mini = i; |
|||
mindist = dist; |
|||
} |
|||
} |
|||
return(mini); |
|||
} |
|||
|
|||
int32_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 myprivkey,bits256 mypub) |
|||
{ |
|||
int32_t enable_utxos = 0; |
|||
char *script,destaddr[64]; struct LP_utxoinfo *utxo; cJSON *array,*item; bits256 txid,deposittxid; int32_t used,i,flag=0,height,n,cmpflag,iambob,vout,depositvout; uint64_t *values=0,satoshis,txfee,biggerval,value,total = 0; int64_t targetval; |
|||
if ( coin == 0 || (IAMLP == 0 && coin->inactive != 0) ) |
|||
{ |
|||
//printf("coin not active\n");
|
|||
return(0); |
|||
} |
|||
if ( coin->privkeydepth > 0 ) |
|||
return(0); |
|||
coin->privkeydepth++; |
|||
LP_address(coin,coin->smartaddr); |
|||
if ( coin->inactive == 0 ) |
|||
LP_listunspent_issue(coin->symbol,coin->smartaddr,0); |
|||
array = LP_listunspent(coin->symbol,coin->smartaddr); |
|||
if ( array != 0 ) |
|||
{ |
|||
txfee = LP_txfeecalc(coin,0,0); |
|||
if ( is_cJSON_Array(array) != 0 && (n= cJSON_GetArraySize(array)) > 0 ) |
|||
{ |
|||
coin->numutxos = n; |
|||
//printf("LP_privkey_init %s %d\n",coin->symbol,n);
|
|||
for (iambob=0; iambob<=1; iambob++) |
|||
{ |
|||
if ( iambob == 0 ) |
|||
values = calloc(n,sizeof(*values)); |
|||
else memset(values,0,n * sizeof(*values)); |
|||
used = 0; |
|||
for (i=0; i<n; i++) |
|||
{ |
|||
item = jitem(array,i); |
|||
if ( coin->electrum == 0 ) |
|||
{ |
|||
txid = jbits256(item,"txid"); |
|||
vout = juint(item,"vout"); |
|||
value = LP_value_extract(item,0); |
|||
height = LP_txheight(coin,txid);//LP_getheight(coin) - jint(item,"confirmations") + 1;
|
|||
} |
|||
else |
|||
{ |
|||
txid = jbits256(item,"tx_hash"); |
|||
vout = juint(item,"tx_pos"); |
|||
value = j64bits(item,"value"); |
|||
height = jint(item,"height"); |
|||
} |
|||
satoshis = LP_txvalue(destaddr,coin->symbol,txid,vout); |
|||
if ( satoshis != 0 && satoshis != value ) |
|||
printf("%s %s privkey_init value %.8f vs %.8f (%s) %.8f %.8f\n",coin->symbol,coin->smartaddr,dstr(satoshis),dstr(value),jprint(item,0),jdouble(item,"amount"),jdouble(item,"interest")); |
|||
if ( coin->electrum != 0 || LP_inventory_prevent(iambob,coin->symbol,txid,vout) == 0 )//&& height > 0 )
|
|||
{ |
|||
values[i] = satoshis; |
|||
//flag += LP_address_utxoadd(coin,destaddr,txid,vout,satoshis,height,-1);
|
|||
} else used++; |
|||
} |
|||
//printf("array.%d\n",n);
|
|||
while ( used < n-1 ) |
|||
{ |
|||
//for (i=0; i<n; i++)
|
|||
// printf("%.8f ",dstr(values[i]));
|
|||
//printf("used.%d of n.%d\n",used,n);
|
|||
if ( (i= LP_maxvalue(values,n)) >= 0 ) |
|||
{ |
|||
item = jitem(array,i); |
|||
if ( coin->electrum == 0 ) |
|||
{ |
|||
deposittxid = jbits256(item,"txid"); |
|||
depositvout = juint(item,"vout"); |
|||
script = jstr(item,"scriptPubKey"); |
|||
} |
|||
else |
|||
{ |
|||
deposittxid = jbits256(item,"tx_hash"); |
|||
depositvout = juint(item,"tx_pos"); |
|||
script = coin->smartaddr; |
|||
} |
|||
biggerval = values[i]; |
|||
values[i] = 0, used++; |
|||
if ( iambob == 0 ) |
|||
targetval = (biggerval / 776) + txfee; |
|||
else targetval = (biggerval / 9) * 8 + 2*txfee; |
|||
if ( targetval < txfee*2 ) |
|||
targetval = txfee*2; |
|||
//printf("iambob.%d i.%d deposit %.8f min %.8f target %.8f\n",iambob,i,dstr(biggerval),dstr((1+LP_MINSIZE_TXFEEMULT)*txfee),dstr(targetval));
|
|||
if ( biggerval < (1+LP_MINSIZE_TXFEEMULT)*txfee ) |
|||
continue; |
|||
i = -1; |
|||
if ( iambob != 0 ) |
|||
{ |
|||
if ( (i= LP_nearestvalue(iambob,values,n,targetval)) < 0 ) |
|||
targetval /= 4; |
|||
if ( targetval < txfee*(1+LP_MINSIZE_TXFEEMULT) ) |
|||
continue; |
|||
} |
|||
if ( i >= 0 || (i= LP_nearestvalue(iambob,values,n,targetval)) >= 0 ) |
|||
{ |
|||
//printf("iambob.%d i.%d %.8f target %.8f\n",iambob,i,dstr(biggerval),dstr(targetval));
|
|||
item = jitem(array,i); |
|||
cmpflag = 0; |
|||
if ( coin->electrum == 0 ) |
|||
{ |
|||
txid = jbits256(item,"txid"); |
|||
vout = juint(item,"vout"); |
|||
if ( jstr(item,"scriptPubKey") != 0 && strcmp(script,jstr(item,"scriptPubKey")) == 0 ) |
|||
cmpflag = 1; |
|||
} |
|||
else |
|||
{ |
|||
txid = jbits256(item,"tx_hash"); |
|||
vout = juint(item,"tx_pos"); |
|||
cmpflag = 1; |
|||
} |
|||
if ( cmpflag != 0 ) |
|||
{ |
|||
value = values[i]; |
|||
values[i] = 0, used++; |
|||
portable_mutex_lock(&LP_UTXOmutex); |
|||
if ( iambob != 0 ) |
|||
{ |
|||
if ( (utxo= LP_utxoadd(1,coin->symbol,txid,vout,value,deposittxid,depositvout,biggerval,coin->smartaddr,mypub,LP_gui,G.LP_sessionid,value)) != 0 ) |
|||
{ |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
//printf("call utxoadd\n");
|
|||
if ( (utxo= LP_utxoadd(0,coin->symbol,deposittxid,depositvout,biggerval,txid,vout,value,coin->smartaddr,mypub,LP_gui,G.LP_sessionid,biggerval)) != 0 ) |
|||
{ |
|||
} |
|||
} |
|||
portable_mutex_unlock(&LP_UTXOmutex); |
|||
total += value; |
|||
} // else printf("scriptmismatch.(%s) vs %s\n",script,jprint(item,0));
|
|||
} //else printf("nothing near i.%d\n",i);
|
|||
} else break; |
|||
} |
|||
if ( enable_utxos == 0 ) |
|||
break; |
|||
} |
|||
} |
|||
free_json(array); |
|||
if ( 0 && flag != 0 ) |
|||
LP_postutxos(coin->symbol,coin->smartaddr); |
|||
} |
|||
if ( values != 0 ) |
|||
free(values); |
|||
if ( coin->privkeydepth > 0 ) |
|||
coin->privkeydepth--; |
|||
//printf("privkey.%s %.8f\n",symbol,dstr(total));
|
|||
return(flag); |
|||
} |
|||
|
|||
char *LP_secretaddresses(void *ctx,char *prefix,char *passphrase,int32_t n,uint8_t taddr,uint8_t pubtype) |
|||
{ |
|||
int32_t i; uint8_t tmptype,pubkey33[33],rmd160[20]; char output[777*45],str[65],str2[65],buf[8192],wifstr[128],coinaddr[64]; bits256 checkprivkey,privkey,pubkey; cJSON *retjson; |
|||
retjson = cJSON_CreateObject(); |
|||
if ( prefix == 0 || prefix[0] == 0 ) |
|||
prefix = "secretaddress"; |
|||
if ( passphrase == 0 || passphrase[0] == 0 ) |
|||
passphrase = "password"; |
|||
if ( n <= 0 ) |
|||
n = 16; |
|||
else if ( n > 777 ) |
|||
n = 777; |
|||
conv_NXTpassword(privkey.bytes,pubkey.bytes,(uint8_t *)passphrase,(int32_t)strlen(passphrase)); |
|||
bitcoin_priv2pub(ctx,pubkey33,coinaddr,privkey,taddr,pubtype); |
|||
printf("generator (%s) secrets.[%d] <%s> t.%u p.%u\n",coinaddr,n,passphrase,taddr,pubtype); |
|||
sprintf(output,"\"addresses\":["); |
|||
for (i=0; i<n; i++) |
|||
{ |
|||
sprintf(buf,"%s %s %03d",prefix,passphrase,i); |
|||
conv_NXTpassword(privkey.bytes,pubkey.bytes,(uint8_t *)buf,(int32_t)strlen(buf)); |
|||
bitcoin_priv2pub(ctx,pubkey33,coinaddr,privkey,taddr,pubtype); |
|||
bitcoin_priv2wif(0,wifstr,privkey,188); |
|||
bitcoin_wif2priv(0,&tmptype,&checkprivkey,wifstr); |
|||
bitcoin_addr2rmd160(taddr,&tmptype,rmd160,coinaddr); |
|||
if ( bits256_cmp(checkprivkey,privkey) != 0 ) |
|||
{ |
|||
printf("WIF.(%s) error -> %s vs %s?\n",wifstr,bits256_str(str,privkey),bits256_str(str2,checkprivkey)); |
|||
free_json(retjson); |
|||
return(clonestr("{\"error\":\"couldnt validate wifstr\"}")); |
|||
} |
|||
else if ( tmptype != pubtype ) |
|||
{ |
|||
printf("checktype.%d != pubtype.%d\n",tmptype,pubtype); |
|||
free_json(retjson); |
|||
return(clonestr("{\"error\":\"couldnt validate pubtype\"}")); |
|||
} |
|||
jaddstr(retjson,coinaddr,wifstr); |
|||
sprintf(output+strlen(output),"\\\"%s\\\"%c ",coinaddr,i<n-1?',':' '); |
|||
printf("./komodo-cli jumblr_secret %s\n",coinaddr); |
|||
} |
|||
printf("%s]\n",output); |
|||
return(jprint(retjson,1)); |
|||
} |
|||
|
|||
bits256 LP_privkeycalc(void *ctx,uint8_t *pubkey33,bits256 *pubkeyp,struct iguana_info *coin,char *passphrase,char *wifstr) |
|||
{ |
|||
//static uint32_t counter;
|
|||
bits256 privkey,userpub,userpass,checkkey; char tmpstr[128]; cJSON *retjson; uint8_t tmptype; |
|||
if ( passphrase != 0 && passphrase[0] != 0 ) |
|||
{ |
|||
conv_NXTpassword(privkey.bytes,pubkeyp->bytes,(uint8_t *)passphrase,(int32_t)strlen(passphrase)); |
|||
//vcalc_sha256(0,checkkey.bytes,(uint8_t *)passphrase,(int32_t)strlen(passphrase));
|
|||
//printf("SHA256.(%s) ",bits256_str(pstr,checkkey));
|
|||
//printf("privkey.(%s)\n",bits256_str(pstr,privkey));
|
|||
} |
|||
else |
|||
{ |
|||
bitcoin_wif2priv(coin->wiftaddr,&tmptype,&privkey,wifstr); |
|||
if ( 0 ) |
|||
{ |
|||
char str[65],str2[65]; |
|||
checkkey = iguana_wif2privkey(wifstr); |
|||
if ( bits256_cmp(checkkey,privkey) != 0 ) |
|||
printf("WIF.(%s) -> %s or %s?\n",wifstr,bits256_str(str,privkey),bits256_str(str2,checkkey)); |
|||
} |
|||
} |
|||
privkey.bytes[0] &= 248, privkey.bytes[31] &= 127, privkey.bytes[31] |= 64; |
|||
bitcoin_priv2pub(ctx,coin->pubkey33,coin->smartaddr,privkey,coin->taddr,coin->pubtype); |
|||
if ( coin->counter == 0 ) |
|||
{ |
|||
coin->counter++; |
|||
memcpy(G.LP_pubsecp,coin->pubkey33,33); |
|||
bitcoin_priv2wif(coin->wiftaddr,tmpstr,privkey,coin->wiftype); |
|||
bitcoin_addr2rmd160(coin->taddr,&tmptype,G.LP_myrmd160,coin->smartaddr); |
|||
LP_privkeyadd(privkey,G.LP_myrmd160); |
|||
G.LP_privkey = privkey; |
|||
if ( 0 && (coin->pubtype != 60 || strcmp(coin->symbol,"KMD") == 0) ) |
|||
printf("%s (%s) %d wif.(%s) (%s)\n",coin->symbol,coin->smartaddr,coin->pubtype,tmpstr,passphrase); |
|||
if ( G.counter++ == 0 ) |
|||
{ |
|||
bitcoin_priv2wif(coin->wiftaddr,G.USERPASS_WIFSTR,privkey,188); |
|||
bitcoin_wif2priv(coin->wiftaddr,&tmptype,&checkkey,G.USERPASS_WIFSTR); |
|||
if ( bits256_cmp(checkkey,privkey) != 0 ) |
|||
{ |
|||
char str[65],str2[65]; |
|||
printf("FATAL ERROR converting USERPASS_WIFSTR %s -> %s != %s\n",G.USERPASS_WIFSTR,bits256_str(str,checkkey),bits256_str(str2,privkey)); |
|||
exit(-1); |
|||
} |
|||
conv_NXTpassword(userpass.bytes,pubkeyp->bytes,(uint8_t *)G.USERPASS_WIFSTR,(int32_t)strlen(G.USERPASS_WIFSTR)); |
|||
userpub = curve25519(userpass,curve25519_basepoint9()); |
|||
printf("userpass.(%s)\n",bits256_str(G.USERPASS,userpub)); |
|||
} |
|||
} |
|||
if ( coin->importedprivkey == 0 && coin->electrum == 0 && coin->userpass[0] != 0 && LP_getheight(coin) > 0 ) |
|||
{ |
|||
LP_listunspent_issue(coin->symbol,coin->smartaddr,0); |
|||
if ( (retjson= LP_importprivkey(coin->symbol,tmpstr,coin->smartaddr,-1)) != 0 ) |
|||
{ |
|||
if ( jobj(retjson,"error") != 0 ) |
|||
{ |
|||
printf("cant importprivkey.%s -> (%s), abort session\n",coin->symbol,jprint(retjson,1)); |
|||
exit(-1); |
|||
} |
|||
free_json(retjson); |
|||
} |
|||
coin->importedprivkey = (uint32_t)time(NULL); |
|||
} |
|||
vcalc_sha256(0,checkkey.bytes,privkey.bytes,sizeof(privkey)); |
|||
checkkey.bytes[0] &= 248, checkkey.bytes[31] &= 127, checkkey.bytes[31] |= 64; |
|||
G.LP_mypub25519 = *pubkeyp = curve25519(checkkey,curve25519_basepoint9()); |
|||
G.LP_mypriv25519 = checkkey; |
|||
LP_pubkeyadd(G.LP_mypub25519); |
|||
return(privkey); |
|||
} |
|||
|
|||
void LP_privkey_updates(void *ctx,int32_t pubsock,char *passphrase) |
|||
{ |
|||
struct iguana_info *coin,*tmp; bits256 pubkey,privkey; uint8_t pubkey33[33]; int32_t initonly; |
|||
initonly = (passphrase != 0); |
|||
memset(privkey.bytes,0,sizeof(privkey)); |
|||
memset(pubkey.bytes,0,sizeof(pubkey)); |
|||
//printf("Total coins: %d\n", HASH_COUNT(LP_coins));
|
|||
//int num_iter = 0;
|
|||
HASH_ITER(hh,LP_coins,coin,tmp) |
|||
{ |
|||
//printf("LP_privkey_updates [%02d / %02d]\n", num_iter++, HASH_COUNT(LP_coins));
|
|||
if ( initonly != 0 ) |
|||
{ |
|||
coin->counter = 0; |
|||
memset(coin->smartaddr,0,sizeof(coin->smartaddr)); |
|||
if ( bits256_nonz(privkey) == 0 || coin->smartaddr[0] == 0 ) |
|||
privkey = LP_privkeycalc(ctx,pubkey33,&pubkey,coin,passphrase,""); |
|||
} |
|||
//printf("i.%d of %d\n",i,LP_numcoins);
|
|||
else if ( IAMLP == 0 || coin->inactive == 0 ) |
|||
{ |
|||
//printf("from updates %s\n",coin->symbol);
|
|||
if ( LP_privkey_init(pubsock,coin,G.LP_privkey,G.LP_mypub25519) == 0 && (LP_rand() % 10) == 0 ) |
|||
{ |
|||
//LP_postutxos(coin->symbol,coin->smartaddr);
|
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
int32_t LP_passphrase_init(char *passphrase,char *gui) |
|||
{ |
|||
static void *ctx; int32_t iambob,counter; struct LP_utxoinfo *utxo,*tmp; |
|||
if ( ctx == 0 ) |
|||
ctx = bitcoin_ctx(); |
|||
if ( G.LP_pendingswaps != 0 ) |
|||
return(-1); |
|||
G.initializing = 1; |
|||
if ( gui == 0 ) |
|||
gui = "cli"; |
|||
counter = G.USERPASS_COUNTER; |
|||
while ( G.waiting == 0 ) |
|||
{ |
|||
printf("waiting for G.waiting\n"); |
|||
sleep(5); |
|||
} |
|||
for (iambob=0; iambob<2; iambob++) |
|||
{ |
|||
if ( G.LP_utxoinfos[iambob] != 0 ) |
|||
{ |
|||
HASH_ITER(hh,G.LP_utxoinfos[iambob],utxo,tmp) |
|||
{ |
|||
HASH_DELETE(hh,G.LP_utxoinfos[iambob],utxo); |
|||
//free(utxo);
|
|||
} |
|||
} |
|||
if ( G.LP_utxoinfos2[iambob] != 0 ) |
|||
{ |
|||
G.LP_utxoinfos2[iambob] = 0; |
|||
/*HASH_ITER(hh,G.LP_utxoinfos2[iambob],utxo,tmp)
|
|||
{ |
|||
HASH_DELETE(hh,G.LP_utxoinfos2[iambob],utxo); |
|||
free(utxo); |
|||
}*/ |
|||
} |
|||
} |
|||
memset(&G,0,sizeof(G)); |
|||
LP_privkey_updates(ctx,LP_mypubsock,passphrase); |
|||
init_hexbytes_noT(G.LP_myrmd160str,G.LP_myrmd160,20); |
|||
G.LP_sessionid = (uint32_t)time(NULL); |
|||
safecopy(G.gui,gui,sizeof(G.gui)); |
|||
G.USERPASS_COUNTER = counter; |
|||
G.initializing = 0; |
|||
return(0); |
|||
} |
|||
|
|||
|
@ -0,0 +1,3 @@ |
|||
#!/bin/bash |
|||
source userpass |
|||
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"zeroconf_claim\",\"address\":\"$1\",\"expiration\":$2}" |
@ -0,0 +1,3 @@ |
|||
#!/bin/bash |
|||
source userpass |
|||
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"zeroconf_deposit\",\"weeks\":0,\"amount\":10.0,\"broadcast\":1}" |
@ -0,0 +1,3 @@ |
|||
#!/bin/bash |
|||
source userpass |
|||
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"zeroconf_deposit\",\"weeks\":1,\"amount\":10.0,\"broadcast\":1}" |
@ -0,0 +1,3 @@ |
|||
#!/bin/bash |
|||
source userpass |
|||
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"dynamictrust\",\"address\":\"RMfQwu5ey23eWJ4as2ckd8dqsQJwo836ny\"}" |
@ -0,0 +1,3 @@ |
|||
#!/bin/bash |
|||
source userpass |
|||
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"electrum\",\"coin\":\"KMD\",\"ipaddr\":\"\",\"port\":0}" |
@ -1,3 +1,3 @@ |
|||
#!/bin/bash |
|||
source userpass |
|||
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"sell\",\"base\":\"KMD\",\"rel\":\"BTC\",\"basevolume\":10.0\",\"price\":0.0005}" |
|||
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"sell\",\"base\":\"KMD\",\"rel\":\"BTC\",\"basevolume\":10.0,\"price\":0.0005}" |
|||
|
@ -0,0 +1,3 @@ |
|||
#!/bin/bash |
|||
source userpass |
|||
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"tradesarray\",\"base\":\"REVS\",\"rel\":\"KMD\",\"timescale\":3600}" |
Loading…
Reference in new issue