Add typed accessors for the PSBT fields read while signing
Accessing PSBT fields needed raw validation at the caller's site, which
ends up mixing the PSBT validation logic with the actual signing logic.
Introduce sign_psbt/psbt_fields.{c,h}, where each accessor owns the
structural validation of exactly one field and returns a typed value.
Every accessor returns a tri-state psbt_field_status_t, so that a caller
can always tell a field that is not in the map from one that could not be
read. The length policy of each field - an exact size, or a maximum -
lives here rather than next to call_get_merkleized_map_value.
Note the accessors return an enum whose ERROR value is -1, which is
truthy. Therefore, every one of the 26 call sites compares against
PSBT_FIELD_PRESENT explicitly.
This is a pure refactor: no behavioral change. In particular the two
optional fields keep the exact defaulting policy they had before, which
is deliberately left alone here and fixed in the next commit:
- the four nSequence reads in txhashes.c fall back to 0xFFFFFFFF on any
non-PRESENT status, as they did on any failed read before;
- psbt_get_global_fallback_locktime keeps its 9-byte varint buffer and
reports every read failure as ABSENT, yielding locktime 0.
Both are marked as such in the accessor docs.
The three unit tests covering the removed u32 wrapper are dropped, as
they are subsumed by a test added here against the real accessor.
The two remaining tests in test_get_merkleized_map_value.c now assert
the named statuses.
Unit tests are added for the new accessors. S
Salvatore Ingala committed
acb931a7e74bc492c2340d501ce632c87a0b72a8
Parent: 941235f