Skip to content

Commit

Permalink
more xbr mm fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
oberstet committed Apr 10, 2020
1 parent 1b82054 commit e50a948
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
6 changes: 3 additions & 3 deletions cfxdb/tests/xbrmm/test_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def fill_transaction(transaction):
transaction.created_paying_channel_seq = random.randint(1, 1000)
transaction.offer = uuid.uuid4()
transaction.amount = random.randint(1, 2**256 - 1)
transaction.payment_channel = os.urandom(20)
transaction.paying_channel = os.urandom(20)
transaction.payment_channel = uuid.uuid4()
transaction.paying_channel = uuid.uuid4()
transaction.state = random.randint(1, 3)
transaction.completed = np.datetime64(now, 'ns')
transaction.completed_payment_channel_seq = random.randint(1, 1000)
Expand Down Expand Up @@ -86,7 +86,7 @@ def test_transaction_roundtrip(transaction, builder):
obj = transaction.build(builder)
builder.Finish(obj)
data = builder.Output()
assert len(data) == 728
assert len(data) == 720

# create python object from bytes (flatbuffes)
_transaction = Transaction.cast(data)
Expand Down
36 changes: 19 additions & 17 deletions cfxdb/xbrmm/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,10 @@ def __init__(self, from_fbs=None):
# uint8[] (uint256)
self._amount = None

# uint8[] (bytes20)
# uint8[] (uuid)
self._payment_channel = None

# uint8[] (bytes20)
# uint8[] (uuid)
self._paying_channel = None

# uint8
Expand Down Expand Up @@ -228,16 +228,18 @@ def marshal(self):
'created_paying_channel_seq': self._created_paying_channel_seq,
'offer': str(self.offer) if self.offer else None,
'amount': pack_uint256(self.amount) if self.amount else 0,
'payment_channel': self.payment_channel,
'paying_channel': self.paying_channel,
'payment_channel': self.payment_channel.bytes if self.payment_channel else None,
'paying_channel': self.paying_channel.bytes if self.paying_channel else None,
'state': self.state,
'completed': self.completed,
'completed_payment_channel_seq': self._completed_payment_channel_seq,
'completed_paying_channel_seq': self._completed_paying_channel_seq,
'key': self.key,
'key': self.key.bytes if self.key else None,
'buyer_pubkey': self.buyer_pubkey,
'payment_channel_after': self.payment_channel_after,
'paying_channel_after': self.paying_channel_after,
'payment_channel_after':
pack_uint256(self.payment_channel_after) if self.payment_channel_after else None,
'paying_channel_after':
pack_uint256(self.paying_channel_after) if self.paying_channel_after else None,
'payment_mm_sig': self.payment_mm_sig,
'payment_del_sig': self.payment_del_sig,
'paying_mm_sig': self.paying_mm_sig,
Expand Down Expand Up @@ -341,33 +343,33 @@ def amount(self, value: int):
self._amount = value

@property
def payment_channel(self) -> bytes:
def payment_channel(self) -> uuid.UUID:
"""
Address of the payment channel (of the buyer) this transaction is transacting on.
"""
if self._payment_channel is None and self._from_fbs:
if self._from_fbs.PaymentChannelLength():
self._payment_channel = self._from_fbs.PaymentChannelAsBytes()
self._payment_channel = uuid.UUID(bytes=bytes(self._from_fbs.PaymentChannelAsBytes()))
return self._payment_channel

@payment_channel.setter
def payment_channel(self, value: bytes):
assert value is None or (type(value) == bytes and len(value) == 20)
def payment_channel(self, value: uuid.UUID):
assert value is None or isinstance(value, uuid.UUID)
self._payment_channel = value

@property
def paying_channel(self) -> bytes:
def paying_channel(self) -> uuid.UUID:
"""
Address of the paying channel (of the seller) this transaction is transacting on.
"""
if self._payment_channel is None and self._from_fbs:
if self._from_fbs.PayingChannelLength():
self._payment_channel = self._from_fbs.PayingChannelAsBytes()
self._payment_channel = uuid.UUID(bytes=bytes(self._from_fbs.PayingChannelAsBytes()))
return self._payment_channel

@paying_channel.setter
def paying_channel(self, value: bytes):
assert value is None or (type(value) == bytes and len(value) == 20)
def paying_channel(self, value: uuid.UUID):
assert value is None or isinstance(value, uuid.UUID)
self._payment_channel = value

@property
Expand Down Expand Up @@ -571,11 +573,11 @@ def build(self, builder):
if amount:
amount = builder.CreateString(pack_uint256(amount))

payment_channel = self.payment_channel
payment_channel = self.payment_channel.bytes if self.payment_channel else None
if payment_channel:
payment_channel = builder.CreateString(payment_channel)

paying_channel = self.paying_channel
paying_channel = self.paying_channel.bytes if self.paying_channel else None
if paying_channel:
paying_channel = builder.CreateString(paying_channel)

Expand Down

0 comments on commit e50a948

Please sign in to comment.