From 869409b710fb6c9e0edc71066b9b87b716caffb2 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Thu, 12 Dec 2019 18:56:36 -0500 Subject: [PATCH] src/wallet/rcpwallet.cpp upstream changes --- src/wallet/rpcwallet.cpp | 987 +++++++++++++++++++-------------------- 1 file changed, 480 insertions(+), 507 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 278ef77b0..169da27ca 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -38,7 +38,8 @@ #include "zcbenchmarks.h" #include "script/interpreter.h" #include "zcash/zip32.h" -#include "cc/CCinclude.h" +#include "notaries_staked.h" + #include "utiltime.h" #include "asyncrpcoperation.h" #include "asyncrpcqueue.h" @@ -115,6 +116,24 @@ void EnsureWalletIsUnlocked() throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please enter the wallet passphrase with walletpassphrase first."); } +void Lock2NSPV(const CPubKey &pk) +{ + if (!pk.IsValid()) + { + ENTER_CRITICAL_SECTION(cs_main); + ENTER_CRITICAL_SECTION(pwalletMain->cs_wallet); + } +} + +void Unlock2NSPV(const CPubKey &pk) +{ + if (!pk.IsValid()) + { + LEAVE_CRITICAL_SECTION(cs_main); + LEAVE_CRITICAL_SECTION(pwalletMain->cs_wallet); + } +} + uint64_t komodo_accrued_interest(int32_t *txheightp,uint32_t *locktimep,uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue,int32_t tipheight); void WalletTxToJSON(const CWalletTx& wtx, UniValue& entry) @@ -161,7 +180,7 @@ char *komodo_chainname() void OS_randombytes(unsigned char *x,long xlen); -UniValue getnewaddress(const UniValue& params, bool fHelp) +UniValue getnewaddress(const UniValue& params, bool fHelp, const CPubKey& mypk) { if ( KOMODO_NSPV_FULLNODE && !EnsureWalletIsAvailable(fHelp) ) return NullUniValue; @@ -255,7 +274,7 @@ CTxDestination GetAccountAddress(std::string strAccount, bool bForceNew=false) return account.vchPubKey.GetID(); } -UniValue getaccountaddress(const UniValue& params, bool fHelp) +UniValue getaccountaddress(const UniValue& params, bool fHelp, const CPubKey& mypk) { if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; @@ -287,7 +306,7 @@ UniValue getaccountaddress(const UniValue& params, bool fHelp) } -UniValue getrawchangeaddress(const UniValue& params, bool fHelp) +UniValue getrawchangeaddress(const UniValue& params, bool fHelp, const CPubKey& mypk) { if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; @@ -322,7 +341,7 @@ UniValue getrawchangeaddress(const UniValue& params, bool fHelp) } -UniValue setaccount(const UniValue& params, bool fHelp) +UniValue setaccount(const UniValue& params, bool fHelp, const CPubKey& mypk) { if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; @@ -368,7 +387,7 @@ UniValue setaccount(const UniValue& params, bool fHelp) } -UniValue getaccount(const UniValue& params, bool fHelp) +UniValue getaccount(const UniValue& params, bool fHelp, const CPubKey& mypk) { if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; @@ -402,7 +421,7 @@ UniValue getaccount(const UniValue& params, bool fHelp) } -UniValue getaddressesbyaccount(const UniValue& params, bool fHelp) +UniValue getaddressesbyaccount(const UniValue& params, bool fHelp, const CPubKey& mypk) { if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; @@ -484,7 +503,7 @@ static void SendMoney(const CTxDestination &address, CAmount nValue, bool fSubtr } -UniValue sendtoaddress(const UniValue& params, bool fHelp) +UniValue sendtoaddress(const UniValue& params, bool fHelp, const CPubKey& mypk) { if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; @@ -573,7 +592,7 @@ int32_t komodo_kvduration(uint32_t flags); uint256 komodo_kvprivkey(uint256 *pubkeyp,char *passphrase); int32_t komodo_kvsigverify(uint8_t *buf,int32_t len,uint256 _pubkey,uint256 sig); -UniValue kvupdate(const UniValue& params, bool fHelp) +UniValue kvupdate(const UniValue& params, bool fHelp, const CPubKey& mypk) { static uint256 zeroes; CWalletTx wtx; UniValue ret(UniValue::VOBJ); @@ -715,7 +734,7 @@ UniValue kvupdate(const UniValue& params, bool fHelp) return ret; } -UniValue paxdeposit(const UniValue& params, bool fHelp) +UniValue paxdeposit(const UniValue& params, bool fHelp, const CPubKey& mypk) { uint64_t available,deposited,issued,withdrawn,approved,redeemed,seed,komodoshis = 0; int32_t height; char destaddr[64]; uint8_t i,pubkey37[33]; bool fSubtractFeeFromAmount = false; @@ -761,7 +780,7 @@ UniValue paxdeposit(const UniValue& params, bool fHelp) return wtx.GetHash().GetHex(); } -UniValue paxwithdraw(const UniValue& params, bool fHelp) +UniValue paxwithdraw(const UniValue& params, bool fHelp, const CPubKey& mypk) { CWalletTx wtx; std::string dest; int32_t kmdheight; uint64_t seed,komodoshis = 0; char destaddr[64]; uint8_t i,pubkey37[37]; bool fSubtractFeeFromAmount = false; if ( ASSETCHAINS_SYMBOL[0] == 0 ) @@ -796,7 +815,7 @@ UniValue paxwithdraw(const UniValue& params, bool fHelp) return wtx.GetHash().GetHex(); } -UniValue listaddressgroupings(const UniValue& params, bool fHelp) +UniValue listaddressgroupings(const UniValue& params, bool fHelp, const CPubKey& mypk) { if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; @@ -847,7 +866,7 @@ UniValue listaddressgroupings(const UniValue& params, bool fHelp) return jsonGroupings; } -UniValue signmessage(const UniValue& params, bool fHelp) +UniValue signmessage(const UniValue& params, bool fHelp, const CPubKey& mypk) { if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; @@ -906,7 +925,7 @@ UniValue signmessage(const UniValue& params, bool fHelp) return EncodeBase64(&vchSig[0], vchSig.size()); } -UniValue getreceivedbyaddress(const UniValue& params, bool fHelp) +UniValue getreceivedbyaddress(const UniValue& params, bool fHelp, const CPubKey& mypk) { if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; @@ -977,7 +996,7 @@ UniValue getreceivedbyaddress(const UniValue& params, bool fHelp) } -UniValue getreceivedbyaccount(const UniValue& params, bool fHelp) +UniValue getreceivedbyaccount(const UniValue& params, bool fHelp, const CPubKey& mypk) { if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; @@ -1075,7 +1094,7 @@ CAmount GetAccountBalance(const string& strAccount, int nMinDepth, const isminef return GetAccountBalance(walletdb, strAccount, nMinDepth, filter); } -UniValue cleanwallettransactions(const UniValue& params, bool fHelp) +UniValue cleanwallettransactions(const UniValue& params, bool fHelp, const CPubKey& mypk) { if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; @@ -1178,7 +1197,7 @@ UniValue cleanwallettransactions(const UniValue& params, bool fHelp) return (ret); } -UniValue getbalance(const UniValue& params, bool fHelp) +UniValue getbalance(const UniValue& params, bool fHelp, const CPubKey& mypk) { if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; @@ -1260,7 +1279,7 @@ UniValue getbalance(const UniValue& params, bool fHelp) return ValueFromAmount(nBalance); } -UniValue getunconfirmedbalance(const UniValue ¶ms, bool fHelp) +UniValue getunconfirmedbalance(const UniValue& params, bool fHelp, const CPubKey& mypk) { if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; @@ -1276,7 +1295,7 @@ UniValue getunconfirmedbalance(const UniValue ¶ms, bool fHelp) } -UniValue movecmd(const UniValue& params, bool fHelp) +UniValue movecmd(const UniValue& params, bool fHelp, const CPubKey& mypk) { if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; @@ -1351,7 +1370,7 @@ UniValue movecmd(const UniValue& params, bool fHelp) } -UniValue sendfrom(const UniValue& params, bool fHelp) +UniValue sendfrom(const UniValue& params, bool fHelp, const CPubKey& mypk) { if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; @@ -1419,7 +1438,7 @@ UniValue sendfrom(const UniValue& params, bool fHelp) } -UniValue sendmany(const UniValue& params, bool fHelp) +UniValue sendmany(const UniValue& params, bool fHelp, const CPubKey& mypk) { if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; @@ -1487,11 +1506,15 @@ UniValue sendmany(const UniValue& params, bool fHelp) for (const std::string& name_ : keys) { CTxDestination dest = DecodeDestination(name_); if (!IsValidDestination(dest)) { - throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, std::string("Invalid Hush address: ") + name_); + CScript tmpspk; + tmpspk << ParseHex(name_) << OP_CHECKSIG; + if ( !ExtractDestination(tmpspk, dest, true) ) + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, std::string("Invalid Komodo address or pubkey: ") + name_); } CScript scriptPubKey = GetScriptForDestination(dest); CAmount nAmount = AmountFromValue(sendTo[i]); + i++; if (nAmount <= 0) throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount for send"); totalAmount += nAmount; @@ -1532,7 +1555,7 @@ UniValue sendmany(const UniValue& params, bool fHelp) // Defined in rpc/misc.cpp extern CScript _createmultisig_redeemScript(const UniValue& params); -UniValue addmultisigaddress(const UniValue& params, bool fHelp) +UniValue addmultisigaddress(const UniValue& params, bool fHelp, const CPubKey& mypk) { if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; @@ -1727,7 +1750,7 @@ UniValue ListReceived(const UniValue& params, bool fByAccounts) return ret; } -UniValue listreceivedbyaddress(const UniValue& params, bool fHelp) +UniValue listreceivedbyaddress(const UniValue& params, bool fHelp, const CPubKey& mypk) { if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; @@ -1764,7 +1787,7 @@ UniValue listreceivedbyaddress(const UniValue& params, bool fHelp) return ListReceived(params, false); } -UniValue listreceivedbyaccount(const UniValue& params, bool fHelp) +UniValue listreceivedbyaccount(const UniValue& params, bool fHelp, const CPubKey& mypk) { if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; @@ -1858,7 +1881,11 @@ void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDe entry.push_back(Pair("involvesWatchonly", true)); entry.push_back(Pair("account", account)); - MaybePushAddress(entry, r.destination); + CTxDestination dest; + if (CScriptExt::ExtractVoutDestination(wtx, r.vout, dest)) + MaybePushAddress(entry, dest); + else + MaybePushAddress(entry, r.destination); if (bIsCoinbase) { @@ -1906,7 +1933,7 @@ void AcentryToJSON(const CAccountingEntry& acentry, const string& strAccount, Un } } -UniValue listtransactions(const UniValue& params, bool fHelp) +UniValue listtransactions(const UniValue& params, bool fHelp, const CPubKey& mypk) { if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; @@ -2031,7 +2058,7 @@ UniValue listtransactions(const UniValue& params, bool fHelp) return ret; } -UniValue listaccounts(const UniValue& params, bool fHelp) +UniValue listaccounts(const UniValue& params, bool fHelp, const CPubKey& mypk) { if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; @@ -2111,7 +2138,7 @@ UniValue listaccounts(const UniValue& params, bool fHelp) return ret; } -UniValue listsinceblock(const UniValue& params, bool fHelp) +UniValue listsinceblock(const UniValue& params, bool fHelp, const CPubKey& mypk) { if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; @@ -2202,7 +2229,7 @@ UniValue listsinceblock(const UniValue& params, bool fHelp) return ret; } -UniValue gettransaction(const UniValue& params, bool fHelp) +UniValue gettransaction(const UniValue& params, bool fHelp, const CPubKey& mypk) { if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; @@ -2291,7 +2318,7 @@ UniValue gettransaction(const UniValue& params, bool fHelp) } -UniValue backupwallet(const UniValue& params, bool fHelp) +UniValue backupwallet(const UniValue& params, bool fHelp, const CPubKey& mypk) { if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; @@ -2334,7 +2361,7 @@ UniValue backupwallet(const UniValue& params, bool fHelp) } -UniValue keypoolrefill(const UniValue& params, bool fHelp) +UniValue keypoolrefill(const UniValue& params, bool fHelp, const CPubKey& mypk) { if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; @@ -2378,7 +2405,7 @@ static void LockWallet(CWallet* pWallet) pWallet->Lock(); } -UniValue walletpassphrase(const UniValue& params, bool fHelp) +UniValue walletpassphrase(const UniValue& params, bool fHelp, const CPubKey& mypk) { if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; @@ -2440,7 +2467,7 @@ UniValue walletpassphrase(const UniValue& params, bool fHelp) } -UniValue walletpassphrasechange(const UniValue& params, bool fHelp) +UniValue walletpassphrasechange(const UniValue& params, bool fHelp, const CPubKey& mypk) { if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; @@ -2486,7 +2513,7 @@ UniValue walletpassphrasechange(const UniValue& params, bool fHelp) } -UniValue walletlock(const UniValue& params, bool fHelp) +UniValue walletlock(const UniValue& params, bool fHelp, const CPubKey& mypk) { if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; @@ -2526,7 +2553,7 @@ UniValue walletlock(const UniValue& params, bool fHelp) int32_t komodo_acpublic(uint32_t tiptime); -UniValue encryptwallet(const UniValue& params, bool fHelp) +UniValue encryptwallet(const UniValue& params, bool fHelp, const CPubKey& mypk) { if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; @@ -2596,7 +2623,7 @@ UniValue encryptwallet(const UniValue& params, bool fHelp) return "wallet encrypted; Komodo server stopping, restart to run with encrypted wallet. The keypool has been flushed, you need to make a new backup."; } -UniValue lockunspent(const UniValue& params, bool fHelp) +UniValue lockunspent(const UniValue& params, bool fHelp, const CPubKey& mypk) { if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; @@ -2680,7 +2707,7 @@ UniValue lockunspent(const UniValue& params, bool fHelp) return true; } -UniValue listlockunspent(const UniValue& params, bool fHelp) +UniValue listlockunspent(const UniValue& params, bool fHelp, const CPubKey& mypk) { if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; @@ -2729,7 +2756,7 @@ UniValue listlockunspent(const UniValue& params, bool fHelp) return ret; } -UniValue settxfee(const UniValue& params, bool fHelp) +UniValue settxfee(const UniValue& params, bool fHelp, const CPubKey& mypk) { if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; @@ -2756,7 +2783,7 @@ UniValue settxfee(const UniValue& params, bool fHelp) return true; } -UniValue getwalletinfo(const UniValue& params, bool fHelp) +UniValue getwalletinfo(const UniValue& params, bool fHelp, const CPubKey& mypk) { if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; @@ -2802,7 +2829,7 @@ UniValue getwalletinfo(const UniValue& params, bool fHelp) return obj; } -UniValue resendwallettransactions(const UniValue& params, bool fHelp) +UniValue resendwallettransactions(const UniValue& params, bool fHelp, const CPubKey& mypk) { if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; @@ -2829,7 +2856,7 @@ UniValue resendwallettransactions(const UniValue& params, bool fHelp) extern uint32_t komodo_segid32(char *coinaddr); -UniValue listunspent(const UniValue& params, bool fHelp) +UniValue listunspent(const UniValue& params, bool fHelp, const CPubKey& mypk) { if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; @@ -3002,7 +3029,7 @@ uint64_t komodo_interestsum() } -UniValue z_listunspent(const UniValue& params, bool fHelp) +UniValue z_listunspent(const UniValue& params, bool fHelp, const CPubKey& mypk) { if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; @@ -3014,6 +3041,7 @@ UniValue z_listunspent(const UniValue& params, bool fHelp) "Optionally filter to only include notes sent to specified addresses.\n" "When minconf is 0, unspent notes with zero confirmations are returned, even though they are not immediately spendable.\n" "Results are an array of Objects, each of which has:\n" + "{txid, jsindex, jsoutindex, confirmations, address, amount, memo} (Sprout)\n" "{txid, outindex, confirmations, address, amount, memo} (Sapling)\n" "\nArguments:\n" "1. minconf (numeric, optional, default=1) The minimum confirmations to filter\n" @@ -3029,6 +3057,7 @@ UniValue z_listunspent(const UniValue& params, bool fHelp) " {\n" " \"txid\" : \"txid\", (string) the transaction id \n" " \"jsindex\" : n (numeric) the joinsplit index\n" + " \"jsoutindex\" (sprout) : n (numeric) the output index of the joinsplit\n" " \"outindex\" (sapling) : n (numeric) the output index\n" " \"confirmations\" : n (numeric) the number of confirmations\n" " \"spendable\" : true|false (boolean) true if note can be spent by wallet, false if note has zero confirmations, false if address is watchonly\n" @@ -3153,7 +3182,7 @@ UniValue z_listunspent(const UniValue& params, bool fHelp) return results; } -UniValue fundrawtransaction(const UniValue& params, bool fHelp) +UniValue fundrawtransaction(const UniValue& params, bool fHelp, const CPubKey& mypk) { if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; @@ -3207,7 +3236,7 @@ UniValue fundrawtransaction(const UniValue& params, bool fHelp) return result; } -UniValue zc_sample_joinsplit(const UniValue& params, bool fHelp) +UniValue zc_sample_joinsplit(const UniValue& params, bool fHelp, const CPubKey& mypk) { if (fHelp) { throw runtime_error( @@ -3236,7 +3265,7 @@ UniValue zc_sample_joinsplit(const UniValue& params, bool fHelp) return HexStr(ss.begin(), ss.end()); } -UniValue zc_benchmark(const UniValue& params, bool fHelp) +UniValue zc_benchmark(const UniValue& params, bool fHelp, const CPubKey& mypk) { if (!EnsureWalletIsAvailable(fHelp)) { return NullUniValue; @@ -3362,7 +3391,7 @@ UniValue zc_benchmark(const UniValue& params, bool fHelp) return results; } -UniValue zc_raw_receive(const UniValue& params, bool fHelp) +UniValue zc_raw_receive(const UniValue& params, bool fHelp, const CPubKey& mypk) { if (!EnsureWalletIsAvailable(fHelp)) { return NullUniValue; @@ -3449,7 +3478,7 @@ UniValue zc_raw_receive(const UniValue& params, bool fHelp) -UniValue zc_raw_joinsplit(const UniValue& params, bool fHelp) +UniValue zc_raw_joinsplit(const UniValue& params, bool fHelp, const CPubKey& mypk) { if (!EnsureWalletIsAvailable(fHelp)) { return NullUniValue; @@ -3648,7 +3677,7 @@ UniValue zc_raw_joinsplit(const UniValue& params, bool fHelp) return result; } -UniValue zc_raw_keygen(const UniValue& params, bool fHelp) +UniValue zc_raw_keygen(const UniValue& params, bool fHelp, const CPubKey& mypk) { if (!EnsureWalletIsAvailable(fHelp)) { return NullUniValue; @@ -3680,7 +3709,7 @@ UniValue zc_raw_keygen(const UniValue& params, bool fHelp) } -UniValue z_getnewaddress(const UniValue& params, bool fHelp) +UniValue z_getnewaddress(const UniValue& params, bool fHelp, const CPubKey& mypk) { if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; @@ -3729,7 +3758,7 @@ UniValue z_getnewaddress(const UniValue& params, bool fHelp) } -UniValue z_listaddresses(const UniValue& params, bool fHelp) +UniValue z_listaddresses(const UniValue& params, bool fHelp, const CPubKey& mypk) { if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; @@ -3853,7 +3882,7 @@ CAmount getBalanceZaddr(std::string address, int minDepth = 1, bool ignoreUnspen } -UniValue z_listreceivedbyaddress(const UniValue& params, bool fHelp) +UniValue z_listreceivedbyaddress(const UniValue& params, bool fHelp, const CPubKey& mypk) { if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; @@ -3963,7 +3992,7 @@ UniValue z_listreceivedbyaddress(const UniValue& params, bool fHelp) return result; } -UniValue z_getbalance(const UniValue& params, bool fHelp) +UniValue z_getbalance(const UniValue& params, bool fHelp, const CPubKey& mypk) { if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; @@ -4024,7 +4053,7 @@ UniValue z_getbalance(const UniValue& params, bool fHelp) } -UniValue z_gettotalbalance(const UniValue& params, bool fHelp) +UniValue z_gettotalbalance(const UniValue& params, bool fHelp, const CPubKey& mypk) { if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; @@ -4247,7 +4276,8 @@ UniValue z_viewtransaction(const UniValue& params, bool fHelp) return entry; } -UniValue z_getoperationresult(const UniValue& params, bool fHelp) + +UniValue z_getoperationresult(const UniValue& params, bool fHelp, const CPubKey& mypk) { if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; @@ -4270,7 +4300,7 @@ UniValue z_getoperationresult(const UniValue& params, bool fHelp) return z_getoperationstatus_IMPL(params, true); } -UniValue z_getoperationstatus(const UniValue& params, bool fHelp) +UniValue z_getoperationstatus(const UniValue& params, bool fHelp, const CPubKey& mypk) { if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; @@ -4363,7 +4393,7 @@ UniValue z_getoperationstatus_IMPL(const UniValue& params, bool fRemoveFinishedO #define CTXIN_SPEND_DUST_SIZE 148 #define CTXOUT_REGULAR_SIZE 34 -UniValue z_sendmany(const UniValue& params, bool fHelp) +UniValue z_sendmany(const UniValue& params, bool fHelp, const CPubKey& mypk) { if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; @@ -4670,7 +4700,7 @@ When estimating the number of coinbase utxos we can shield in a single transacti #define SHIELD_COINBASE_DEFAULT_LIMIT 50 -UniValue z_shieldcoinbase(const UniValue& params, bool fHelp) +UniValue z_shieldcoinbase(const UniValue& params, bool fHelp, const CPubKey& mypk) { if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; @@ -4901,7 +4931,7 @@ UniValue z_shieldcoinbase(const UniValue& params, bool fHelp) #define OUTPUTDESCRIPTION_SIZE GetSerializeSize(OutputDescription(), SER_NETWORK, PROTOCOL_VERSION) #define SPENDDESCRIPTION_SIZE GetSerializeSize(SpendDescription(), SER_NETWORK, PROTOCOL_VERSION) -UniValue z_mergetoaddress(const UniValue& params, bool fHelp) +UniValue z_mergetoaddress(const UniValue& params, bool fHelp, const CPubKey& mypk) { if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; @@ -5330,7 +5360,7 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp) return o; } -UniValue z_listoperationids(const UniValue& params, bool fHelp) +UniValue z_listoperationids(const UniValue& params, bool fHelp, const CPubKey& mypk) { if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; @@ -5382,9 +5412,9 @@ UniValue z_listoperationids(const UniValue& params, bool fHelp) int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex); extern std::string NOTARY_PUBKEY; -int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33) +int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33, void *pTr) { - set setAddress; uint8_t *script,utxosig[128]; uint256 utxotxid; uint64_t utxovalue; int32_t i,siglen=0,nMinDepth = 1,nMaxDepth = 9999999; vector vecOutputs; uint32_t utxovout,eligible,earliest = 0; CScript best_scriptPubKey; bool fNegative,fOverflow; + set setAddress; uint8_t *script,utxosig[128]; uint256 utxotxid; uint64_t utxovalue; int32_t i,siglen=0,nMinDepth = 0,nMaxDepth = 9999999; vector vecOutputs; uint32_t utxovout,eligible,earliest = 0; CScript best_scriptPubKey; bool fNegative,fOverflow; bool signSuccess; SignatureData sigdata; uint64_t txfee; uint8_t *ptr; auto consensusBranchId = CurrentEpochBranchId(chainActive.Height() + 1, Params().GetConsensus()); if (!EnsureWalletIsAvailable(0)) @@ -5435,7 +5465,7 @@ int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33) //fprintf(stderr,"check %s/v%d %llu\n",(char *)utxotxid.GetHex().c_str(),utxovout,(long long)utxovalue); txNew.vin.resize(1); - txNew.vout.resize(1); + txNew.vout.resize((pTr!=0)+1); txfee = utxovalue / 2; //for (i=0; i<32; i++) // ((uint8_t *)&revtxid)[i] = ((uint8_t *)&utxotxid)[31 - i]; @@ -5443,6 +5473,13 @@ int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33) txNew.vin[0].prevout.n = utxovout; txNew.vout[0].nValue = utxovalue - txfee; txNew.vout[0].scriptPubKey = CScript() << ParseHex(CRYPTO777_PUBSECPSTR) << OP_CHECKSIG; + if ( pTr != 0 ) + { + void **p = (void**)pTr; + txNew.vout[1].nValue = 0; + txNew.vout[1].scriptPubKey = *(CScript*)p[0]; + txNew.nLockTime = (uint32_t)(unsigned long long)p[1]; + } CTransaction txNewConst(txNew); signSuccess = ProduceSignature(TransactionSignatureCreator(&keystore, &txNewConst, 0, utxovalue, SIGHASH_ALL), best_scriptPubKey, sigdata, consensusBranchId); if (!signSuccess) @@ -5577,11 +5614,8 @@ UniValue CCaddress(struct CCcontract_info *cp,char *name,std::vector 1 ) @@ -5664,7 +5698,7 @@ UniValue channelsaddress(const UniValue& params, bool fHelp) return(CCaddress(cp,(char *)"Channels",pubkey)); } -UniValue cclibaddress(const UniValue& params, bool fHelp) +UniValue cclibaddress(const UniValue& params, bool fHelp, const CPubKey& mypk) { struct CCcontract_info *cp,C; std::vector pubkey; uint8_t evalcode = EVAL_FIRSTUSER; if ( fHelp || params.size() > 2 ) @@ -5685,7 +5719,7 @@ UniValue cclibaddress(const UniValue& params, bool fHelp) return(CCaddress(cp,(char *)"CClib",pubkey)); } -UniValue cclibinfo(const UniValue& params, bool fHelp) +UniValue cclibinfo(const UniValue& params, bool fHelp, const CPubKey& mypk) { struct CCcontract_info *cp,C; uint8_t evalcode = EVAL_FIRSTUSER; if ( fHelp || params.size() > 0 ) @@ -5696,7 +5730,7 @@ UniValue cclibinfo(const UniValue& params, bool fHelp) return(CClib_info(cp)); } -UniValue cclib(const UniValue& params, bool fHelp) +UniValue cclib(const UniValue& params, bool fHelp, const CPubKey& mypk) { struct CCcontract_info *cp,C; char *method,*jsonstr=0; uint8_t evalcode = EVAL_FIRSTUSER; std::string vobjJsonSerialized; @@ -5733,7 +5767,7 @@ UniValue cclib(const UniValue& params, bool fHelp) return(CClib(cp,method,jsonstr)); } -UniValue payments_release(const UniValue& params, bool fHelp) +UniValue payments_release(const UniValue& params, bool fHelp, const CPubKey& mypk) { struct CCcontract_info *cp,C; if ( fHelp || params.size() != 1 ) @@ -5746,7 +5780,7 @@ UniValue payments_release(const UniValue& params, bool fHelp) return(PaymentsRelease(cp,(char *)params[0].get_str().c_str())); } -UniValue payments_fund(const UniValue& params, bool fHelp) +UniValue payments_fund(const UniValue& params, bool fHelp, const CPubKey& mypk) { struct CCcontract_info *cp,C; if ( fHelp || params.size() != 1 ) @@ -5759,7 +5793,7 @@ UniValue payments_fund(const UniValue& params, bool fHelp) return(PaymentsFund(cp,(char *)params[0].get_str().c_str())); } -UniValue payments_merge(const UniValue& params, bool fHelp) +UniValue payments_merge(const UniValue& params, bool fHelp, const CPubKey& mypk) { struct CCcontract_info *cp,C; if ( fHelp || params.size() != 1 ) @@ -5772,7 +5806,7 @@ UniValue payments_merge(const UniValue& params, bool fHelp) return(PaymentsMerge(cp,(char *)params[0].get_str().c_str())); } -UniValue payments_txidopret(const UniValue& params, bool fHelp) +UniValue payments_txidopret(const UniValue& params, bool fHelp, const CPubKey& mypk) { struct CCcontract_info *cp,C; if ( fHelp || params.size() != 1 ) @@ -5785,7 +5819,7 @@ UniValue payments_txidopret(const UniValue& params, bool fHelp) return(PaymentsTxidopret(cp,(char *)params[0].get_str().c_str())); } -UniValue payments_create(const UniValue& params, bool fHelp) +UniValue payments_create(const UniValue& params, bool fHelp, const CPubKey& mypk) { struct CCcontract_info *cp,C; if ( fHelp || params.size() != 1 ) @@ -5798,7 +5832,7 @@ UniValue payments_create(const UniValue& params, bool fHelp) return(PaymentsCreate(cp,(char *)params[0].get_str().c_str())); } -UniValue payments_airdrop(const UniValue& params, bool fHelp) +UniValue payments_airdrop(const UniValue& params, bool fHelp, const CPubKey& mypk) { struct CCcontract_info *cp,C; if ( fHelp || params.size() != 1 ) @@ -5811,7 +5845,7 @@ UniValue payments_airdrop(const UniValue& params, bool fHelp) return(PaymentsAirdrop(cp,(char *)params[0].get_str().c_str())); } -UniValue payments_airdroptokens(const UniValue& params, bool fHelp) +UniValue payments_airdroptokens(const UniValue& params, bool fHelp, const CPubKey& mypk) { struct CCcontract_info *cp,C; if ( fHelp || params.size() != 1 ) @@ -5824,7 +5858,7 @@ UniValue payments_airdroptokens(const UniValue& params, bool fHelp) return(PaymentsAirdropTokens(cp,(char *)params[0].get_str().c_str())); } -UniValue payments_info(const UniValue& params, bool fHelp) +UniValue payments_info(const UniValue& params, bool fHelp, const CPubKey& mypk) { struct CCcontract_info *cp,C; if ( fHelp || params.size() != 1 ) @@ -5837,7 +5871,7 @@ UniValue payments_info(const UniValue& params, bool fHelp) return(PaymentsInfo(cp,(char *)params[0].get_str().c_str())); } -UniValue payments_list(const UniValue& params, bool fHelp) +UniValue payments_list(const UniValue& params, bool fHelp, const CPubKey& mypk) { struct CCcontract_info *cp,C; if ( fHelp || params.size() != 0 ) @@ -5850,7 +5884,7 @@ UniValue payments_list(const UniValue& params, bool fHelp) return(PaymentsList(cp,(char *)"")); } -UniValue oraclesaddress(const UniValue& params, bool fHelp) +UniValue oraclesaddress(const UniValue& params, bool fHelp, const CPubKey& mypk) { struct CCcontract_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_ORACLES); @@ -5863,9 +5897,9 @@ UniValue oraclesaddress(const UniValue& params, bool fHelp) return(CCaddress(cp,(char *)"Oracles",pubkey)); } -UniValue pricesaddress(const UniValue& params, bool fHelp) +UniValue pricesaddress(const UniValue& params, bool fHelp, const CPubKey& mypk) { - UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C,*assetscp,C2; std::vector pubkey; CPubKey mypk,planpk,pricespk; char myaddr[64],houseaddr[64],exposureaddr[64]; + UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C,*assetscp,C2; std::vector pubkey; CPubKey pk,planpk,pricespk; char myaddr[64],houseaddr[64],exposureaddr[64]; cp = CCinit(&C,EVAL_PRICES); assetscp = CCinit(&C2,EVAL_PRICES); if ( fHelp || params.size() > 1 ) @@ -5875,9 +5909,10 @@ UniValue pricesaddress(const UniValue& params, bool fHelp) if ( params.size() == 1 ) pubkey = ParseHex(params[0].get_str().c_str()); result = CCaddress(cp,(char *)"Prices",pubkey); - mypk = pubkey2pk(Mypubkey()); + if (mypk.IsValid()) pk=mypk; + else pk = pubkey2pk(Mypubkey()); pricespk = GetUnspendable(cp,0); - GetCCaddress(assetscp,myaddr,mypk); + GetCCaddress(assetscp,myaddr,pk); GetCCaddress1of2(assetscp,houseaddr,pricespk,planpk); GetCCaddress1of2(assetscp,exposureaddr,pricespk,pricespk); result.push_back(Pair("myaddr",myaddr)); // for holding my asssets @@ -5886,7 +5921,7 @@ UniValue pricesaddress(const UniValue& params, bool fHelp) return(result); } -UniValue pegsaddress(const UniValue& params, bool fHelp) +UniValue pegsaddress(const UniValue& params, bool fHelp, const CPubKey& mypk) { struct CCcontract_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_PEGS); @@ -5899,7 +5934,7 @@ UniValue pegsaddress(const UniValue& params, bool fHelp) return(CCaddress(cp,(char *)"Pegs",pubkey)); } -UniValue marmaraaddress(const UniValue& params, bool fHelp) +UniValue marmaraaddress(const UniValue& params, bool fHelp, const CPubKey& mypk) { struct CCcontract_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_MARMARA); @@ -5912,7 +5947,7 @@ UniValue marmaraaddress(const UniValue& params, bool fHelp) return(CCaddress(cp,(char *)"Marmara",pubkey)); } -UniValue paymentsaddress(const UniValue& params, bool fHelp) +UniValue paymentsaddress(const UniValue& params, bool fHelp, const CPubKey& mypk) { struct CCcontract_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_PAYMENTS); @@ -5925,7 +5960,7 @@ UniValue paymentsaddress(const UniValue& params, bool fHelp) return(CCaddress(cp,(char *)"Payments",pubkey)); } -UniValue gatewaysaddress(const UniValue& params, bool fHelp) +UniValue gatewaysaddress(const UniValue& params, bool fHelp, const CPubKey& mypk) { struct CCcontract_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_GATEWAYS); @@ -5938,7 +5973,7 @@ UniValue gatewaysaddress(const UniValue& params, bool fHelp) return(CCaddress(cp,(char *)"Gateways",pubkey)); } -UniValue heiraddress(const UniValue& params, bool fHelp) +UniValue heiraddress(const UniValue& params, bool fHelp, const CPubKey& mypk) { struct CCcontract_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_HEIR); @@ -5950,7 +5985,7 @@ UniValue heiraddress(const UniValue& params, bool fHelp) return(CCaddress(cp,(char *)"Heir",pubkey)); } -UniValue lottoaddress(const UniValue& params, bool fHelp) +UniValue lottoaddress(const UniValue& params, bool fHelp, const CPubKey& mypk) { struct CCcontract_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_LOTTO); @@ -5963,7 +5998,7 @@ UniValue lottoaddress(const UniValue& params, bool fHelp) return(CCaddress(cp,(char *)"Lotto",pubkey)); } -UniValue FSMaddress(const UniValue& params, bool fHelp) +UniValue FSMaddress(const UniValue& params, bool fHelp, const CPubKey& mypk) { struct CCcontract_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_FSM); @@ -5976,7 +6011,7 @@ UniValue FSMaddress(const UniValue& params, bool fHelp) return(CCaddress(cp,(char *)"FSM",pubkey)); } -UniValue auctionaddress(const UniValue& params, bool fHelp) +UniValue auctionaddress(const UniValue& params, bool fHelp, const CPubKey& mypk) { struct CCcontract_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_AUCTION); @@ -5989,7 +6024,7 @@ UniValue auctionaddress(const UniValue& params, bool fHelp) return(CCaddress(cp,(char *)"Auction",pubkey)); } -UniValue diceaddress(const UniValue& params, bool fHelp) +UniValue diceaddress(const UniValue& params, bool fHelp, const CPubKey& mypk) { struct CCcontract_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_DICE); @@ -6002,7 +6037,7 @@ UniValue diceaddress(const UniValue& params, bool fHelp) return(CCaddress(cp,(char *)"Dice",pubkey)); } -UniValue faucetaddress(const UniValue& params, bool fHelp) +UniValue faucetaddress(const UniValue& params, bool fHelp, const CPubKey& mypk) { struct CCcontract_info *cp,C; std::vector pubkey; int error; @@ -6017,7 +6052,7 @@ UniValue faucetaddress(const UniValue& params, bool fHelp) return(CCaddress(cp,(char *)"Faucet",pubkey)); } -UniValue rewardsaddress(const UniValue& params, bool fHelp) +UniValue rewardsaddress(const UniValue& params, bool fHelp, const CPubKey& mypk) { struct CCcontract_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_REWARDS); @@ -6030,7 +6065,7 @@ UniValue rewardsaddress(const UniValue& params, bool fHelp) return(CCaddress(cp,(char *)"Rewards",pubkey)); } -UniValue assetsaddress(const UniValue& params, bool fHelp) +UniValue assetsaddress(const UniValue& params, bool fHelp, const CPubKey& mypk) { struct CCcontract_info *cp, C; std::vector pubkey; cp = CCinit(&C, EVAL_ASSETS); @@ -6043,7 +6078,7 @@ UniValue assetsaddress(const UniValue& params, bool fHelp) return(CCaddress(cp, (char *)"Assets", pubkey)); } -UniValue tokenaddress(const UniValue& params, bool fHelp) +UniValue tokenaddress(const UniValue& params, bool fHelp, const CPubKey& mypk) { struct CCcontract_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_TOKENS); @@ -6056,7 +6091,7 @@ UniValue tokenaddress(const UniValue& params, bool fHelp) return(CCaddress(cp,(char *)"Tokens", pubkey)); } -UniValue importgatewayaddress(const UniValue& params, bool fHelp) +UniValue importgatewayaddress(const UniValue& params, bool fHelp, const CPubKey& mypk) { struct CCcontract_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_IMPORTGATEWAY); @@ -6069,7 +6104,7 @@ UniValue importgatewayaddress(const UniValue& params, bool fHelp) return(CCaddress(cp,(char *)"ImportGateway", pubkey)); } -UniValue marmara_poolpayout(const UniValue& params, bool fHelp) +UniValue marmara_poolpayout(const UniValue& params, bool fHelp, const CPubKey& mypk) { int32_t firstheight; double perc; char *jsonstr; if ( fHelp || params.size() != 3 ) @@ -6088,7 +6123,7 @@ UniValue marmara_poolpayout(const UniValue& params, bool fHelp) return(MarmaraPoolPayout(0,firstheight,perc,jsonstr)); // [[pk0, shares0], [pk1, shares1], ...] } -UniValue marmara_receive(const UniValue& params, bool fHelp) +UniValue marmara_receive(const UniValue& params, bool fHelp, const CPubKey& mypk) { UniValue result(UniValue::VOBJ); uint256 batontxid; std::vector senderpub; int64_t amount; int32_t matures; std::string currency; if ( fHelp || (params.size() != 5 && params.size() != 4) ) @@ -6119,7 +6154,7 @@ UniValue marmara_receive(const UniValue& params, bool fHelp) return(MarmaraReceive(0,pubkey2pk(senderpub),amount,currency,matures,batontxid,true)); } -UniValue marmara_issue(const UniValue& params, bool fHelp) +UniValue marmara_issue(const UniValue& params, bool fHelp, const CPubKey& mypk) { UniValue result(UniValue::VOBJ); uint256 approvaltxid; std::vector receiverpub; int64_t amount; int32_t matures; std::string currency; if ( fHelp || params.size() != 5 ) @@ -6146,7 +6181,7 @@ UniValue marmara_issue(const UniValue& params, bool fHelp) return(MarmaraIssue(0,'I',pubkey2pk(receiverpub),amount,currency,matures,approvaltxid,zeroid)); } -UniValue marmara_transfer(const UniValue& params, bool fHelp) +UniValue marmara_transfer(const UniValue& params, bool fHelp, const CPubKey& mypk) { UniValue result(UniValue::VOBJ); uint256 approvaltxid,batontxid; std::vector receiverpub; int64_t amount; int32_t matures; std::string currency; std::vector creditloop; if ( fHelp || params.size() != 5 ) @@ -6173,7 +6208,7 @@ UniValue marmara_transfer(const UniValue& params, bool fHelp) return(MarmaraIssue(0,'T',pubkey2pk(receiverpub),amount,currency,matures,approvaltxid,batontxid)); } -UniValue marmara_info(const UniValue& params, bool fHelp) +UniValue marmara_info(const UniValue& params, bool fHelp, const CPubKey& mypk) { UniValue result(UniValue::VOBJ); CPubKey issuerpk; std::vector issuerpub; int64_t minamount,maxamount; int32_t firstheight,lastheight; std::string currency; if ( fHelp || params.size() < 4 || params.size() > 6 ) @@ -6204,7 +6239,7 @@ UniValue marmara_info(const UniValue& params, bool fHelp) return(result); } -UniValue marmara_creditloop(const UniValue& params, bool fHelp) +UniValue marmara_creditloop(const UniValue& params, bool fHelp, const CPubKey& mypk) { UniValue result(UniValue::VOBJ); uint256 txid; if ( fHelp || params.size() != 1 ) @@ -6221,7 +6256,7 @@ UniValue marmara_creditloop(const UniValue& params, bool fHelp) return(result); } -UniValue marmara_settlement(const UniValue& params, bool fHelp) +UniValue marmara_settlement(const UniValue& params, bool fHelp, const CPubKey& mypk) { UniValue result(UniValue::VOBJ); uint256 batontxid; if ( fHelp || params.size() != 1 ) @@ -6239,7 +6274,7 @@ UniValue marmara_settlement(const UniValue& params, bool fHelp) return(result); } -UniValue marmara_lock(const UniValue& params, bool fHelp) +UniValue marmara_lock(const UniValue& params, bool fHelp, const CPubKey& mypk) { UniValue result(UniValue::VOBJ); int64_t amount; int32_t height; if ( fHelp || params.size() > 2 || params.size() == 0 ) @@ -6255,151 +6290,119 @@ UniValue marmara_lock(const UniValue& params, bool fHelp) return(MarmaraLock(0,amount,height)); } -UniValue channelslist(const UniValue& params, bool fHelp) +UniValue channelslist(const UniValue& params, bool fHelp, const CPubKey& mypk) { if ( fHelp || params.size() > 0 ) - throw runtime_error("channelsinfo\n"); + throw runtime_error("channelslist\n"); if ( ensure_CCrequirements(EVAL_CHANNELS) < 0 ) throw runtime_error(CC_REQUIREMENTS_MSG); - const CKeyStore& keystore = *pwalletMain; - LOCK2(cs_main, pwalletMain->cs_wallet); - return(ChannelsList()); + return(ChannelsList(mypk)); } -UniValue channelsinfo(const UniValue& params, bool fHelp) +UniValue channelsinfo(const UniValue& params, bool fHelp, const CPubKey& mypk) { uint256 opentxid; if ( fHelp || params.size() > 1 ) throw runtime_error("channelsinfo [opentxid]\n"); if ( ensure_CCrequirements(EVAL_CHANNELS) < 0 ) throw runtime_error(CC_REQUIREMENTS_MSG); - const CKeyStore& keystore = *pwalletMain; - LOCK2(cs_main, pwalletMain->cs_wallet); opentxid=zeroid; if (params.size() > 0 && !params[0].isNull() && !params[0].get_str().empty()) opentxid = Parseuint256((char *)params[0].get_str().c_str()); - return(ChannelsInfo(opentxid)); + return(ChannelsInfo(mypk,opentxid)); } -UniValue channelsopen(const UniValue& params, bool fHelp) +UniValue channelsopen(const UniValue& params, bool fHelp, const CPubKey& mypk) { - UniValue result(UniValue::VOBJ); int32_t numpayments; int64_t payment; std::vector destpub; struct CCcontract_info *cp,C; std::string hex; + UniValue result(UniValue::VOBJ); int32_t numpayments; int64_t payment; std::vector destpub; struct CCcontract_info *cp,C; uint256 tokenid=zeroid; cp = CCinit(&C,EVAL_CHANNELS); if ( fHelp || params.size() < 3 || params.size() > 4) - throw runtime_error("channelsopen destpubkey numpayments payment\n"); + throw runtime_error("channelsopen destpubkey numpayments payment [tokenid]\n"); if ( ensure_CCrequirements(EVAL_CHANNELS) < 0 ) throw runtime_error(CC_REQUIREMENTS_MSG); - const CKeyStore& keystore = *pwalletMain; - LOCK2(cs_main, pwalletMain->cs_wallet); + Lock2NSPV(mypk); destpub = ParseHex(params[0].get_str().c_str()); - if (destpub.size()!= 33) - { - ERR_RESULT("invalid destination pubkey"); - return result; - } numpayments = atoi(params[1].get_str().c_str()); - if (numpayments <1) - { - ERR_RESULT("invalid number of payments, must be greater than 0"); - return result; - } payment = atol(params[2].get_str().c_str()); - if (payment <1) - { - ERR_RESULT("invalid payment amount, must be greater than 0"); - return result; - } if (params.size()==4) { tokenid=Parseuint256((char *)params[3].get_str().c_str()); } - hex = ChannelOpen(0,pubkey2pk(destpub),numpayments,payment,tokenid); - RETURN_IF_ERROR(CCerror); - if ( hex.size() > 0 ) + result = ChannelOpen(mypk,0,pubkey2pk(destpub),numpayments,payment,tokenid); + if ( result[JSON_HEXTX].getValStr().size() > 0 ) { result.push_back(Pair("result", "success")); - result.push_back(Pair("hex", hex)); - } else ERR_RESULT("couldnt create channelsopen transaction"); + } + Unlock2NSPV(mypk); return(result); } -UniValue channelspayment(const UniValue& params, bool fHelp) +UniValue channelspayment(const UniValue& params, bool fHelp, const CPubKey& mypk) { - UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; std::string hex; uint256 opentxid,secret=zeroid; int32_t n; int64_t amount; + UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; uint256 opentxid,secret=zeroid; int32_t n; int64_t amount; cp = CCinit(&C,EVAL_CHANNELS); if ( fHelp || params.size() < 2 || params.size() >3 ) throw runtime_error("channelspayment opentxid amount [secret]\n"); if ( ensure_CCrequirements(EVAL_CHANNELS) < 0 ) throw runtime_error(CC_REQUIREMENTS_MSG); - const CKeyStore& keystore = *pwalletMain; - LOCK2(cs_main, pwalletMain->cs_wallet); + Lock2NSPV(mypk); opentxid = Parseuint256((char *)params[0].get_str().c_str()); amount = atoi((char *)params[1].get_str().c_str()); - if (amount <1) - { - ERR_RESULT("invalid payment amount, must be greater than 0"); - return result; - } if (params.size() > 2 && !params[2].isNull() && !params[2].get_str().empty()) { secret = Parseuint256((char *)params[2].get_str().c_str()); } - hex = ChannelPayment(0,opentxid,amount,secret); - RETURN_IF_ERROR(CCerror); - if ( hex.size() > 0 ) + result = ChannelPayment(mypk,0,opentxid,amount,secret); + if ( result[JSON_HEXTX].getValStr().size() > 0 ) { result.push_back(Pair("result", "success")); - result.push_back(Pair("hex", hex)); - } else ERR_RESULT("couldnt create channelspayment transaction"); + } + Unlock2NSPV(mypk); return(result); } -UniValue channelsclose(const UniValue& params, bool fHelp) +UniValue channelsclose(const UniValue& params, bool fHelp, const CPubKey& mypk) { - UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; std::string hex; uint256 opentxid; + UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; uint256 opentxid; cp = CCinit(&C,EVAL_CHANNELS); if ( fHelp || params.size() != 1 ) throw runtime_error("channelsclose opentxid\n"); if ( ensure_CCrequirements(EVAL_CHANNELS) < 0 ) throw runtime_error(CC_REQUIREMENTS_MSG); - const CKeyStore& keystore = *pwalletMain; - LOCK2(cs_main, pwalletMain->cs_wallet); + Lock2NSPV(mypk); opentxid = Parseuint256((char *)params[0].get_str().c_str()); - hex = ChannelClose(0,opentxid); - RETURN_IF_ERROR(CCerror); - if ( hex.size() > 0 ) + result = ChannelClose(mypk,0,opentxid); + if ( result[JSON_HEXTX].getValStr().size() > 0 ) { result.push_back(Pair("result", "success")); - result.push_back(Pair("hex", hex)); - } else ERR_RESULT("couldnt create channelsclose transaction"); + } + Unlock2NSPV(mypk); return(result); } -UniValue channelsrefund(const UniValue& params, bool fHelp) +UniValue channelsrefund(const UniValue& params, bool fHelp, const CPubKey& mypk) { - UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; std::string hex; uint256 opentxid,closetxid; + UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; uint256 opentxid,closetxid; cp = CCinit(&C,EVAL_CHANNELS); if ( fHelp || params.size() != 2 ) throw runtime_error("channelsrefund opentxid closetxid\n"); if ( ensure_CCrequirements(EVAL_CHANNELS) < 0 ) throw runtime_error(CC_REQUIREMENTS_MSG); - const CKeyStore& keystore = *pwalletMain; - LOCK2(cs_main, pwalletMain->cs_wallet); + Lock2NSPV(mypk); opentxid = Parseuint256((char *)params[0].get_str().c_str()); closetxid = Parseuint256((char *)params[1].get_str().c_str()); - hex = ChannelRefund(0,opentxid,closetxid); - RETURN_IF_ERROR(CCerror); - if ( hex.size() > 0 ) + result = ChannelRefund(mypk,0,opentxid,closetxid); + if ( result[JSON_HEXTX].getValStr().size() > 0 ) { result.push_back(Pair("result", "success")); - result.push_back(Pair("hex", hex)); - } else ERR_RESULT("couldnt create channelsrefund transaction"); + } + Unlock2NSPV(mypk); return(result); } -UniValue rewardscreatefunding(const UniValue& params, bool fHelp) +UniValue rewardscreatefunding(const UniValue& params, bool fHelp, const CPubKey& mypk) { UniValue result(UniValue::VOBJ); char *name; int64_t funds,APR,minseconds,maxseconds,mindeposit; std::string hex; if ( fHelp || params.size() > 6 || params.size() < 2 ) @@ -6468,7 +6471,7 @@ UniValue rewardscreatefunding(const UniValue& params, bool fHelp) return(result); } -UniValue rewardslock(const UniValue& params, bool fHelp) +UniValue rewardslock(const UniValue& params, bool fHelp, const CPubKey& mypk) { UniValue result(UniValue::VOBJ); char *name; uint256 fundingtxid; int64_t amount; std::string hex; if ( fHelp || params.size() != 3 ) @@ -6498,7 +6501,7 @@ UniValue rewardslock(const UniValue& params, bool fHelp) return(result); } -UniValue rewardsaddfunding(const UniValue& params, bool fHelp) +UniValue rewardsaddfunding(const UniValue& params, bool fHelp, const CPubKey& mypk) { UniValue result(UniValue::VOBJ); char *name; uint256 fundingtxid; int64_t amount; std::string hex; if ( fHelp || params.size() != 3 ) @@ -6533,7 +6536,7 @@ UniValue rewardsaddfunding(const UniValue& params, bool fHelp) return(result); } -UniValue rewardsunlock(const UniValue& params, bool fHelp) +UniValue rewardsunlock(const UniValue& params, bool fHelp, const CPubKey& mypk) { UniValue result(UniValue::VOBJ); std::string hex; char *name; uint256 fundingtxid,txid; if ( fHelp || params.size() > 3 || params.size() < 2 ) @@ -6562,7 +6565,7 @@ UniValue rewardsunlock(const UniValue& params, bool fHelp) return(result); } -UniValue rewardslist(const UniValue& params, bool fHelp) +UniValue rewardslist(const UniValue& params, bool fHelp, const CPubKey& mypk) { if ( fHelp || params.size() > 0 ) throw runtime_error("rewardslist\n"); @@ -6573,7 +6576,7 @@ UniValue rewardslist(const UniValue& params, bool fHelp) return(RewardsList()); } -UniValue rewardsinfo(const UniValue& params, bool fHelp) +UniValue rewardsinfo(const UniValue& params, bool fHelp, const CPubKey& mypk) { uint256 fundingtxid; if ( fHelp || params.size() != 1 ) @@ -6586,18 +6589,17 @@ UniValue rewardsinfo(const UniValue& params, bool fHelp) return(RewardsInfo(fundingtxid)); } -UniValue gatewayslist(const UniValue& params, bool fHelp) +UniValue gatewayslist(const UniValue& params, bool fHelp, const CPubKey& mypk) { if ( fHelp || params.size() > 0 ) throw runtime_error("gatewayslist\n"); if ( ensure_CCrequirements(EVAL_GATEWAYS) < 0 ) throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; - LOCK2(cs_main, pwalletMain->cs_wallet); return(GatewaysList()); } -UniValue gatewaysexternaladdress(const UniValue& params, bool fHelp) +UniValue gatewaysexternaladdress(const UniValue& params, bool fHelp, const CPubKey& mypk) { uint256 bindtxid; CPubKey pubkey; @@ -6605,14 +6607,12 @@ UniValue gatewaysexternaladdress(const UniValue& params, bool fHelp) throw runtime_error("gatewaysexternaladdress bindtxid pubkey\n"); if ( ensure_CCrequirements(EVAL_GATEWAYS) < 0 ) throw runtime_error(CC_REQUIREMENTS_MSG); - const CKeyStore& keystore = *pwalletMain; - LOCK2(cs_main, pwalletMain->cs_wallet); bindtxid = Parseuint256((char *)params[0].get_str().c_str()); pubkey = ParseHex(params[1].get_str().c_str()); return(GatewaysExternalAddress(bindtxid,pubkey)); } -UniValue gatewaysdumpprivkey(const UniValue& params, bool fHelp) +UniValue gatewaysdumpprivkey(const UniValue& params, bool fHelp, const CPubKey& mypk) { uint256 bindtxid; @@ -6620,7 +6620,6 @@ UniValue gatewaysdumpprivkey(const UniValue& params, bool fHelp) throw runtime_error("gatewaysdumpprivkey bindtxid address\n"); if ( ensure_CCrequirements(EVAL_GATEWAYS) < 0 ) throw runtime_error(CC_REQUIREMENTS_MSG); - LOCK2(cs_main, pwalletMain->cs_wallet); bindtxid = Parseuint256((char *)params[0].get_str().c_str()); std::string strAddress = params[1].get_str(); CTxDestination dest = DecodeDestination(strAddress); @@ -6638,30 +6637,27 @@ UniValue gatewaysdumpprivkey(const UniValue& params, bool fHelp) return(GatewaysDumpPrivKey(bindtxid,vchSecret)); } -UniValue gatewaysinfo(const UniValue& params, bool fHelp) +UniValue gatewaysinfo(const UniValue& params, bool fHelp, const CPubKey& mypk) { uint256 txid; if ( fHelp || params.size() != 1 ) throw runtime_error("gatewaysinfo bindtxid\n"); if ( ensure_CCrequirements(EVAL_GATEWAYS) < 0 ) throw runtime_error(CC_REQUIREMENTS_MSG); - const CKeyStore& keystore = *pwalletMain; - LOCK2(cs_main, pwalletMain->cs_wallet); txid = Parseuint256((char *)params[0].get_str().c_str()); return(GatewaysInfo(txid)); } -UniValue gatewaysbind(const UniValue& params, bool fHelp) +UniValue gatewaysbind(const UniValue& params, bool fHelp, const CPubKey& mypk) { UniValue result(UniValue::VOBJ); uint256 tokenid,oracletxid; int32_t i; int64_t totalsupply; std::vector pubkeys; - uint8_t M,N,p1,p2,p3,p4=0; std::string hex,coin; std::vector pubkey; + uint8_t M,N,p1,p2,p3,p4=0; std::string coin; std::vector pubkey; if ( fHelp || params.size() < 10 ) throw runtime_error("gatewaysbind tokenid oracletxid coin tokensupply M N pubkey(s) pubtype p2shtype wiftype [taddr]\n"); if ( ensure_CCrequirements(EVAL_GATEWAYS) < 0 ) throw runtime_error(CC_REQUIREMENTS_MSG); - const CKeyStore& keystore = *pwalletMain; - LOCK2(cs_main, pwalletMain->cs_wallet); + Lock2NSPV(mypk); tokenid = Parseuint256((char *)params[0].get_str().c_str()); oracletxid = Parseuint256((char *)params[1].get_str().c_str()); coin = params[2].get_str(); @@ -6669,39 +6665,46 @@ UniValue gatewaysbind(const UniValue& params, bool fHelp) M = atoi((char *)params[4].get_str().c_str()); N = atoi((char *)params[5].get_str().c_str()); if ( M > N || N == 0 || N > 15 || totalsupply < COIN/100 || tokenid == zeroid ) + { + Unlock2NSPV(mypk); throw runtime_error("illegal M or N > 15 or tokensupply or invalid tokenid\n"); + } if ( params.size() < 6+N+3 ) + { + Unlock2NSPV(mypk); throw runtime_error("not enough parameters for N pubkeys\n"); + } for (i=0; i 0 ) + result = GatewaysBind(mypk,0,coin,tokenid,totalsupply,oracletxid,M,N,pubkeys,p1,p2,p3,p4); + if ( result[JSON_HEXTX].getValStr().size() > 0 ) { result.push_back(Pair("result", "success")); - result.push_back(Pair("hex", hex)); - } else ERR_RESULT("couldnt gatewaysbind"); + } + Unlock2NSPV(mypk); return(result); } -UniValue gatewaysdeposit(const UniValue& params, bool fHelp) +UniValue gatewaysdeposit(const UniValue& params, bool fHelp, const CPubKey& mypk) { - UniValue result(UniValue::VOBJ); int32_t i,claimvout,height; int64_t amount; std::string hex,coin,deposithex; uint256 bindtxid,cointxid; std::vectorproof,destpub,pubkey; + UniValue result(UniValue::VOBJ); int32_t i,claimvout,height; int64_t amount; std::string coin,deposithex; uint256 bindtxid,cointxid; std::vectorproof,destpub,pubkey; if ( fHelp || params.size() != 9 ) throw runtime_error("gatewaysdeposit bindtxid height coin cointxid claimvout deposithex proof destpub amount\n"); if ( ensure_CCrequirements(EVAL_GATEWAYS) < 0 ) throw runtime_error(CC_REQUIREMENTS_MSG); - const CKeyStore& keystore = *pwalletMain; - LOCK2(cs_main, pwalletMain->cs_wallet); + Lock2NSPV(mypk); bindtxid = Parseuint256((char *)params[0].get_str().c_str()); height = atoi((char *)params[1].get_str().c_str()); coin = params[2].get_str(); @@ -6712,354 +6715,315 @@ UniValue gatewaysdeposit(const UniValue& params, bool fHelp) destpub = ParseHex(params[7].get_str()); amount = atof((char *)params[8].get_str().c_str()) * COIN + 0.00000000499999; if ( amount <= 0 || claimvout < 0 ) + { + Unlock2NSPV(mypk); throw runtime_error("invalid param: amount, numpks or claimvout\n"); + } if (destpub.size()!= 33) + { + Unlock2NSPV(mypk); throw runtime_error("invalid destination pubkey"); - hex = GatewaysDeposit(0,bindtxid,height,coin,cointxid,claimvout,deposithex,proof,pubkey2pk(destpub),amount); - - RETURN_IF_ERROR(CCerror); - if ( hex.size() > 0 ) + } + result = GatewaysDeposit(mypk,0,bindtxid,height,coin,cointxid,claimvout,deposithex,proof,pubkey2pk(destpub),amount); + if ( result[JSON_HEXTX].getValStr().size() > 0 ) { result.push_back(Pair("result", "success")); - result.push_back(Pair("hex", hex)); - } else ERR_RESULT("couldnt gatewaysdeposit"); + } + Unlock2NSPV(mypk); return(result); } -UniValue gatewaysclaim(const UniValue& params, bool fHelp) +UniValue gatewaysclaim(const UniValue& params, bool fHelp, const CPubKey& mypk) { - UniValue result(UniValue::VOBJ); std::string hex,coin; uint256 bindtxid,deposittxid; std::vectordestpub; int64_t amount; + UniValue result(UniValue::VOBJ); std::string coin; uint256 bindtxid,deposittxid; std::vectordestpub; int64_t amount; if ( fHelp || params.size() != 5 ) throw runtime_error("gatewaysclaim bindtxid coin deposittxid destpub amount\n"); if ( ensure_CCrequirements(EVAL_GATEWAYS) < 0 ) throw runtime_error(CC_REQUIREMENTS_MSG); - const CKeyStore& keystore = *pwalletMain; - LOCK2(cs_main, pwalletMain->cs_wallet); + Lock2NSPV(mypk); bindtxid = Parseuint256((char *)params[0].get_str().c_str()); coin = params[1].get_str(); deposittxid = Parseuint256((char *)params[2].get_str().c_str()); destpub = ParseHex(params[3].get_str()); amount = atof((char *)params[4].get_str().c_str()) * COIN + 0.00000000499999; if (destpub.size()!= 33) + { + Unlock2NSPV(mypk); throw runtime_error("invalid destination pubkey"); - hex = GatewaysClaim(0,bindtxid,coin,deposittxid,pubkey2pk(destpub),amount); - RETURN_IF_ERROR(CCerror); - if ( hex.size() > 0 ) + } + result = GatewaysClaim(mypk,0,bindtxid,coin,deposittxid,pubkey2pk(destpub),amount); + if ( result[JSON_HEXTX].getValStr().size() > 0 ) { result.push_back(Pair("result", "success")); - result.push_back(Pair("hex", hex)); - } else ERR_RESULT("couldnt gatewaysclaim"); + } + Unlock2NSPV(mypk); return(result); } -UniValue gatewayswithdraw(const UniValue& params, bool fHelp) +UniValue gatewayswithdraw(const UniValue& params, bool fHelp, const CPubKey& mypk) { - UniValue result(UniValue::VOBJ); uint256 bindtxid; int64_t amount; std::string hex,coin; std::vector withdrawpub; + UniValue result(UniValue::VOBJ); uint256 bindtxid; int64_t amount; std::string coin; std::vector withdrawpub; if ( fHelp || params.size() != 4 ) throw runtime_error("gatewayswithdraw bindtxid coin withdrawpub amount\n"); if ( ensure_CCrequirements(EVAL_GATEWAYS) < 0 ) throw runtime_error(CC_REQUIREMENTS_MSG); - const CKeyStore& keystore = *pwalletMain; - LOCK2(cs_main, pwalletMain->cs_wallet); + Lock2NSPV(mypk); bindtxid = Parseuint256((char *)params[0].get_str().c_str()); coin = params[1].get_str(); withdrawpub = ParseHex(params[2].get_str()); amount = atof((char *)params[3].get_str().c_str()) * COIN + 0.00000000499999; if (withdrawpub.size()!= 33) + { + Unlock2NSPV(mypk); throw runtime_error("invalid destination pubkey"); - hex = GatewaysWithdraw(0,bindtxid,coin,pubkey2pk(withdrawpub),amount); - RETURN_IF_ERROR(CCerror); - if ( hex.size() > 0 ) + } + result = GatewaysWithdraw(mypk,0,bindtxid,coin,pubkey2pk(withdrawpub),amount); + if ( result[JSON_HEXTX].getValStr().size() > 0 ) { result.push_back(Pair("result", "success")); - result.push_back(Pair("hex", hex)); - } else ERR_RESULT("couldnt gatewayswithdraw"); + } + Lock2NSPV(mypk); return(result); } -UniValue gatewayspartialsign(const UniValue& params, bool fHelp) +UniValue gatewayspartialsign(const UniValue& params, bool fHelp, const CPubKey& mypk) { - UniValue result(UniValue::VOBJ); std::string coin,parthex,hex; uint256 txid; + UniValue result(UniValue::VOBJ); std::string coin,parthex; uint256 txid; if ( fHelp || params.size() != 3 ) throw runtime_error("gatewayspartialsign txidaddr refcoin hex\n"); if ( ensure_CCrequirements(EVAL_GATEWAYS) < 0 ) throw runtime_error(CC_REQUIREMENTS_MSG); - const CKeyStore& keystore = *pwalletMain; - LOCK2(cs_main, pwalletMain->cs_wallet); + Lock2NSPV(mypk); txid = Parseuint256((char *)params[0].get_str().c_str()); coin = params[1].get_str(); parthex = params[2].get_str(); - hex = GatewaysPartialSign(0,txid,coin,parthex); - RETURN_IF_ERROR(CCerror); - if ( hex.size() > 0 ) + result = GatewaysPartialSign(mypk,0,txid,coin,parthex); + if ( result[JSON_HEXTX].getValStr().size() > 0 ) { result.push_back(Pair("result", "success")); - result.push_back(Pair("hex",hex)); - } else ERR_RESULT("couldnt gatewayspartialsign"); + } + Unlock2NSPV(mypk); return(result); } -UniValue gatewayscompletesigning(const UniValue& params, bool fHelp) +UniValue gatewayscompletesigning(const UniValue& params, bool fHelp, const CPubKey& mypk) { - UniValue result(UniValue::VOBJ); uint256 withdrawtxid; std::string txhex,hex,coin; + UniValue result(UniValue::VOBJ); uint256 withdrawtxid; std::string txhex,coin; if ( fHelp || params.size() != 3 ) throw runtime_error("gatewayscompletesigning withdrawtxid coin hex\n"); if ( ensure_CCrequirements(EVAL_GATEWAYS) < 0 ) throw runtime_error(CC_REQUIREMENTS_MSG); - const CKeyStore& keystore = *pwalletMain; - LOCK2(cs_main, pwalletMain->cs_wallet); + Lock2NSPV(mypk); withdrawtxid = Parseuint256((char *)params[0].get_str().c_str()); coin = params[1].get_str(); txhex = params[2].get_str(); - hex = GatewaysCompleteSigning(0,withdrawtxid,coin,txhex); - RETURN_IF_ERROR(CCerror); - if ( hex.size() > 0 ) + result = GatewaysCompleteSigning(mypk,0,withdrawtxid,coin,txhex); + if ( result[JSON_HEXTX].getValStr().size() > 0 ) { result.push_back(Pair("result", "success")); - result.push_back(Pair("hex", hex)); - } else ERR_RESULT("couldnt gatewayscompletesigning"); + } + Unlock2NSPV(mypk); return(result); } -UniValue gatewaysmarkdone(const UniValue& params, bool fHelp) +UniValue gatewaysmarkdone(const UniValue& params, bool fHelp, const CPubKey& mypk) { - UniValue result(UniValue::VOBJ); uint256 completetxid; std::string hex,coin; + UniValue result(UniValue::VOBJ); uint256 completetxid; std::string coin; if ( fHelp || params.size() != 2 ) throw runtime_error("gatewaysmarkdone completesigningtx coin\n"); if ( ensure_CCrequirements(EVAL_GATEWAYS) < 0 ) throw runtime_error(CC_REQUIREMENTS_MSG); - const CKeyStore& keystore = *pwalletMain; - LOCK2(cs_main, pwalletMain->cs_wallet); + Lock2NSPV(mypk); completetxid = Parseuint256((char *)params[0].get_str().c_str()); coin = params[1].get_str(); - hex = GatewaysMarkDone(0,completetxid,coin); - RETURN_IF_ERROR(CCerror); - if ( hex.size() > 0 ) + result = GatewaysMarkDone(mypk,0,completetxid,coin); + if ( result[JSON_HEXTX].getValStr().size() > 0 ) { result.push_back(Pair("result", "success")); - result.push_back(Pair("hex", hex)); - } else ERR_RESULT("couldnt gatewaysmarkdone"); + } + Unlock2NSPV(mypk); return(result); } -UniValue gatewayspendingdeposits(const UniValue& params, bool fHelp) +UniValue gatewayspendingdeposits(const UniValue& params, bool fHelp, const CPubKey& mypk) { uint256 bindtxid; std::string coin; if ( fHelp || params.size() != 2 ) throw runtime_error("gatewayspendingdeposits bindtxid coin\n"); if ( ensure_CCrequirements(EVAL_GATEWAYS) < 0 ) throw runtime_error(CC_REQUIREMENTS_MSG); - const CKeyStore& keystore = *pwalletMain; - LOCK2(cs_main, pwalletMain->cs_wallet); bindtxid = Parseuint256((char *)params[0].get_str().c_str()); coin = params[1].get_str(); - return(GatewaysPendingDeposits(bindtxid,coin)); + return(GatewaysPendingDeposits(mypk,bindtxid,coin)); } -UniValue gatewayspendingwithdraws(const UniValue& params, bool fHelp) +UniValue gatewayspendingwithdraws(const UniValue& params, bool fHelp, const CPubKey& mypk) { uint256 bindtxid; std::string coin; if ( fHelp || params.size() != 2 ) throw runtime_error("gatewayspendingwithdraws bindtxid coin\n"); if ( ensure_CCrequirements(EVAL_GATEWAYS) < 0 ) throw runtime_error(CC_REQUIREMENTS_MSG); - const CKeyStore& keystore = *pwalletMain; - LOCK2(cs_main, pwalletMain->cs_wallet); bindtxid = Parseuint256((char *)params[0].get_str().c_str()); coin = params[1].get_str(); - return(GatewaysPendingWithdraws(bindtxid,coin)); + return(GatewaysPendingWithdraws(mypk,bindtxid,coin)); } -UniValue gatewaysprocessed(const UniValue& params, bool fHelp) +UniValue gatewaysprocessed(const UniValue& params, bool fHelp, const CPubKey& mypk) { uint256 bindtxid; std::string coin; if ( fHelp || params.size() != 2 ) throw runtime_error("gatewaysprocessed bindtxid coin\n"); if ( ensure_CCrequirements(EVAL_GATEWAYS) < 0 ) throw runtime_error(CC_REQUIREMENTS_MSG); - const CKeyStore& keystore = *pwalletMain; - LOCK2(cs_main, pwalletMain->cs_wallet); bindtxid = Parseuint256((char *)params[0].get_str().c_str()); coin = params[1].get_str(); - return(GatewaysProcessedWithdraws(bindtxid,coin)); + return(GatewaysProcessedWithdraws(mypk,bindtxid,coin)); } -UniValue oracleslist(const UniValue& params, bool fHelp) +UniValue oracleslist(const UniValue& params, bool fHelp, const CPubKey& mypk) { if ( fHelp || params.size() > 0 ) throw runtime_error("oracleslist\n"); if ( ensure_CCrequirements(EVAL_ORACLES) < 0 ) throw runtime_error(CC_REQUIREMENTS_MSG); - const CKeyStore& keystore = *pwalletMain; - LOCK2(cs_main, pwalletMain->cs_wallet); return(OraclesList()); } -UniValue oraclesinfo(const UniValue& params, bool fHelp) +UniValue oraclesinfo(const UniValue& params, bool fHelp, const CPubKey& mypk) { uint256 txid; if ( fHelp || params.size() != 1 ) throw runtime_error("oraclesinfo oracletxid\n"); if ( ensure_CCrequirements(EVAL_ORACLES) < 0 ) throw runtime_error(CC_REQUIREMENTS_MSG); - const CKeyStore& keystore = *pwalletMain; - LOCK2(cs_main, pwalletMain->cs_wallet); txid = Parseuint256((char *)params[0].get_str().c_str()); return(OracleInfo(txid)); } -UniValue oraclesfund(const UniValue& params, bool fHelp) +UniValue oraclesfund(const UniValue& params, bool fHelp, const CPubKey& mypk) { - UniValue result(UniValue::VOBJ); uint256 txid; std::string hex; + UniValue result(UniValue::VOBJ); uint256 txid; if ( fHelp || params.size() != 1 ) throw runtime_error("oraclesfund oracletxid\n"); if ( ensure_CCrequirements(EVAL_ORACLES) < 0 ) throw runtime_error(CC_REQUIREMENTS_MSG); - const CKeyStore& keystore = *pwalletMain; - LOCK2(cs_main, pwalletMain->cs_wallet); + Lock2NSPV(mypk); txid = Parseuint256((char *)params[0].get_str().c_str()); - hex = OracleFund(0,txid); - RETURN_IF_ERROR(CCerror); - if ( hex.size() > 0 ) + result = OracleFund(mypk,0,txid); + if ( result[JSON_HEXTX].getValStr().size() > 0 ) { result.push_back(Pair("result", "success")); - result.push_back(Pair("hex", hex)); - } else ERR_RESULT("couldnt fund with oracle txid"); + } + Unlock2NSPV(mypk); return(result); } -UniValue oraclesregister(const UniValue& params, bool fHelp) +UniValue oraclesregister(const UniValue& params, bool fHelp, const CPubKey& mypk) { - UniValue result(UniValue::VOBJ); uint256 txid; int64_t datafee; std::string hex; + UniValue result(UniValue::VOBJ); uint256 txid; int64_t datafee; if ( fHelp || params.size() != 2 ) throw runtime_error("oraclesregister oracletxid datafee\n"); if ( ensure_CCrequirements(EVAL_ORACLES) < 0 ) throw runtime_error(CC_REQUIREMENTS_MSG); - const CKeyStore& keystore = *pwalletMain; - LOCK2(cs_main, pwalletMain->cs_wallet); + Lock2NSPV(mypk); txid = Parseuint256((char *)params[0].get_str().c_str()); if ( (datafee= atol((char *)params[1].get_str().c_str())) == 0 ) datafee = atof((char *)params[1].get_str().c_str()) * COIN + 0.00000000499999; - hex = OracleRegister(0,txid,datafee); - RETURN_IF_ERROR(CCerror); - if ( hex.size() > 0 ) + result = OracleRegister(mypk,0,txid,datafee); + if ( result[JSON_HEXTX].getValStr().size() > 0 ) { result.push_back(Pair("result", "success")); - result.push_back(Pair("hex", hex)); - } else ERR_RESULT("couldnt register with oracle txid"); + } + Unlock2NSPV(mypk); return(result); } -UniValue oraclessubscribe(const UniValue& params, bool fHelp) +UniValue oraclessubscribe(const UniValue& params, bool fHelp, const CPubKey& mypk) { - UniValue result(UniValue::VOBJ); uint256 txid; int64_t amount; std::string hex; std::vector pubkey; + UniValue result(UniValue::VOBJ); uint256 txid; int64_t amount; std::vector pubkey; if ( fHelp || params.size() != 3 ) throw runtime_error("oraclessubscribe oracletxid publisher amount\n"); if ( ensure_CCrequirements(EVAL_ORACLES) < 0 ) throw runtime_error(CC_REQUIREMENTS_MSG); - const CKeyStore& keystore = *pwalletMain; - LOCK2(cs_main, pwalletMain->cs_wallet); + Lock2NSPV(mypk); txid = Parseuint256((char *)params[0].get_str().c_str()); pubkey = ParseHex(params[1].get_str().c_str()); amount = atof((char *)params[2].get_str().c_str()) * COIN + 0.00000000499999; - hex = OracleSubscribe(0,txid,pubkey2pk(pubkey),amount); - RETURN_IF_ERROR(CCerror); - if ( hex.size() > 0 ) + result = OracleSubscribe(mypk,0,txid,pubkey2pk(pubkey),amount); + if ( result[JSON_HEXTX].getValStr().size() > 0 ) { result.push_back(Pair("result", "success")); - result.push_back(Pair("hex", hex)); - } else ERR_RESULT("couldnt subscribe with oracle txid"); + } + Unlock2NSPV(mypk); return(result); } -UniValue oraclessample(const UniValue& params, bool fHelp) +UniValue oraclessample(const UniValue& params, bool fHelp, const CPubKey& mypk) { UniValue result(UniValue::VOBJ); uint256 oracletxid,txid; int32_t num; char *batonaddr; if ( fHelp || params.size() != 2 ) throw runtime_error("oraclessample oracletxid txid\n"); if ( ensure_CCrequirements(EVAL_ORACLES) < 0 ) throw runtime_error(CC_REQUIREMENTS_MSG); - const CKeyStore& keystore = *pwalletMain; - LOCK2(cs_main, pwalletMain->cs_wallet); oracletxid = Parseuint256((char *)params[0].get_str().c_str()); txid = Parseuint256((char *)params[1].get_str().c_str()); return(OracleDataSample(oracletxid,txid)); } -UniValue oraclessamples(const UniValue& params, bool fHelp) +UniValue oraclessamples(const UniValue& params, bool fHelp, const CPubKey& mypk) { UniValue result(UniValue::VOBJ); uint256 txid; int32_t num; char *batonaddr; if ( fHelp || params.size() != 3 ) throw runtime_error("oraclessamples oracletxid batonaddress num\n"); if ( ensure_CCrequirements(EVAL_ORACLES) < 0 ) throw runtime_error(CC_REQUIREMENTS_MSG); - const CKeyStore& keystore = *pwalletMain; - LOCK2(cs_main, pwalletMain->cs_wallet); txid = Parseuint256((char *)params[0].get_str().c_str()); batonaddr = (char *)params[1].get_str().c_str(); num = atoi((char *)params[2].get_str().c_str()); return(OracleDataSamples(txid,batonaddr,num)); } -UniValue oraclesdata(const UniValue& params, bool fHelp) +UniValue oraclesdata(const UniValue& params, bool fHelp, const CPubKey& mypk) { - UniValue result(UniValue::VOBJ); uint256 txid; std::vector data; std::string hex; + UniValue result(UniValue::VOBJ); uint256 txid; std::vector data; if ( fHelp || params.size() != 2 ) throw runtime_error("oraclesdata oracletxid hexstr\n"); if ( ensure_CCrequirements(EVAL_ORACLES) < 0 ) throw runtime_error(CC_REQUIREMENTS_MSG); - const CKeyStore& keystore = *pwalletMain; - LOCK2(cs_main, pwalletMain->cs_wallet); + Lock2NSPV(mypk); txid = Parseuint256((char *)params[0].get_str().c_str()); data = ParseHex(params[1].get_str().c_str()); - hex = OracleData(0,txid,data); - RETURN_IF_ERROR(CCerror); - if ( hex.size() > 0 ) + result = OracleData(mypk,0,txid,data); + if ( result[JSON_HEXTX].getValStr().size() > 0 ) { result.push_back(Pair("result", "success")); - result.push_back(Pair("hex", hex)); - } else ERR_RESULT("couldnt publish data with oracle txid"); + } + Unlock2NSPV(mypk); return(result); } -UniValue oraclescreate(const UniValue& params, bool fHelp) +UniValue oraclescreate(const UniValue& params, bool fHelp, const CPubKey& mypk) { - UniValue result(UniValue::VOBJ); std::string name,description,format,hex; + UniValue result(UniValue::VOBJ); std::string name,description,format; if ( fHelp || params.size() != 3 ) throw runtime_error("oraclescreate name description format\n"); if ( ensure_CCrequirements(EVAL_ORACLES) < 0 ) throw runtime_error(CC_REQUIREMENTS_MSG); - const CKeyStore& keystore = *pwalletMain; - LOCK2(cs_main, pwalletMain->cs_wallet); + Lock2NSPV(mypk); name = params[0].get_str(); - if ( name.size() == 0 || name.size() > 32) - { - ERR_RESULT("oracles name must not be empty and up to 32 characters"); - return(result); - } description = params[1].get_str(); - if ( description.size() > 4096 ) - { - ERR_RESULT("oracles description must be <= 4096 characters"); - return(result); - } format = params[2].get_str(); - if ( format.size() > 4096 ) - { - ERR_RESULT("oracles format must be <= 4096 characters"); - return(result); - } - hex = OracleCreate(0,name,description,format); - RETURN_IF_ERROR(CCerror); - if ( hex.size() > 0 ) + result = OracleCreate(mypk,0,name,description,format); + if ( result[JSON_HEXTX].getValStr().size() > 0 ) { result.push_back(Pair("result", "success")); - result.push_back(Pair("hex", hex)); - } else ERR_RESULT("couldnt create oracle"); + } + Unlock2NSPV(mypk); return(result); } -UniValue FSMcreate(const UniValue& params, bool fHelp) +UniValue FSMcreate(const UniValue& params, bool fHelp, const CPubKey& mypk) { UniValue result(UniValue::VOBJ); std::string name,states,hex; if ( fHelp || params.size() != 2 ) @@ -7079,7 +7043,7 @@ UniValue FSMcreate(const UniValue& params, bool fHelp) return(result); } -UniValue FSMlist(const UniValue& params, bool fHelp) +UniValue FSMlist(const UniValue& params, bool fHelp, const CPubKey& mypk) { uint256 tokenid; if ( fHelp || params.size() > 0 ) @@ -7089,7 +7053,7 @@ UniValue FSMlist(const UniValue& params, bool fHelp) return(FSMList()); } -UniValue FSMinfo(const UniValue& params, bool fHelp) +UniValue FSMinfo(const UniValue& params, bool fHelp, const CPubKey& mypk) { uint256 FSMtxid; if ( fHelp || params.size() != 1 ) @@ -7100,7 +7064,7 @@ UniValue FSMinfo(const UniValue& params, bool fHelp) return(FSMInfo(FSMtxid)); } -UniValue faucetinfo(const UniValue& params, bool fHelp) +UniValue faucetinfo(const UniValue& params, bool fHelp, const CPubKey& mypk) { uint256 fundingtxid; if ( fHelp || params.size() != 0 ) @@ -7110,10 +7074,10 @@ UniValue faucetinfo(const UniValue& params, bool fHelp) return(FaucetInfo()); } -UniValue faucetfund(const UniValue& params, bool fHelp) +UniValue faucetfund(const UniValue& params, bool fHelp, const CPubKey& mypk) { UniValue result(UniValue::VOBJ); int64_t funds; std::string hex; - if ( fHelp || params.size() > 1 ) + if ( fHelp || params.size() != 1 ) throw runtime_error("faucetfund amount\n"); funds = atof(params[0].get_str().c_str()) * COIN + 0.00000000499999; if ( (0) && KOMODO_NSPV_SUPERLITE ) @@ -7126,32 +7090,68 @@ UniValue faucetfund(const UniValue& params, bool fHelp) } if ( ensure_CCrequirements(EVAL_FAUCET) < 0 ) throw runtime_error(CC_REQUIREMENTS_MSG); - const CKeyStore& keystore = *pwalletMain; - LOCK2(cs_main, pwalletMain->cs_wallet); - if (funds > 0) { - hex = FaucetFund(0,(uint64_t) funds); - if ( hex.size() > 0 ) + + //const CKeyStore& keystore = *pwalletMain; + //LOCK2(cs_main, pwalletMain->cs_wallet); + + bool lockWallet = false; + if (!mypk.IsValid()) // if mypk is not set then it is a local call, use local wallet in AddNormalInputs + lockWallet = true; + + if (funds > 0) + { + if (lockWallet) + { + ENTER_CRITICAL_SECTION(cs_main); + ENTER_CRITICAL_SECTION(pwalletMain->cs_wallet); + } + result = FaucetFund(mypk, 0,(uint64_t) funds); + if (lockWallet) + { + LEAVE_CRITICAL_SECTION(pwalletMain->cs_wallet); + LEAVE_CRITICAL_SECTION(cs_main); + } + + if ( result[JSON_HEXTX].getValStr().size() > 0 ) { result.push_back(Pair("result", "success")); - result.push_back(Pair("hex", hex)); + //result.push_back(Pair("hex", hex)); } else ERR_RESULT("couldnt create faucet funding transaction"); } else ERR_RESULT( "funding amount must be positive"); return(result); } -UniValue faucetget(const UniValue& params, bool fHelp) +UniValue faucetget(const UniValue& params, bool fHelp, const CPubKey& mypk) { UniValue result(UniValue::VOBJ); std::string hex; - if ( fHelp || params.size() > 0 ) + if ( fHelp || params.size() !=0 ) throw runtime_error("faucetget\n"); if ( ensure_CCrequirements(EVAL_FAUCET) < 0 ) throw runtime_error(CC_REQUIREMENTS_MSG); - const CKeyStore& keystore = *pwalletMain; - LOCK2(cs_main, pwalletMain->cs_wallet); - hex = FaucetGet(0); - if ( hex.size() > 0 ) { + + bool lockWallet = false; + if (!mypk.IsValid()) // if mypk is not set then it is a local call, use wallet in AddNormalInputs (see check for this there) + lockWallet = true; + + //const CKeyStore& keystore = *pwalletMain; + //LOCK2(cs_main, pwalletMain->cs_wallet); + + if (lockWallet) + { + // use this instead LOCK2 because we need conditional wallet lock + ENTER_CRITICAL_SECTION(cs_main); + ENTER_CRITICAL_SECTION(pwalletMain->cs_wallet); + } + result = FaucetGet(mypk, 0); + if (lockWallet) + { + LEAVE_CRITICAL_SECTION(pwalletMain->cs_wallet); + LEAVE_CRITICAL_SECTION(cs_main); + } + + if (result[JSON_HEXTX].getValStr().size() > 0 ) { result.push_back(Pair("result", "success")); - result.push_back(Pair("hex", hex)); + //result.push_back(Pair("hex", hex)); } else ERR_RESULT("couldnt create faucet get transaction"); return(result); } @@ -7169,7 +7169,7 @@ uint32_t pricesGetParam(UniValue param) { return filter; } -UniValue priceslist(const UniValue& params, bool fHelp) +UniValue priceslist(const UniValue& params, bool fHelp, const CPubKey& mypk) { if ( fHelp || params.size() != 0 && params.size() != 1) throw runtime_error("priceslist [all|open|closed]\n"); @@ -7184,7 +7184,7 @@ UniValue priceslist(const UniValue& params, bool fHelp) return(PricesList(filter, emptypk)); } -UniValue mypriceslist(const UniValue& params, bool fHelp) +UniValue mypriceslist(const UniValue& params, bool fHelp, const CPubKey& mypk) { if (fHelp || params.size() != 0 && params.size() != 1) throw runtime_error("mypriceslist [all|open|closed]\n"); @@ -7194,12 +7194,14 @@ UniValue mypriceslist(const UniValue& params, bool fHelp) uint32_t filter = 0; if (params.size() == 1) filter = pricesGetParam(params[0]); - CPubKey mypk = pubkey2pk(Mypubkey()); + CPubKey pk; + if (mypk.IsValid()) pk=mypk; + else pk = pubkey2pk(Mypubkey()); - return(PricesList(filter, mypk)); + return(PricesList(filter, pk)); } -UniValue pricesinfo(const UniValue& params, bool fHelp) +UniValue pricesinfo(const UniValue& params, bool fHelp, const CPubKey& mypk) { uint256 bettxid; int32_t height; if ( fHelp || params.size() != 1 && params.size() != 2) @@ -7213,7 +7215,7 @@ UniValue pricesinfo(const UniValue& params, bool fHelp) return(PricesInfo(bettxid, height)); } -UniValue dicefund(const UniValue& params, bool fHelp) +UniValue dicefund(const UniValue& params, bool fHelp, const CPubKey& mypk) { UniValue result(UniValue::VOBJ); int64_t funds,minbet,maxbet,maxodds,timeoutblocks; std::string hex; char *name; if ( fHelp || params.size() != 6 ) @@ -7246,7 +7248,7 @@ UniValue dicefund(const UniValue& params, bool fHelp) return(result); } -UniValue diceaddfunds(const UniValue& params, bool fHelp) +UniValue diceaddfunds(const UniValue& params, bool fHelp, const CPubKey& mypk) { UniValue result(UniValue::VOBJ); char *name; uint256 fundingtxid; int64_t amount; std::string hex; if ( fHelp || params.size() != 3 ) @@ -7274,7 +7276,7 @@ UniValue diceaddfunds(const UniValue& params, bool fHelp) return(result); } -UniValue dicebet(const UniValue& params, bool fHelp) +UniValue dicebet(const UniValue& params, bool fHelp, const CPubKey& mypk) { UniValue result(UniValue::VOBJ); std::string hex,error; uint256 fundingtxid; int64_t amount,odds; char *name; if ( fHelp || params.size() != 4 ) @@ -7306,7 +7308,7 @@ UniValue dicebet(const UniValue& params, bool fHelp) return(result); } -UniValue dicefinish(const UniValue& params, bool fHelp) +UniValue dicefinish(const UniValue& params, bool fHelp, const CPubKey& mypk) { UniValue result(UniValue::VOBJ); uint8_t funcid; char *name; uint256 entropyused,fundingtxid,bettxid; std::string hex; int32_t r,entropyvout; if ( fHelp || params.size() != 3 ) @@ -7341,7 +7343,7 @@ UniValue dicefinish(const UniValue& params, bool fHelp) return(result); } -UniValue dicestatus(const UniValue& params, bool fHelp) +UniValue dicestatus(const UniValue& params, bool fHelp, const CPubKey& mypk) { UniValue result(UniValue::VOBJ); char *name; uint256 fundingtxid,bettxid; std::string status,error; double winnings; if ( fHelp || (params.size() != 2 && params.size() != 3) ) @@ -7390,7 +7392,7 @@ UniValue dicestatus(const UniValue& params, bool fHelp) return(result); } -UniValue dicelist(const UniValue& params, bool fHelp) +UniValue dicelist(const UniValue& params, bool fHelp, const CPubKey& mypk) { if ( fHelp || params.size() > 0 ) throw runtime_error("dicelist\n"); @@ -7399,7 +7401,7 @@ UniValue dicelist(const UniValue& params, bool fHelp) return(DiceList()); } -UniValue diceinfo(const UniValue& params, bool fHelp) +UniValue diceinfo(const UniValue& params, bool fHelp, const CPubKey& mypk) { uint256 fundingtxid; if ( fHelp || params.size() != 1 ) @@ -7410,7 +7412,7 @@ UniValue diceinfo(const UniValue& params, bool fHelp) return(DiceInfo(fundingtxid)); } -UniValue tokenlist(const UniValue& params, bool fHelp) +UniValue tokenlist(const UniValue& params, bool fHelp, const CPubKey& mypk) { uint256 tokenid; if ( fHelp || params.size() > 0 ) @@ -7420,51 +7422,48 @@ UniValue tokenlist(const UniValue& params, bool fHelp) return(TokenList()); } -UniValue tokeninfo(const UniValue& params, bool fHelp) +UniValue tokeninfo(const UniValue& params, bool fHelp, const CPubKey& mypk) { uint256 tokenid; if ( fHelp || params.size() != 1 ) throw runtime_error("tokeninfo tokenid\n"); if ( ensure_CCrequirements(EVAL_TOKENS) < 0 ) throw runtime_error(CC_REQUIREMENTS_MSG); - const CKeyStore& keystore = *pwalletMain; - LOCK2(cs_main, pwalletMain->cs_wallet); tokenid = Parseuint256((char *)params[0].get_str().c_str()); return(TokenInfo(tokenid)); } -UniValue tokenorders(const UniValue& params, bool fHelp) +UniValue tokenorders(const UniValue& params, bool fHelp, const CPubKey& mypk) { uint256 tokenid; if ( fHelp || params.size() > 1 ) - throw runtime_error("tokenorders tokenid\n"); + throw runtime_error("tokenorders [tokenid]\n" + "returns token orders for the tokenid or all available token orders if tokenid is not set\n" + "(this rpc supports only fungible tokens)\n" "\n"); if (ensure_CCrequirements(EVAL_ASSETS) < 0 || ensure_CCrequirements(EVAL_TOKENS) < 0) throw runtime_error(CC_REQUIREMENTS_MSG); - const CKeyStore& keystore = *pwalletMain; - LOCK2(cs_main, pwalletMain->cs_wallet); if (params.size() == 1) { tokenid = Parseuint256((char *)params[0].get_str().c_str()); if (tokenid == zeroid) throw runtime_error("incorrect tokenid\n"); + return AssetOrders(tokenid, CPubKey(), 0); } else { - // memset(&tokenid, 0, sizeof(tokenid)); - throw runtime_error("no tokenid\n"); + // throw runtime_error("no tokenid\n"); + return AssetOrders(zeroid, CPubKey(), 0); } - return AssetOrders(tokenid, CPubKey(), 0); } -UniValue mytokenorders(const UniValue& params, bool fHelp) +UniValue mytokenorders(const UniValue& params, bool fHelp, const CPubKey& mypk) { uint256 tokenid; - if (fHelp || params.size() > 2) - throw runtime_error("mytokenorders [evalcode]\n"); + if (fHelp || params.size() > 1) + throw runtime_error("mytokenorders [evalcode]\n" + "returns all the token orders for mypubkey\n" + "if evalcode is set then returns mypubkey token orders for non-fungible tokens with this evalcode\n" "\n"); if (ensure_CCrequirements(EVAL_ASSETS) < 0 || ensure_CCrequirements(EVAL_TOKENS) < 0) throw runtime_error(CC_REQUIREMENTS_MSG); - const CKeyStore& keystore = *pwalletMain; - LOCK2(cs_main, pwalletMain->cs_wallet); - uint8_t additionalEvalCode = 0; if (params.size() == 1) additionalEvalCode = strtol(params[0].get_str().c_str(), NULL, 0); // supports also 0xEE-like values @@ -7472,7 +7471,7 @@ UniValue mytokenorders(const UniValue& params, bool fHelp) return AssetOrders(zeroid, Mypubkey(), additionalEvalCode); } -UniValue tokenbalance(const UniValue& params, bool fHelp) +UniValue tokenbalance(const UniValue& params, bool fHelp, const CPubKey& mypk) { UniValue result(UniValue::VOBJ); uint256 tokenid; uint64_t balance; std::vector pubkey; struct CCcontract_info *cp,C; CCerror.clear(); @@ -7510,7 +7509,7 @@ UniValue tokenbalance(const UniValue& params, bool fHelp) return(result); } -UniValue tokencreate(const UniValue& params, bool fHelp) +UniValue tokencreate(const UniValue& params, bool fHelp, const CPubKey& mypk) { UniValue result(UniValue::VOBJ); std::string name, description, hextx; @@ -7570,7 +7569,7 @@ UniValue tokencreate(const UniValue& params, bool fHelp) return(result); } -UniValue tokentransfer(const UniValue& params, bool fHelp) +UniValue tokentransfer(const UniValue& params, bool fHelp, const CPubKey& mypk) { UniValue result(UniValue::VOBJ); std::string hex; @@ -7612,7 +7611,7 @@ UniValue tokentransfer(const UniValue& params, bool fHelp) return(result); } -UniValue tokenconvert(const UniValue& params, bool fHelp) +UniValue tokenconvert(const UniValue& params, bool fHelp, const CPubKey& mypk) { UniValue result(UniValue::VOBJ); std::string hex; int32_t evalcode; int64_t amount; uint256 tokenid; if ( fHelp || params.size() != 4 ) @@ -7653,7 +7652,7 @@ UniValue tokenconvert(const UniValue& params, bool fHelp) return(result); */ } -UniValue tokenbid(const UniValue& params, bool fHelp) +UniValue tokenbid(const UniValue& params, bool fHelp, const CPubKey& mypk) { UniValue result(UniValue::VOBJ); int64_t bidamount,numtokens; std::string hex; double price; uint256 tokenid; if ( fHelp || params.size() != 3 ) @@ -7695,7 +7694,7 @@ UniValue tokenbid(const UniValue& params, bool fHelp) return(result); } -UniValue tokencancelbid(const UniValue& params, bool fHelp) +UniValue tokencancelbid(const UniValue& params, bool fHelp, const CPubKey& mypk) { UniValue result(UniValue::VOBJ); std::string hex; int32_t i; uint256 tokenid,bidtxid; if ( fHelp || params.size() != 2 ) @@ -7720,7 +7719,7 @@ UniValue tokencancelbid(const UniValue& params, bool fHelp) return(result); } -UniValue tokenfillbid(const UniValue& params, bool fHelp) +UniValue tokenfillbid(const UniValue& params, bool fHelp, const CPubKey& mypk) { UniValue result(UniValue::VOBJ); int64_t fillamount; std::string hex; uint256 tokenid,bidtxid; if ( fHelp || params.size() != 3 ) @@ -7752,7 +7751,7 @@ UniValue tokenfillbid(const UniValue& params, bool fHelp) return(result); } -UniValue tokenask(const UniValue& params, bool fHelp) +UniValue tokenask(const UniValue& params, bool fHelp, const CPubKey& mypk) { UniValue result(UniValue::VOBJ); int64_t askamount,numtokens; std::string hex; double price; uint256 tokenid; if ( fHelp || params.size() != 3 ) @@ -7785,7 +7784,7 @@ UniValue tokenask(const UniValue& params, bool fHelp) return(result); } -UniValue tokenswapask(const UniValue& params, bool fHelp) +UniValue tokenswapask(const UniValue& params, bool fHelp, const CPubKey& mypk) { static uint256 zeroid; UniValue result(UniValue::VOBJ); int64_t askamount,numtokens; std::string hex; double price; uint256 tokenid,otherid; @@ -7814,7 +7813,7 @@ UniValue tokenswapask(const UniValue& params, bool fHelp) return(result); } -UniValue tokencancelask(const UniValue& params, bool fHelp) +UniValue tokencancelask(const UniValue& params, bool fHelp, const CPubKey& mypk) { UniValue result(UniValue::VOBJ); std::string hex; int32_t i; uint256 tokenid,asktxid; if ( fHelp || params.size() != 2 ) @@ -7839,7 +7838,7 @@ UniValue tokencancelask(const UniValue& params, bool fHelp) return(result); } -UniValue tokenfillask(const UniValue& params, bool fHelp) +UniValue tokenfillask(const UniValue& params, bool fHelp, const CPubKey& mypk) { UniValue result(UniValue::VOBJ); int64_t fillunits; std::string hex; uint256 tokenid,asktxid; if ( fHelp || params.size() != 3 ) @@ -7878,7 +7877,7 @@ UniValue tokenfillask(const UniValue& params, bool fHelp) return(result); } -UniValue tokenfillswap(const UniValue& params, bool fHelp) +UniValue tokenfillswap(const UniValue& params, bool fHelp, const CPubKey& mypk) { static uint256 zeroid; UniValue result(UniValue::VOBJ); int64_t fillunits; std::string hex; uint256 tokenid,otherid,asktxid; @@ -7905,7 +7904,7 @@ UniValue tokenfillswap(const UniValue& params, bool fHelp) return(result); } -UniValue getbalance64(const UniValue& params, bool fHelp) +UniValue getbalance64(const UniValue& params, bool fHelp, const CPubKey& mypk) { set setAddress; vector vecOutputs; UniValue ret(UniValue::VOBJ); UniValue a(UniValue::VARR),b(UniValue::VARR); CTxDestination address; @@ -7949,7 +7948,7 @@ UniValue getbalance64(const UniValue& params, bool fHelp) // heir contract functions for coins and tokens -UniValue heirfund(const UniValue& params, bool fHelp) +UniValue heirfund(const UniValue& params, bool fHelp, const CPubKey& mypk) { UniValue result(UniValue::VOBJ); uint256 tokenid = zeroid; @@ -8018,7 +8017,7 @@ UniValue heirfund(const UniValue& params, bool fHelp) return result; } -UniValue heiradd(const UniValue& params, bool fHelp) +UniValue heiradd(const UniValue& params, bool fHelp, const CPubKey& mypk) { UniValue result; uint256 fundingtxid; @@ -8039,97 +8038,88 @@ UniValue heiradd(const UniValue& params, bool fHelp) const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); - std::string strAmount = params[0].get_str(); - fundingtxid = Parseuint256((char*)params[1].get_str().c_str()); + std::string strAmount = params[0].get_str(); + fundingtxid = Parseuint256((char*)params[1].get_str().c_str()); result = HeirAddCaller(fundingtxid, 0, strAmount); return result; } -UniValue heirclaim(const UniValue& params, bool fHelp) +UniValue heirclaim(const UniValue& params, bool fHelp, const CPubKey& mypk) { - UniValue result; - uint256 fundingtxid; - int64_t txfee; - int64_t inactivitytime; - std::string hex; - std::vector pubkey; - std::string name; + UniValue result; uint256 fundingtxid; if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; - - if (fHelp || params.size() != 3) - throw runtime_error("heirclaim txfee funds fundingtxid\n"); + if (fHelp || params.size() != 2) + throw runtime_error("heirclaim funds fundingtxid\n"); if (ensure_CCrequirements(EVAL_HEIR) < 0) throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); - std::string strAmount = params[0].get_str(); + std::string strAmount = params[0].get_str(); fundingtxid = Parseuint256((char*)params[1].get_str().c_str()); result = HeirClaimCaller(fundingtxid, 0, strAmount); return result; } -UniValue heirinfo(const UniValue& params, bool fHelp) +UniValue heirinfo(const UniValue& params, bool fHelp, const CPubKey& mypk) { uint256 fundingtxid; if (fHelp || params.size() != 1) throw runtime_error("heirinfo fundingtxid\n"); - - // if ( ensure_CCrequirements(EVAL_HEIR) < 0 ) - // throw runtime_error(CC_REQUIREMENTS_MSG); - + if ( ensure_CCrequirements(EVAL_HEIR) < 0 ) + throw runtime_error(CC_REQUIREMENTS_MSG); fundingtxid = Parseuint256((char*)params[0].get_str().c_str()); return (HeirInfo(fundingtxid)); } -UniValue heirlist(const UniValue& params, bool fHelp) +UniValue heirlist(const UniValue& params, bool fHelp, const CPubKey& mypk) { if (fHelp || params.size() != 0) throw runtime_error("heirlist\n"); - - // if ( ensure_CCrequirements(EVAL_HEIR) < 0 ) - // throw runtime_error(CC_REQUIREMENTS_MSG); - + if ( ensure_CCrequirements(EVAL_HEIR) < 0 ) + throw runtime_error(CC_REQUIREMENTS_MSG); return (HeirList()); } -UniValue pegscreate(const UniValue& params, bool fHelp) +UniValue pegscreate(const UniValue& params, bool fHelp, const CPubKey& mypk) { UniValue result(UniValue::VOBJ); int32_t i; std::vector txids; - uint8_t N; std::string hex; uint256 txid; int64_t amount; + uint8_t N; 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(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; - LOCK2(cs_main, pwalletMain->cs_wallet); + Lock2NSPV(mypk); 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"); + { + Unlock2NSPV(mypk); + throw runtime_error("not enough parameters for N pegscreate\n"); + } for (i=0; i 0 ) + result = PegsCreate(mypk,0,amount,txids); + if ( result[JSON_HEXTX].getValStr().size() > 0 ) { result.push_back(Pair("result", "success")); - result.push_back(Pair("hex", hex)); - } else ERR_RESULT("couldnt pegscreate"); + } + Unlock2NSPV(mypk); return(result); } -UniValue pegsfund(const UniValue& params, bool fHelp) +UniValue pegsfund(const UniValue& params, bool fHelp, const CPubKey& mypk) { - UniValue result(UniValue::VOBJ); std::string hex; uint256 pegstxid,tokenid; int64_t amount; + UniValue result(UniValue::VOBJ); uint256 pegstxid,tokenid; int64_t amount; if ( fHelp || params.size()!=3) @@ -8137,112 +8127,103 @@ UniValue pegsfund(const UniValue& params, bool fHelp) if ( ensure_CCrequirements(EVAL_PEGS) < 0 ) throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; - LOCK2(cs_main, pwalletMain->cs_wallet); + Lock2NSPV(mypk); 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 = PegsFund(mypk,0,pegstxid,tokenid,amount); + if ( result[JSON_HEXTX].getValStr().size() > 0 ) { result.push_back(Pair("result", "success")); - result.push_back(Pair("hex", hex)); - } else ERR_RESULT("couldnt pegsfund"); + } + Unlock2NSPV(mypk); return(result); } -UniValue pegsget(const UniValue& params, bool fHelp) +UniValue pegsget(const UniValue& params, bool fHelp, const CPubKey& mypk) { - UniValue result(UniValue::VOBJ); std::string hex; uint256 pegstxid,tokenid; int64_t amount; + UniValue result(UniValue::VOBJ); 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(CC_REQUIREMENTS_MSG); - const CKeyStore& keystore = *pwalletMain; - LOCK2(cs_main, pwalletMain->cs_wallet); + Lock2NSPV(mypk); 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 = PegsGet(mypk,0,pegstxid,tokenid,amount); + if ( result[JSON_HEXTX].getValStr().size() > 0 ) { result.push_back(Pair("result", "success")); - result.push_back(Pair("hex", hex)); - } else ERR_RESULT("couldnt pegsget"); + } + Unlock2NSPV(mypk); return(result); } -UniValue pegsredeem(const UniValue& params, bool fHelp) +UniValue pegsredeem(const UniValue& params, bool fHelp, const CPubKey& mypk) { - UniValue result(UniValue::VOBJ); std::string hex; uint256 pegstxid,tokenid; int64_t amount; + UniValue result(UniValue::VOBJ); uint256 pegstxid,tokenid; int64_t amount; if ( fHelp || params.size()!=2) - throw runtime_error("pegsredem pegstxid tokenid\n"); + throw runtime_error("pegsredeem pegstxid tokenid\n"); if ( ensure_CCrequirements(EVAL_PEGS) < 0 ) throw runtime_error(CC_REQUIREMENTS_MSG); - const CKeyStore& keystore = *pwalletMain; - LOCK2(cs_main, pwalletMain->cs_wallet); + Lock2NSPV(mypk); 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 = PegsRedeem(mypk,0,pegstxid,tokenid); + if ( result[JSON_HEXTX].getValStr().size() > 0 ) { result.push_back(Pair("result", "success")); - result.push_back(Pair("hex", hex)); - } else ERR_RESULT("couldnt pegsredeem"); + } + Unlock2NSPV(mypk); return(result); } -UniValue pegsliquidate(const UniValue& params, bool fHelp) +UniValue pegsliquidate(const UniValue& params, bool fHelp, const CPubKey& mypk) { - UniValue result(UniValue::VOBJ); std::string hex; uint256 pegstxid,tokenid,accounttxid; + UniValue result(UniValue::VOBJ); 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(CC_REQUIREMENTS_MSG); - const CKeyStore& keystore = *pwalletMain; - LOCK2(cs_main, pwalletMain->cs_wallet); + Lock2NSPV(mypk); 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 = PegsLiquidate(mypk,0,pegstxid,tokenid,accounttxid); + if ( result[JSON_HEXTX].getValStr().size() > 0 ) { result.push_back(Pair("result", "success")); - result.push_back(Pair("hex", hex)); - } else ERR_RESULT("couldnt pegsliquidate"); + } + Unlock2NSPV(mypk); return(result); } -UniValue pegsexchange(const UniValue& params, bool fHelp) +UniValue pegsexchange(const UniValue& params, bool fHelp, const CPubKey& mypk) { - UniValue result(UniValue::VOBJ); std::string hex; uint256 pegstxid,tokenid,accounttxid; int64_t amount; + UniValue result(UniValue::VOBJ); uint256 pegstxid,tokenid,accounttxid; int64_t amount; if ( fHelp || params.size()!=3) - throw runtime_error("pegsliquidate pegstxid tokenid accounttxid\n"); + throw runtime_error("pegsexchange pegstxid tokenid amount\n"); if ( ensure_CCrequirements(EVAL_PEGS) < 0 ) throw runtime_error(CC_REQUIREMENTS_MSG); - const CKeyStore& keystore = *pwalletMain; - LOCK2(cs_main, pwalletMain->cs_wallet); + Lock2NSPV(mypk); 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 = PegsExchange(mypk,0,pegstxid,tokenid,amount); + if ( result[JSON_HEXTX].getValStr().size() > 0 ) { result.push_back(Pair("result", "success")); - result.push_back(Pair("hex", hex)); - } else ERR_RESULT("couldnt pegsliquidate"); + } + Unlock2NSPV(mypk); return(result); } -UniValue pegsaccounthistory(const UniValue& params, bool fHelp) +UniValue pegsaccounthistory(const UniValue& params, bool fHelp, const CPubKey& mypk) { uint256 pegstxid; @@ -8250,13 +8231,11 @@ UniValue pegsaccounthistory(const UniValue& params, bool fHelp) throw runtime_error("pegsaccounthistory pegstxid\n"); if ( ensure_CCrequirements(EVAL_GATEWAYS) < 0 ) throw runtime_error(CC_REQUIREMENTS_MSG); - const CKeyStore& keystore = *pwalletMain; - LOCK2(cs_main, pwalletMain->cs_wallet); pegstxid = Parseuint256((char *)params[0].get_str().c_str()); - return(PegsAccountHistory(pegstxid)); + return(PegsAccountHistory(mypk,pegstxid)); } -UniValue pegsaccountinfo(const UniValue& params, bool fHelp) +UniValue pegsaccountinfo(const UniValue& params, bool fHelp, const CPubKey& mypk) { uint256 pegstxid; @@ -8264,13 +8243,11 @@ UniValue pegsaccountinfo(const UniValue& params, bool fHelp) throw runtime_error("pegsaccountinfo pegstxid\n"); if ( ensure_CCrequirements(EVAL_GATEWAYS) < 0 ) throw runtime_error(CC_REQUIREMENTS_MSG); - const CKeyStore& keystore = *pwalletMain; - LOCK2(cs_main, pwalletMain->cs_wallet); pegstxid = Parseuint256((char *)params[0].get_str().c_str()); - return(PegsAccountInfo(pegstxid)); + return(PegsAccountInfo(mypk,pegstxid)); } -UniValue pegsworstaccounts(const UniValue& params, bool fHelp) +UniValue pegsworstaccounts(const UniValue& params, bool fHelp, const CPubKey& mypk) { uint256 pegstxid; @@ -8278,13 +8255,11 @@ UniValue pegsworstaccounts(const UniValue& params, bool fHelp) throw runtime_error("pegsworstaccounts pegstxid\n"); if ( ensure_CCrequirements(EVAL_GATEWAYS) < 0 ) throw runtime_error(CC_REQUIREMENTS_MSG); - 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) +UniValue pegsinfo(const UniValue& params, bool fHelp, const CPubKey& mypk) { uint256 pegstxid; @@ -8292,27 +8267,25 @@ UniValue pegsinfo(const UniValue& params, bool fHelp) throw runtime_error("pegsinfo pegstxid\n"); if ( ensure_CCrequirements(EVAL_GATEWAYS) < 0 ) throw runtime_error(CC_REQUIREMENTS_MSG); - 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); -extern UniValue importwallet(const UniValue& params, bool fHelp); -extern UniValue z_exportkey(const UniValue& params, bool fHelp); -extern UniValue z_importkey(const UniValue& params, bool fHelp); -extern UniValue z_exportviewingkey(const UniValue& params, bool fHelp); -extern UniValue z_importviewingkey(const UniValue& params, bool fHelp); -extern UniValue z_exportwallet(const UniValue& params, bool fHelp); -extern UniValue z_importwallet(const UniValue& params, bool fHelp); +extern UniValue dumpprivkey(const UniValue& params, bool fHelp, const CPubKey& mypk); // in rpcdump.cpp +extern UniValue convertpassphrase(const UniValue& params, bool fHelp, const CPubKey& mypk); +extern UniValue importprivkey(const UniValue& params, bool fHelp, const CPubKey& mypk); +extern UniValue importaddress(const UniValue& params, bool fHelp, const CPubKey& mypk); +extern UniValue dumpwallet(const UniValue& params, bool fHelp, const CPubKey& mypk); +extern UniValue importwallet(const UniValue& params, bool fHelp, const CPubKey& mypk); +extern UniValue z_exportkey(const UniValue& params, bool fHelp, const CPubKey& mypk); +extern UniValue z_importkey(const UniValue& params, bool fHelp, const CPubKey& mypk); +extern UniValue z_exportviewingkey(const UniValue& params, bool fHelp, const CPubKey& mypk); +extern UniValue z_importviewingkey(const UniValue& params, bool fHelp, const CPubKey& mypk); +extern UniValue z_exportwallet(const UniValue& params, bool fHelp, const CPubKey& mypk); +extern UniValue z_importwallet(const UniValue& params, bool fHelp, const CPubKey& mypk); -extern UniValue z_getpaymentdisclosure(const UniValue& params, bool fHelp); // in rpcdisclosure.cpp -extern UniValue z_validatepaymentdisclosure(const UniValue ¶ms, bool fHelp); +extern UniValue z_getpaymentdisclosure(const UniValue& params, bool fHelp, const CPubKey& mypk); // in rpcdisclosure.cpp +extern UniValue z_validatepaymentdisclosure(const UniValue& params, bool fHelp, const CPubKey& mypk); static const CRPCCommand commands[] = { // category name actor (function) okSafeMode @@ -8394,7 +8367,7 @@ void RegisterWalletRPCCommands(CRPCTable &tableRPC) tableRPC.appendCommand(commands[vcidx].name, &commands[vcidx]); } -UniValue opreturn_burn(const UniValue& params, bool fHelp) +UniValue opreturn_burn(const UniValue& params, bool fHelp, const CPubKey& mypk) { std::vector vHexStr; CScript opret; int32_t txfee = 10000;CPubKey myPubkey; if (fHelp || (params.size() < 2) || (params.size() > 4) )