MCPcopy Create free account
hub / github.com/ElementsProject/lightning / json_newaddr

Function json_newaddr

wallet/walletrpc.c:129–172  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

127
128
129static struct command_result *json_newaddr(struct command *cmd,
130 const char *buffer,
131 const jsmntok_t *obj UNNEEDED,
132 const jsmntok_t *params)
133{
134 struct json_stream *response;
135 struct pubkey pubkey;
136 enum addrtype *addrtype;
137 char *bech32, *p2tr;
138
139 if (!param(cmd, buffer, params,
140 p_opt("addresstype", param_newaddr, &addrtype),
141 NULL))
142 return command_param_failed();
143
144 if (!addrtype) {
145 addrtype = tal(cmd, enum addrtype);
146 if (command_deprecated_in_ok(cmd, "addresstype.defaultbech32",
147 "v25.12", "v26.12"))
148 *addrtype = ADDR_ALL;
149 else
150 *addrtype = ADDR_P2TR;
151 }
152
153 if (!newaddr_inner(cmd, &pubkey, *addrtype)) {
154 return command_fail(cmd, LIGHTNINGD, "Keys exhausted ");
155 };
156
157 response = json_stream_success(cmd);
158
159 /* Generate addresses based on requested type */
160 bech32 = encode_pubkey_to_addr(cmd, &pubkey, ADDR_BECH32, NULL);
161 p2tr = encode_pubkey_to_addr(cmd, &pubkey, ADDR_P2TR, NULL);
162 if (!bech32 || !p2tr) {
163 return command_fail(cmd, LIGHTNINGD,
164 "p2wpkh address encoding failure.");
165 }
166
167 if (*addrtype & ADDR_BECH32)
168 json_add_string(response, "bech32", bech32);
169 if (*addrtype & ADDR_P2TR)
170 json_add_string(response, "p2tr", p2tr);
171 return command_success(cmd, response);
172}
173
174static const struct json_command newaddr_command = {
175 "newaddr",

Callers

nothing calls this directly

Calls 9

encode_pubkey_to_addrFunction · 0.85
newaddr_innerFunction · 0.70
paramFunction · 0.50
command_param_failedFunction · 0.50
command_deprecated_in_okFunction · 0.50
command_failFunction · 0.50
json_stream_successFunction · 0.50
json_add_stringFunction · 0.50
command_successFunction · 0.50

Tested by

no test coverage detected