Merge pull request #1579 from jl777/jl777

Jl777
This commit is contained in:
jl777
2019-07-02 08:09:15 -11:00
committed by GitHub
11 changed files with 67 additions and 27 deletions

View File

@@ -206,12 +206,12 @@ void OS_nonportable_randombytes(uint8_t *x,long xlen);
int32_t OS_nonportable_init();
#endif
void OS_portable_init();
void OS_init();
void OS_portable_init(void);
void OS_init(void);
int32_t sortds(double *buf,uint32_t num,int32_t size);
int32_t revsortds(double *buf,uint32_t num,int32_t size);
double OS_portable_milliseconds();
double OS_portable_milliseconds(void);
void OS_portable_randombytes(uint8_t *x,long xlen);
int32_t OS_portable_truncate(char *fname,long filesize);
char *OS_portable_path(char *str);
@@ -256,7 +256,7 @@ int32_t OS_removefile(char *fname,int32_t scrubflag);
void *OS_mapfile(char *fname,long *filesizep,int32_t enablewrite);
int32_t OS_releasemap(void *ptr,unsigned long filesize);
double OS_milliseconds();
double OS_milliseconds(void);
void OS_randombytes(uint8_t *x,long xlen);
//int32_t OS_syncmap(struct OS_mappedptr *mp,long len);
@@ -313,7 +313,7 @@ void sort64s(uint64_t *buf,uint32_t num,int32_t size);
void revsort64s(uint64_t *buf,uint32_t num,int32_t size);
int decode_base32(uint8_t *token,uint8_t *tokenstr,int32_t len);
int init_base32(char *tokenstr,uint8_t *token,int32_t len);
char *OS_mvstr();
char *OS_mvstr(void);
long _stripwhite(char *buf,int accept);
int32_t is_DST(int32_t datenum);
@@ -381,7 +381,7 @@ double dxblend(double *destp,double val,double decay);
uint64_t calc_ipbits(char *ip_port);
void expand_ipbits(char *ipaddr,uint64_t ipbits);
void escape_code(char *escaped,char *str);
void SaM_PrepareIndices();
void SaM_PrepareIndices(void);
// iguana_serdes.c
#ifndef IGUANA_LOG2PACKETSIZE

View File

@@ -40,7 +40,10 @@ long stripquotes(char *str)
return(0);
len = strlen(str);
if ( str[0] == '"' && str[len-1] == '"' )
str[len-1] = 0, offset = 1;
{
str[len-1] = 0;
offset = 1;
}
else offset = 0;
return(offset);
}

View File

@@ -1041,6 +1041,7 @@ int32_t itemvalid(char *refcoin,int64_t *refundedp,int64_t *waitingp,struct clai
*refundedp = *waitingp = 0;
if ( item->refundvalue < 0 )
return(-1);
// change "kmd" -> %s, tolowerstr(refcoin)
sprintf(url,"https://kmd.explorer.dexstats.info/insight-api-komodo/addr/%s",item->destaddr);
if ( (retstr= send_curl(url,"/tmp/itemvalid")) != 0 )
{
@@ -1061,7 +1062,7 @@ int32_t itemvalid(char *refcoin,int64_t *refundedp,int64_t *waitingp,struct clai
}
free_json(curljson);
}
//printf("%s\n",retstr);
printf("%s\n",retstr);
free(retstr);
}
if ( item->approved != 0 )
@@ -1086,18 +1087,19 @@ void scan_claims(int32_t issueflag,char *refcoin,int32_t batchid)
else if ( batchid == 2 )
{
batchmin = 1;//777 * SATOSHIDEN;
batchmax = 77777 * SATOSHIDEN;
batchmax = 5000 * SATOSHIDEN;
}
else if ( batchid == 3 )
{
batchmin = 77777 * SATOSHIDEN;
batchmax = 1000000 * SATOSHIDEN;
batchmin = 1;//117777 * SATOSHIDEN;
batchmax = 10000000 * SATOSHIDEN;
}
for (i=0; i<NUM_CLAIMS; i++)
{
item = &CLAIMS[i];
if ( item->refundvalue < batchmin || item->refundvalue >= batchmax )
continue;
printf("check.%d %s %.8f vs refund %.8f -> %s\n",batchid,item->oldaddr,dstr(item->total),dstr(item->refundvalue),item->destaddr);
if ( itemvalid(refcoin,&refunded,&waiting,item) < 0 )
{
if ( refunded != 0 )
@@ -1170,7 +1172,7 @@ int32_t update_claimvalue(int32_t *disputedp,char *addr,int64_t amount,bits256 t
item = &CLAIMS[i];
item->refundvalue = amount;
if ( bits256_nonz(item->txid) != 0 )
printf("disputed.%d %s claimed %.8f vs %.8f\n",item->disputed,addr,dstr(item->total),dstr(amount));
printf("disputed.%d (%s) %s claimed %.8f vs %.8f\n",item->disputed,item->username,addr,dstr(item->total),dstr(amount));
item->txid = txid;
if ( item->disputed != 0 )
*disputedp = 1;
@@ -1183,6 +1185,7 @@ int32_t update_claimvalue(int32_t *disputedp,char *addr,int64_t amount,bits256 t
int64_t update_claimstats(char *username,char *oldaddr,char *destaddr,int64_t amount)
{
int32_t i; struct claimitem *item;
printf("claim user.(%s) (%s) -> (%s) %.8f\n",username,oldaddr,destaddr,dstr(amount));
for (i=0; i<NUM_CLAIMS; i++)
{
if ( strcmp(oldaddr,CLAIMS[i].oldaddr) == 0 )
@@ -1191,7 +1194,7 @@ int64_t update_claimstats(char *username,char *oldaddr,char *destaddr,int64_t am
if ( strcmp(destaddr,item->destaddr) != 0 )//|| strcmp(username,item->username) != 0 )
{
item->disputed++;
printf("disputed.%d claim.%-4d: (%36s -> %36s %s) vs. (%36s -> %36s %s) \n",item->disputed,i,oldaddr,destaddr,username,item->oldaddr,item->destaddr,item->username);
printf("disputed.%d claim.%-4d: (%36s -> [%36s] %s) vs. (%36s -> [%36s] %s) \n",item->disputed,i,oldaddr,destaddr,username,item->oldaddr,item->destaddr,item->username);
}
item->numutxos++;
item->total += amount;
@@ -1258,14 +1261,14 @@ int64_t sum_of_vins(char *refcoin,int32_t *totalvinsp,int32_t *uniqaddrsp,bits25
return(total);
}
void reconcile_claims(char *fname)
void reconcile_claims(char *refcoin,char *fname)
{
FILE *fp; double amount; int32_t i,n,numlines = 0; char buf[1024],fields[16][256],*str; int64_t total = 0;
if ( (fp= fopen(fname,"rb")) != 0 )
{
while ( fgets(buf,sizeof(buf),fp) > 0 )
{
//printf("%d.(%s)\n",numlines,buf);
printf("%d.(%s)\n",numlines,buf);
str = buf;
n = i = 0;
memset(fields,0,sizeof(fields));
@@ -1277,7 +1280,7 @@ void reconcile_claims(char *fname)
i = 0;
if ( n > 1 )
{
//printf("(%16s) ",fields[n]);
printf("(%16s) ",fields[n]);
}
n++;
if ( *str == '\n' || *str == '\r' )
@@ -1287,8 +1290,8 @@ void reconcile_claims(char *fname)
str++;
else fields[n][i++] = *str++;
}
//printf("%s\n",fields[0]);
total += update_claimstats(fields[1],fields[3],fields[6],atof(fields[4])*SATOSHIDEN + 0.0000000049);
printf("%s\n",fields[1]);
total += update_claimstats(fields[1],fields[3],fields[5 + (strcmp("KMD",refcoin)==0)],atof(fields[4])*SATOSHIDEN + 0.0000000049);
numlines++;
}
fclose(fp);
@@ -1326,7 +1329,7 @@ int32_t main(int32_t argc,char **argv)
if ( 1 )//strcmp(coinstr,"KMD") == 0 )
{
sprintf(buf,"%s-Claims.csv",coinstr);
reconcile_claims(buf);
reconcile_claims(coinstr,buf);
for (i=0; i<NUM_CLAIMS; i++)
{
if ( CLAIMS[i].disputed != 0 )
@@ -1393,8 +1396,8 @@ int32_t main(int32_t argc,char **argv)
}
//scan_claims(0,coinstr,0);
//scan_claims(0,coinstr,1);
scan_claims(0,coinstr,2);
//scan_claims(0,coinstr,3);
//scan_claims(0,coinstr,2);
scan_claims(1,coinstr,3);
}
else if ( (retjson= get_listunspent(coinstr,acstr)) != 0 )
{

View File

@@ -48,7 +48,7 @@ bits320 crecip(const bits320 z);
bits256 curve25519(bits256 mysecret,bits256 basepoint);
void OS_randombytes(unsigned char *x,long xlen);
bits256 rand256(int32_t privkeyflag);
bits256 curve25519_basepoint9();
bits256 curve25519_basepoint9(void);
bits256 curve25519_keypair(bits256 *pubkeyp);
void vcalc_sha256(char hashstr[(256 >> 3) * 2 + 1],uint8_t hash[256 >> 3],uint8_t *src,int32_t len);

View File

@@ -207,6 +207,22 @@ CKey DecodeSecret(const std::string& str)
return key;
}
CKey DecodeCustomSecret(const std::string& str, uint8_t secret_key)
{
CKey key;
std::vector<unsigned char> data;
if (DecodeBase58Check(str, data)) {
const std::vector<unsigned char>& privkey_prefix = std::vector<unsigned char>(1, secret_key);
if ((data.size() == 32 + privkey_prefix.size() || (data.size() == 33 + privkey_prefix.size() && data.back() == 1)) &&
std::equal(privkey_prefix.begin(), privkey_prefix.end(), data.begin())) {
bool compressed = data.size() == 33 + privkey_prefix.size();
key.Set(data.begin() + privkey_prefix.size(), data.begin() + privkey_prefix.size() + 32, compressed);
}
}
memory_cleanse(data.data(), data.size());
return key;
}
std::string EncodeSecret(const CKey& key)
{
assert(key.IsValid());

View File

@@ -17,6 +17,7 @@
#include <string>
CKey DecodeSecret(const std::string& str);
CKey DecodeCustomSecret(const std::string& str, uint8_t secret_key);
std::string EncodeSecret(const CKey& key);
std::string EncodeCustomSecret(const CKey& key,uint8_t secret_key);

View File

@@ -18,7 +18,7 @@
#include "komodo_nk.h"
#define ASSETCHAINS_MINHEIGHT 128
#define ASSETCHAINS_MAX_ERAS 3
#define ASSETCHAINS_MAX_ERAS 7
#define KOMODO_ELECTION_GAP 2000
#define ROUNDROBIN_DELAY 61
#define KOMODO_ASSETCHAIN_MAXLEN 65

View File

@@ -652,6 +652,7 @@ const char *banned_txids[] =
//"01d8c839463bda2f2f6400ede4611357913684927a767422a8560ead1b22557c",
//"6e4980a9e1bd669f4df04732dc6f11b7773b6de88d1abcf89a6b9007d72ef9ac",
//"6cc1d0495170bc0e11fd3925297623562e529ea1336b66ea61f8a1159041aed2",
//"250875424cece9bcd98cb226b09da7671625633d6958589e3a462bad89ad87cc", // missed
};
int32_t komodo_checkvout(int32_t vout,int32_t k,int32_t indallvouts)

View File

@@ -109,6 +109,7 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "lockunspent", 1 },
{ "importprivkey", 2 },
{ "importprivkey", 3 },
{ "importprivkey", 4 },
{ "importaddress", 2 },
{ "verifychain", 0 },
{ "verifychain", 1 },

View File

@@ -757,7 +757,7 @@ UniValue createrawtransaction(const UniValue& params, bool fHelp)
"\nExamples\n"
+ HelpExampleCli("createrawtransaction", "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\" \"{\\\"address\\\":0.01}\"")
+ HelpExampleRpc("createrawtransaction", "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\", \"{\\\"address\\\":0.01}\"")
+ HelpExampleRpc("createrawtransaction", "[{\"txid\":\"myid\",\"vout\":0}], {\"address\":0.01}")
);
LOCK(cs_main);

View File

@@ -153,15 +153,16 @@ UniValue importprivkey(const UniValue& params, bool fHelp)
if (!EnsureWalletIsAvailable(fHelp))
return NullUniValue;
if (fHelp || params.size() < 1 || params.size() > 4)
if (fHelp || params.size() < 1 || params.size() > 5)
throw runtime_error(
"importprivkey \"komodoprivkey\" ( \"label\" rescan height)\n"
"importprivkey \"komodoprivkey\" ( \"label\" rescan height secret_key)\n"
"\nAdds a private key (as returned by dumpprivkey) to your wallet.\n"
"\nArguments:\n"
"1. \"komodoprivkey\" (string, required) The private key (see dumpprivkey)\n"
"2. \"label\" (string, optional, default=\"\") An optional label\n"
"3. rescan (boolean, optional, default=true) Rescan the wallet for transactions\n"
"4. height (integer, optional, default=0) start at block height?\n"
"5. secret_key (integer, optional, default=188) used to import WIFs of other coins\n"
"\nNote: This call can take minutes to complete if rescan is true.\n"
"\nExamples:\n"
"\nDump a private key\n"
@@ -174,6 +175,10 @@ UniValue importprivkey(const UniValue& params, bool fHelp)
+ HelpExampleRpc("importprivkey", "\"mykey\", \"testing\", false") +
"\nImport with rescan from a block height\n"
+ HelpExampleCli("importprivkey", "\"mykey\" \"testing\" true 1000") +
"\nImport a BTC WIF with rescan\n"
+ HelpExampleCli("importprivkey", "\"BTCWIF\" \"testing\" true 0 128") +
"\nImport a BTC WIF without rescan\n"
+ HelpExampleCli("importprivkey", "\"BTCWIF\" \"testing\" false 0 128") +
"\nAs a JSON-RPC call\n"
+ HelpExampleRpc("importprivkey", "\"mykey\", \"testing\", true, 1000")
);
@@ -185,6 +190,8 @@ UniValue importprivkey(const UniValue& params, bool fHelp)
string strSecret = params[0].get_str();
string strLabel = "";
int32_t height = 0;
uint8_t secret_key = 0;
CKey key;
if (params.size() > 1)
strLabel = params[1].get_str();
@@ -195,10 +202,18 @@ UniValue importprivkey(const UniValue& params, bool fHelp)
if ( fRescan && params.size() == 4 )
height = params[3].get_int();
if (params.size() > 4)
{
auto secret_key = AmountFromValue(params[4])/100000000;
key = DecodeCustomSecret(strSecret, secret_key);
} else {
key = DecodeSecret(strSecret);
}
if ( height < 0 || height > chainActive.Height() )
throw JSONRPCError(RPC_WALLET_ERROR, "Rescan height is out of range.");
CKey key = DecodeSecret(strSecret);
if (!key.IsValid()) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid private key encoding");
CPubKey pubkey = key.GetPubKey();