From 6f159d393034badeec215c1de51b8a00e8d92a53 Mon Sep 17 00:00:00 2001 From: Sylvain Bellemare Date: Fri, 19 Aug 2016 16:00:18 +0200 Subject: [PATCH] Closes #348 (#578) --- bigchaindb/client.py | 12 +-- bigchaindb/consensus.py | 10 +-- bigchaindb/core.py | 10 +-- bigchaindb/util.py | 78 +++++++++---------- .../http-client-server-api.rst | 12 +-- .../python-driver-api-examples.md | 8 +- .../python-server-api-examples.md | 78 +++++++++---------- docs/source/topic-guides/models.md | 18 ++--- tests/db/test_bigchain_api.py | 58 +++++++------- .../doc/run_doc_python_server_api_examples.py | 8 +- tests/test_client.py | 10 +-- tests/test_util.py | 10 +-- tests/web/test_basic_views.py | 8 +- 13 files changed, 160 insertions(+), 160 deletions(-) diff --git a/bigchaindb/client.py b/bigchaindb/client.py index fcf1a7f8..9f12c8e4 100644 --- a/bigchaindb/client.py +++ b/bigchaindb/client.py @@ -56,8 +56,8 @@ class Client: """ tx = self.consensus.create_transaction( - current_owner=self.public_key, - new_owner=self.public_key, + owner_before=self.public_key, + owner_after=self.public_key, tx_input=None, operation='CREATE', payload=payload) @@ -66,11 +66,11 @@ class Client: tx, private_key=self.private_key) return self._push(signed_tx) - def transfer(self, new_owner, tx_input, payload=None): + def transfer(self, owner_after, tx_input, payload=None): """Issue a transaction to transfer an asset. Args: - new_owner (str): the public key of the new owner + owner_after (str): the public key of the new owner tx_input (str): the id of the transaction to use as input payload (dict, optional): the payload for the transaction. @@ -79,8 +79,8 @@ class Client: """ tx = self.consensus.create_transaction( - current_owner=self.public_key, - new_owner=new_owner, + owner_before=self.public_key, + owner_after=owner_after, tx_input=tx_input, operation='TRANSFER', payload=payload) diff --git a/bigchaindb/consensus.py b/bigchaindb/consensus.py index 66313809..d799018f 100644 --- a/bigchaindb/consensus.py +++ b/bigchaindb/consensus.py @@ -133,14 +133,14 @@ class BaseConsensusRules(AbstractConsensusRules): # TODO: for now lets assume a CREATE transaction only has one fulfillment if transaction['transaction']['fulfillments'][0]['input']: raise ValueError('A CREATE operation has no inputs') - # TODO: for now lets assume a CREATE transaction only has one current_owner - if transaction['transaction']['fulfillments'][0]['current_owners'][0] not in ( + # TODO: for now lets assume a CREATE transaction only has one owner_before + if transaction['transaction']['fulfillments'][0]['owners_before'][0] not in ( bigchain.nodes_except_me + [bigchain.me]): raise exceptions.OperationError( 'Only federation nodes can use the operation `CREATE`') else: - # check if the input exists, is owned by the current_owner + # check if the input exists, is owned by the owner_before if not transaction['transaction']['fulfillments']: raise ValueError('Transaction contains no fulfillments') @@ -206,14 +206,14 @@ class BaseConsensusRules(AbstractConsensusRules): return block @staticmethod - def create_transaction(current_owner, new_owner, tx_input, operation, + def create_transaction(owner_before, owner_after, tx_input, operation, payload=None): """Create a new transaction Refer to the documentation of ``bigchaindb.util.create_tx`` """ - return util.create_tx(current_owner, new_owner, tx_input, operation, + return util.create_tx(owner_before, owner_after, tx_input, operation, payload) @staticmethod diff --git a/bigchaindb/core.py b/bigchaindb/core.py index 0856cd2f..5e67dbea 100644 --- a/bigchaindb/core.py +++ b/bigchaindb/core.py @@ -299,11 +299,11 @@ class Bigchain(object): list: list of `txids` currently owned by `owner` """ - # get all transactions in which owner is in the `new_owners` list + # get all transactions in which owner is in the `owners_after` list response = r.table('bigchain', read_mode=self.read_mode) \ .concat_map(lambda doc: doc['block']['transactions']) \ .filter(lambda tx: tx['transaction']['conditions'] - .contains(lambda c: c['new_owners'] + .contains(lambda c: c['owners_after'] .contains(owner))) \ .run(self.conn) owned = [] @@ -319,12 +319,12 @@ class Bigchain(object): # to get a list of outputs available to spend for condition in tx['transaction']['conditions']: # for simple signature conditions there are no subfulfillments - # check if the owner is in the condition `new_owners` - if len(condition['new_owners']) == 1: + # check if the owner is in the condition `owners_after` + if len(condition['owners_after']) == 1: if condition['condition']['details']['public_key'] == owner: tx_input = {'txid': tx['id'], 'cid': condition['cid']} else: - # for transactions with multiple `new_owners` there will be several subfulfillments nested + # for transactions with multiple `owners_after` there will be several subfulfillments nested # in the condition. We need to iterate the subfulfillments to make sure there is a # subfulfillment for `owner` if util.condition_details_has_owner(condition['condition']['details'], owner): diff --git a/bigchaindb/util.py b/bigchaindb/util.py index 67853ed2..8e7da785 100644 --- a/bigchaindb/util.py +++ b/bigchaindb/util.py @@ -137,7 +137,7 @@ def timestamp(): # TODO: Consider remove the operation (if there are no inputs CREATE else TRANSFER) -def create_tx(current_owners, new_owners, inputs, operation, payload=None): +def create_tx(owners_before, owners_after, inputs, operation, payload=None): """Create a new transaction A transaction in the bigchain is a transfer of a digital asset between two entities represented @@ -153,8 +153,8 @@ def create_tx(current_owners, new_owners, inputs, operation, payload=None): `TRANSFER` - A transfer operation allows for a transfer of the digital assets between entities. Args: - current_owners (list): base58 encoded public key of the current owners of the asset. - new_owners (list): base58 encoded public key of the new owners of the digital asset. + owners_before (list): base58 encoded public key of the current owners of the asset. + owners_after (list): base58 encoded public key of the new owners of the digital asset. inputs (list): id of the transaction to use as input. operation (str): Either `CREATE` or `TRANSFER` operation. payload (Optional[dict]): dictionary with information about asset. @@ -173,7 +173,7 @@ def create_tx(current_owners, new_owners, inputs, operation, payload=None): "version": "transaction version number", "fulfillments": [ { - "current_owners": ["list of "], + "owners_before": ["list of "], "input": { "txid": "", "cid": "condition index" @@ -184,7 +184,7 @@ def create_tx(current_owners, new_owners, inputs, operation, payload=None): ], "conditions": [ { - "new_owners": ["list of "], + "owners_after": ["list of "], "condition": "condition to be met", "cid": "condition index (1-to-1 mapping with fid)" } @@ -205,16 +205,16 @@ def create_tx(current_owners, new_owners, inputs, operation, payload=None): # validate arguments (owners and inputs should be lists or None) # The None case appears on fulfilling a hashlock - if current_owners is None: - current_owners = [] - if not isinstance(current_owners, list): - current_owners = [current_owners] + if owners_before is None: + owners_before = [] + if not isinstance(owners_before, list): + owners_before = [owners_before] # The None case appears on assigning a hashlock - if new_owners is None: - new_owners = [] - if not isinstance(new_owners, list): - new_owners = [new_owners] + if owners_after is None: + owners_after = [] + if not isinstance(owners_after, list): + owners_after = [owners_after] if not isinstance(inputs, list): inputs = [inputs] @@ -235,7 +235,7 @@ def create_tx(current_owners, new_owners, inputs, operation, payload=None): if inputs: for fid, tx_input in enumerate(inputs): fulfillments.append({ - 'current_owners': current_owners, + 'owners_before': owners_before, 'input': tx_input, 'fulfillment': None, 'fid': fid @@ -243,7 +243,7 @@ def create_tx(current_owners, new_owners, inputs, operation, payload=None): # create else: fulfillments.append({ - 'current_owners': current_owners, + 'owners_before': owners_before, 'input': None, 'fulfillment': None, 'fid': 0 @@ -254,14 +254,14 @@ def create_tx(current_owners, new_owners, inputs, operation, payload=None): for fulfillment in fulfillments: # threshold condition - if len(new_owners) > 1: - condition = cc.ThresholdSha256Fulfillment(threshold=len(new_owners)) - for new_owner in new_owners: - condition.add_subfulfillment(cc.Ed25519Fulfillment(public_key=new_owner)) + if len(owners_after) > 1: + condition = cc.ThresholdSha256Fulfillment(threshold=len(owners_after)) + for owner_after in owners_after: + condition.add_subfulfillment(cc.Ed25519Fulfillment(public_key=owner_after)) # simple signature condition - elif len(new_owners) == 1: - condition = cc.Ed25519Fulfillment(public_key=new_owners[0]) + elif len(owners_after) == 1: + condition = cc.Ed25519Fulfillment(public_key=owners_after[0]) # to be added later (hashlock conditions) else: @@ -269,7 +269,7 @@ def create_tx(current_owners, new_owners, inputs, operation, payload=None): if condition: conditions.append({ - 'new_owners': new_owners, + 'owners_after': owners_after, 'condition': { 'details': condition.to_dict(), 'uri': condition.condition_uri @@ -301,7 +301,7 @@ def create_tx(current_owners, new_owners, inputs, operation, payload=None): def sign_tx(transaction, signing_keys, bigchain=None): """Sign a transaction - A transaction signed with the `current_owner` corresponding private key. + A transaction signed with the `owner_before` corresponding private key. Args: transaction (dict): transaction to sign. @@ -317,7 +317,7 @@ def sign_tx(transaction, signing_keys, bigchain=None): if not isinstance(signing_keys, list): signing_keys = [signing_keys] - # create a mapping between sk and vk so that we can match the private key to the current_owners + # create a mapping between sk and vk so that we can match the private key to the owners_before key_pairs = {} for sk in signing_keys: signing_key = crypto.SigningKey(sk) @@ -368,13 +368,13 @@ def fulfill_simple_signature_fulfillment(fulfillment, parsed_fulfillment, fulfil object: fulfilled cryptoconditions.Ed25519Fulfillment """ - current_owner = fulfillment['current_owners'][0] + owner_before = fulfillment['owners_before'][0] try: - parsed_fulfillment.sign(serialize(fulfillment_message), key_pairs[current_owner]) + parsed_fulfillment.sign(serialize(fulfillment_message), key_pairs[owner_before]) except KeyError: raise exceptions.KeypairMismatchException('Public key {} is not a pair to any of the private keys' - .format(current_owner)) + .format(owner_before)) return parsed_fulfillment @@ -395,17 +395,17 @@ def fulfill_threshold_signature_fulfillment(fulfillment, parsed_fulfillment, ful parsed_fulfillment_copy = copy.deepcopy(parsed_fulfillment) parsed_fulfillment.subconditions = [] - for current_owner in fulfillment['current_owners']: + for owner_before in fulfillment['owners_before']: try: - subfulfillment = parsed_fulfillment_copy.get_subcondition_from_vk(current_owner)[0] + subfulfillment = parsed_fulfillment_copy.get_subcondition_from_vk(owner_before)[0] except IndexError: raise exceptions.KeypairMismatchException( - 'Public key {} cannot be found in the fulfillment'.format(current_owner)) + 'Public key {} cannot be found in the fulfillment'.format(owner_before)) try: - private_key = key_pairs[current_owner] + private_key = key_pairs[owner_before] except KeyError: raise exceptions.KeypairMismatchException( - 'Public key {} is not a pair to any of the private keys'.format(current_owner)) + 'Public key {} is not a pair to any of the private keys'.format(owner_before)) subfulfillment.sign(serialize(fulfillment_message), private_key) parsed_fulfillment.add_subfulfillment(subfulfillment) @@ -413,8 +413,8 @@ def fulfill_threshold_signature_fulfillment(fulfillment, parsed_fulfillment, ful return parsed_fulfillment -def create_and_sign_tx(private_key, current_owner, new_owner, tx_input, operation='TRANSFER', payload=None): - tx = create_tx(current_owner, new_owner, tx_input, operation, payload) +def create_and_sign_tx(private_key, owner_before, owner_after, tx_input, operation='TRANSFER', payload=None): + tx = create_tx(owner_before, owner_after, tx_input, operation, payload) return sign_tx(tx, private_key) @@ -432,7 +432,7 @@ def check_hash_and_signature(transaction): def validate_fulfillments(signed_transaction): """Verify the signature of a transaction - A valid transaction should have been signed `current_owner` corresponding private key. + A valid transaction should have been signed `owner_before` corresponding private key. Args: signed_transaction (dict): a transaction with the `signature` included. @@ -516,8 +516,8 @@ def get_input_condition(bigchain, fulfillment): # if `CREATE` transaction # there is no previous transaction so we need to create one on the fly else: - current_owner = fulfillment['current_owners'][0] - condition = cc.Ed25519Fulfillment(public_key=current_owner) + owner_before = fulfillment['owners_before'][0] + condition = cc.Ed25519Fulfillment(public_key=owner_before) return { 'condition': { @@ -581,7 +581,7 @@ def get_hash_data(transaction): def verify_vote_signature(block, signed_vote): """Verify the signature of a vote - A valid vote should have been signed `current_owner` corresponding private key. + A valid vote should have been signed `owner_before` corresponding private key. Args: block (dict): block under election @@ -612,7 +612,7 @@ def transform_create(tx): payload = None if transaction['data'] and 'payload' in transaction['data']: payload = transaction['data']['payload'] - new_tx = create_tx(b.me, transaction['fulfillments'][0]['current_owners'], None, 'CREATE', payload=payload) + new_tx = create_tx(b.me, transaction['fulfillments'][0]['owners_before'], None, 'CREATE', payload=payload) return new_tx diff --git a/docs/source/drivers-clients/http-client-server-api.rst b/docs/source/drivers-clients/http-client-server-api.rst index 1da816ae..27216ea2 100644 --- a/docs/source/drivers-clients/http-client-server-api.rst +++ b/docs/source/drivers-clients/http-client-server-api.rst @@ -52,7 +52,7 @@ The HTTP API currently exposes two endpoints, one to get information about a spe }, "uri":"cc:4:20:sVA_3p8gvl8yRFNTomqm6MaavKewka6dGYcFAuPrRXQ:96" }, - "new_owners":[ + "owners_after":[ "CwA8s2QYQBfNz4WvjEwmJi83zYr7JhxRhidx6uZ5KBVd" ] } @@ -63,7 +63,7 @@ The HTTP API currently exposes two endpoints, one to get information about a spe }, "fulfillments":[ { - "current_owners":[ + "owners_before":[ "JEAkEJqLbbgDRAtMm8YAjGp759Aq2qTn9eaEHUj2XePE" ], "fid":0, @@ -113,7 +113,7 @@ The HTTP API currently exposes two endpoints, one to get information about a spe }, "uri":"cc:4:20:sVA_3p8gvl8yRFNTomqm6MaavKewka6dGYcFAuPrRXQ:96" }, - "new_owners":[ + "owners_after":[ "CwA8s2QYQBfNz4WvjEwmJi83zYr7JhxRhidx6uZ5KBVd" ] } @@ -124,7 +124,7 @@ The HTTP API currently exposes two endpoints, one to get information about a spe }, "fulfillments":[ { - "current_owners":[ + "owners_before":[ "JEAkEJqLbbgDRAtMm8YAjGp759Aq2qTn9eaEHUj2XePE" ], "fid":0, @@ -165,7 +165,7 @@ The HTTP API currently exposes two endpoints, one to get information about a spe }, "uri":"cc:4:20:sVA_3p8gvl8yRFNTomqm6MaavKewka6dGYcFAuPrRXQ:96" }, - "new_owners":[ + "owners_after":[ "CwA8s2QYQBfNz4WvjEwmJi83zYr7JhxRhidx6uZ5KBVd" ] } @@ -176,7 +176,7 @@ The HTTP API currently exposes two endpoints, one to get information about a spe }, "fulfillments":[ { - "current_owners":[ + "owners_before":[ "JEAkEJqLbbgDRAtMm8YAjGp759Aq2qTn9eaEHUj2XePE" ], "fid":0, diff --git a/docs/source/drivers-clients/python-driver-api-examples.md b/docs/source/drivers-clients/python-driver-api-examples.md index 6e66b346..817df4c2 100644 --- a/docs/source/drivers-clients/python-driver-api-examples.md +++ b/docs/source/drivers-clients/python-driver-api-examples.md @@ -19,9 +19,9 @@ Out[5]: 'type': 'fulfillment', 'type_id': 4}, 'uri': 'cc:4:20:eoUROTxUArrpXGVBrvrYqkcEGG8lB_leliNvSvSddDg:96'}, - 'new_owners': ['9FGRd2jLxmwtRkwsWTpEoqy1rZpg6ycuT7NwmCR4QVk3']}], + 'owners_after': ['9FGRd2jLxmwtRkwsWTpEoqy1rZpg6ycuT7NwmCR4QVk3']}], 'data': {'payload': None, 'uuid': 'b4884e37-3c8e-4cc2-bfc8-68a05ed090ad'}, - 'fulfillments': [{'current_owners': ['3NsvDXiiuf2BRPnqfRuBM9yHNjsH4L33gcZ4rh4GMY2J'], + 'fulfillments': [{'owners_before': ['3NsvDXiiuf2BRPnqfRuBM9yHNjsH4L33gcZ4rh4GMY2J'], 'fid': 0, 'fulfillment': 'cf:4:I1IkuhCSf_hGqJ-JKHTQIO1g4apbQuaZXNMEX4isyxd7azkJreyGKyaMLs6Xk9kxQClwz1nQiKM6OMRk7fdusN0373szGbq-PppnsjY6ilbx1JmP-IH7hdjjwjjx9coM', 'input': None}], @@ -40,9 +40,9 @@ Out[6]: 'type': 'fulfillment', 'type_id': 4}, 'uri': 'cc:4:20:akjKWxLO2hbe6RVva_FsWNDJmnUKYjQ57HIhUQbwb2Q:96'}, - 'new_owners': ['89tbMBospYsTNDgpqFS4RLszNsxuE4JEumNuY3WTAnT5']}], + 'owners_after': ['89tbMBospYsTNDgpqFS4RLszNsxuE4JEumNuY3WTAnT5']}], 'data': {'payload': None, 'uuid': 'a640a9d6-9384-4e9c-a130-e899ea6416aa'}, - 'fulfillments': [{'current_owners': ['9FGRd2jLxmwtRkwsWTpEoqy1rZpg6ycuT7NwmCR4QVk3'], + 'fulfillments': [{'owners_before': ['9FGRd2jLxmwtRkwsWTpEoqy1rZpg6ycuT7NwmCR4QVk3'], 'fid': 0, 'fulfillment': 'cf:4:eoUROTxUArrpXGVBrvrYqkcEGG8lB_leliNvSvSddDgVmY6O7YTER04mWjAVd6m0qOv5R44Cxpv_65OtLnNUD-HEgD-9z3ys4GvPf7BZF5dKSbAs_3a8yCQM0bkCcqkB', 'input': {'cid': 0, diff --git a/docs/source/drivers-clients/python-server-api-examples.md b/docs/source/drivers-clients/python-server-api-examples.md index 68a8f99e..62231e0c 100644 --- a/docs/source/drivers-clients/python-server-api-examples.md +++ b/docs/source/drivers-clients/python-server-api-examples.md @@ -87,7 +87,7 @@ tx_retrieved }, "uri":"cc:4:20:oqXTWvR3afHHX8OaOO84kZxS6nH4GEBXD4Vw8Mc5iBo:96" }, - "new_owners":[ + "owners_after":[ "BwuhqQX8FPsmqYiRV2CSZYWWsSWgSSQQFHjqxKEuqkPs" ] } @@ -100,7 +100,7 @@ tx_retrieved }, "fulfillments":[ { - "current_owners":[ + "owners_before":[ "3LQ5dTiddXymDhNzETB1rEkp4mA7fEV1Qeiu5ghHiJm9" ], "fid":0, @@ -182,7 +182,7 @@ tx_transfer_retrieved }, "uri":"cc:4:20:DIfyalZvV_9ukoO01mxmK3nxsfAWSKYYF33XDYkbY4E:96" }, - "new_owners":[ + "owners_after":[ "qv8DvdNG5nZHWCP5aPSqgqxAvaPJpQj19abRvFCntor" ] } @@ -190,7 +190,7 @@ tx_transfer_retrieved "data":None, "fulfillments":[ { - "current_owners":[ + "owners_before":[ "BwuhqQX8FPsmqYiRV2CSZYWWsSWgSSQQFHjqxKEuqkPs" ], "fid":0, @@ -231,7 +231,7 @@ DoubleSpend: input `{'cid': 0, 'txid': '933cd83a419d2735822a2154c84176a2f419cbd4 ## Multiple Owners -To create a new digital asset with _multiple_ owners, one can simply provide a list of `new_owners`: +To create a new digital asset with _multiple_ owners, one can simply provide a list of `owners_after`: ```python # Create a new asset and assign it to multiple owners @@ -282,7 +282,7 @@ tx_multisig_retrieved }, "uri":"cc:2:29:DpflJzUSlnTUBx8lD8QUolOA-M9nQnrGwvWSk7f3REc:206" }, - "new_owners":[ + "owners_after":[ "BwuhqQX8FPsmqYiRV2CSZYWWsSWgSSQQFHjqxKEuqkPs", "qv8DvdNG5nZHWCP5aPSqgqxAvaPJpQj19abRvFCntor" ] @@ -291,7 +291,7 @@ tx_multisig_retrieved "data":None, "fulfillments":[ { - "current_owners":[ + "owners_before":[ "3LQ5dTiddXymDhNzETB1rEkp4mA7fEV1Qeiu5ghHiJm9" ], "fid":0, @@ -306,7 +306,7 @@ tx_multisig_retrieved } ``` -The asset can be transfered as soon as each of the `new_owners` signs the transaction. +The asset can be transfered as soon as each of the `owners_after` signs the transaction. To do so, simply provide a list of all private keys to the signing routine: @@ -348,7 +348,7 @@ tx_multisig_transfer_retrieved }, "uri":"cc:4:20:cAq6JQJXtwlxURqrksiyqLThB9zh08ZxSPLTDSaReYE:96" }, - "new_owners":[ + "owners_after":[ "8YN9fALMj9CkeCcmTiM2kxwurpkMzHg9RkwSLJKMasvG" ] } @@ -356,7 +356,7 @@ tx_multisig_transfer_retrieved "data":None, "fulfillments":[ { - "current_owners":[ + "owners_before":[ "BwuhqQX8FPsmqYiRV2CSZYWWsSWgSSQQFHjqxKEuqkPs", "qv8DvdNG5nZHWCP5aPSqgqxAvaPJpQj19abRvFCntor" ], @@ -427,7 +427,7 @@ tx_mimo_retrieved }, "uri":"cc:4:20:2AXg2JJ7mQ8o2Q9-hafP-XmFh3YR7I2_Sz55AubfxIc:96" }, - "new_owners":[ + "owners_after":[ "qv8DvdNG5nZHWCP5aPSqgqxAvaPJpQj19abRvFCntor" ] }, @@ -443,7 +443,7 @@ tx_mimo_retrieved }, "uri":"cc:4:20:2AXg2JJ7mQ8o2Q9-hafP-XmFh3YR7I2_Sz55AubfxIc:96" }, - "new_owners":[ + "owners_after":[ "qv8DvdNG5nZHWCP5aPSqgqxAvaPJpQj19abRvFCntor" ] }, @@ -459,7 +459,7 @@ tx_mimo_retrieved }, "uri":"cc:4:20:2AXg2JJ7mQ8o2Q9-hafP-XmFh3YR7I2_Sz55AubfxIc:96" }, - "new_owners":[ + "owners_after":[ "qv8DvdNG5nZHWCP5aPSqgqxAvaPJpQj19abRvFCntor" ] } @@ -467,7 +467,7 @@ tx_mimo_retrieved "data":None, "fulfillments":[ { - "current_owners":[ + "owners_before":[ "BwuhqQX8FPsmqYiRV2CSZYWWsSWgSSQQFHjqxKEuqkPs" ], "fid":0, @@ -478,7 +478,7 @@ tx_mimo_retrieved } }, { - "current_owners":[ + "owners_before":[ "BwuhqQX8FPsmqYiRV2CSZYWWsSWgSSQQFHjqxKEuqkPs" ], "fid":1, @@ -489,7 +489,7 @@ tx_mimo_retrieved } }, { - "current_owners":[ + "owners_before":[ "BwuhqQX8FPsmqYiRV2CSZYWWsSWgSSQQFHjqxKEuqkPs" ], "fid":2, @@ -529,11 +529,11 @@ Setting up a generic threshold condition is a bit more elaborate than regular tr The basic workflow for creating a more complex cryptocondition is the following: -1. Create a transaction template that include the public key of all (nested) parties as `new_owners` +1. Create a transaction template that include the public key of all (nested) parties as `owners_after` 2. Set up the threshold condition using the [cryptocondition library](https://github.com/bigchaindb/cryptoconditions) 3. Update the condition and hash in the transaction template -We'll illustrate this by a threshold condition where 2 out of 3 `new_owners` need to sign the transaction: +We'll illustrate this by a threshold condition where 2 out of 3 `owners_after` need to sign the transaction: ```python import copy @@ -620,7 +620,7 @@ tx_threshold_retrieved }, "uri":"cc:2:29:FoElId4TE5TU2loonT7sayXhxwcmaJVoCeIduh56Dxw:246" }, - "new_owners":[ + "owners_after":[ "8NaGq26YMcEvj8Sc5MnqspKzFTQd1eZBAuuPDw4ERHpz", "ALE9Agojob28D1fHWCxFXJwpqrYPkcsUs26YksBVj27z", "Cx4jWSGci7fw6z5QyeApCijbwnMpyuhp4C1kzuFc3XrM" @@ -630,7 +630,7 @@ tx_threshold_retrieved "data":None, "fulfillments":[ { - "current_owners":[ + "owners_before":[ "qv8DvdNG5nZHWCP5aPSqgqxAvaPJpQj19abRvFCntor" ], "fid":0, @@ -652,7 +652,7 @@ The transaction can now be transfered by fulfilling the threshold condition. The fulfillment involves: -1. Create a transaction template that include the public key of all (nested) parties as `current_owners` +1. Create a transaction template that include the public key of all (nested) parties as `owners_before` 2. Parsing the threshold condition into a fulfillment using the [cryptocondition library](https://github.com/bigchaindb/cryptoconditions) 3. Signing all necessary subfulfillments and updating the fulfillment field in the transaction @@ -721,7 +721,7 @@ threshold_tx_transfer }, "uri":"cc:4:20:xDz3NhRG-3eVzIB9sgnd99LKjOyDF-KlxWuf1TgNT0s:96" }, - "new_owners":[ + "owners_after":[ "ED2pyPfsbNRTHkdMnaFkAwCSpZWRmbaM1h8fYzgRRMmc" ] } @@ -729,7 +729,7 @@ threshold_tx_transfer "data":None, "fulfillments":[ { - "current_owners":[ + "owners_before":[ "8NaGq26YMcEvj8Sc5MnqspKzFTQd1eZBAuuPDw4ERHpz", "ALE9Agojob28D1fHWCxFXJwpqrYPkcsUs26YksBVj27z", "Cx4jWSGci7fw6z5QyeApCijbwnMpyuhp4C1kzuFc3XrM" @@ -758,10 +758,10 @@ Under the hood, fulfilling a hash-lock condition amounts to finding a string (a One possible use case is to distribute preimages as "digital vouchers." The first person to redeem a voucher will get the associated asset. -A federation node can create an asset with a hash-lock condition and no `new_owners`. Anyone who can fullfill the hash-lock condition can transfer the asset to themselves. +A federation node can create an asset with a hash-lock condition and no `owners_after`. Anyone who can fullfill the hash-lock condition can transfer the asset to themselves. ```python -# Create a hash-locked asset without any new_owners +# Create a hash-locked asset without any owners_after hashlock_tx = b.create_transaction(b.me, None, None, 'CREATE') # Define a secret that will be hashed - fulfillments need to guess the secret @@ -774,13 +774,13 @@ hashlock_tx['transaction']['conditions'].append({ 'uri': first_tx_condition.condition.serialize_uri() }, 'cid': 0, - 'new_owners': None + 'owners_after': None }) # Conditions have been updated, so the hash needs updating hashlock_tx['id'] = util.get_hash_data(hashlock_tx) -# The asset needs to be signed by the current_owner +# The asset needs to be signed by the owner_before hashlock_tx_signed = b.sign_transaction(hashlock_tx, b.me_private) # Some validations @@ -800,13 +800,13 @@ hashlock_tx_signed "condition":{ "uri":"cc:0:3:nsW2IiYgk9EUtsg4uBe3pBnOgRoAEX2IIsPgjqZz47U:17" }, - "new_owners":None + "owners_after":None } ], "data":None, "fulfillments":[ { - "current_owners":[ + "owners_before":[ "FmLm6MxCABc8TsiZKdeYaZKo5yZWMM6Vty7Q1B6EgcP2" ], "fid":0, @@ -864,7 +864,7 @@ hashlock_fulfill_tx }, "uri":"cc:4:20:y9884Md2YI_wdnGSTJGhwvFaNsKLe8sqwimqk-2JLSI:96" }, - "new_owners":[ + "owners_after":[ "EiqCKxnBCmmNb83qyGch48tULK9RLaEt4xFA43UVCVDb" ] } @@ -872,7 +872,7 @@ hashlock_fulfill_tx "data":None, "fulfillments":[ { - "current_owners":[], + "owners_before":[], "fid":0, "fulfillment":"cf:0:bXVjaCBzZWNyZXQhIHdvdyE", "input":{ @@ -901,7 +901,7 @@ __Note__: The timeout conditions are BigchainDB-specific and not (yet) supported __Caveat__: The times between nodes in a BigchainDB federation may (and will) differ slightly. In this case, the majority of the nodes will decide. ```python -# Create a timeout asset without any new_owners +# Create a timeout asset without any owners_after tx_timeout = b.create_transaction(b.me, None, None, 'CREATE') # Set expiry time - the asset needs to be transfered before expiration @@ -916,13 +916,13 @@ tx_timeout['transaction']['conditions'].append({ 'uri': condition_timeout.condition.serialize_uri() }, 'cid': 0, - 'new_owners': None + 'owners_after': None }) # Conditions have been updated, so the hash needs updating tx_timeout['id'] = util.get_hash_data(tx_timeout) -# The asset needs to be signed by the current_owner +# The asset needs to be signed by the owner_before tx_timeout_signed = b.sign_transaction(tx_timeout, b.me_private) # Some validations @@ -948,13 +948,13 @@ tx_timeout_signed }, "uri":"cc:63:9:sceU_NZc3cAjAvaR1TVmgj7am5y8hJEBoqLm-tbqGbQ:17" }, - "new_owners":null + "owners_after":null } ], "data":null, "fulfillments":[ { - "current_owners":[ + "owners_before":[ "FmLm6MxCABc8TsiZKdeYaZKo5yZWMM6Vty7Q1B6EgcP2" ], "fid":0, @@ -1086,7 +1086,7 @@ tx_escrow['transaction']['conditions'][0]['condition'] = { # Conditions have been updated, so the hash needs updating tx_escrow['id'] = util.get_hash_data(tx_escrow) -# The asset needs to be signed by the current_owner +# The asset needs to be signed by the owner_before tx_escrow_signed = b.sign_transaction(tx_escrow, testuser2_priv) # Some validations @@ -1171,7 +1171,7 @@ tx_escrow_signed }, "uri":"cc:2:29:sg08ERtppQrGxot7mu7XMdNkZTc29xCbWE1r8DgxuL8:181" }, - "new_owners":[ + "owners_after":[ "BwuhqQX8FPsmqYiRV2CSZYWWsSWgSSQQFHjqxKEuqkPs", "qv8DvdNG5nZHWCP5aPSqgqxAvaPJpQj19abRvFCntor" ] @@ -1180,7 +1180,7 @@ tx_escrow_signed "data":null, "fulfillments":[ { - "current_owners":[ + "owners_before":[ "qv8DvdNG5nZHWCP5aPSqgqxAvaPJpQj19abRvFCntor" ], "fid":0, diff --git a/docs/source/topic-guides/models.md b/docs/source/topic-guides/models.md index 8e0add9d..fd6b20a3 100644 --- a/docs/source/topic-guides/models.md +++ b/docs/source/topic-guides/models.md @@ -120,7 +120,7 @@ When one creates a condition, one can calculate its fulfillment length (e.g. 96) If someone tries to make a condition where the output of a threshold condition feeds into the input of another “earlier” threshold condition (i.e. in a closed logical circuit), then their computer will take forever to calculate the (infinite) “condition URI”, at least in theory. In practice, their computer will run out of memory or their client software will timeout after a while. -Aside: In what follows, the list of `new_owners` (in a condition) is always who owned the asset at the time the transaction completed, but before the next transaction started. The list of `current_owners` (in a fulfillment) is always equal to the list of `new_owners` in that asset's previous transaction. +Aside: In what follows, the list of `owners_after` (in a condition) is always who owned the asset at the time the transaction completed, but before the next transaction started. The list of `owners_before` (in a fulfillment) is always equal to the list of `owners_after` in that asset's previous transaction. ### Conditions @@ -141,17 +141,17 @@ If there is only one _new owner_, the condition will be a simple signature condi }, "uri": "" }, - "new_owners": [""] + "owners_after": [""] } ``` - **Condition header**: - `cid`: Condition index so that we can reference this output as an input to another transaction. It also matches the input `fid`, making this the condition to fulfill in order to spend the asset used as input with `fid`. - - `new_owners`: A list containing one item: the public key of the new owner. + - `owners_after`: A list containing one item: the public key of the new owner. - **Condition body**: - `bitmask`: A set of bits representing the features required by the condition type. - - `public_key`: The _new_owner's_ public key. + - `public_key`: The new owner's public key. - `type_id`: The fulfillment type ID; see the [ILP spec](https://interledger.org/five-bells-condition/spec.html). - `uri`: Binary representation of the condition using only URL-safe characters. @@ -189,9 +189,9 @@ to spend the asset. For example: "type_id": 2 }, "uri": "cc:2:29:ytNK3X6-bZsbF-nCGDTuopUIMi1HCyCkyPewm6oLI3o:206"}, - "new_owners": [ - "", - "" + "owners_after": [ + "owner 1 public key>", + "owner 2 public key>" ] } ``` @@ -210,7 +210,7 @@ If there is only one _current owner_, the fulfillment will be a simple signature ```json { - "current_owners": [""], + "owners_before": [""], "fid": 0, "fulfillment": "cf:4:RxFzIE679tFBk8zwEgizhmTuciAylvTUwy6EL6ehddHFJOhK5F4IjwQ1xLu2oQK9iyRCZJdfWAefZVjTt3DeG5j2exqxpGliOPYseNkRAWEakqJ_UrCwgnj92dnFRAEE", "input": { @@ -222,7 +222,7 @@ If there is only one _current owner_, the fulfillment will be a simple signature - `fid`: Fulfillment index. It matches a `cid` in the conditions with a new _crypto-condition_ that the new owner needs to fulfill to spend this asset. -- `current_owners`: A list of public keys of the current owners; in this case it has just one public key. +- `owners_before`: A list of public keys of the owners before the transaction; in this case it has just one public key. - `fulfillment`: A crypto-conditions URI that encodes the cryptographic fulfillments like signatures and others, see [crypto-conditions](https://interledger.org/five-bells-condition/spec.html). - `input`: Pointer to the asset and condition of a previous transaction - `cid`: Condition index diff --git a/tests/db/test_bigchain_api.py b/tests/db/test_bigchain_api.py index 76f07ee1..b00828e8 100644 --- a/tests/db/test_bigchain_api.py +++ b/tests/db/test_bigchain_api.py @@ -422,7 +422,7 @@ class TestTransactionValidation(object): with pytest.raises(exceptions.InvalidSignature) as excinfo: b.validate_transaction(tx) - # assert excinfo.value.args[0] == 'current_owner `a` does not own the input `{}`'.format(valid_input) + # assert excinfo.value.args[0] == 'owner_before `a` does not own the input `{}`'.format(valid_input) assert b.is_valid_transaction(tx) is False @pytest.mark.usefixtures('inputs') @@ -550,7 +550,7 @@ class TestBlockValidation(object): with pytest.raises(exceptions.TransactionOwnerError) as excinfo: b.validate_block(block) - assert excinfo.value.args[0] == 'current_owner `a` does not own the input `{}`'.format(valid_input) + assert excinfo.value.args[0] == 'owner_before `a` does not own the input `{}`'.format(valid_input) def test_invalid_block_id(self, b): block = dummy_block() @@ -689,7 +689,7 @@ class TestMultipleInputs(object): assert len(tx_signed['transaction']['fulfillments']) == 1 assert len(tx_signed['transaction']['conditions']) == 1 - def test_single_current_owner_multiple_new_owners_single_input(self, b, user_sk, user_vk, inputs): + def test_single_owner_before_multiple_owners_after_single_input(self, b, user_sk, user_vk, inputs): # create a new users user2_sk, user2_vk = crypto.generate_key_pair() user3_sk, user3_vk = crypto.generate_key_pair() @@ -707,7 +707,7 @@ class TestMultipleInputs(object): assert len(tx_signed['transaction']['fulfillments']) == 1 assert len(tx_signed['transaction']['conditions']) == 1 - def test_single_current_owner_multiple_new_owners_multiple_inputs(self, b, user_sk, user_vk): + def test_single_owner_before_multiple_owners_after_multiple_inputs(self, b, user_sk, user_vk): # create a new users user2_sk, user2_vk = crypto.generate_key_pair() user3_sk, user3_vk = crypto.generate_key_pair() @@ -735,7 +735,7 @@ class TestMultipleInputs(object): assert len(tx_signed['transaction']['fulfillments']) == 3 assert len(tx_signed['transaction']['conditions']) == 3 - def test_multiple_current_owners_single_new_owner_single_input(self, b, user_sk, user_vk): + def test_multiple_owners_before_single_owner_after_single_input(self, b, user_sk, user_vk): # create a new users user2_sk, user2_vk = crypto.generate_key_pair() user3_sk, user3_vk = crypto.generate_key_pair() @@ -759,7 +759,7 @@ class TestMultipleInputs(object): assert len(tx_signed['transaction']['fulfillments']) == 1 assert len(tx_signed['transaction']['conditions']) == 1 - def test_multiple_current_owners_single_new_owner_multiple_inputs(self, b, user_sk, user_vk): + def test_multiple_owners_before_single_owner_after_multiple_inputs(self, b, user_sk, user_vk): # create a new users user2_sk, user2_vk = crypto.generate_key_pair() user3_sk, user3_vk = crypto.generate_key_pair() @@ -786,7 +786,7 @@ class TestMultipleInputs(object): assert len(tx_signed['transaction']['fulfillments']) == 3 assert len(tx_signed['transaction']['conditions']) == 3 - def test_multiple_current_owners_multiple_new_owners_single_input(self, b, user_sk, user_vk): + def test_multiple_owners_before_multiple_owners_after_single_input(self, b, user_sk, user_vk): # create a new users user2_sk, user2_vk = crypto.generate_key_pair() user3_sk, user3_vk = crypto.generate_key_pair() @@ -811,7 +811,7 @@ class TestMultipleInputs(object): assert len(tx_signed['transaction']['fulfillments']) == 1 assert len(tx_signed['transaction']['conditions']) == 1 - def test_multiple_current_owners_multiple_new_owners_multiple_inputs(self, b, user_sk, user_vk): + def test_multiple_owners_before_multiple_owners_after_multiple_inputs(self, b, user_sk, user_vk): # create a new users user2_sk, user2_vk = crypto.generate_key_pair() user3_sk, user3_vk = crypto.generate_key_pair() @@ -1121,7 +1121,7 @@ class TestFulfillmentMessage(object): assert fulfillment_message['data']['payload'] == tx['transaction']['data']['payload'] assert fulfillment_message['id'] == tx['id'] assert fulfillment_message['condition'] == tx['transaction']['conditions'][0] - assert fulfillment_message['fulfillment']['current_owners'] == original_fulfillment['current_owners'] + assert fulfillment_message['fulfillment']['owners_before'] == original_fulfillment['owners_before'] assert fulfillment_message['fulfillment']['fid'] == original_fulfillment['fid'] assert fulfillment_message['fulfillment']['input'] == original_fulfillment['input'] assert fulfillment_message['operation'] == tx['transaction']['operation'] @@ -1144,14 +1144,14 @@ class TestFulfillmentMessage(object): assert fulfillment_message['data']['payload'] == tx['transaction']['data']['payload'] assert fulfillment_message['id'] == tx['id'] assert fulfillment_message['condition'] == tx['transaction']['conditions'][0] - assert fulfillment_message['fulfillment']['current_owners'] == original_fulfillment['current_owners'] + assert fulfillment_message['fulfillment']['owners_before'] == original_fulfillment['owners_before'] assert fulfillment_message['fulfillment']['fid'] == original_fulfillment['fid'] 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['transaction']['version'] - def test_fulfillment_message_multiple_current_owners_multiple_new_owners_multiple_inputs(self, b, user_vk): + def test_fulfillment_message_multiple_owners_before_multiple_owners_after_multiple_inputs(self, b, user_vk): # create a new users user2_sk, user2_vk = crypto.generate_key_pair() user3_sk, user3_vk = crypto.generate_key_pair() @@ -1182,7 +1182,7 @@ class TestFulfillmentMessage(object): assert fulfillment_message['data']['payload'] == tx['transaction']['data']['payload'] assert fulfillment_message['id'] == tx['id'] assert fulfillment_message['condition'] == tx['transaction']['conditions'][original_fulfillment['fid']] - assert fulfillment_message['fulfillment']['current_owners'] == original_fulfillment['current_owners'] + assert fulfillment_message['fulfillment']['owners_before'] == original_fulfillment['owners_before'] assert fulfillment_message['fulfillment']['fid'] == original_fulfillment['fid'] assert fulfillment_message['fulfillment']['input'] == original_fulfillment['input'] assert fulfillment_message['operation'] == tx['transaction']['operation'] @@ -1235,7 +1235,7 @@ class TestTransactionMalleability(object): tx_changed = copy.deepcopy(tx_signed) tx_changed['transaction']['fulfillments'] = [ { - "current_owners": [ + "owners_before": [ "AFbofwJYEB7Cx2fgrPrCJzbdDVRzRKysoGXt4DsvuTGN" ], "fid": 0, @@ -1253,7 +1253,7 @@ class TestTransactionMalleability(object): assert b.is_valid_transaction(tx_changed) is False tx_changed = copy.deepcopy(tx_signed) - tx_changed['transaction']['fulfillments'][0]['current_owners'] = [ + tx_changed['transaction']['fulfillments'][0]['owners_before'] = [ "AFbofwJYEB7Cx2fgrPrCJzbdDVRzRKysoGXt4DsvuTGN"] assert b.validate_fulfillments(tx_changed) is False assert b.is_valid_transaction(tx_changed) is False @@ -1282,7 +1282,7 @@ class TestCryptoconditions(object): fulfillment = tx_signed['transaction']['fulfillments'][0] fulfillment_from_uri = cc.Fulfillment.from_uri(fulfillment['fulfillment']) - assert fulfillment['current_owners'][0] == b.me + assert fulfillment['owners_before'][0] == b.me assert fulfillment_from_uri.public_key.to_ascii().decode() == b.me assert b.validate_fulfillments(tx_signed) == True assert b.is_valid_transaction(tx_signed) == tx_signed @@ -1313,7 +1313,7 @@ class TestCryptoconditions(object): fulfillment = tx_signed['transaction']['fulfillments'][0] fulfillment_from_uri = cc.Fulfillment.from_uri(fulfillment['fulfillment']) - assert fulfillment['current_owners'][0] == user_vk + assert fulfillment['owners_before'][0] == user_vk assert fulfillment_from_uri.public_key.to_ascii().decode() == user_vk assert fulfillment_from_uri.condition.serialize_uri() == prev_condition['uri'] assert b.validate_fulfillments(tx_signed) == True @@ -1332,7 +1332,7 @@ class TestCryptoconditions(object): fulfillment = tx_signed['transaction']['fulfillments'][0] fulfillment_from_uri = cc.Fulfillment.from_uri(fulfillment['fulfillment']) - assert fulfillment['current_owners'][0] == b.me + assert fulfillment['owners_before'][0] == b.me assert fulfillment_from_uri.public_key.to_ascii().decode() == b.me assert b.validate_fulfillments(tx_signed) == True assert b.is_valid_transaction(tx_signed) == tx_signed @@ -1354,7 +1354,7 @@ class TestCryptoconditions(object): fulfillment = tx_signed['transaction']['fulfillments'][0] fulfillment_from_uri = cc.Fulfillment.from_uri(fulfillment['fulfillment']) - assert fulfillment['current_owners'][0] == user_vk + assert fulfillment['owners_before'][0] == user_vk assert fulfillment_from_uri.public_key.to_ascii().decode() == user_vk assert b.validate_fulfillments(tx_signed) == True assert b.is_valid_transaction(tx_signed) == tx_signed @@ -1593,7 +1593,7 @@ class TestCryptoconditions(object): def test_default_threshold_conditions_for_multiple_owners(self, b, user_sk, user_vk): user2_sk, user2_vk = crypto.generate_key_pair() - # create transaction with multiple new_owners + # create transaction with multiple owners_after tx = b.create_transaction(b.me, [user_vk, user2_vk], None, 'CREATE') assert len(tx['transaction']['conditions']) == 1 @@ -1613,7 +1613,7 @@ class TestCryptoconditions(object): def test_default_threshold_fulfillments_for_multiple_owners(self, b, user_sk, user_vk): user2_sk, user2_vk = crypto.generate_key_pair() - # create transaction with multiple new_owners + # create transaction with multiple owners_after tx_create = b.create_transaction(b.me, [user_vk, user2_vk], None, 'CREATE') tx_create_signed = b.sign_transaction(tx_create, b.me_private) block = b.create_block([tx_create_signed]) @@ -1654,7 +1654,7 @@ class TestCryptoconditions(object): 'uri': first_tx_condition.condition.serialize_uri() }, 'cid': 0, - 'new_owners': None + 'owners_after': None }) # conditions have been updated, so hash needs updating hashlock_tx['id'] = util.get_hash_data(hashlock_tx) @@ -1686,7 +1686,7 @@ class TestCryptoconditions(object): 'uri': first_tx_condition.condition.serialize_uri() }, 'cid': 0, - 'new_owners': None + 'owners_after': None }) # conditions have been updated, so hash needs updating hashlock_tx['id'] = util.get_hash_data(hashlock_tx) @@ -1717,7 +1717,7 @@ class TestCryptoconditions(object): 'uri': first_tx_condition.condition.serialize_uri() }, 'cid': 0, - 'new_owners': None + 'owners_after': None }) # conditions have been updated, so hash needs updating hashlock_tx['id'] = util.get_hash_data(hashlock_tx) @@ -1779,15 +1779,15 @@ class TestCryptoconditions(object): user3_sk, user3_vk = crypto.generate_key_pair() user4_sk, user4_vk = crypto.generate_key_pair() user5_sk, user5_vk = crypto.generate_key_pair() - new_owners = [user_vk, user2_vk, user3_vk, user4_vk, user5_vk] + owners_after = [user_vk, user2_vk, user3_vk, user4_vk, user5_vk] - # create a transaction with multiple new_owners - tx = b.create_transaction(b.me, new_owners, None, 'CREATE') + # create a transaction with multiple owners_after + tx = b.create_transaction(b.me, owners_after, None, 'CREATE') condition = cc.Fulfillment.from_dict(tx['transaction']['conditions'][0]['condition']['details']) - for new_owner in new_owners: - subcondition = condition.get_subcondition_from_vk(new_owner)[0] - assert subcondition.public_key.to_ascii().decode() == new_owner + for owner_after in owners_after: + subcondition = condition.get_subcondition_from_vk(owner_after)[0] + assert subcondition.public_key.to_ascii().decode() == owner_after @pytest.mark.usefixtures('inputs') def test_transfer_asset_with_escrow_condition(self, b, user_vk, user_sk): diff --git a/tests/doc/run_doc_python_server_api_examples.py b/tests/doc/run_doc_python_server_api_examples.py index 8c92916a..63bd899e 100644 --- a/tests/doc/run_doc_python_server_api_examples.py +++ b/tests/doc/run_doc_python_server_api_examples.py @@ -252,7 +252,7 @@ print(json.dumps(threshold_tx_transfer, sort_keys=True, indent=4, separators=(', Hashlocked Conditions """ -# Create a hash-locked asset without any new_owners +# Create a hash-locked asset without any owners_after hashlock_tx = b.create_transaction(b.me, None, None, 'CREATE') # Define a secret that will be hashed - fulfillments need to guess the secret @@ -265,13 +265,13 @@ hashlock_tx['transaction']['conditions'].append({ 'uri': first_tx_condition.condition.serialize_uri() }, 'cid': 0, - 'new_owners': None + 'owners_after': None }) # Conditions have been updated, so hash needs updating hashlock_tx['id'] = util.get_hash_data(hashlock_tx) -# The asset needs to be signed by the current_owner +# The asset needs to be signed by the owner_before hashlock_tx_signed = b.sign_transaction(hashlock_tx, b.me_private) # Some validations @@ -327,7 +327,7 @@ tx_timeout['transaction']['conditions'].append({ 'uri': condition_timeout.condition.serialize_uri() }, 'cid': 0, - 'new_owners': None + 'owners_after': None }) # conditions have been updated, so hash needs updating diff --git a/tests/test_client.py b/tests/test_client.py index 96e57ca4..e4b49dd6 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -44,11 +44,11 @@ def test_client_can_create_assets(mock_requests_post, client): # XXX: `CREATE` operations require the node that receives the transaction to modify the data in # the transaction itself. - # `current_owner` will be overwritten with the public key of the node in the federation + # `owner_before` will be overwritten with the public key of the node in the federation # that will create the real transaction. `signature` will be overwritten with the new signature. # Note that this scenario is ignored by this test. - assert tx['transaction']['fulfillments'][0]['current_owners'][0] == client.public_key - assert tx['transaction']['conditions'][0]['new_owners'][0] == client.public_key + assert tx['transaction']['fulfillments'][0]['owners_before'][0] == client.public_key + assert tx['transaction']['conditions'][0]['owners_after'][0] == client.public_key assert tx['transaction']['fulfillments'][0]['input'] is None assert util.validate_fulfillments(tx) @@ -56,8 +56,8 @@ def test_client_can_create_assets(mock_requests_post, client): def test_client_can_transfer_assets(mock_requests_post, mock_bigchaindb_sign, client): tx = client.transfer(client.public_key, 123) - assert tx['transaction']['fulfillments'][0]['current_owners'][0] == client.public_key - assert tx['transaction']['conditions'][0]['new_owners'][0] == client.public_key + assert tx['transaction']['fulfillments'][0]['owners_before'][0] == client.public_key + assert tx['transaction']['conditions'][0]['owners_after'][0] == client.public_key assert tx['transaction']['fulfillments'][0]['input'] == 123 diff --git a/tests/test_util.py b/tests/test_util.py index a4fe5a74..ae0b05ec 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -35,8 +35,8 @@ def test_transform_create(b, user_sk, user_vk): tx = util.transform_create(tx) tx = util.sign_tx(tx, b.me_private) - assert tx['transaction']['fulfillments'][0]['current_owners'][0] == b.me - assert tx['transaction']['conditions'][0]['new_owners'][0] == user_vk + assert tx['transaction']['fulfillments'][0]['owners_before'][0] == b.me + assert tx['transaction']['conditions'][0]['owners_after'][0] == user_vk assert util.validate_fulfillments(tx) @@ -159,7 +159,7 @@ def test_create_tx_with_empty_inputs(): assert 'data' in tx['transaction'] assert len(tx['transaction']['fulfillments']) == 1 assert tx['transaction']['fulfillments'][0] == { - 'current_owners': [], 'input': None, 'fulfillment': None, 'fid': 0} + 'owners_before': [], 'input': None, 'fulfillment': None, 'fid': 0} def test_fulfill_threshold_signature_fulfillment_pubkey_notfound(monkeypatch): @@ -170,7 +170,7 @@ def test_fulfill_threshold_signature_fulfillment_pubkey_notfound(monkeypatch): 'get_subcondition_from_vk', lambda x, y: [] ) - fulfillment = {'current_owners': (None,)} + fulfillment = {'owners_before': (None,)} parsed_fulfillment = ThresholdSha256Fulfillment() with pytest.raises(KeypairMismatchException): fulfill_threshold_signature_fulfillment( @@ -185,7 +185,7 @@ def test_fulfill_threshold_signature_fulfillment_wrong_privkeys(monkeypatch): 'get_subcondition_from_vk', lambda x, y: (None,) ) - fulfillment = {'current_owners': ('alice-pub-key',)} + fulfillment = {'owners_before': ('alice-pub-key',)} parsed_fulfillment = ThresholdSha256Fulfillment() with pytest.raises(KeypairMismatchException): fulfill_threshold_signature_fulfillment( diff --git a/tests/web/test_basic_views.py b/tests/web/test_basic_views.py index 2ed05caf..17a30e39 100644 --- a/tests/web/test_basic_views.py +++ b/tests/web/test_basic_views.py @@ -36,8 +36,8 @@ def test_post_create_transaction_endpoint(b, client): tx = util.create_and_sign_tx(keypair[0], keypair[1], keypair[1], None, 'CREATE') res = client.post(TX_ENDPOINT, data=json.dumps(tx)) - assert res.json['transaction']['fulfillments'][0]['current_owners'][0] == b.me - assert res.json['transaction']['conditions'][0]['new_owners'][0] == keypair[1] + assert res.json['transaction']['fulfillments'][0]['owners_before'][0] == b.me + assert res.json['transaction']['conditions'][0]['owners_after'][0] == keypair[1] @pytest.mark.usefixtures('inputs') @@ -48,8 +48,8 @@ def test_post_transfer_transaction_endpoint(b, client, user_vk, user_sk): transfer = util.create_and_sign_tx(user_sk, user_vk, to_keypair[1], input_valid) res = client.post(TX_ENDPOINT, data=json.dumps(transfer)) - assert res.json['transaction']['fulfillments'][0]['current_owners'][0] == user_vk - assert res.json['transaction']['conditions'][0]['new_owners'][0] == to_keypair[1] + assert res.json['transaction']['fulfillments'][0]['owners_before'][0] == user_vk + assert res.json['transaction']['conditions'][0]['owners_after'][0] == to_keypair[1] @pytest.mark.usefixtures('inputs')