From 3bf626a750ad546865f991a02235485bdc9d2147 Mon Sep 17 00:00:00 2001 From: ZmnSCPxj Date: Sat, 21 Apr 2018 10:32:40 +0000 Subject: [PATCH] walletrpc: Correct generation of P2SH-P2WPKH addresses for listfunds. --- tests/test_lightningd.py | 1 - wallet/walletrpc.c | 6 +++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/test_lightningd.py b/tests/test_lightningd.py index 38206b33d..8c050c5f9 100644 --- a/tests/test_lightningd.py +++ b/tests/test_lightningd.py @@ -3479,7 +3479,6 @@ class LightningDTests(BaseLightningDTests): assert len(l1.rpc.listfunds()['outputs']) == 1 - @unittest.expectedFailure def test_addfunds_from_block(self): """Send funds to the daemon without telling it explicitly """ diff --git a/wallet/walletrpc.c b/wallet/walletrpc.c index af3e3d6b0..33154b97f 100644 --- a/wallet/walletrpc.c +++ b/wallet/walletrpc.c @@ -371,6 +371,7 @@ static void json_listfunds(struct command *cmd, const char *buffer UNUSED, struct utxo **utxos = wallet_get_utxos(cmd, cmd->ld->wallet, output_state_available); char* out; + struct sha256 h; struct ripemd160 h160; struct pubkey funding_pubkey; json_object_start(response, NULL); @@ -385,8 +386,10 @@ static void json_listfunds(struct command *cmd, const char *buffer UNUSED, if (utxos[i]->close_info == NULL) { bip32_pubkey(cmd->ld->wallet->bip32_base, &funding_pubkey, utxos[i]->keyindex); - pubkey_to_hash160(&funding_pubkey, &h160); if (utxos[i]->is_p2sh) { + u8 *redeemscript = bitcoin_redeem_p2sh_p2wpkh(cmd, &funding_pubkey); + sha256(&h, redeemscript, tal_count(redeemscript)); + ripemd160(&h160, h.u.u8, sizeof(h)); out = p2sh_to_base58(cmd, get_chainparams(cmd->ld)->testnet, &h160); @@ -394,6 +397,7 @@ static void json_listfunds(struct command *cmd, const char *buffer UNUSED, const char *hrp = get_chainparams(cmd->ld)->bip173_name; /* out buffer is 73 + strlen(human readable part). see bech32.h */ out = tal_arr(cmd, char, 73 + strlen(hrp)); + pubkey_to_hash160(&funding_pubkey, &h160); bool ok = segwit_addr_encode(out, hrp, 0, h160.u.u8, sizeof(h160.u.u8)); if (!ok) { command_fail(cmd, "p2wpkh address encoding failure.");