Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcwallet.cpp
Show All 11 Lines | |||||
#include <dstencode.h> | #include <dstencode.h> | ||||
#include <net.h> | #include <net.h> | ||||
#include <policy/fees.h> | #include <policy/fees.h> | ||||
#include <policy/policy.h> | #include <policy/policy.h> | ||||
#include <rpc/mining.h> | #include <rpc/mining.h> | ||||
#include <rpc/misc.h> | #include <rpc/misc.h> | ||||
#include <rpc/rawtransaction.h> | #include <rpc/rawtransaction.h> | ||||
#include <rpc/server.h> | #include <rpc/server.h> | ||||
#include <rpc/util.h> | |||||
#include <timedata.h> | #include <timedata.h> | ||||
#include <util.h> | #include <util.h> | ||||
#include <utilmoneystr.h> | #include <utilmoneystr.h> | ||||
#include <validation.h> | #include <validation.h> | ||||
#include <wallet/coincontrol.h> | #include <wallet/coincontrol.h> | ||||
#include <wallet/wallet.h> | #include <wallet/wallet.h> | ||||
#include <wallet/walletdb.h> | #include <wallet/walletdb.h> | ||||
#include <wallet/walletutil.h> | #include <wallet/walletutil.h> | ||||
▲ Show 20 Lines • Show All 1,306 Lines • ▼ Show 20 Lines | if (!pwallet->CommitTransaction(tx, std::move(mapValue), {} /* orderForm */, | ||||
strFailReason = strprintf("Transaction commit failed:: %s", | strFailReason = strprintf("Transaction commit failed:: %s", | ||||
state.GetRejectReason()); | state.GetRejectReason()); | ||||
throw JSONRPCError(RPC_WALLET_ERROR, strFailReason); | throw JSONRPCError(RPC_WALLET_ERROR, strFailReason); | ||||
} | } | ||||
return tx->GetId().GetHex(); | return tx->GetId().GetHex(); | ||||
} | } | ||||
static UniValue addmultisigaddress(const Config &config, | UniValue addmultisigaddress(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | ||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if (request.fHelp || request.params.size() < 2 || | if (request.fHelp || request.params.size() < 2 || | ||||
request.params.size() > 3) { | request.params.size() > 3) { | ||||
std::string msg = | std::string msg = | ||||
Show All 13 Lines | if (request.fHelp || request.params.size() < 2 || | ||||
" \"address\" (string) bitcoin address or hex-encoded " | " \"address\" (string) bitcoin address or hex-encoded " | ||||
"public key\n" | "public key\n" | ||||
" ...,\n" | " ...,\n" | ||||
" ]\n" | " ]\n" | ||||
"3. \"label\" (string, optional) A label to " | "3. \"label\" (string, optional) A label to " | ||||
"assign the addresses to.\n" | "assign the addresses to.\n" | ||||
"\nResult:\n" | "\nResult:\n" | ||||
"\"address\" (string) A bitcoin address associated with " | "{\n" | ||||
"the keys.\n" | " \"address\":\"multisigaddress\", (string) The value of the " | ||||
"new multisig address.\n" | |||||
" \"redeemScript\":\"script\" (string) The string value " | |||||
"of the hex-encoded redemption script.\n" | |||||
"}\n" | |||||
"\nResult (DEPRECATED. To see this result in v0.19.6 instead, " | |||||
"please start bitcoind with -deprecatedrpc=addmultisigaddress).\n" | |||||
" clients should transition to the new output api before " | |||||
"upgrading to v0.20.\n" | |||||
"\"address\" (string) A bitcoin address " | |||||
"associated with the keys.\n" | |||||
"\nExamples:\n" | "\nExamples:\n" | ||||
"\nAdd a multisig address from 2 addresses\n" + | "\nAdd a multisig address from 2 addresses\n" + | ||||
HelpExampleCli("addmultisigaddress", | HelpExampleCli("addmultisigaddress", | ||||
"2 " | "2 " | ||||
"\"[\\\"16sSauSf5pF2UkUwvKGq4qjNRzBZYqgEL5\\\"," | "\"[\\\"16sSauSf5pF2UkUwvKGq4qjNRzBZYqgEL5\\\"," | ||||
"\\\"171sgjn4YtPu27adkKGrdDwzRTxnRkBfKV\\\"]\"") + | "\\\"171sgjn4YtPu27adkKGrdDwzRTxnRkBfKV\\\"]\"") + | ||||
"\nAs json rpc call\n" + | "\nAs json rpc call\n" + | ||||
HelpExampleRpc("addmultisigaddress", | HelpExampleRpc("addmultisigaddress", | ||||
"2, " | "2, " | ||||
"\"[\\\"16sSauSf5pF2UkUwvKGq4qjNRzBZYqgEL5\\\"," | "\"[\\\"16sSauSf5pF2UkUwvKGq4qjNRzBZYqgEL5\\\"," | ||||
"\\\"171sgjn4YtPu27adkKGrdDwzRTxnRkBfKV\\\"]\""); | "\\\"171sgjn4YtPu27adkKGrdDwzRTxnRkBfKV\\\"]\""); | ||||
throw std::runtime_error(msg); | throw std::runtime_error(msg); | ||||
} | } | ||||
LOCK2(cs_main, pwallet->cs_wallet); | LOCK2(cs_main, pwallet->cs_wallet); | ||||
std::string label; | std::string label; | ||||
if (!request.params[2].isNull()) { | if (!request.params[2].isNull()) { | ||||
label = LabelFromValue(request.params[2]); | label = LabelFromValue(request.params[2]); | ||||
} | } | ||||
int required = request.params[0].get_int(); | |||||
// Get the public keys | |||||
const UniValue &keys_or_addrs = request.params[1].get_array(); | |||||
std::vector<CPubKey> pubkeys; | |||||
for (size_t i = 0; i < keys_or_addrs.size(); ++i) { | |||||
if (IsHex(keys_or_addrs[i].get_str()) && | |||||
(keys_or_addrs[i].get_str().length() == 66 || | |||||
keys_or_addrs[i].get_str().length() == 130)) { | |||||
pubkeys.push_back(HexToPubKey(keys_or_addrs[i].get_str())); | |||||
} else { | |||||
pubkeys.push_back(AddrToPubKey(config.GetChainParams(), pwallet, | |||||
keys_or_addrs[i].get_str())); | |||||
} | |||||
} | |||||
// Construct using pay-to-script-hash: | // Construct using pay-to-script-hash: | ||||
CScript inner = createmultisig_redeemScript(pwallet, request.params); | CScript inner = CreateMultisigRedeemscript(required, pubkeys); | ||||
CScriptID innerID(inner); | CScriptID innerID(inner); | ||||
pwallet->AddCScript(inner); | pwallet->AddCScript(inner); | ||||
pwallet->SetAddressBook(innerID, label, "send"); | pwallet->SetAddressBook(innerID, label, "send"); | ||||
// Return old style interface | |||||
if (IsDeprecatedRPCEnabled(gArgs, "addmultisigaddress")) { | |||||
return EncodeDestination(innerID); | return EncodeDestination(innerID); | ||||
} | } | ||||
UniValue result(UniValue::VOBJ); | |||||
result.pushKV("address", EncodeDestination(innerID)); | |||||
result.pushKV("redeemScript", HexStr(inner.begin(), inner.end())); | |||||
return result; | |||||
} | |||||
struct tallyitem { | struct tallyitem { | ||||
Amount nAmount; | Amount nAmount; | ||||
int nConf; | int nConf; | ||||
std::vector<uint256> txids; | std::vector<uint256> txids; | ||||
bool fIsWatchonly; | bool fIsWatchonly; | ||||
tallyitem() { | tallyitem() { | ||||
nAmount = Amount::zero(); | nAmount = Amount::zero(); | ||||
nConf = std::numeric_limits<int>::max(); | nConf = std::numeric_limits<int>::max(); | ||||
▲ Show 20 Lines • Show All 2,529 Lines • Show Last 20 Lines |