wallet: properly handle case where peer has no address when saving channel.

In practice, it currently always does, so we've never hit an error.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2018-02-12 20:40:43 +10:30 committed by Christian Decker
parent 81ca1db347
commit 65c09c895d
1 changed files with 6 additions and 3 deletions

View File

@ -737,9 +737,12 @@ void wallet_channel_save(struct wallet *w, struct wallet_channel *chan)
/* Need to store the peer first */
stmt = db_prepare(w->db, "INSERT INTO peers (node_id, address) VALUES (?, ?);");
sqlite3_bind_pubkey(stmt, 1, &chan->peer->id);
sqlite3_bind_text(stmt, 2,
type_to_string(tmpctx, struct wireaddr, &chan->peer->addr),
-1, SQLITE_TRANSIENT);
if (chan->peer->addr.type == ADDR_TYPE_PADDING)
sqlite3_bind_null(stmt, 2);
else
sqlite3_bind_text(stmt, 2,
type_to_string(tmpctx, struct wireaddr, &chan->peer->addr),
-1, SQLITE_TRANSIENT);
db_exec_prepared(w->db, stmt);
p->dbid = sqlite3_last_insert_rowid(w->db->sql);
}