remove Condition.cid and Fulfillment.fid in favour of dereferencing conditions and fulfillments by their location in their respective arrays

This commit is contained in:
Scott Sadler 2016-11-29 09:59:43 +01:00
parent 839035b203
commit 18d018519f
6 changed files with 16 additions and 78 deletions

View File

@ -152,11 +152,6 @@ definitions:
- condition - condition
- amount - amount
properties: properties:
cid:
"$ref": "#/definitions/offset"
description: |
Index of this condition's appearance in the `Transaction.conditions`_
array. In a transaction with 2 conditions, the ``cid``s will be 0 and 1.
condition: condition:
description: | description: |
Body of the condition. Has the properties: Body of the condition. Has the properties:
@ -197,10 +192,6 @@ definitions:
- input - input
- fulfillment - fulfillment
properties: properties:
fid:
"$ref": "#/definitions/offset"
description: |
The offset of the fulfillment within the fulfillents array.
owners_before: owners_before:
"$ref": "#/definitions/owners_list" "$ref": "#/definitions/owners_list"
description: | description: |

View File

@ -52,19 +52,13 @@ class Fulfillment(object):
# TODO: If `other !== Fulfillment` return `False` # TODO: If `other !== Fulfillment` return `False`
return self.to_dict() == other.to_dict() return self.to_dict() == other.to_dict()
def to_dict(self, fid=None): def to_dict(self):
"""Transforms the object to a Python dictionary. """Transforms the object to a Python dictionary.
Note: Note:
A `fid` can be submitted to be included in the dictionary
representation.
If a Fulfillment hasn't been signed yet, this method returns a If a Fulfillment hasn't been signed yet, this method returns a
dictionary representation. dictionary representation.
Args:
fid (int, optional): The Fulfillment's index in a Transaction.
Returns: Returns:
dict: The Fulfillment as an alternative serialization format. dict: The Fulfillment as an alternative serialization format.
""" """
@ -92,8 +86,6 @@ class Fulfillment(object):
'input': tx_input, 'input': tx_input,
'fulfillment': fulfillment, 'fulfillment': fulfillment,
} }
if fid is not None:
ffill['fid'] = fid
return ffill return ffill
@classmethod @classmethod
@ -234,19 +226,13 @@ class Condition(object):
# TODO: If `other !== Condition` return `False` # TODO: If `other !== Condition` return `False`
return self.to_dict() == other.to_dict() return self.to_dict() == other.to_dict()
def to_dict(self, cid=None): def to_dict(self):
"""Transforms the object to a Python dictionary. """Transforms the object to a Python dictionary.
Note: Note:
A `cid` can be submitted to be included in the dictionary
representation.
A dictionary serialization of the Fulfillment the Condition was A dictionary serialization of the Fulfillment the Condition was
derived from is always provided. derived from is always provided.
Args:
cid (int, optional): The Condition's index in a Transaction.
Returns: Returns:
dict: The Condition as an alternative serialization format. dict: The Condition as an alternative serialization format.
""" """
@ -268,8 +254,6 @@ class Condition(object):
'condition': condition, 'condition': condition,
'amount': self.amount 'amount': self.amount
} }
if cid is not None:
cond['cid'] = cid
return cond return cond
@classmethod @classmethod
@ -858,11 +842,12 @@ class Transaction(object):
""" """
# NOTE: If no condition indices are passed, we just assume to # NOTE: If no condition indices are passed, we just assume to
# take all conditions as inputs. # take all conditions as inputs.
indices = condition_indices or range(len(self.conditions))
return [ return [
Fulfillment(self.conditions[cid].fulfillment, Fulfillment(self.conditions[cid].fulfillment,
self.conditions[cid].owners_after, self.conditions[cid].owners_after,
TransactionLink(self.id, cid)) TransactionLink(self.id, cid))
for cid in condition_indices or range(len(self.conditions)) for cid in indices
] ]
def add_fulfillment(self, fulfillment): def add_fulfillment(self, fulfillment):
@ -1179,10 +1164,10 @@ class Transaction(object):
asset = {'id': self.asset.data_id} asset = {'id': self.asset.data_id}
tx_body = { tx_body = {
'fulfillments': [fulfillment.to_dict(fid) for fid, fulfillment 'fulfillments': [fulfillment.to_dict() for fulfillment
in enumerate(self.fulfillments)], in self.fulfillments],
'conditions': [condition.to_dict(cid) for cid, condition 'conditions': [condition.to_dict() for condition
in enumerate(self.conditions)], in self.conditions],
'operation': str(self.operation), 'operation': str(self.operation),
'metadata': metadata, 'metadata': metadata,
'asset': asset, 'asset': asset,

View File

@ -32,7 +32,6 @@ If there is only one _new owner_, the condition will be a simple signature condi
```json ```json
{ {
"cid": "<condition index>",
"condition": { "condition": {
"details": { "details": {
"bitmask": "<base16 int>", "bitmask": "<base16 int>",
@ -49,8 +48,6 @@ If there is only one _new owner_, the condition will be a simple signature condi
``` ```
- **Condition header**: - **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`.
- `owners_after`: 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.
- `amount`: The amount of shares for a divisible asset to send to the new owners. - `amount`: The amount of shares for a divisible asset to send to the new owners.
- **Condition body**: - **Condition body**:
@ -66,7 +63,6 @@ to spend the asset. For example:
```json ```json
{ {
"cid": "<condition index>",
"condition": { "condition": {
"details": { "details": {
"bitmask": 41, "bitmask": 41,
@ -115,7 +111,6 @@ If there is only one _current owner_, the fulfillment will be a simple signature
```json ```json
{ {
"owners_before": ["<public key of the owner before the transaction happened>"], "owners_before": ["<public key of the owner before the transaction happened>"],
"fid": 0,
"fulfillment": "cf:4:RxFzIE679tFBk8zwEgizhmTuciAylvTUwy6EL6ehddHFJOhK5F4IjwQ1xLu2oQK9iyRCZJdfWAefZVjTt3DeG5j2exqxpGliOPYseNkRAWEakqJ_UrCwgnj92dnFRAEE", "fulfillment": "cf:4:RxFzIE679tFBk8zwEgizhmTuciAylvTUwy6EL6ehddHFJOhK5F4IjwQ1xLu2oQK9iyRCZJdfWAefZVjTt3DeG5j2exqxpGliOPYseNkRAWEakqJ_UrCwgnj92dnFRAEE",
"input": { "input": {
"cid": 0, "cid": 0,
@ -124,10 +119,8 @@ 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.
- `owners_before`: A list of public keys of the owners before the transaction; 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). - `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 - `input`: Pointer to the asset and condition of a previous transaction
- `cid`: Condition index - `cid`: Condition index - the index of the condition in the array of conditions in the previous transaction
- `txid`: Transaction id - `txid`: Transaction id

View File

@ -73,7 +73,6 @@ POST /transactions/
"transaction": { "transaction": {
"conditions": [ "conditions": [
{ {
"cid": 0,
"condition": { "condition": {
"uri": "cc:4:20:GG-pi3CeIlySZhQoJVBh9O23PzrOuhnYI7OHqIbHjkk:96", "uri": "cc:4:20:GG-pi3CeIlySZhQoJVBh9O23PzrOuhnYI7OHqIbHjkk:96",
"details": { "details": {
@ -101,7 +100,6 @@ POST /transactions/
"metadata": null, "metadata": null,
"fulfillments": [ "fulfillments": [
{ {
"fid": 0,
"input": null, "input": null,
"fulfillment": "cf:4:GG-pi3CeIlySZhQoJVBh9O23PzrOuhnYI7OHqIbHjkn2VnQaEWvecO1x82Qr2Va_JjFywLKIOEV1Ob9Ofkeln2K89ny2mB-s7RLNvYAVzWNiQnp18_nQEUsvwACEXTYJ", "fulfillment": "cf:4:GG-pi3CeIlySZhQoJVBh9O23PzrOuhnYI7OHqIbHjkn2VnQaEWvecO1x82Qr2Va_JjFywLKIOEV1Ob9Ofkeln2K89ny2mB-s7RLNvYAVzWNiQnp18_nQEUsvwACEXTYJ",
"owners_before": [ "owners_before": [
@ -141,14 +139,12 @@ POST /transactions/
"owners_after": [ "owners_after": [
"2ePYHfV3yS3xTxF9EE3Xjo8zPwq2RmLPFAJGQqQKc3j6" "2ePYHfV3yS3xTxF9EE3Xjo8zPwq2RmLPFAJGQqQKc3j6"
], ],
"cid": 0
} }
], ],
"fulfillments": [ "fulfillments": [
{ {
"input": null, "input": null,
"fulfillment": "cf:4:GG-pi3CeIlySZhQoJVBh9O23PzrOuhnYI7OHqIbHjkn2VnQaEWvecO1x82Qr2Va_JjFywLKIOEV1Ob9Ofkeln2K89ny2mB-s7RLNvYAVzWNiQnp18_nQEUsvwACEXTYJ", "fulfillment": "cf:4:GG-pi3CeIlySZhQoJVBh9O23PzrOuhnYI7OHqIbHjkn2VnQaEWvecO1x82Qr2Va_JjFywLKIOEV1Ob9Ofkeln2K89ny2mB-s7RLNvYAVzWNiQnp18_nQEUsvwACEXTYJ",
"fid": 0,
"owners_before": [ "owners_before": [
"2ePYHfV3yS3xTxF9EE3Xjo8zPwq2RmLPFAJGQqQKc3j6" "2ePYHfV3yS3xTxF9EE3Xjo8zPwq2RmLPFAJGQqQKc3j6"
] ]
@ -237,7 +233,6 @@ GET /transactions/{tx_id}
"transaction": { "transaction": {
"conditions": [ "conditions": [
{ {
"cid": 0,
"condition": { "condition": {
"uri": "cc:4:20:GG-pi3CeIlySZhQoJVBh9O23PzrOuhnYI7OHqIbHjkk:96", "uri": "cc:4:20:GG-pi3CeIlySZhQoJVBh9O23PzrOuhnYI7OHqIbHjkk:96",
"details": { "details": {
@ -265,7 +260,6 @@ GET /transactions/{tx_id}
"metadata": null, "metadata": null,
"fulfillments": [ "fulfillments": [
{ {
"fid": 0,
"input": null, "input": null,
"fulfillment": "cf:4:GG-pi3CeIlySZhQoJVBh9O23PzrOuhnYI7OHqIbHjkn2VnQaEWvecO1x82Qr2Va_JjFywLKIOEV1Ob9Ofkeln2K89ny2mB-s7RLNvYAVzWNiQnp18_nQEUsvwACEXTYJ", "fulfillment": "cf:4:GG-pi3CeIlySZhQoJVBh9O23PzrOuhnYI7OHqIbHjkn2VnQaEWvecO1x82Qr2Va_JjFywLKIOEV1Ob9Ofkeln2K89ny2mB-s7RLNvYAVzWNiQnp18_nQEUsvwACEXTYJ",
"owners_before": [ "owners_before": [

View File

@ -152,16 +152,6 @@ and what conditions must be met in order for it to be fulfilled. See also:
fulfillment_. fulfillment_.
Condition.cid
^^^^^^^^^^^^^
**type:** integer
Index of this condition's appearance in the Transaction.conditions_
array. In a transaction with 2 conditions, the ``cid``\ s will be 0 and 1.
Condition.condition Condition.condition
^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^
@ -201,15 +191,6 @@ Fulfillment
A fulfillment is an input to a transaction, named as such because it fulfills a condition of a previous transaction. In the case of a ``CREATE`` transaction, a fulfillment may provide no ``input``. A fulfillment is an input to a transaction, named as such because it fulfills a condition of a previous transaction. In the case of a ``CREATE`` transaction, a fulfillment may provide no ``input``.
Fulfillment.fid
^^^^^^^^^^^^^^^
**type:** integer
The offset of the fulfillment within the fulfillents array.
Fulfillment.owners_before Fulfillment.owners_before
^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -304,8 +304,8 @@ def test_transaction_serialization(user_ffill, user_cond, data, data_id):
'transaction': { 'transaction': {
# NOTE: This test assumes that Fulfillments and Conditions can # NOTE: This test assumes that Fulfillments and Conditions can
# successfully be serialized # successfully be serialized
'fulfillments': [user_ffill.to_dict(0)], 'fulfillments': [user_ffill.to_dict()],
'conditions': [user_cond.to_dict(0)], 'conditions': [user_cond.to_dict()],
'operation': Transaction.CREATE, 'operation': Transaction.CREATE,
'metadata': None, 'metadata': None,
'asset': { 'asset': {
@ -761,7 +761,7 @@ def test_create_create_transaction_single_io(user_cond, user_pub, data, uuid4):
expected = { expected = {
'transaction': { 'transaction': {
'conditions': [user_cond.to_dict(0)], 'conditions': [user_cond.to_dict()],
'metadata': { 'metadata': {
'data': data, 'data': data,
}, },
@ -777,7 +777,6 @@ def test_create_create_transaction_single_io(user_cond, user_pub, data, uuid4):
'owners_before': [ 'owners_before': [
user_pub user_pub
], ],
'fid': 0,
'fulfillment': None, 'fulfillment': None,
'input': None 'input': None
} }
@ -815,10 +814,9 @@ def test_create_create_transaction_multiple_io(user_cond, user2_cond, user_pub,
# is a fulfillment for an implicit threshold condition with # is a fulfillment for an implicit threshold condition with
# weight = len(owners_before) # weight = len(owners_before)
ffill = Fulfillment.generate([user_pub, user2_pub]).to_dict() ffill = Fulfillment.generate([user_pub, user2_pub]).to_dict()
ffill.update({'fid': 0})
expected = { expected = {
'transaction': { 'transaction': {
'conditions': [user_cond.to_dict(0), user2_cond.to_dict(1)], 'conditions': [user_cond.to_dict(), user2_cond.to_dict()],
'metadata': { 'metadata': {
'data': { 'data': {
'message': 'hello' 'message': 'hello'
@ -864,7 +862,7 @@ def test_create_create_transaction_threshold(user_pub, user2_pub, user3_pub,
expected = { expected = {
'transaction': { 'transaction': {
'conditions': [user_user2_threshold_cond.to_dict(0)], 'conditions': [user_user2_threshold_cond.to_dict()],
'metadata': { 'metadata': {
'data': data, 'data': data,
}, },
@ -880,7 +878,6 @@ def test_create_create_transaction_threshold(user_pub, user2_pub, user3_pub,
'owners_before': [ 'owners_before': [
user_pub, user_pub,
], ],
'fid': 0,
'fulfillment': None, 'fulfillment': None,
'input': None 'input': None
}, },
@ -950,7 +947,7 @@ def test_create_transfer_transaction_single_io(tx, user_pub, user2_pub,
expected = { expected = {
'transaction': { 'transaction': {
'conditions': [user2_cond.to_dict(0)], 'conditions': [user2_cond.to_dict()],
'metadata': None, 'metadata': None,
'asset': { 'asset': {
'id': uuid4, 'id': uuid4,
@ -960,7 +957,6 @@ def test_create_transfer_transaction_single_io(tx, user_pub, user2_pub,
'owners_before': [ 'owners_before': [
user_pub user_pub
], ],
'fid': 0,
'fulfillment': None, 'fulfillment': None,
'input': { 'input': {
'txid': tx.id, 'txid': tx.id,
@ -1006,14 +1002,13 @@ def test_create_transfer_transaction_multiple_io(user_pub, user_priv,
expected = { expected = {
'transaction': { 'transaction': {
'conditions': [user2_cond.to_dict(0), user2_cond.to_dict(1)], 'conditions': [user2_cond.to_dict(), user2_cond.to_dict()],
'metadata': None, 'metadata': None,
'fulfillments': [ 'fulfillments': [
{ {
'owners_before': [ 'owners_before': [
user_pub user_pub
], ],
'fid': 0,
'fulfillment': None, 'fulfillment': None,
'input': { 'input': {
'txid': tx.id, 'txid': tx.id,
@ -1023,7 +1018,6 @@ def test_create_transfer_transaction_multiple_io(user_pub, user_priv,
'owners_before': [ 'owners_before': [
user2_pub user2_pub
], ],
'fid': 1,
'fulfillment': None, 'fulfillment': None,
'input': { 'input': {
'txid': tx.id, 'txid': tx.id,