Skip to content

Commit

Permalink
lightningd: deprecate p2sh-segwit addresses for newaddr addresstype
Browse files Browse the repository at this point in the history
Signed-off-by: Rusty Russell <[email protected]>
Changelog-Deprecated: JSON-RPC: `newaddr`: `addresstype` `p2sh-segwit` (use default, or `bech32`).
  • Loading branch information
rustyrussell committed Jan 11, 2023
1 parent a158287 commit cd41fcb
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 141 deletions.
1 change: 0 additions & 1 deletion cln-grpc/proto/node.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions cln-rpc/src/model.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

234 changes: 117 additions & 117 deletions contrib/pyln-testing/pyln/testing/node_pb2.py

Large diffs are not rendered by default.

12 changes: 5 additions & 7 deletions doc/lightning-newaddr.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ lightning-newaddr -- Command for generating a new address to be used by Core Lig
SYNOPSIS
--------

**newaddr** [ *addresstype* ]
**newaddr** [*addresstype*]

DESCRIPTION
-----------
Expand All @@ -14,12 +14,10 @@ subsequently be used to fund channels managed by the Core Lightning node.

The funding transaction needs to be confirmed before funds can be used.

*addresstype* specifies the type of address wanted; i.e. *p2sh-segwit*
(e.g. `2MxaozoqWwiUcuD9KKgUSrLFDafLqimT9Ta` on bitcoin testnet or
`3MZxzq3jBSKNQ2e7dzneo9hy4FvNzmMmt3` on bitcoin mainnet) or *bech32*
*addresstype* specifies the type of address wanted; currently *bech32*
(e.g. `tb1qu9j4lg5f9rgjyfhvfd905vw46eg39czmktxqgg` on bitcoin testnet
or `bc1qwqdg6squsna38e46795at95yu9atm8azzmyvckulcc7kytlcckxswvvzej` on
bitcoin mainnet). The special value *all* generates both address types
bitcoin mainnet). The special value *all* generates all known address types
for the same underlying key.

If no *addresstype* is specified the address generated is a *bech32* address.
Expand All @@ -33,7 +31,7 @@ RETURN VALUE
On success, an object is returned, containing:

- **bech32** (string, optional): The bech32 (native segwit) address
- **p2sh-segwit** (string, optional): The p2sh-wrapped address
- **p2sh-segwit** (string, optional): The p2sh-wrapped address **deprecated, removal in v23.11**

[comment]: # (GENERATE-FROM-SCHEMA-END)

Expand All @@ -58,4 +56,4 @@ RESOURCES

Main web site: <https://github.com/ElementsProject/lightning>

[comment]: # ( SHA256STAMP:8ed49212ffddf29077007efe38a6b6446cc9c351cb24a1454030526c89407175)
[comment]: # ( SHA256STAMP:9d8dc613c005127a0807f2c8b26b0a96ddc5bf3ebdfa59c3f95a888476c0ce2a)
1 change: 0 additions & 1 deletion doc/schemas/newaddr.request.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"type": "string",
"enum": [
"bech32",
"p2sh-segwit",
"all"
]
}
Expand Down
1 change: 1 addition & 0 deletions doc/schemas/newaddr.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"description": "The bech32 (native segwit) address"
},
"p2sh-segwit": {
"deprecated": "v23.02",
"type": "string",
"description": "The p2sh-wrapped address"
}
Expand Down
5 changes: 1 addition & 4 deletions tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1856,14 +1856,11 @@ def test_bad_onion_immediate_peer(node_factory, bitcoind):

def test_newaddr(node_factory, chainparams):
l1 = node_factory.get_node()
p2sh = l1.rpc.newaddr('p2sh-segwit')
assert 'bech32' not in p2sh
assert p2sh['p2sh-segwit'].startswith(chainparams['p2sh_prefix'])
bech32 = l1.rpc.newaddr('bech32')
assert 'p2sh-segwit' not in bech32
assert bech32['bech32'].startswith(chainparams['bip173_prefix'])
both = l1.rpc.newaddr('all')
assert both['p2sh-segwit'].startswith(chainparams['p2sh_prefix'])
assert 'p2sh-segwit' not in both
assert both['bech32'].startswith(chainparams['bip173_prefix'])


Expand Down
15 changes: 8 additions & 7 deletions wallet/walletrpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,28 +77,29 @@ encode_pubkey_to_addr(const tal_t *ctx,
}

enum addrtype {
/* Deprecated! */
ADDR_P2SH_SEGWIT = 1,
ADDR_BECH32 = 2,
ADDR_ALL = (ADDR_P2SH_SEGWIT + ADDR_BECH32)
};

/* Extract bool indicating "p2sh-segwit" or "bech32" */
/* Extract bool indicating "bech32" */
static struct command_result *param_newaddr(struct command *cmd,
const char *name,
const char *buffer,
const jsmntok_t *tok,
enum addrtype **addrtype)
{
*addrtype = tal(cmd, enum addrtype);
if (json_tok_streq(buffer, tok, "p2sh-segwit"))
if (deprecated_apis && json_tok_streq(buffer, tok, "p2sh-segwit"))
**addrtype = ADDR_P2SH_SEGWIT;
else if (json_tok_streq(buffer, tok, "bech32"))
**addrtype = ADDR_BECH32;
else if (json_tok_streq(buffer, tok, "all"))
**addrtype = ADDR_ALL;
else
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"'%s' should be 'bech32', 'p2sh-segwit' or 'all', not '%.*s'",
"'%s' should be 'bech32', or 'all', not '%.*s'",
name, tok->end - tok->start, buffer + tok->start);
return NULL;
}
Expand Down Expand Up @@ -131,7 +132,7 @@ static struct command_result *json_newaddr(struct command *cmd,
b32script = scriptpubkey_p2wpkh(tmpctx, &pubkey);
if (*addrtype & ADDR_BECH32)
txfilter_add_scriptpubkey(cmd->ld->owned_txfilter, b32script);
if (*addrtype & ADDR_P2SH_SEGWIT)
if (deprecated_apis && (*addrtype & ADDR_P2SH_SEGWIT))
txfilter_add_scriptpubkey(cmd->ld->owned_txfilter,
scriptpubkey_p2sh(tmpctx, b32script));

Expand All @@ -145,7 +146,7 @@ static struct command_result *json_newaddr(struct command *cmd,
response = json_stream_success(cmd);
if (*addrtype & ADDR_BECH32)
json_add_string(response, "bech32", bech32);
if (*addrtype & ADDR_P2SH_SEGWIT)
if (deprecated_apis && (*addrtype & ADDR_P2SH_SEGWIT))
json_add_string(response, "p2sh-segwit", p2sh);
return command_success(cmd, response);
}
Expand All @@ -154,8 +155,8 @@ static const struct json_command newaddr_command = {
"newaddr",
"bitcoin",
json_newaddr,
"Get a new {bech32, p2sh-segwit} (or all) address to fund a channel (default is bech32)", false,
"Generates a new address (or both) that belongs to the internal wallet. Funds sent to these addresses will be managed by lightningd. Use `withdraw` to withdraw funds to an external wallet."
"Get a new {bech32} (or all) address to fund a channel", false,
"Generates a new address that belongs to the internal wallet. Funds sent to these addresses will be managed by lightningd. Use `withdraw` to withdraw funds to an external wallet."
};
AUTODATA(json_command, &newaddr_command);

Expand Down

0 comments on commit cd41fcb

Please sign in to comment.