decode static method
Decode into sections: global, input0, ..., output0, ....
Implementation
static List<List<PsbtKeyValue>> decode(Uint8List bytes) {
if (!hasMagic(bytes)) {
throw FormatException('Invalid PSBT: missing magic bytes');
}
final reader = WireReader(bytes, psbtMagic.length);
final sections = <List<PsbtKeyValue>>[];
// Each section is key-value pairs terminated by a 0x00 separator.
while (!reader.atEnd) {
final section = <PsbtKeyValue>[];
while (!reader.atEnd) {
final keyLen = reader.readVarInt().toInt();
if (keyLen == 0) break; // separator
final key = reader.readSlice(keyLen);
final valueLen = reader.readVarInt().toInt();
final value = reader.readSlice(valueLen);
section.add(PsbtKeyValue(key: key, value: value));
}
sections.add(section);
}
return sections;
}