From 6ee1f9b7eefc85a004ec12c3a3728254cc12e025 Mon Sep 17 00:00:00 2001 From: cjepson Date: Wed, 22 Jul 2015 15:48:24 -0400 Subject: [PATCH] Fix retrieval of public key addresses from address manager The behaviour of function Address() in waddrmgr has been updated such that it now displays the correct behaviour as described in the comments. That is, when a public key address is given as a btcutil.Address, the key is converted to a public key hash address so that serializing with ScriptAddress() yields the corresponding public key hash. This allows the address manager to find the corresponding private key, and fixes the signing of multisignature transactions. --- waddrmgr/manager.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/waddrmgr/manager.go b/waddrmgr/manager.go index 46a77d2..ca6f9c5 100644 --- a/waddrmgr/manager.go +++ b/waddrmgr/manager.go @@ -678,6 +678,15 @@ func (m *Manager) loadAndCacheAddress(address btcutil.Address) (ManagedAddress, // pay-to-pubkey-hash addresses and the script associated with // pay-to-script-hash addresses. func (m *Manager) Address(address btcutil.Address) (ManagedAddress, error) { + // ScriptAddress will only return a script hash if we're + // accessing an address that is either PKH or SH. In + // the event we're passed a PK address, convert the + // PK to PKH address so that we can access it from + // the addrs map and database. + if pka, ok := address.(*btcutil.AddressPubKey); ok { + address = pka.AddressPubKeyHash() + } + // Return the address from cache if it's available. // // NOTE: Not using a defer on the lock here since a write lock is