aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/rpcwallet.cpp
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2016-06-24 16:25:44 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2016-06-24 18:07:44 +0200
commitd612837814020ae832499d18e6ee5eb919a87907 (patch)
treea93b5e382503577109efaa5cf7526e4dc378b7ea /src/wallet/rpcwallet.cpp
parentaf2421c291c42fd0119bf27261fdeeba93cadbcc (diff)
parentf8528134fc188abc5c7175a19680206964a8fade (diff)
Merge #8149: Segregated witness rebased
f852813 BIP9 parameters for testnet (Johnson Lau) 070dbc4 --- [SEGWIT] begin: deployment --- (Pieter Wuille) fdb43df [qa] Add GetTransactionSigOpCost unit tests (Jonas Nick) d846e02 [qa] script_tests: witness tests can specify tx amount (Suhas Daftuar) 330b0f3 [qa] p2p segwit tests (Suhas Daftuar) 4f7ff00 [qa] Add rpc test for segwit (Alex Morcos) 66cca79 [qa] Autogeneration support for witness in script_tests (Pieter Wuille) 06d3805 [qa] Add segwit support to script_tests (Pieter Wuille) 00f46cb [qa] Add transaction tests for segwit (NicolasDorier) 0aa9207 [qa] Witness version 0 signing unit tests (Pieter Wuille) 978e200 --- [SEGWIT] begin: tests --- (Pieter Wuille) 745eb67 [RPC] signrawtransaction can sign P2WSH (NicolasDorier) f4691ab [RPC] Add wallet support for witness transactions (using P2SH) (Pieter Wuille) 605e847 BIP143: Signing logic (Pieter Wuille) 9757b57 --- [SEGWIT] begin: wallet --- (Pieter Wuille) af87a67 Do not use compact blocks when segwit is enabled (Pieter Wuille) 6032f69 Add rewind logic to deal with post-fork software updates (Pieter Wuille) b7dbeb2 [libconsensus] Script verification API with amounts (Thomas Kerin) 2b1f6f9 BIP141: Other consensus critical limits, and BIP145 (Pieter Wuille) 7c4bf77 [RPC] Return witness data in blockchain RPCs (Johnson Lau) 3dd4102 BIP143: Verification logic (Pieter Wuille) 0ef1dd3 Refactor script validation to observe amounts (Pieter Wuille) b8a9749 BIP144: Handshake and relay (receiver side) (Pieter Wuille) 8b49040 BIP141: Commitment structure and deployment (Pieter Wuille) 449f9b8 BIP141: Witness program (Pieter Wuille) 7030d9e BIP144: Serialization, hashes, relay (sender side) (Pieter Wuille) ecacfd9 --- [SEGWIT] begin: P2P/node/consensus --- (Pieter Wuille)
Diffstat (limited to 'src/wallet/rpcwallet.cpp')
-rw-r--r--src/wallet/rpcwallet.cpp82
1 files changed, 81 insertions, 1 deletions
diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp
index 2d4e95911d..8538f880ff 100644
--- a/src/wallet/rpcwallet.cpp
+++ b/src/wallet/rpcwallet.cpp
@@ -1011,6 +1011,85 @@ UniValue addmultisigaddress(const UniValue& params, bool fHelp)
return CBitcoinAddress(innerID).ToString();
}
+class Witnessifier : public boost::static_visitor<bool>
+{
+public:
+ CScriptID result;
+
+ bool operator()(const CNoDestination &dest) const { return false; }
+
+ bool operator()(const CKeyID &keyID) {
+ CPubKey pubkey;
+ if (pwalletMain && pwalletMain->GetPubKey(keyID, pubkey)) {
+ CScript basescript;
+ basescript << ToByteVector(pubkey) << OP_CHECKSIG;
+ CScript witscript = GetScriptForWitness(basescript);
+ pwalletMain->AddCScript(witscript);
+ result = CScriptID(witscript);
+ return true;
+ }
+ return false;
+ }
+
+ bool operator()(const CScriptID &scriptID) {
+ CScript subscript;
+ if (pwalletMain && pwalletMain->GetCScript(scriptID, subscript)) {
+ int witnessversion;
+ std::vector<unsigned char> witprog;
+ if (subscript.IsWitnessProgram(witnessversion, witprog)) {
+ result = scriptID;
+ return true;
+ }
+ CScript witscript = GetScriptForWitness(subscript);
+ pwalletMain->AddCScript(witscript);
+ result = CScriptID(witscript);
+ return true;
+ }
+ return false;
+ }
+};
+
+UniValue addwitnessaddress(const UniValue& params, bool fHelp)
+{
+ if (!EnsureWalletIsAvailable(fHelp))
+ return NullUniValue;
+
+ if (fHelp || params.size() < 1 || params.size() > 1)
+ {
+ string msg = "addwitnessaddress \"address\"\n"
+ "\nAdd a witness address for a script (with pubkey or redeemscript known).\n"
+ "It returns the witness script.\n"
+
+ "\nArguments:\n"
+ "1. \"address\" (string, required) An address known to the wallet\n"
+
+ "\nResult:\n"
+ "\"witnessaddress\", (string) The value of the new address (P2SH of witness script).\n"
+ "}\n"
+ ;
+ throw runtime_error(msg);
+ }
+
+ {
+ LOCK(cs_main);
+ if (!IsWitnessEnabled(chainActive.Tip(), Params().GetConsensus()) && !GetBoolArg("-walletprematurewitness", false)) {
+ throw JSONRPCError(RPC_WALLET_ERROR, "Segregated witness not enabled on network");
+ }
+ }
+
+ CBitcoinAddress address(params[0].get_str());
+ if (!address.IsValid())
+ throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address");
+
+ Witnessifier w;
+ CTxDestination dest = address.Get();
+ bool ret = boost::apply_visitor(w, dest);
+ if (!ret) {
+ throw JSONRPCError(RPC_WALLET_ERROR, "Public key or redeemscript not known to wallet");
+ }
+
+ return CBitcoinAddress(w.result).ToString();
+}
struct tallyitem
{
@@ -2451,7 +2530,7 @@ UniValue fundrawtransaction(const UniValue& params, bool fHelp)
// parse hex string from parameter
CTransaction origTx;
- if (!DecodeHexTx(origTx, params[0].get_str()))
+ if (!DecodeHexTx(origTx, params[0].get_str(), true))
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");
if (origTx.vout.size() == 0)
@@ -2491,6 +2570,7 @@ static const CRPCCommand commands[] =
{ "hidden", "resendwallettransactions", &resendwallettransactions, true },
{ "wallet", "abandontransaction", &abandontransaction, false },
{ "wallet", "addmultisigaddress", &addmultisigaddress, true },
+ { "wallet", "addwitnessaddress", &addwitnessaddress, true },
{ "wallet", "backupwallet", &backupwallet, true },
{ "wallet", "dumpprivkey", &dumpprivkey, true },
{ "wallet", "dumpwallet", &dumpwallet, true },