Merge pull request #6 from jl777/jl777

Jl777
This commit is contained in:
Alrighttt
2019-07-12 03:48:10 +02:00
committed by GitHub
45 changed files with 4542 additions and 365 deletions

View File

@@ -89,6 +89,65 @@ std::string DecodeDumpString(const std::string &str) {
return ret.str();
}
UniValue convertpassphrase(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() < 1 || params.size() > 1)
throw runtime_error(
"convertpassphrase \"agamapassphrase\"\n"
"\nConverts Agama passphrase to a private key and WIF (for import with importprivkey).\n"
"\nArguments:\n"
"1. \"agamapassphrase\" (string, required) Agama passphrase\n"
"\nResult:\n"
"\"agamapassphrase\": \"agamapassphrase\", (string) Agama passphrase you entered\n"
"\"address\": \"komodoaddress\", (string) Address corresponding to your passphrase\n"
"\"pubkey\": \"publickeyhex\", (string) The hex value of the raw public key\n"
"\"privkey\": \"privatekeyhex\", (string) The hex value of the raw private key\n"
"\"wif\": \"wif\" (string) The private key in WIF format to use with 'importprivkey'\n"
"\nExamples:\n"
+ HelpExampleCli("convertpassphrase", "\"agamapassphrase\"")
+ HelpExampleRpc("convertpassphrase", "\"agamapassphrase\"")
);
bool fCompressed = true;
string strAgamaPassphrase = params[0].get_str();
UniValue ret(UniValue::VOBJ);
ret.push_back(Pair("agamapassphrase", strAgamaPassphrase));
CKey tempkey = DecodeSecret(strAgamaPassphrase);
/* first we should check if user pass wif to method, instead of passphrase */
if (!tempkey.IsValid()) {
/* it's a passphrase, not wif */
uint256 sha256;
CSHA256().Write((const unsigned char *)strAgamaPassphrase.c_str(), strAgamaPassphrase.length()).Finalize(sha256.begin());
std::vector<unsigned char> privkey(sha256.begin(), sha256.begin() + sha256.size());
privkey.front() &= 0xf8;
privkey.back() &= 0x7f;
privkey.back() |= 0x40;
CKey key;
key.Set(privkey.begin(),privkey.end(), fCompressed);
CPubKey pubkey = key.GetPubKey();
assert(key.VerifyPubKey(pubkey));
CKeyID vchAddress = pubkey.GetID();
ret.push_back(Pair("address", EncodeDestination(vchAddress)));
ret.push_back(Pair("pubkey", HexStr(pubkey)));
ret.push_back(Pair("privkey", HexStr(privkey)));
ret.push_back(Pair("wif", EncodeSecret(key)));
} else {
/* seems it's a wif */
CPubKey pubkey = tempkey.GetPubKey();
assert(tempkey.VerifyPubKey(pubkey));
CKeyID vchAddress = pubkey.GetID();
ret.push_back(Pair("address", EncodeDestination(vchAddress)));
ret.push_back(Pair("pubkey", HexStr(pubkey)));
ret.push_back(Pair("privkey", HexStr(tempkey)));
ret.push_back(Pair("wif", strAgamaPassphrase));
}
return ret;
}
UniValue importprivkey(const UniValue& params, bool fHelp)
{
if (!EnsureWalletIsAvailable(fHelp))
@@ -912,3 +971,120 @@ UniValue z_exportviewingkey(const UniValue& params, bool fHelp)
return EncodeViewingKey(vk);
}
UniValue NSPV_getinfo_req(int32_t reqht);
UniValue NSPV_login(char *wifstr);
UniValue NSPV_logout();
UniValue NSPV_addressutxos(char *coinaddr,int32_t CCflag);
UniValue NSPV_broadcast(char *hex);
UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis);
UniValue NSPV_spentinfo(uint256 txid,int32_t vout);
UniValue NSPV_notarizations(int32_t height);
UniValue NSPV_hdrsproof(int32_t prevheight,int32_t nextheight);
UniValue NSPV_txproof(int32_t vout,uint256 txid,int32_t height);
uint256 Parseuint256(const char *hexstr);
extern std::string NSPV_address;
UniValue nspv_getinfo(const UniValue& params, bool fHelp)
{
int32_t reqht = 0;
if ( fHelp || params.size() > 1 )
throw runtime_error("nspv_getinfo [hdrheight]\n");
if ( params.size() == 1 )
reqht = atoi((char *)params[0].get_str().c_str());
return(NSPV_getinfo_req(reqht));
}
UniValue nspv_logout(const UniValue& params, bool fHelp)
{
if ( fHelp || params.size() != 0 )
throw runtime_error("nspv_logout\n");
return(NSPV_logout());
}
UniValue nspv_login(const UniValue& params, bool fHelp)
{
if ( fHelp || params.size() != 1 )
throw runtime_error("nspv_login wif\n");
return(NSPV_login((char *)params[0].get_str().c_str()));
}
UniValue nspv_listunspent(const UniValue& params, bool fHelp)
{
int32_t CCflag = 0;
if ( fHelp || params.size() > 2 )
throw runtime_error("nspv_listunspent address [isCC]\n");
if ( params.size() == 0 )
{
if ( NSPV_address.size() != 0 )
return(NSPV_addressutxos((char *)NSPV_address.c_str(),0));
else throw runtime_error("nspv_listunspent address [isCC]\n");
}
if ( params.size() >= 1 )
{
if ( params.size() == 2 )
CCflag = atoi((char *)params[1].get_str().c_str());
return(NSPV_addressutxos((char *)params[0].get_str().c_str(),CCflag));
}
else throw runtime_error("nspv_listunspent address [isCC]\n");
}
UniValue nspv_spentinfo(const UniValue& params, bool fHelp)
{
uint256 txid; int32_t vout;
if ( fHelp || params.size() != 2 )
throw runtime_error("nspv_spentinfo txid vout\n");
txid = Parseuint256((char *)params[0].get_str().c_str());
vout = atoi((char *)params[1].get_str().c_str());
return(NSPV_spentinfo(txid,vout));
}
UniValue nspv_notarizations(const UniValue& params, bool fHelp)
{
int32_t height;
if ( fHelp || params.size() != 1 )
throw runtime_error("nspv_notarizations height\n");
height = atoi((char *)params[0].get_str().c_str());
return(NSPV_notarizations(height));
}
UniValue nspv_hdrsproof(const UniValue& params, bool fHelp)
{
int32_t prevheight,nextheight;
if ( fHelp || params.size() != 2 )
throw runtime_error("nspv_hdrsproof prevheight nextheight\n");
prevheight = atoi((char *)params[0].get_str().c_str());
nextheight = atoi((char *)params[1].get_str().c_str());
return(NSPV_hdrsproof(prevheight,nextheight));
}
UniValue nspv_txproof(const UniValue& params, bool fHelp)
{
uint256 txid; int32_t height;
if ( fHelp || params.size() != 2 )
throw runtime_error("nspv_txproof txid height\n");
txid = Parseuint256((char *)params[0].get_str().c_str());
height = atoi((char *)params[1].get_str().c_str());
return(NSPV_txproof(0,txid,height));
}
UniValue nspv_spend(const UniValue& params, bool fHelp)
{
uint64_t satoshis;
if ( fHelp || params.size() != 2 )
throw runtime_error("nspv_spend destaddr amount\n");
if ( NSPV_address.size() == 0 )
throw runtime_error("to nspv_send you need an active nspv_login\n");
satoshis = atof(params[1].get_str().c_str())*COIN + 0.0000000049;
//fprintf(stderr,"satoshis.%lld from %.8f\n",(long long)satoshis,atof(params[1].get_str().c_str()));
if ( satoshis < 1000 )
throw runtime_error("amount too small\n");
return(NSPV_spend((char *)NSPV_address.c_str(),(char *)params[0].get_str().c_str(),satoshis));
}
UniValue nspv_broadcast(const UniValue& params, bool fHelp)
{
if ( fHelp || params.size() != 1 )
throw runtime_error("nspv_broadcast hex\n");
return(NSPV_broadcast((char *)params[0].get_str().c_str()));
}

View File

@@ -158,9 +158,11 @@ char *komodo_chainname()
return(ASSETCHAINS_SYMBOL[0] == 0 ? (char *)"KMD" : ASSETCHAINS_SYMBOL);
}
void OS_randombytes(unsigned char *x,long xlen);
UniValue getnewaddress(const UniValue& params, bool fHelp)
{
if (!EnsureWalletIsAvailable(fHelp))
if ( KOMODO_NSPV == 0 && !EnsureWalletIsAvailable(fHelp) )
return NullUniValue;
if (fHelp || params.size() > 1)
@@ -176,6 +178,23 @@ UniValue getnewaddress(const UniValue& params, bool fHelp)
+ HelpExampleRpc("getnewaddress", "")
);
if ( KOMODO_NSPV != 0 )
{
UniValue result(UniValue::VOBJ); uint8_t priv32[32];
#ifndef __WIN32
OS_randombytes(priv32,sizeof(priv32));
#else
randombytes_buf(priv32,sizeof(priv32));
#endif
CKey key;
key.Set(&priv32[0],&priv32[32], true);
CPubKey pubkey = key.GetPubKey();
CKeyID vchAddress = pubkey.GetID();
result.push_back(Pair("wif",EncodeSecret(key)));
result.push_back(Pair("address",EncodeDestination(vchAddress)));
result.push_back(Pair("pubkey",HexStr(pubkey)));
return(result);
}
LOCK2(cs_main, pwalletMain->cs_wallet);
// Parse the account first so we don't generate a key if there's an error
@@ -2955,7 +2974,7 @@ UniValue listunspent(const UniValue& params, bool fHelp)
uint64_t komodo_interestsum()
{
#ifdef ENABLE_WALLET
if ( ASSETCHAINS_SYMBOL[0] == 0 && GetBoolArg("-disablewallet", false) == 0 )
if ( ASSETCHAINS_SYMBOL[0] == 0 && GetBoolArg("-disablewallet", false) == 0 && KOMODO_NSPV == 0 )
{
uint64_t interest,sum = 0; int32_t txheight; uint32_t locktime;
vector<COutput> vecOutputs;
@@ -5336,6 +5355,7 @@ int32_t verus_staked(CBlock *pBlock, CMutableTransaction &txNew, uint32_t &nBits
#include "../cc/CCHeir.h"
#include "../cc/CCMarmara.h"
#include "../cc/CCPayments.h"
#include "../cc/CCPegs.h"
int32_t ensure_CCrequirements(uint8_t evalcode)
{
@@ -7973,10 +7993,209 @@ UniValue heirlist(const UniValue& params, bool fHelp)
return (HeirList());
}
UniValue pegscreate(const UniValue& params, bool fHelp)
{
UniValue result(UniValue::VOBJ); int32_t i; std::vector<uint256> txids;
uint8_t N; std::string hex; uint256 txid; int64_t amount;
if ( fHelp || params.size()<3)
throw runtime_error("pegscreate amount N bindtxid1 [bindtxid2 ...]\n");
if ( ensure_CCrequirements(EVAL_PEGS) < 0 )
throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
const CKeyStore& keystore = *pwalletMain;
LOCK2(cs_main, pwalletMain->cs_wallet);
amount = atof((char *)params[0].get_str().c_str()) * COIN + 0.00000000499999;
N = atoi((char *)params[1].get_str().c_str());
if ( params.size() < N+1 )
throw runtime_error("not enough parameters for N gatewaysbind\n");
for (i=0; i<N; i++)
{
txid = Parseuint256(params[i+2].get_str().c_str());
txids.push_back(txid);
}
hex = PegsCreate(0,amount,txids);
RETURN_IF_ERROR(CCerror);
if ( hex.size() > 0 )
{
result.push_back(Pair("result", "success"));
result.push_back(Pair("hex", hex));
} else ERR_RESULT("couldnt pegscreate");
return(result);
}
UniValue pegsfund(const UniValue& params, bool fHelp)
{
UniValue result(UniValue::VOBJ); std::string hex; uint256 pegstxid,tokenid; int64_t amount;
if ( fHelp || params.size()!=3)
throw runtime_error("pegsfund pegstxid tokenid amount\n");
if ( ensure_CCrequirements(EVAL_PEGS) < 0 )
throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
const CKeyStore& keystore = *pwalletMain;
LOCK2(cs_main, pwalletMain->cs_wallet);
pegstxid = Parseuint256(params[0].get_str().c_str());
tokenid = Parseuint256(params[1].get_str().c_str());
amount = atof((char *)params[2].get_str().c_str()) * COIN + 0.00000000499999;
hex = PegsFund(0,pegstxid,tokenid,amount);
RETURN_IF_ERROR(CCerror);
if ( hex.size() > 0 )
{
result.push_back(Pair("result", "success"));
result.push_back(Pair("hex", hex));
} else ERR_RESULT("couldnt pegsfund");
return(result);
}
UniValue pegsget(const UniValue& params, bool fHelp)
{
UniValue result(UniValue::VOBJ); std::string hex; uint256 pegstxid,tokenid; int64_t amount;
if ( fHelp || params.size()!=3)
throw runtime_error("pegsget pegstxid tokenid amount\n");
if ( ensure_CCrequirements(EVAL_PEGS) < 0 )
throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
const CKeyStore& keystore = *pwalletMain;
LOCK2(cs_main, pwalletMain->cs_wallet);
pegstxid = Parseuint256(params[0].get_str().c_str());
tokenid = Parseuint256(params[1].get_str().c_str());
amount = atof((char *)params[2].get_str().c_str()) * COIN + 0.00000000499999;
hex = PegsGet(0,pegstxid,tokenid,amount);
RETURN_IF_ERROR(CCerror);
if ( hex.size() > 0 )
{
result.push_back(Pair("result", "success"));
result.push_back(Pair("hex", hex));
} else ERR_RESULT("couldnt pegsget");
return(result);
}
UniValue pegsredeem(const UniValue& params, bool fHelp)
{
UniValue result(UniValue::VOBJ); std::string hex; uint256 pegstxid,tokenid; int64_t amount;
if ( fHelp || params.size()!=2)
throw runtime_error("pegsredem pegstxid tokenid\n");
if ( ensure_CCrequirements(EVAL_PEGS) < 0 )
throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
const CKeyStore& keystore = *pwalletMain;
LOCK2(cs_main, pwalletMain->cs_wallet);
pegstxid = Parseuint256(params[0].get_str().c_str());
tokenid = Parseuint256(params[1].get_str().c_str());
hex = PegsRedeem(0,pegstxid,tokenid);
RETURN_IF_ERROR(CCerror);
if ( hex.size() > 0 )
{
result.push_back(Pair("result", "success"));
result.push_back(Pair("hex", hex));
} else ERR_RESULT("couldnt pegsredeem");
return(result);
}
UniValue pegsliquidate(const UniValue& params, bool fHelp)
{
UniValue result(UniValue::VOBJ); std::string hex; uint256 pegstxid,tokenid,accounttxid;
if ( fHelp || params.size()!=3)
throw runtime_error("pegsliquidate pegstxid tokenid accounttxid\n");
if ( ensure_CCrequirements(EVAL_PEGS) < 0 )
throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
const CKeyStore& keystore = *pwalletMain;
LOCK2(cs_main, pwalletMain->cs_wallet);
pegstxid = Parseuint256(params[0].get_str().c_str());
tokenid = Parseuint256(params[1].get_str().c_str());
accounttxid = Parseuint256(params[2].get_str().c_str());
hex = PegsLiquidate(0,pegstxid,tokenid,accounttxid);
RETURN_IF_ERROR(CCerror);
if ( hex.size() > 0 )
{
result.push_back(Pair("result", "success"));
result.push_back(Pair("hex", hex));
} else ERR_RESULT("couldnt pegsliquidate");
return(result);
}
UniValue pegsexchange(const UniValue& params, bool fHelp)
{
UniValue result(UniValue::VOBJ); std::string hex; uint256 pegstxid,tokenid,accounttxid; int64_t amount;
if ( fHelp || params.size()!=3)
throw runtime_error("pegsliquidate pegstxid tokenid accounttxid\n");
if ( ensure_CCrequirements(EVAL_PEGS) < 0 )
throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
const CKeyStore& keystore = *pwalletMain;
LOCK2(cs_main, pwalletMain->cs_wallet);
pegstxid = Parseuint256(params[0].get_str().c_str());
tokenid = Parseuint256(params[1].get_str().c_str());
amount = atof((char *)params[2].get_str().c_str()) * COIN + 0.00000000499999;
hex = PegsExchange(0,pegstxid,tokenid,amount);
RETURN_IF_ERROR(CCerror);
if ( hex.size() > 0 )
{
result.push_back(Pair("result", "success"));
result.push_back(Pair("hex", hex));
} else ERR_RESULT("couldnt pegsliquidate");
return(result);
}
UniValue pegsaccounthistory(const UniValue& params, bool fHelp)
{
uint256 pegstxid;
if ( fHelp || params.size() != 1 )
throw runtime_error("pegsaccounthistory pegstxid\n");
if ( ensure_CCrequirements(EVAL_GATEWAYS) < 0 )
throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
const CKeyStore& keystore = *pwalletMain;
LOCK2(cs_main, pwalletMain->cs_wallet);
pegstxid = Parseuint256((char *)params[0].get_str().c_str());
return(PegsAccountHistory(pegstxid));
}
UniValue pegsaccountinfo(const UniValue& params, bool fHelp)
{
uint256 pegstxid;
if ( fHelp || params.size() != 1 )
throw runtime_error("pegsaccountinfo pegstxid\n");
if ( ensure_CCrequirements(EVAL_GATEWAYS) < 0 )
throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
const CKeyStore& keystore = *pwalletMain;
LOCK2(cs_main, pwalletMain->cs_wallet);
pegstxid = Parseuint256((char *)params[0].get_str().c_str());
return(PegsAccountInfo(pegstxid));
}
UniValue pegsworstaccounts(const UniValue& params, bool fHelp)
{
uint256 pegstxid;
if ( fHelp || params.size() != 1 )
throw runtime_error("pegsworstaccounts pegstxid\n");
if ( ensure_CCrequirements(EVAL_GATEWAYS) < 0 )
throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
const CKeyStore& keystore = *pwalletMain;
LOCK2(cs_main, pwalletMain->cs_wallet);
pegstxid = Parseuint256((char *)params[0].get_str().c_str());
return(PegsWorstAccounts(pegstxid));
}
UniValue pegsinfo(const UniValue& params, bool fHelp)
{
uint256 pegstxid;
if ( fHelp || params.size() != 1 )
throw runtime_error("pegsinfo pegstxid\n");
if ( ensure_CCrequirements(EVAL_GATEWAYS) < 0 )
throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
const CKeyStore& keystore = *pwalletMain;
LOCK2(cs_main, pwalletMain->cs_wallet);
pegstxid = Parseuint256((char *)params[0].get_str().c_str());
return(PegsInfo(pegstxid));
}
extern UniValue dumpprivkey(const UniValue& params, bool fHelp); // in rpcdump.cpp
extern UniValue convertpassphrase(const UniValue& params, bool fHelp);
extern UniValue importprivkey(const UniValue& params, bool fHelp);
extern UniValue importaddress(const UniValue& params, bool fHelp);
extern UniValue dumpwallet(const UniValue& params, bool fHelp);
@@ -8012,6 +8231,7 @@ static const CRPCCommand commands[] =
{ "wallet", "gettransaction", &gettransaction, false },
{ "wallet", "getunconfirmedbalance", &getunconfirmedbalance, false },
{ "wallet", "getwalletinfo", &getwalletinfo, false },
{ "wallet", "convertpassphrase", &convertpassphrase, true },
{ "wallet", "importprivkey", &importprivkey, true },
{ "wallet", "importwallet", &importwallet, true },
{ "wallet", "importaddress", &importaddress, true },