Skip to content

Commit e50a948

Browse files
committed
more xbr mm fixes
1 parent 1b82054 commit e50a948

File tree

2 files changed

+22
-20
lines changed

2 files changed

+22
-20
lines changed

cfxdb/tests/xbrmm/test_transaction.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ def fill_transaction(transaction):
2929
transaction.created_paying_channel_seq = random.randint(1, 1000)
3030
transaction.offer = uuid.uuid4()
3131
transaction.amount = random.randint(1, 2**256 - 1)
32-
transaction.payment_channel = os.urandom(20)
33-
transaction.paying_channel = os.urandom(20)
32+
transaction.payment_channel = uuid.uuid4()
33+
transaction.paying_channel = uuid.uuid4()
3434
transaction.state = random.randint(1, 3)
3535
transaction.completed = np.datetime64(now, 'ns')
3636
transaction.completed_payment_channel_seq = random.randint(1, 1000)
@@ -86,7 +86,7 @@ def test_transaction_roundtrip(transaction, builder):
8686
obj = transaction.build(builder)
8787
builder.Finish(obj)
8888
data = builder.Output()
89-
assert len(data) == 728
89+
assert len(data) == 720
9090

9191
# create python object from bytes (flatbuffes)
9292
_transaction = Transaction.cast(data)

cfxdb/xbrmm/transaction.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,10 @@ def __init__(self, from_fbs=None):
178178
# uint8[] (uint256)
179179
self._amount = None
180180

181-
# uint8[] (bytes20)
181+
# uint8[] (uuid)
182182
self._payment_channel = None
183183

184-
# uint8[] (bytes20)
184+
# uint8[] (uuid)
185185
self._paying_channel = None
186186

187187
# uint8
@@ -228,16 +228,18 @@ def marshal(self):
228228
'created_paying_channel_seq': self._created_paying_channel_seq,
229229
'offer': str(self.offer) if self.offer else None,
230230
'amount': pack_uint256(self.amount) if self.amount else 0,
231-
'payment_channel': self.payment_channel,
232-
'paying_channel': self.paying_channel,
231+
'payment_channel': self.payment_channel.bytes if self.payment_channel else None,
232+
'paying_channel': self.paying_channel.bytes if self.paying_channel else None,
233233
'state': self.state,
234234
'completed': self.completed,
235235
'completed_payment_channel_seq': self._completed_payment_channel_seq,
236236
'completed_paying_channel_seq': self._completed_paying_channel_seq,
237-
'key': self.key,
237+
'key': self.key.bytes if self.key else None,
238238
'buyer_pubkey': self.buyer_pubkey,
239-
'payment_channel_after': self.payment_channel_after,
240-
'paying_channel_after': self.paying_channel_after,
239+
'payment_channel_after':
240+
pack_uint256(self.payment_channel_after) if self.payment_channel_after else None,
241+
'paying_channel_after':
242+
pack_uint256(self.paying_channel_after) if self.paying_channel_after else None,
241243
'payment_mm_sig': self.payment_mm_sig,
242244
'payment_del_sig': self.payment_del_sig,
243245
'paying_mm_sig': self.paying_mm_sig,
@@ -341,33 +343,33 @@ def amount(self, value: int):
341343
self._amount = value
342344

343345
@property
344-
def payment_channel(self) -> bytes:
346+
def payment_channel(self) -> uuid.UUID:
345347
"""
346348
Address of the payment channel (of the buyer) this transaction is transacting on.
347349
"""
348350
if self._payment_channel is None and self._from_fbs:
349351
if self._from_fbs.PaymentChannelLength():
350-
self._payment_channel = self._from_fbs.PaymentChannelAsBytes()
352+
self._payment_channel = uuid.UUID(bytes=bytes(self._from_fbs.PaymentChannelAsBytes()))
351353
return self._payment_channel
352354

353355
@payment_channel.setter
354-
def payment_channel(self, value: bytes):
355-
assert value is None or (type(value) == bytes and len(value) == 20)
356+
def payment_channel(self, value: uuid.UUID):
357+
assert value is None or isinstance(value, uuid.UUID)
356358
self._payment_channel = value
357359

358360
@property
359-
def paying_channel(self) -> bytes:
361+
def paying_channel(self) -> uuid.UUID:
360362
"""
361363
Address of the paying channel (of the seller) this transaction is transacting on.
362364
"""
363365
if self._payment_channel is None and self._from_fbs:
364366
if self._from_fbs.PayingChannelLength():
365-
self._payment_channel = self._from_fbs.PayingChannelAsBytes()
367+
self._payment_channel = uuid.UUID(bytes=bytes(self._from_fbs.PayingChannelAsBytes()))
366368
return self._payment_channel
367369

368370
@paying_channel.setter
369-
def paying_channel(self, value: bytes):
370-
assert value is None or (type(value) == bytes and len(value) == 20)
371+
def paying_channel(self, value: uuid.UUID):
372+
assert value is None or isinstance(value, uuid.UUID)
371373
self._payment_channel = value
372374

373375
@property
@@ -571,11 +573,11 @@ def build(self, builder):
571573
if amount:
572574
amount = builder.CreateString(pack_uint256(amount))
573575

574-
payment_channel = self.payment_channel
576+
payment_channel = self.payment_channel.bytes if self.payment_channel else None
575577
if payment_channel:
576578
payment_channel = builder.CreateString(payment_channel)
577579

578-
paying_channel = self.paying_channel
580+
paying_channel = self.paying_channel.bytes if self.paying_channel else None
579581
if paying_channel:
580582
paying_channel = builder.CreateString(paying_channel)
581583

0 commit comments

Comments
 (0)