From 89661a9979c85b775c22f28fa3e7854ff919adc0 Mon Sep 17 00:00:00 2001 From: "Elad-PC\\elad" Date: Wed, 3 Aug 2016 06:34:16 +0200 Subject: [PATCH 1/4] moved transaction version inside the tx object that gets hashed moved the transaction version (currently fixed to 1.0) from the outer "transaction" object to the inside part, where it will get hashed together with the rest of the transaction. updated docs accordingly. --- bigchaindb/util.py | 4 ++-- docs/source/topic-guides/models.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bigchaindb/util.py b/bigchaindb/util.py index 8492cc81..9e08b415 100644 --- a/bigchaindb/util.py +++ b/bigchaindb/util.py @@ -169,8 +169,8 @@ def create_tx(current_owners, new_owners, inputs, operation, payload=None): Reference: { "id": "", - "version": "transaction version number", "transaction": { + "version": "transaction version number", "fulfillments": [ { "current_owners": ["list of "], @@ -278,6 +278,7 @@ def create_tx(current_owners, new_owners, inputs, operation, payload=None): }) tx = { + 'version': 1, 'fulfillments': fulfillments, 'conditions': conditions, 'operation': operation, @@ -291,7 +292,6 @@ def create_tx(current_owners, new_owners, inputs, operation, payload=None): # create the transaction transaction = { 'id': tx_hash, - 'version': 1, 'transaction': tx } diff --git a/docs/source/topic-guides/models.md b/docs/source/topic-guides/models.md index c130ce83..8e0add9d 100644 --- a/docs/source/topic-guides/models.md +++ b/docs/source/topic-guides/models.md @@ -58,8 +58,8 @@ Assets can be mutable (changeable) or immutable. To change a mutable asset, you ```json { "id": "", - "version": "", "transaction": { + "version": "", "fulfillments": [""], "conditions": [""], "operation": "", @@ -75,8 +75,8 @@ Assets can be mutable (changeable) or immutable. To change a mutable asset, you Here's some explanation of the contents of a transaction: - `id`: The hash of everything inside the serialized `transaction` body (i.e. `fulfillments`, `conditions`, `operation`, `timestamp` and `data`; see below), with one wrinkle: for each fulfillment in `fulfillments`, `fulfillment` is set to `null`. The `id` is also the database primary key. -- `version`: Version number of the transaction model, so that software can support different transaction models. - `transaction`: + - `version`: Version number of the transaction model, so that software can support different transaction models. - `fulfillments`: List of fulfillments. Each _fulfillment_ contains a pointer to an unspent asset and a _crypto fulfillment_ that satisfies a spending condition set on the unspent asset. A _fulfillment_ is usually a signature proving the ownership of the asset. From 8c9d0fba3504d65e109b7a0a15cebc774c982ef3 Mon Sep 17 00:00:00 2001 From: "Elad-PC\\elad" Date: Wed, 3 Aug 2016 08:31:40 +0200 Subject: [PATCH 2/4] fixed reference to version in get_fulfillment_message --- bigchaindb/util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bigchaindb/util.py b/bigchaindb/util.py index 9e08b415..67853ed2 100644 --- a/bigchaindb/util.py +++ b/bigchaindb/util.py @@ -479,7 +479,7 @@ def get_fulfillment_message(transaction, fulfillment, serialized=False): 'operation': transaction['transaction']['operation'], 'timestamp': transaction['transaction']['timestamp'], 'data': transaction['transaction']['data'], - 'version': transaction['version'], + 'version': transaction['transaction']['version'], 'id': transaction['id'] } # and the condition which needs to be retrieved from the output of a previous transaction From f35d5a708e2a7b3922ce561b2c65218b3f2eb12c Mon Sep 17 00:00:00 2001 From: "Elad-PC\\elad" Date: Wed, 3 Aug 2016 08:31:55 +0200 Subject: [PATCH 3/4] fixed tests to deal with new location of 'version' --- tests/db/test_bigchain_api.py | 14 +++++++------- tests/test_util.py | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/db/test_bigchain_api.py b/tests/db/test_bigchain_api.py index 7082e52f..2eb8af7e 100644 --- a/tests/db/test_bigchain_api.py +++ b/tests/db/test_bigchain_api.py @@ -38,8 +38,8 @@ class TestBigchainApi(object): def test_create_transaction_create(self, b, user_sk): tx = b.create_transaction(b.me, user_sk, None, 'CREATE') - assert sorted(tx) == ['id', 'transaction', 'version'] - assert sorted(tx['transaction']) == ['conditions', 'data', 'fulfillments', 'operation', 'timestamp'] + assert sorted(tx) == ['id', 'transaction'] + assert sorted(tx['transaction']) == ['conditions', 'data', 'fulfillments', 'operation', 'timestamp', 'version'] def test_create_transaction_with_unsupported_payload_raises(self, b): with pytest.raises(TypeError): @@ -79,8 +79,8 @@ class TestBigchainApi(object): tx = b.create_transaction(user_vk, b.me, input_tx, 'TRANSFER') - assert sorted(tx) == ['id', 'transaction', 'version'] - assert sorted(tx['transaction']) == ['conditions', 'data', 'fulfillments', 'operation', 'timestamp'] + assert sorted(tx) == ['id', 'transaction'] + assert sorted(tx['transaction']) == ['conditions', 'data', 'fulfillments', 'operation', 'timestamp', 'version'] tx_signed = b.sign_transaction(tx, user_sk) @@ -1169,7 +1169,7 @@ class TestFulfillmentMessage(object): assert fulfillment_message['fulfillment']['input'] == original_fulfillment['input'] assert fulfillment_message['operation'] == tx['transaction']['operation'] assert fulfillment_message['timestamp'] == tx['transaction']['timestamp'] - assert fulfillment_message['version'] == tx['version'] + assert fulfillment_message['version'] == tx['transaction']['version'] @pytest.mark.usefixtures('inputs') def test_fulfillment_message_transfer(self, b, user_vk): @@ -1192,7 +1192,7 @@ class TestFulfillmentMessage(object): assert fulfillment_message['fulfillment']['input'] == original_fulfillment['input'] assert fulfillment_message['operation'] == tx['transaction']['operation'] assert fulfillment_message['timestamp'] == tx['transaction']['timestamp'] - assert fulfillment_message['version'] == tx['version'] + assert fulfillment_message['version'] == tx['transaction']['version'] def test_fulfillment_message_multiple_current_owners_multiple_new_owners_multiple_inputs(self, b, user_vk): # create a new users @@ -1230,7 +1230,7 @@ class TestFulfillmentMessage(object): assert fulfillment_message['fulfillment']['input'] == original_fulfillment['input'] assert fulfillment_message['operation'] == tx['transaction']['operation'] assert fulfillment_message['timestamp'] == tx['transaction']['timestamp'] - assert fulfillment_message['version'] == tx['version'] + assert fulfillment_message['version'] == tx['transaction']['version'] class TestTransactionMalleability(object): diff --git a/tests/test_util.py b/tests/test_util.py index 4a440d60..a4fe5a74 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -151,7 +151,7 @@ def test_create_tx_with_empty_inputs(): tx = create_tx(None, None, [], None) assert 'id' in tx assert 'transaction' in tx - assert 'version' in tx + assert 'version' in tx['transaction'] assert 'fulfillments' in tx['transaction'] assert 'conditions' in tx['transaction'] assert 'operation' in tx['transaction'] From 2e1abc3d6a2008f2da62cb7dbe1f6bb976c2d2a2 Mon Sep 17 00:00:00 2001 From: "Elad-PC\\elad" Date: Wed, 3 Aug 2016 08:55:37 +0200 Subject: [PATCH 4/4] fixed another test --- tests/db/test_bigchain_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/db/test_bigchain_api.py b/tests/db/test_bigchain_api.py index 2eb8af7e..32691468 100644 --- a/tests/db/test_bigchain_api.py +++ b/tests/db/test_bigchain_api.py @@ -1252,7 +1252,7 @@ class TestTransactionMalleability(object): assert b.is_valid_transaction(tx_changed) is False tx_changed = copy.deepcopy(tx_signed) - tx_changed['version'] = '0' + tx_changed['transaction']['version'] = '0' assert b.validate_fulfillments(tx_changed) is False assert b.is_valid_transaction(tx_changed) is False