mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-22 06:41:44 +01:00
Reduce variable scopes
This commit is contained in:
parent
94ca824cf5
commit
7e9750ffee
15 changed files with 35 additions and 60 deletions
|
@ -2299,11 +2299,10 @@ static void handle_fail(struct peer *peer, const u8 *inmsg)
|
||||||
failcode);
|
failcode);
|
||||||
} else {
|
} else {
|
||||||
u8 *reply;
|
u8 *reply;
|
||||||
u8 *failmsg;
|
|
||||||
|
|
||||||
if (failcode) {
|
if (failcode) {
|
||||||
failmsg = make_failmsg(inmsg, peer, h,
|
u8 *failmsg = make_failmsg(inmsg, peer, h,
|
||||||
failcode, &scid);
|
failcode, &scid);
|
||||||
errpkt = create_onionreply(inmsg,
|
errpkt = create_onionreply(inmsg,
|
||||||
h->shared_secret,
|
h->shared_secret,
|
||||||
failmsg);
|
failmsg);
|
||||||
|
|
|
@ -889,14 +889,12 @@ char *bolt11_encode_(const tal_t *ctx,
|
||||||
{
|
{
|
||||||
u5 *data = tal_arr(tmpctx, u5, 0);
|
u5 *data = tal_arr(tmpctx, u5, 0);
|
||||||
char *hrp, *output;
|
char *hrp, *output;
|
||||||
char postfix;
|
|
||||||
u64 amount;
|
u64 amount;
|
||||||
struct bolt11_field *extra;
|
struct bolt11_field *extra;
|
||||||
secp256k1_ecdsa_recoverable_signature rsig;
|
secp256k1_ecdsa_recoverable_signature rsig;
|
||||||
u8 sig_and_recid[65];
|
u8 sig_and_recid[65];
|
||||||
u8 *hrpu8;
|
u8 *hrpu8;
|
||||||
int recid;
|
int recid;
|
||||||
size_t i;
|
|
||||||
|
|
||||||
/* BOLT #11:
|
/* BOLT #11:
|
||||||
*
|
*
|
||||||
|
@ -905,10 +903,12 @@ char *bolt11_encode_(const tal_t *ctx,
|
||||||
* representation possible.
|
* representation possible.
|
||||||
*/
|
*/
|
||||||
if (b11->msatoshi) {
|
if (b11->msatoshi) {
|
||||||
|
char postfix;
|
||||||
if (*b11->msatoshi % MSAT_PER_BTC == 0) {
|
if (*b11->msatoshi % MSAT_PER_BTC == 0) {
|
||||||
postfix = '\0';
|
postfix = '\0';
|
||||||
amount = *b11->msatoshi / MSAT_PER_BTC;
|
amount = *b11->msatoshi / MSAT_PER_BTC;
|
||||||
} else {
|
} else {
|
||||||
|
size_t i;
|
||||||
for (i = 0; i < ARRAY_SIZE(multipliers)-1; i++) {
|
for (i = 0; i < ARRAY_SIZE(multipliers)-1; i++) {
|
||||||
if (!(*b11->msatoshi * 10 % multipliers[i].m10))
|
if (!(*b11->msatoshi * 10 % multipliers[i].m10))
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -82,7 +82,6 @@ static int test_json_filter(void)
|
||||||
static void test_json_escape(void)
|
static void test_json_escape(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
const char *str;
|
|
||||||
|
|
||||||
for (i = 1; i < 256; i++) {
|
for (i = 1; i < 256; i++) {
|
||||||
char badstr[2];
|
char badstr[2];
|
||||||
|
@ -97,7 +96,7 @@ static void test_json_escape(void)
|
||||||
json_add_escaped_string(result, "x", take(esc));
|
json_add_escaped_string(result, "x", take(esc));
|
||||||
json_object_end(result);
|
json_object_end(result);
|
||||||
|
|
||||||
str = json_result_string(result);
|
const char *str = json_result_string(result);
|
||||||
if (i == '\\' || i == '"'
|
if (i == '\\' || i == '"'
|
||||||
|| i == '\n' || i == '\r' || i == '\b'
|
|| i == '\n' || i == '\r' || i == '\b'
|
||||||
|| i == '\t' || i == '\f')
|
|| i == '\t' || i == '\f')
|
||||||
|
|
|
@ -1302,7 +1302,6 @@ void routing_failure(struct routing_state *rstate,
|
||||||
const u8 *channel_update)
|
const u8 *channel_update)
|
||||||
{
|
{
|
||||||
struct node *node;
|
struct node *node;
|
||||||
int i;
|
|
||||||
time_t now = time_now().ts.tv_sec;
|
time_t now = time_now().ts.tv_sec;
|
||||||
|
|
||||||
status_trace("Received routing failure 0x%04x (%s), "
|
status_trace("Received routing failure 0x%04x (%s), "
|
||||||
|
@ -1330,7 +1329,7 @@ void routing_failure(struct routing_state *rstate,
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
if (failcode & NODE) {
|
if (failcode & NODE) {
|
||||||
for (i = 0; i < tal_count(node->chans); ++i) {
|
for (int i = 0; i < tal_count(node->chans); ++i) {
|
||||||
routing_failure_channel_out(tmpctx, node, failcode,
|
routing_failure_channel_out(tmpctx, node, failcode,
|
||||||
node->chans[i],
|
node->chans[i],
|
||||||
now);
|
now);
|
||||||
|
|
|
@ -608,7 +608,6 @@ static void sign_funding_tx(struct daemon_conn *master, const u8 *msg)
|
||||||
struct pubkey local_pubkey, remote_pubkey;
|
struct pubkey local_pubkey, remote_pubkey;
|
||||||
struct utxo **utxomap;
|
struct utxo **utxomap;
|
||||||
struct bitcoin_tx *tx;
|
struct bitcoin_tx *tx;
|
||||||
u8 *wscript;
|
|
||||||
u16 outnum;
|
u16 outnum;
|
||||||
size_t i;
|
size_t i;
|
||||||
struct pubkey changekey;
|
struct pubkey changekey;
|
||||||
|
@ -644,7 +643,7 @@ static void sign_funding_tx(struct daemon_conn *master, const u8 *msg)
|
||||||
subscript = bitcoin_redeem_p2sh_p2wpkh(tmpctx, &inkey);
|
subscript = bitcoin_redeem_p2sh_p2wpkh(tmpctx, &inkey);
|
||||||
else
|
else
|
||||||
subscript = NULL;
|
subscript = NULL;
|
||||||
wscript = p2wpkh_scriptcode(tmpctx, &inkey);
|
u8 *wscript = p2wpkh_scriptcode(tmpctx, &inkey);
|
||||||
|
|
||||||
sign_tx_input(tx, i, subscript, wscript, &inprivkey, &inkey,
|
sign_tx_input(tx, i, subscript, wscript, &inprivkey, &inkey,
|
||||||
&sig);
|
&sig);
|
||||||
|
@ -673,7 +672,6 @@ static void sign_withdrawal_tx(struct daemon_conn *master, const u8 *msg)
|
||||||
u64 satoshi_out, change_out;
|
u64 satoshi_out, change_out;
|
||||||
u32 change_keyindex;
|
u32 change_keyindex;
|
||||||
struct utxo **utxos;
|
struct utxo **utxos;
|
||||||
u8 *wscript;
|
|
||||||
u8 **scriptSigs;
|
u8 **scriptSigs;
|
||||||
struct bitcoin_tx *tx;
|
struct bitcoin_tx *tx;
|
||||||
struct ext_key ext;
|
struct ext_key ext;
|
||||||
|
@ -715,7 +713,7 @@ static void sign_withdrawal_tx(struct daemon_conn *master, const u8 *msg)
|
||||||
subscript = bitcoin_redeem_p2sh_p2wpkh(tmpctx, &inkey);
|
subscript = bitcoin_redeem_p2sh_p2wpkh(tmpctx, &inkey);
|
||||||
else
|
else
|
||||||
subscript = NULL;
|
subscript = NULL;
|
||||||
wscript = p2wpkh_scriptcode(tmpctx, &inkey);
|
u8 *wscript = p2wpkh_scriptcode(tmpctx, &inkey);
|
||||||
|
|
||||||
sign_tx_input(tx, i, subscript, wscript, &inprivkey, &inkey,
|
sign_tx_input(tx, i, subscript, wscript, &inprivkey, &inkey,
|
||||||
&sig);
|
&sig);
|
||||||
|
|
|
@ -738,10 +738,9 @@ static void fatal_bitcoind_failure(struct bitcoind *bitcoind, const char *error_
|
||||||
|
|
||||||
void wait_for_bitcoind(struct bitcoind *bitcoind)
|
void wait_for_bitcoind(struct bitcoind *bitcoind)
|
||||||
{
|
{
|
||||||
int from, ret, status;
|
int from, status;
|
||||||
pid_t child;
|
pid_t child;
|
||||||
const char **cmd = cmdarr(bitcoind, bitcoind, "echo", NULL);
|
const char **cmd = cmdarr(bitcoind, bitcoind, "echo", NULL);
|
||||||
char *output;
|
|
||||||
bool printed = false;
|
bool printed = false;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
@ -753,12 +752,12 @@ void wait_for_bitcoind(struct bitcoind *bitcoind)
|
||||||
fatal("%s exec failed: %s", cmd[0], strerror(errno));
|
fatal("%s exec failed: %s", cmd[0], strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
output = grab_fd(cmd, from);
|
char *output = grab_fd(cmd, from);
|
||||||
if (!output)
|
if (!output)
|
||||||
fatal("Reading from %s failed: %s",
|
fatal("Reading from %s failed: %s",
|
||||||
cmd[0], strerror(errno));
|
cmd[0], strerror(errno));
|
||||||
|
|
||||||
ret = waitpid(child, &status, 0);
|
int ret = waitpid(child, &status, 0);
|
||||||
if (ret != child)
|
if (ret != child)
|
||||||
fatal("Waiting for %s: %s", cmd[0], strerror(errno));
|
fatal("Waiting for %s: %s", cmd[0], strerror(errno));
|
||||||
if (!WIFEXITED(status))
|
if (!WIFEXITED(status))
|
||||||
|
|
|
@ -287,7 +287,6 @@ void channel_fail_permanent(struct channel *channel, const char *fmt, ...)
|
||||||
struct lightningd *ld = channel->peer->ld;
|
struct lightningd *ld = channel->peer->ld;
|
||||||
va_list ap;
|
va_list ap;
|
||||||
char *why;
|
char *why;
|
||||||
u8 *msg;
|
|
||||||
struct channel_id cid;
|
struct channel_id cid;
|
||||||
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
|
@ -295,7 +294,7 @@ void channel_fail_permanent(struct channel *channel, const char *fmt, ...)
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
if (channel->scid) {
|
if (channel->scid) {
|
||||||
msg = towire_gossip_disable_channel(NULL,
|
u8 *msg = towire_gossip_disable_channel(NULL,
|
||||||
channel->scid,
|
channel->scid,
|
||||||
channel->peer->direction,
|
channel->peer->direction,
|
||||||
false);
|
false);
|
||||||
|
|
|
@ -111,7 +111,6 @@ static void json_connect(struct command *cmd,
|
||||||
char *id_str;
|
char *id_str;
|
||||||
char *atptr;
|
char *atptr;
|
||||||
char *ataddr = NULL;
|
char *ataddr = NULL;
|
||||||
int atidx;
|
|
||||||
const char *name;
|
const char *name;
|
||||||
struct wireaddr addr;
|
struct wireaddr addr;
|
||||||
u8 *msg;
|
u8 *msg;
|
||||||
|
@ -130,7 +129,7 @@ static void json_connect(struct command *cmd,
|
||||||
idtok->end - idtok->start);
|
idtok->end - idtok->start);
|
||||||
atptr = strchr(id_str, '@');
|
atptr = strchr(id_str, '@');
|
||||||
if (atptr) {
|
if (atptr) {
|
||||||
atidx = atptr - id_str;
|
int atidx = atptr - id_str;
|
||||||
ataddr = tal_strdup(cmd, atptr + 1);
|
ataddr = tal_strdup(cmd, atptr + 1);
|
||||||
/* Cut id. */
|
/* Cut id. */
|
||||||
idtok->end = idtok->start + atidx;
|
idtok->end = idtok->start + atidx;
|
||||||
|
|
|
@ -487,7 +487,7 @@ bool json_get_params(struct command *cmd,
|
||||||
const char **names;
|
const char **names;
|
||||||
size_t num_names;
|
size_t num_names;
|
||||||
/* Uninitialized warnings on p and end */
|
/* Uninitialized warnings on p and end */
|
||||||
const jsmntok_t **tokptr, *p = NULL, *end = NULL;
|
const jsmntok_t *p = NULL, *end = NULL;
|
||||||
|
|
||||||
if (param->type == JSMN_ARRAY) {
|
if (param->type == JSMN_ARRAY) {
|
||||||
if (param->size == 0)
|
if (param->size == 0)
|
||||||
|
@ -505,7 +505,7 @@ bool json_get_params(struct command *cmd,
|
||||||
names = tal_arr(cmd, const char *, num_names + 1);
|
names = tal_arr(cmd, const char *, num_names + 1);
|
||||||
va_start(ap, param);
|
va_start(ap, param);
|
||||||
while ((names[num_names] = va_arg(ap, const char *)) != NULL) {
|
while ((names[num_names] = va_arg(ap, const char *)) != NULL) {
|
||||||
tokptr = va_arg(ap, const jsmntok_t **);
|
const jsmntok_t **tokptr = va_arg(ap, const jsmntok_t **);
|
||||||
bool compulsory = true;
|
bool compulsory = true;
|
||||||
if (names[num_names][0] == '?') {
|
if (names[num_names][0] == '?') {
|
||||||
names[num_names]++;
|
names[num_names]++;
|
||||||
|
@ -788,7 +788,6 @@ json_tok_address_scriptpubkey(const tal_t *cxt,
|
||||||
* of fixed size 40 will not overflow. */
|
* of fixed size 40 will not overflow. */
|
||||||
uint8_t witness_program[40];
|
uint8_t witness_program[40];
|
||||||
size_t witness_program_len;
|
size_t witness_program_len;
|
||||||
bool witness_ok;
|
|
||||||
|
|
||||||
char *addrz;
|
char *addrz;
|
||||||
const char *bip173;
|
const char *bip173;
|
||||||
|
@ -826,7 +825,7 @@ json_tok_address_scriptpubkey(const tal_t *cxt,
|
||||||
&witness_program_len, addrz);
|
&witness_program_len, addrz);
|
||||||
|
|
||||||
if (bip173) {
|
if (bip173) {
|
||||||
witness_ok = false;
|
bool witness_ok = false;
|
||||||
if (witness_version == 0 && (witness_program_len == 20 ||
|
if (witness_version == 0 && (witness_program_len == 20 ||
|
||||||
witness_program_len == 32)) {
|
witness_program_len == 32)) {
|
||||||
witness_ok = true;
|
witness_ok = true;
|
||||||
|
|
|
@ -419,8 +419,6 @@ void payment_store(struct lightningd *ld,
|
||||||
void payment_failed(struct lightningd *ld, const struct htlc_out *hout,
|
void payment_failed(struct lightningd *ld, const struct htlc_out *hout,
|
||||||
const char *localfail)
|
const char *localfail)
|
||||||
{
|
{
|
||||||
struct onionreply *reply;
|
|
||||||
struct secret *path_secrets;
|
|
||||||
struct wallet_payment *payment;
|
struct wallet_payment *payment;
|
||||||
struct routing_failure* fail = NULL;
|
struct routing_failure* fail = NULL;
|
||||||
const char *failmsg;
|
const char *failmsg;
|
||||||
|
@ -468,8 +466,8 @@ void payment_failed(struct lightningd *ld, const struct htlc_out *hout,
|
||||||
assert(!hout->failcode);
|
assert(!hout->failcode);
|
||||||
failmsg = "reply from remote";
|
failmsg = "reply from remote";
|
||||||
/* Try to parse reply. */
|
/* Try to parse reply. */
|
||||||
path_secrets = payment->path_secrets;
|
struct secret *path_secrets = payment->path_secrets;
|
||||||
reply = unwrap_onionreply(tmpctx, path_secrets,
|
struct onionreply *reply = unwrap_onionreply(tmpctx, path_secrets,
|
||||||
tal_count(path_secrets),
|
tal_count(path_secrets),
|
||||||
hout->failuremsg);
|
hout->failuremsg);
|
||||||
if (!reply) {
|
if (!reply) {
|
||||||
|
@ -895,11 +893,10 @@ static void json_sendpay_on_resolve(const struct sendpay_result* r,
|
||||||
void *vcmd)
|
void *vcmd)
|
||||||
{
|
{
|
||||||
struct command *cmd = (struct command*) vcmd;
|
struct command *cmd = (struct command*) vcmd;
|
||||||
struct json_result *response;
|
|
||||||
|
|
||||||
if (!r->succeeded && r->errorcode == PAY_IN_PROGRESS) {
|
if (!r->succeeded && r->errorcode == PAY_IN_PROGRESS) {
|
||||||
/* This is normal for sendpay. Succeed. */
|
/* This is normal for sendpay. Succeed. */
|
||||||
response = new_json_result(cmd);
|
struct json_result *response = new_json_result(cmd);
|
||||||
json_object_start(response, NULL);
|
json_object_start(response, NULL);
|
||||||
json_add_string(response, "message",
|
json_add_string(response, "message",
|
||||||
"Monitor status with listpayments or waitsendpay");
|
"Monitor status with listpayments or waitsendpay");
|
||||||
|
|
|
@ -200,7 +200,7 @@ json_pay_success(struct pay *pay,
|
||||||
static void json_pay_failure(struct pay *pay,
|
static void json_pay_failure(struct pay *pay,
|
||||||
const struct sendpay_result *r)
|
const struct sendpay_result *r)
|
||||||
{
|
{
|
||||||
struct json_result *data = NULL;
|
struct json_result *data;
|
||||||
const char *msg = NULL;
|
const char *msg = NULL;
|
||||||
struct routing_failure *fail;
|
struct routing_failure *fail;
|
||||||
|
|
||||||
|
@ -485,12 +485,11 @@ static bool json_pay_try(struct pay *pay)
|
||||||
u8 *req;
|
u8 *req;
|
||||||
struct command *cmd = pay->cmd;
|
struct command *cmd = pay->cmd;
|
||||||
struct timeabs now = time_now();
|
struct timeabs now = time_now();
|
||||||
struct json_result *data;
|
|
||||||
struct siphash_seed seed;
|
struct siphash_seed seed;
|
||||||
|
|
||||||
/* If too late anyway, fail now. */
|
/* If too late anyway, fail now. */
|
||||||
if (time_after(now, pay->expiry)) {
|
if (time_after(now, pay->expiry)) {
|
||||||
data = new_json_result(cmd);
|
struct json_result *data = new_json_result(cmd);
|
||||||
json_object_start(data, NULL);
|
json_object_start(data, NULL);
|
||||||
json_add_num(data, "now", now.ts.tv_sec);
|
json_add_num(data, "now", now.ts.tv_sec);
|
||||||
json_add_num(data, "expiry", pay->expiry.ts.tv_sec);
|
json_add_num(data, "expiry", pay->expiry.ts.tv_sec);
|
||||||
|
|
|
@ -525,7 +525,6 @@ s64 db_get_intvar(struct db *db, char *varname, s64 defval)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
s64 res = defval;
|
s64 res = defval;
|
||||||
const unsigned char *stringvar;
|
|
||||||
sqlite3_stmt *stmt =
|
sqlite3_stmt *stmt =
|
||||||
db_query(__func__, db,
|
db_query(__func__, db,
|
||||||
"SELECT val FROM vars WHERE name='%s' LIMIT 1", varname);
|
"SELECT val FROM vars WHERE name='%s' LIMIT 1", varname);
|
||||||
|
@ -535,7 +534,7 @@ s64 db_get_intvar(struct db *db, char *varname, s64 defval)
|
||||||
|
|
||||||
err = sqlite3_step(stmt);
|
err = sqlite3_step(stmt);
|
||||||
if (err == SQLITE_ROW) {
|
if (err == SQLITE_ROW) {
|
||||||
stringvar = sqlite3_column_text(stmt, 0);
|
const unsigned char *stringvar = sqlite3_column_text(stmt, 0);
|
||||||
res = atol((const char *)stringvar);
|
res = atol((const char *)stringvar);
|
||||||
}
|
}
|
||||||
sqlite3_finalize(stmt);
|
sqlite3_finalize(stmt);
|
||||||
|
|
|
@ -75,9 +75,8 @@ void txfilter_add_derkey(struct txfilter *filter,
|
||||||
|
|
||||||
bool txfilter_match(const struct txfilter *filter, const struct bitcoin_tx *tx)
|
bool txfilter_match(const struct txfilter *filter, const struct bitcoin_tx *tx)
|
||||||
{
|
{
|
||||||
u8 *oscript;
|
|
||||||
for (size_t i = 0; i < tal_count(tx->output); i++) {
|
for (size_t i = 0; i < tal_count(tx->output); i++) {
|
||||||
oscript = tx->output[i].script;
|
u8 *oscript = tx->output[i].script;
|
||||||
|
|
||||||
for (size_t j = 0; j < tal_count(filter->scriptpubkeys); j++) {
|
for (size_t j = 0; j < tal_count(filter->scriptpubkeys); j++) {
|
||||||
if (scripteq(oscript, filter->scriptpubkeys[j]))
|
if (scripteq(oscript, filter->scriptpubkeys[j]))
|
||||||
|
|
|
@ -526,7 +526,6 @@ bool wallet_peer_by_nodeid(struct wallet *w, const struct pubkey *nodeid,
|
||||||
struct peer *peer)
|
struct peer *peer)
|
||||||
{
|
{
|
||||||
bool ok;
|
bool ok;
|
||||||
const unsigned char *addrstr;
|
|
||||||
sqlite3_stmt *stmt = db_prepare(w->db, "SELECT id, node_id, address FROM peers WHERE node_id=?;");
|
sqlite3_stmt *stmt = db_prepare(w->db, "SELECT id, node_id, address FROM peers WHERE node_id=?;");
|
||||||
sqlite3_bind_pubkey(stmt, 1, nodeid);
|
sqlite3_bind_pubkey(stmt, 1, nodeid);
|
||||||
|
|
||||||
|
@ -534,7 +533,7 @@ bool wallet_peer_by_nodeid(struct wallet *w, const struct pubkey *nodeid,
|
||||||
if (ok) {
|
if (ok) {
|
||||||
peer->dbid = sqlite3_column_int64(stmt, 0);
|
peer->dbid = sqlite3_column_int64(stmt, 0);
|
||||||
ok &= sqlite3_column_pubkey(stmt, 1, &peer->id);
|
ok &= sqlite3_column_pubkey(stmt, 1, &peer->id);
|
||||||
addrstr = sqlite3_column_text(stmt, 2);
|
const unsigned char *addrstr = sqlite3_column_text(stmt, 2);
|
||||||
|
|
||||||
if (addrstr)
|
if (addrstr)
|
||||||
parse_wireaddr((const char*)addrstr, &peer->addr, DEFAULT_PORT, NULL);
|
parse_wireaddr((const char*)addrstr, &peer->addr, DEFAULT_PORT, NULL);
|
||||||
|
@ -1852,7 +1851,6 @@ void wallet_payment_set_failinfo(struct wallet *wallet,
|
||||||
const u8 *failupdate /*tal_arr*/)
|
const u8 *failupdate /*tal_arr*/)
|
||||||
{
|
{
|
||||||
sqlite3_stmt *stmt;
|
sqlite3_stmt *stmt;
|
||||||
struct short_channel_id *scid;
|
|
||||||
|
|
||||||
stmt = db_prepare(wallet->db,
|
stmt = db_prepare(wallet->db,
|
||||||
"UPDATE payments"
|
"UPDATE payments"
|
||||||
|
@ -1880,7 +1878,7 @@ void wallet_payment_set_failinfo(struct wallet *wallet,
|
||||||
if (failchannel) {
|
if (failchannel) {
|
||||||
/* sqlite3_bind_short_channel_id requires the input
|
/* sqlite3_bind_short_channel_id requires the input
|
||||||
* channel to be tal-allocated... */
|
* channel to be tal-allocated... */
|
||||||
scid = tal(tmpctx, struct short_channel_id);
|
struct short_channel_id *scid = tal(tmpctx, struct short_channel_id);
|
||||||
*scid = *failchannel;
|
*scid = *failchannel;
|
||||||
sqlite3_bind_short_channel_id(stmt, 6, scid);
|
sqlite3_bind_short_channel_id(stmt, 6, scid);
|
||||||
} else
|
} else
|
||||||
|
|
|
@ -46,7 +46,6 @@ static void wallet_withdrawal_broadcast(struct bitcoind *bitcoind UNUSED,
|
||||||
{
|
{
|
||||||
struct command *cmd = withdraw->cmd;
|
struct command *cmd = withdraw->cmd;
|
||||||
struct lightningd *ld = withdraw->cmd->ld;
|
struct lightningd *ld = withdraw->cmd->ld;
|
||||||
struct bitcoin_tx *tx;
|
|
||||||
u64 change_satoshi = 0;
|
u64 change_satoshi = 0;
|
||||||
|
|
||||||
/* Massage output into shape so it doesn't kill the JSON serialization */
|
/* Massage output into shape so it doesn't kill the JSON serialization */
|
||||||
|
@ -57,7 +56,7 @@ static void wallet_withdrawal_broadcast(struct bitcoind *bitcoind UNUSED,
|
||||||
|
|
||||||
/* Parse the tx and extract the change output. We
|
/* Parse the tx and extract the change output. We
|
||||||
* generated the hex tx, so this should always work */
|
* generated the hex tx, so this should always work */
|
||||||
tx = bitcoin_tx_from_hex(withdraw, withdraw->hextx, strlen(withdraw->hextx));
|
struct bitcoin_tx *tx = bitcoin_tx_from_hex(withdraw, withdraw->hextx, strlen(withdraw->hextx));
|
||||||
assert(tx != NULL);
|
assert(tx != NULL);
|
||||||
wallet_extract_owned_outputs(ld->wallet, tx, NULL, &change_satoshi);
|
wallet_extract_owned_outputs(ld->wallet, tx, NULL, &change_satoshi);
|
||||||
|
|
||||||
|
@ -208,11 +207,9 @@ static void json_newaddr(struct command *cmd, const char *buffer UNUSED,
|
||||||
struct ripemd160 h160;
|
struct ripemd160 h160;
|
||||||
struct pubkey pubkey;
|
struct pubkey pubkey;
|
||||||
jsmntok_t *addrtype;
|
jsmntok_t *addrtype;
|
||||||
u8 *redeemscript;
|
bool is_p2wpkh;
|
||||||
bool is_p2wpkh, ok;
|
|
||||||
s64 keyidx;
|
s64 keyidx;
|
||||||
char *out;
|
char *out;
|
||||||
const char *hrp;
|
|
||||||
|
|
||||||
if (!json_get_params(cmd, buffer, params,
|
if (!json_get_params(cmd, buffer, params,
|
||||||
"?addresstype", &addrtype, NULL)) {
|
"?addresstype", &addrtype, NULL)) {
|
||||||
|
@ -251,18 +248,18 @@ static void json_newaddr(struct command *cmd, const char *buffer UNUSED,
|
||||||
txfilter_add_derkey(cmd->ld->owned_txfilter, ext.pub_key);
|
txfilter_add_derkey(cmd->ld->owned_txfilter, ext.pub_key);
|
||||||
|
|
||||||
if (is_p2wpkh) {
|
if (is_p2wpkh) {
|
||||||
hrp = get_chainparams(cmd->ld)->bip173_name;
|
const char *hrp = get_chainparams(cmd->ld)->bip173_name;
|
||||||
/* out buffer is 73 + strlen(human readable part). see bech32.h */
|
/* out buffer is 73 + strlen(human readable part). see bech32.h */
|
||||||
out = tal_arr(cmd, char, 73 + strlen(hrp));
|
out = tal_arr(cmd, char, 73 + strlen(hrp));
|
||||||
pubkey_to_hash160(&pubkey, &h160);
|
pubkey_to_hash160(&pubkey, &h160);
|
||||||
ok = segwit_addr_encode(out, hrp, 0, h160.u.u8, sizeof(h160.u.u8));
|
bool ok = segwit_addr_encode(out, hrp, 0, h160.u.u8, sizeof(h160.u.u8));
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
command_fail(cmd, "p2wpkh address encoding failure.");
|
command_fail(cmd, "p2wpkh address encoding failure.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
redeemscript = bitcoin_redeem_p2sh_p2wpkh(cmd, &pubkey);
|
u8 *redeemscript = bitcoin_redeem_p2sh_p2wpkh(cmd, &pubkey);
|
||||||
sha256(&h, redeemscript, tal_count(redeemscript));
|
sha256(&h, redeemscript, tal_count(redeemscript));
|
||||||
ripemd160(&h160, h.u.u8, sizeof(h));
|
ripemd160(&h160, h.u.u8, sizeof(h));
|
||||||
out = p2sh_to_base58(cmd,
|
out = p2sh_to_base58(cmd,
|
||||||
|
@ -292,11 +289,6 @@ static void json_listaddrs(struct command *cmd,
|
||||||
struct ripemd160 h160;
|
struct ripemd160 h160;
|
||||||
struct pubkey pubkey;
|
struct pubkey pubkey;
|
||||||
jsmntok_t *bip32tok;
|
jsmntok_t *bip32tok;
|
||||||
u8 *redeemscript;
|
|
||||||
bool ok;
|
|
||||||
char *out_p2sh;
|
|
||||||
char *out_p2wpkh;
|
|
||||||
const char *hrp;
|
|
||||||
u64 bip32_max_index;
|
u64 bip32_max_index;
|
||||||
|
|
||||||
if (!json_get_params(cmd, buffer, params,
|
if (!json_get_params(cmd, buffer, params,
|
||||||
|
@ -330,18 +322,18 @@ static void json_listaddrs(struct command *cmd,
|
||||||
}
|
}
|
||||||
|
|
||||||
// p2sh
|
// p2sh
|
||||||
redeemscript = bitcoin_redeem_p2sh_p2wpkh(cmd, &pubkey);
|
u8 *redeemscript = bitcoin_redeem_p2sh_p2wpkh(cmd, &pubkey);
|
||||||
sha256(&h, redeemscript, tal_count(redeemscript));
|
sha256(&h, redeemscript, tal_count(redeemscript));
|
||||||
ripemd160(&h160, h.u.u8, sizeof(h));
|
ripemd160(&h160, h.u.u8, sizeof(h));
|
||||||
out_p2sh = p2sh_to_base58(cmd,
|
char *out_p2sh = p2sh_to_base58(cmd,
|
||||||
get_chainparams(cmd->ld)->testnet, &h160);
|
get_chainparams(cmd->ld)->testnet, &h160);
|
||||||
|
|
||||||
// bech32 : p2wpkh
|
// bech32 : p2wpkh
|
||||||
hrp = get_chainparams(cmd->ld)->bip173_name;
|
const char *hrp = get_chainparams(cmd->ld)->bip173_name;
|
||||||
/* out buffer is 73 + strlen(human readable part). see bech32.h */
|
/* out buffer is 73 + strlen(human readable part). see bech32.h */
|
||||||
out_p2wpkh = tal_arr(cmd, char, 73 + strlen(hrp));
|
char *out_p2wpkh = tal_arr(cmd, char, 73 + strlen(hrp));
|
||||||
pubkey_to_hash160(&pubkey, &h160);
|
pubkey_to_hash160(&pubkey, &h160);
|
||||||
ok = segwit_addr_encode(out_p2wpkh, hrp, 0, h160.u.u8, sizeof(h160.u.u8));
|
bool ok = segwit_addr_encode(out_p2wpkh, hrp, 0, h160.u.u8, sizeof(h160.u.u8));
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
command_fail(cmd, "p2wpkh address encoding failure.");
|
command_fail(cmd, "p2wpkh address encoding failure.");
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Add table
Reference in a new issue