walletrpc: Correct generation of P2SH-P2WPKH addresses for listfunds.

This commit is contained in:
ZmnSCPxj 2018-04-21 10:32:40 +00:00 committed by Christian Decker
parent c2e85cd051
commit 3bf626a750
2 changed files with 5 additions and 2 deletions

View File

@ -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
"""

View File

@ -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.");