Rename "output" to "output_index" in /api/v1/outputs (#1596)

* rename output to output_index in /api/v1/outputs

* rename transaction.input.fulfills.output to output_index

* fix rethinkdb queries for output_index
This commit is contained in:
libscott 2017-06-30 09:40:50 +02:00 committed by GitHub
parent 8ef6385a8c
commit b1ad6045b6
11 changed files with 28 additions and 28 deletions

View File

@ -158,7 +158,7 @@ def get_spent(conn, transaction_id, output):
'block.transactions.inputs': {
'$elemMatch': {
'fulfills.transaction_id': transaction_id,
'fulfills.output': output,
'fulfills.output_index': output,
},
},
}},
@ -167,7 +167,7 @@ def get_spent(conn, transaction_id, output):
'block.transactions.inputs': {
'$elemMatch': {
'fulfills.transaction_id': transaction_id,
'fulfills.output': output,
'fulfills.output_index': output,
},
},
}},

View File

@ -72,7 +72,7 @@ def create_bigchain_secondary_index(conn, dbname):
conn.conn[dbname]['bigchain']\
.create_index([
('block.transactions.inputs.fulfills.transaction_id', ASCENDING),
('block.transactions.inputs.fulfills.output', ASCENDING),
('block.transactions.inputs.fulfills.output_index', ASCENDING),
], name='inputs')

View File

@ -123,7 +123,7 @@ def get_spent(connection, transaction_id, output):
.concat_map(lambda doc: doc['block']['transactions'])
.filter(lambda transaction: transaction['inputs'].contains(
lambda input_: input_['fulfills'] == {
'transaction_id': transaction_id, 'output': output})))
'transaction_id': transaction_id, 'output_index': output})))
@register_query(RethinkDBConnection)
@ -287,7 +287,7 @@ def unwind_block_transactions(block):
def get_spending_transactions(connection, links):
query = (
r.table('bigchain')
.get_all(*[(l['transaction_id'], l['output']) for l in links],
.get_all(*[(l['transaction_id'], l['output_index']) for l in links],
index='inputs')
.concat_map(unwind_block_transactions)
# filter transactions spending output

View File

@ -86,9 +86,9 @@ def create_bigchain_secondary_index(connection, dbname):
.index_create('inputs',
r.row['block']['transactions']
.concat_map(lambda tx: tx['inputs']['fulfills'])
.with_fields('transaction_id', 'output')
.with_fields('transaction_id', 'output_index')
.map(lambda fulfills: [fulfills['transaction_id'],
fulfills['output']]),
fulfills['output_index']]),
multi=True))
# wait for rethinkdb to finish creating secondary indexes

View File

@ -203,10 +203,10 @@ definitions:
Reference to the output that is being spent.
additionalProperties: false
required:
- output
- output_index
- transaction_id
properties:
output:
output_index:
"$ref": "#/definitions/offset"
description: |
Index of the output containing the condition being fulfilled

View File

@ -178,7 +178,7 @@ class TransactionLink(object):
:class:`~bigchaindb.common.transaction.TransactionLink`
"""
try:
return cls(link['transaction_id'], link['output'])
return cls(link['transaction_id'], link['output_index'])
except TypeError:
return cls()
@ -193,7 +193,7 @@ class TransactionLink(object):
else:
return {
'transaction_id': self.txid,
'output': self.output,
'output_index': self.output,
}
def to_uri(self, path=''):

View File

@ -22,5 +22,5 @@ class OutputListApi(Resource):
with pool() as bigchain:
outputs = bigchain.get_outputs_filtered(args['public_key'],
args['spent'])
return [{'transaction_id': output.txid, 'output': output.output}
return [{'transaction_id': output.txid, 'output_index': output.output}
for output in outputs]

View File

@ -132,7 +132,7 @@ If there is only one *current owner*, the fulfillment will be a simple signature
"owners_before": ["<public key of the owner before the transaction happened>"],
"fulfillment": "cf:4:RxFzIE679tFBk8zwEgizhmTuciAylvTUwy6EL6ehddHFJOhK5F4IjwQ1xLu2oQK9iyRCZJdfWAefZVjTt3DeG5j2exqxpGliOPYseNkRAWEakqJ_UrCwgnj92dnFRAEE",
"fulfills": {
"output": 0,
"output_index": 0,
"transaction_id": "11b3e7d893cc5fdfcf1a1706809c7def290a3b10b0bef6525d10b024649c42d3"
}
}
@ -151,7 +151,7 @@ If there are multiple *current owners*, the fulfillment will be a little differe
"owners_before": ["<public key of the first owner before the transaction happened>","<public key of the second owner before the transaction happened>"],
"fulfillment": "cf:2:AQIBAgEBYwAEYEv6O5HjHGl7OWo2Tu5mWcWQcL_OGrFuUjyej-dK3LM99TbZsRd8c9luQhU30xCH5AdNaupxg-pLHuk8DoSaDA1MHQGXUZ80a_cV-4UaaaCpdey8K0CEcJxre0X96hTHCwABAWMABGBnsuHExhuSj5Mdm-q0KoPgX4nAt0s00k1WTMCzuUpQIp6aStLoTSMlsvS4fmDtOSv9gubekKLuHTMAk-LQFSKF1JdzwaVWAA2UOv0v_OS2gY3A-r0kRq8HtzjYdcmVswUA",
"fulfills": {
"output": 0,
"output_index": 0,
"transaction_id": "e4805f1bfc999d6409b38e3a4c3b2fafad7c1280eb0d441da7083e945dd89eb8"
}
}
@ -160,5 +160,5 @@ If there are multiple *current owners*, the fulfillment will be a little differe
- ``owners_before``: A list of public keys of the owners before the transaction; in this case it has two owners, hence two public keys.
- ``fulfillment``: A crypto-conditions URI that encodes the cryptographic fulfillments like signatures and others;'cf' indicates this is a fulfillment, '2' indicates the condition type is THRESHOLD-SHA-256 (while '4' in `One Current Owner`_ indicates its condition type is ED25519).
- ``fulfills``: Pointer to an output from a previous transaction that is being spent
- ``output``: The index of the output in a previous transaction
- ``output_index``: The index of the output in a previous transaction
- ``transaction_id``: ID of the transaction

View File

@ -206,11 +206,11 @@ unspent outputs.
[
{
"output": 0,
"output_index": 0,
"transaction_id": "2d431073e1477f3073a4693ac7ff9be5634751de1b8abaa1f4e19548ef0b4b0e"
},
{
"output": 1,
"output_index": 1,
"transaction_id": "2d431073e1477f3073a4693ac7ff9be5634751de1b8abaa1f4e19548ef0b4b0e"
}
]
@ -238,7 +238,7 @@ unspent outputs.
[
{
"output": 0,
"output_index": 0,
"transaction_id": "2d431073e1477f3073a4693ac7ff9be5634751de1b8abaa1f4e19548ef0b4b0e"
}
]
@ -266,7 +266,7 @@ unspent outputs.
[
{
"output": 1,
"output_index": 1,
"transaction_id": "2d431073e1477f3073a4693ac7ff9be5634751de1b8abaa1f4e19548ef0b4b0e"
}
]

View File

@ -366,7 +366,7 @@ def test_transaction_link_serialization():
tx_id = 'a transaction id'
expected = {
'transaction_id': tx_id,
'output': 0,
'output_index': 0,
}
tx_link = TransactionLink(tx_id, 0)
@ -389,7 +389,7 @@ def test_transaction_link_deserialization():
expected = TransactionLink(tx_id, 0)
tx_link = {
'transaction_id': tx_id,
'output': 0,
'output_index': 0,
}
tx_link = TransactionLink.from_dict(tx_link)
@ -842,7 +842,7 @@ def test_create_transfer_transaction_single_io(tx, user_pub, user2_pub,
'fulfillment': None,
'fulfills': {
'transaction_id': tx.id,
'output': 0
'output_index': 0
}
}
],
@ -891,7 +891,7 @@ def test_create_transfer_transaction_multiple_io(user_pub, user_priv,
'fulfillment': None,
'fulfills': {
'transaction_id': tx.id,
'output': 0
'output_index': 0
}
}, {
'owners_before': [
@ -900,7 +900,7 @@ def test_create_transfer_transaction_multiple_io(user_pub, user_priv,
'fulfillment': None,
'fulfills': {
'transaction_id': tx.id,
'output': 1
'output_index': 1
}
}
],

View File

@ -14,8 +14,8 @@ def test_get_outputs_endpoint(client, user_pk):
gof.return_value = [m, m]
res = client.get(OUTPUTS_ENDPOINT + '?public_key={}'.format(user_pk))
assert res.json == [
{'transaction_id': 'a', 'output': 0},
{'transaction_id': 'a', 'output': 0}
{'transaction_id': 'a', 'output_index': 0},
{'transaction_id': 'a', 'output_index': 0}
]
assert res.status_code == 200
gof.assert_called_once_with(user_pk, None)
@ -29,7 +29,7 @@ def test_get_outputs_endpoint_unspent(client, user_pk):
gof.return_value = [m]
params = '?spent=False&public_key={}'.format(user_pk)
res = client.get(OUTPUTS_ENDPOINT + params)
assert res.json == [{'transaction_id': 'a', 'output': 0}]
assert res.json == [{'transaction_id': 'a', 'output_index': 0}]
assert res.status_code == 200
gof.assert_called_once_with(user_pk, False)
@ -42,7 +42,7 @@ def test_get_outputs_endpoint_spent(client, user_pk):
gof.return_value = [m]
params = '?spent=true&public_key={}'.format(user_pk)
res = client.get(OUTPUTS_ENDPOINT + params)
assert res.json == [{'transaction_id': 'a', 'output': 0}]
assert res.json == [{'transaction_id': 'a', 'output_index': 0}]
assert res.status_code == 200
gof.assert_called_once_with(user_pk, True)