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

Function json_newaddr

wallet/walletrpc.c:130–173  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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