psbt: pull out changeset logic into common, update API

Greatly simplify the changeset API. Instead of 'diff' we simply generate
the changes.

Also pulls up the 'next message' method, as at some point the
interactive tx protocol will be used for other things as well
(splices/closes etc)

Suggested-By: @rustyrussell
This commit is contained in:
niftynei
2020-09-09 19:40:29 +09:30
committed by Rusty Russell
parent 5cd06227d7
commit c50f377a85
12 changed files with 190 additions and 204 deletions

View File

@@ -389,14 +389,16 @@ static bool psbt_side_contribs_changed(struct wally_psbt *orig,
struct wally_psbt *new,
enum side opener_side)
{
struct input_set *added_in, *rm_in;
struct output_set *added_out, *rm_out;
struct psbt_changeset *cs;
u16 serial_id;
bool ok;
if (!psbt_has_diff(tmpctx, orig, new,
&added_in, &rm_in,
&added_out, &rm_out))
cs = psbt_get_changeset(tmpctx, orig, new);
if (tal_count(cs->added_ins) == 0 &&
tal_count(cs->rm_ins) == 0 &&
tal_count(cs->added_outs) == 0 &&
tal_count(cs->rm_outs) == 0)
return false;
/* If there were *any* changes, then the answer to the 'both sides'
@@ -406,10 +408,10 @@ static bool psbt_side_contribs_changed(struct wally_psbt *orig,
/* Check that none of the included updates have a serial
* id that's the peer's parity */
CHECK_CHANGES(added_in, input);
CHECK_CHANGES(rm_in, input);
CHECK_CHANGES(added_out, output);
CHECK_CHANGES(rm_out, output);
CHECK_CHANGES(cs->added_ins, input);
CHECK_CHANGES(cs->rm_ins, input);
CHECK_CHANGES(cs->added_outs, output);
CHECK_CHANGES(cs->rm_outs, output);
return false;
}