Skip to content

Commit

Permalink
update 1.0.12
Browse files Browse the repository at this point in the history
  • Loading branch information
laalaguer committed Jan 12, 2022
1 parent 04979b9 commit 21d5f23
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setuptools.setup(
name="thor-devkit",
version="1.0.11",
version="1.0.12",
author="laalaguer",
author_email="[email protected]",
description="SDK to interact with VeChain Thor public blockchain.",
Expand Down
11 changes: 10 additions & 1 deletion tests/test_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,4 +238,13 @@ def test_unused():

reserved_list = delegated_tx_3._encode_reserved()
assert reserved_list == [bytes.fromhex("01"), bytes.fromhex("0F0F")]
assert transaction.Transaction.decode(delegated_tx_3.encode(), True) == delegated_tx_3
assert transaction.Transaction.decode(delegated_tx_3.encode(), True) == delegated_tx_3

def test_body_copy():
b1 = copy.deepcopy(body)
tx = transaction.Transaction(b1)
b2 = tx.get_body(False)
b3 = tx.get_body(True)

assert id(b2) != id(b3) # id should be different
assert b2 == b3 # content should be the same
16 changes: 16 additions & 0 deletions thor_devkit/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,22 @@ def __init__(self, body: dict):
''' Construct a transaction from a given body. '''
self.body = BODY(body)
self.signature = None

def get_body(self, as_copy:bool = True):
'''
Get a dict of the body represents the transaction.
If as_copy, return a newly created dict.
If not, return the body used in this Transaction object.
Parameters
----------
as_copy : bool, optional
Return a new dict clone of the body, by default True
'''
if as_copy:
return deepcopy(self.body)
else:
return self.body

def _encode_reserved(self) -> List:
r = self.body.get('reserved', None)
Expand Down

0 comments on commit 21d5f23

Please sign in to comment.