MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / PSBTMap

Class PSBTMap

test/functional/test_framework/psbt.py:76–106  ·  view source on GitHub ↗

Class for serializing and deserializing PSBT maps

Source from the content-addressed store, hash-verified

74
75
76class PSBTMap:
77 """Class for serializing and deserializing PSBT maps"""
78
79 def __init__(self, map=None):
80 self.map = map if map is not None else {}
81
82 def deserialize(self, f):
83 m = {}
84 while True:
85 k = deser_string(f)
86 if len(k) == 0:
87 break
88 v = deser_string(f)
89 if len(k) == 1:
90 k = k[0]
91 assert k not in m
92 m[k] = v
93 self.map = m
94
95 def serialize(self):
96 m = b""
97 for k,v in self.map.items():
98 if isinstance(k, int) and 0 <= k and k <= 255:
99 k = bytes([k])
100 if isinstance(v, list):
101 assert all(type(elem) is bytes for elem in v)
102 v = b"".join(v) # simply concatenate the byte-strings w/o size prefixes
103 m += ser_compact_size(len(k)) + k
104 m += ser_compact_size(len(v)) + v
105 m += b"\x00"
106 return m
107
108class PSBT:
109 """Class for serializing and deserializing PSBTs"""

Callers 6

create_psbtMethod · 0.90
run_testMethod · 0.90
__init__Method · 0.85
make_blankMethod · 0.85

Calls

no outgoing calls