Skip to content

Conversation

ajtowns
Copy link
Contributor

@ajtowns ajtowns commented Apr 25, 2018

Adds an "address_type" parameter that accepts "legacy", "p2sh-segwit", and "bech32" to choose the type of address created. Defaults to "legacy" rather than the value of the -address-type option for backwards compatibility.

As part of implementing this, OutputType is moved from wallet into its own module, and AddAndGetDestinationForScript is changed to apply to a CKeyStore rather than a wallet, and to invoke keystore.AddCScript(script) itself rather than expecting the caller to have done that.

Fixes #12502

@instagibbs
Copy link
Member

I think this would resolve #12502

Thanks for working on this!

@ajtowns ajtowns force-pushed the signmultisig branch 2 times, most recently from 7a43ed7 to 894da17 Compare April 25, 2018 21:00
@jonasschnelli
Copy link
Contributor

Nice!
Concept ACK.

@luke-jr
Copy link
Member

luke-jr commented Jun 12, 2018

"legacy" doesn't support multisig... I think you need to add a "bip16" type for this.

@sipa
Copy link
Member

sipa commented Jun 13, 2018

@luke-jr The existing "legacy" address type (argument to -addresstype command line option) causes P2SH-multisig addresses for the multisig RPC. "p2sh-segwit" will cause P2SH-P2WSH-multisig addresses, and "bech32" will cause P2WSH-multisig.

@ajtowns
Copy link
Contributor Author

ajtowns commented Jun 22, 2018

Ping @instagibbs @jonasschnelli ; Care to review code?

@@ -75,6 +75,8 @@ std::vector<CTxDestination> GetAllDestinationsForKey(const CPubKey& key)

CTxDestination AddAndGetDestinationForScript(CKeyStore& keystore, const CScript& script, OutputType type)
{
keystore.AddCScript(script);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this a bugfix?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It moves the AddCScript() call from the function invoking AddAndGetDestinationForScript() into AAGDFS(); see corresponding change in src/wallet/rpcwallet.cpp

CScriptID innerID(inner);
const CScript inner = CreateMultisigRedeemscript(required, pubkeys);
CBasicKeyStore keystore;
const CTxDestination dest = AddAndGetDestinationForScript(keystore, inner, output_type);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't think this rpc call changed wallet state previously?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't change wallet state either -- keystore is a dummy variable that's just declared here and discarded. The functional tests don't work without wallet support compiled in, but I think I gave it a quick test by hand and it was okay.


UniValue result(UniValue::VOBJ);
result.pushKV("address", EncodeDestination(innerID));
result.pushKV("address", EncodeDestination(dest));
result.pushKV("redeemScript", HexStr(inner.begin(), inner.end()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This field becomes essentially useless for new address types. I'm not sure what to do about that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be changed to script and have redeemScript behind a deprecation switch.

@DrahtBot
Copy link
Contributor

DrahtBot commented Jul 7, 2018

Needs rebase

ajtowns added 4 commits July 9, 2018 22:21
Moves OutputType into its own module
Makes AddAndGetDestinationForScript use a generic CKeyStore rather than
the wallet, and makes it always add the script to the keystore, rather
than only adding related (redeem) scripts.
@achow101
Copy link
Member

achow101 commented Jul 9, 2018

utACK f40b3b8

1 similar comment
@laanwj
Copy link
Member

laanwj commented Jul 11, 2018

utACK f40b3b8

@sipa
Copy link
Member

sipa commented Jul 12, 2018

utACK f40b3b8.

@sipa sipa merged commit f40b3b8 into bitcoin:master Jul 14, 2018
sipa added a commit that referenced this pull request Jul 14, 2018
f40b3b8 [tests] functional test for createmultisig RPC (Anthony Towns)
b9024fd segwit support for createmultisig RPC (Anthony Towns)
d58055d Move AddAndGetDestinationForScript from wallet to outputype module (Anthony Towns)
9a44db2 Add outputtype module (Anthony Towns)

Pull request description:

  Adds an "address_type" parameter that accepts "legacy", "p2sh-segwit", and "bech32" to choose the type of address created. Defaults to "legacy" rather than the value of the `-address-type` option for backwards compatibility.

  As part of implementing this, OutputType is moved from wallet into its own module, and `AddAndGetDestinationForScript` is changed to apply to a `CKeyStore` rather than a wallet, and to invoke `keystore.AddCScript(script)` itself rather than expecting the caller to have done that.

  Fixes #12502

Tree-SHA512: a08c1cfa89976e4fd7d29caa90919ebd34a446354d17abb862e99f2ee60ed9bc19d8a21a18547c51dc3812cb9fbed86af0bef2f1e971f62bf95cade4a7d86237
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[RPC] createmultisig does not respect -addresstype
8 participants