From 21d5f23bdfb86d58ff029e68d3d8cc764b1e4d4c Mon Sep 17 00:00:00 2001 From: laalauger Date: Wed, 12 Jan 2022 11:31:36 +0800 Subject: [PATCH] update 1.0.12 --- setup.py | 2 +- tests/test_transaction.py | 11 ++++++++++- thor_devkit/transaction.py | 16 ++++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 5730158..d32121d 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ setuptools.setup( name="thor-devkit", - version="1.0.11", + version="1.0.12", author="laalaguer", author_email="laalaguer@gmail.com", description="SDK to interact with VeChain Thor public blockchain.", diff --git a/tests/test_transaction.py b/tests/test_transaction.py index dc5e5c8..6cba40d 100644 --- a/tests/test_transaction.py +++ b/tests/test_transaction.py @@ -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 \ No newline at end of file + 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 \ No newline at end of file diff --git a/thor_devkit/transaction.py b/thor_devkit/transaction.py index db329e1..4a9045b 100644 --- a/thor_devkit/transaction.py +++ b/thor_devkit/transaction.py @@ -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)