1
0

channel backups: add another version number, for the backup itself

This commit is contained in:
ThomasV
2020-06-16 11:08:52 +02:00
parent 26ae6d68a3
commit 6922d81a1e

View File

@@ -154,6 +154,8 @@ class ChannelConstraints(StoredObject):
is_initiator = attr.ib(type=bool) # note: sometimes also called "funder"
funding_txn_minimum_depth = attr.ib(type=int)
CHANNEL_BACKUP_VERSION = 0
@attr.s
class ChannelBackupStorage(StoredObject):
node_id = attr.ib(type=bytes, converter=hex_to_bytes)
@@ -179,6 +181,7 @@ class ChannelBackupStorage(StoredObject):
def to_bytes(self):
vds = BCDataStream()
vds.write_int16(CHANNEL_BACKUP_VERSION)
vds.write_boolean(self.is_initiator)
vds.write_bytes(self.privkey, 32)
vds.write_bytes(self.channel_seed, 32)
@@ -198,6 +201,8 @@ class ChannelBackupStorage(StoredObject):
def from_bytes(s):
vds = BCDataStream()
vds.write(s)
version = vds.read_int16()
assert version == CHANNEL_BACKUP_VERSION
return ChannelBackupStorage(
is_initiator = bool(vds.read_bytes(1)),
privkey = vds.read_bytes(32).hex(),