mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
GET transactions?operation&asset_id examples --> samples
Updated example to include more than one TRANSFER
This commit is contained in:
parent
a37b505c87
commit
b947cf7c72
@ -4,8 +4,7 @@ import json
|
|||||||
import os
|
import os
|
||||||
import os.path
|
import os.path
|
||||||
|
|
||||||
from bigchaindb.common.transaction import Transaction
|
from bigchaindb.common.transaction import Transaction, Input, TransactionLink
|
||||||
|
|
||||||
|
|
||||||
TPLS = {}
|
TPLS = {}
|
||||||
|
|
||||||
@ -27,7 +26,7 @@ X-BigchainDB-Timestamp: 1482766245
|
|||||||
|
|
||||||
|
|
||||||
TPLS['get-tx-unfulfilled-request'] = """\
|
TPLS['get-tx-unfulfilled-request'] = """\
|
||||||
GET /transactions?fulfilled=false&public_keys=%(public_keys)s HTTP/1.1
|
GET /transactions?fulfilled=false&public_keys=%(public_keys_transfer_last)s HTTP/1.1
|
||||||
Host: example.com
|
Host: example.com
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@ -37,7 +36,23 @@ TPLS['get-tx-unfulfilled-response'] = """\
|
|||||||
HTTP/1.1 200 OK
|
HTTP/1.1 200 OK
|
||||||
Content-Type: application/json
|
Content-Type: application/json
|
||||||
|
|
||||||
[%(tx)s]
|
[%(tx_transfer_last)s]
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
TPLS['get-tx-by-asset-request'] = """\
|
||||||
|
GET /transactions?operation=transfer&asset_id=%(txid)s HTTP/1.1
|
||||||
|
Host: example.com
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
TPLS['get-tx-by-asset-response'] = """\
|
||||||
|
HTTP/1.1 200 OK
|
||||||
|
Content-Type: application/json
|
||||||
|
|
||||||
|
[%(tx_transfer)s,
|
||||||
|
%(tx_transfer_last)s]
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
@ -80,10 +95,33 @@ def main():
|
|||||||
""" Main function """
|
""" Main function """
|
||||||
privkey = 'CfdqtD7sS7FgkMoGPXw55MVGGFwQLAoHYTcBhZDtF99Z'
|
privkey = 'CfdqtD7sS7FgkMoGPXw55MVGGFwQLAoHYTcBhZDtF99Z'
|
||||||
pubkey = '4K9sWUMFwTgaDGPfdynrbxWqWS6sWmKbZoTjxLtVUibD'
|
pubkey = '4K9sWUMFwTgaDGPfdynrbxWqWS6sWmKbZoTjxLtVUibD'
|
||||||
tx = Transaction.create([pubkey], [([pubkey], 1)])
|
asset = {'msg': 'Hello BigchainDB!'}
|
||||||
|
tx = Transaction.create([pubkey], [([pubkey], 1)], asset=asset)
|
||||||
tx = tx.sign([privkey])
|
tx = tx.sign([privkey])
|
||||||
tx_json = json.dumps(tx.to_dict(), indent=2, sort_keys=True)
|
tx_json = json.dumps(tx.to_dict(), indent=2, sort_keys=True)
|
||||||
|
|
||||||
|
privkey_transfer = '3AeWpPdhEZzWLYfkfYHBfMFC2r1f8HEaGS9NtbbKssya'
|
||||||
|
pubkey_transfer = '3yfQPHeWAa1MxTX9Zf9176QqcpcnWcanVZZbaHb8B3h9'
|
||||||
|
|
||||||
|
cid = 0
|
||||||
|
input_ = Input(fulfillment=tx.outputs[cid].fulfillment,
|
||||||
|
fulfills=TransactionLink(txid=tx.id, output=cid),
|
||||||
|
owners_before=tx.outputs[cid].public_keys)
|
||||||
|
tx_transfer = Transaction.transfer([input_], [([pubkey_transfer], 1)], asset_id=tx.id)
|
||||||
|
tx_transfer = tx_transfer.sign([privkey])
|
||||||
|
tx_transfer_json = json.dumps(tx_transfer.to_dict(), indent=2, sort_keys=True)
|
||||||
|
|
||||||
|
privkey_transfer_last = 'sG3jWDtdTXUidBJK53ucSTrosktG616U3tQHBk81eQe'
|
||||||
|
pubkey_transfer_last = '3Af3fhhjU6d9WecEM9Uw5hfom9kNEwE7YuDWdqAUssqm'
|
||||||
|
|
||||||
|
cid = 0
|
||||||
|
input_ = Input(fulfillment=tx_transfer.outputs[cid].fulfillment,
|
||||||
|
fulfills=TransactionLink(txid=tx_transfer.id, output=cid),
|
||||||
|
owners_before=tx_transfer.outputs[cid].public_keys)
|
||||||
|
tx_transfer_last = Transaction.transfer([input_], [([pubkey_transfer_last], 1)], asset_id=tx.id)
|
||||||
|
tx_transfer_last = tx_transfer_last.sign([privkey_transfer])
|
||||||
|
tx_transfer_last_json = json.dumps(tx_transfer_last.to_dict(), indent=2, sort_keys=True)
|
||||||
|
|
||||||
base_path = os.path.join(os.path.dirname(__file__),
|
base_path = os.path.join(os.path.dirname(__file__),
|
||||||
'source/drivers-clients/samples')
|
'source/drivers-clients/samples')
|
||||||
|
|
||||||
@ -94,7 +132,13 @@ def main():
|
|||||||
path = os.path.join(base_path, name + '.http')
|
path = os.path.join(base_path, name + '.http')
|
||||||
code = tpl % {'tx': tx_json,
|
code = tpl % {'tx': tx_json,
|
||||||
'txid': tx.id,
|
'txid': tx.id,
|
||||||
'public_keys': tx.outputs[0].public_keys[0]}
|
'tx_transfer': tx_transfer_json,
|
||||||
|
'tx_transfer_id': tx_transfer.id,
|
||||||
|
'tx_transfer_last': tx_transfer_last_json,
|
||||||
|
'tx_transfer_last_id': tx_transfer_last.id,
|
||||||
|
'public_keys': tx.outputs[0].public_keys[0],
|
||||||
|
'public_keys_transfer': tx_transfer.outputs[0].public_keys[0],
|
||||||
|
'public_keys_transfer_last': tx_transfer_last.outputs[0].public_keys[0]}
|
||||||
with open(path, 'w') as handle:
|
with open(path, 'w') as handle:
|
||||||
handle.write(code)
|
handle.write(code)
|
||||||
|
|
||||||
|
@ -156,63 +156,13 @@ Transactions
|
|||||||
|
|
||||||
**Example request**:
|
**Example request**:
|
||||||
|
|
||||||
.. sourcecode:: http
|
.. literalinclude:: samples/get-tx-by-asset-request.http
|
||||||
|
:language: http
|
||||||
GET /transactions?operation=CREATE&asset_id=1AAAbbb...ccc HTTP/1.1
|
|
||||||
Host: example.com
|
|
||||||
|
|
||||||
**Example response**:
|
**Example response**:
|
||||||
|
|
||||||
.. sourcecode:: http
|
.. literalinclude:: samples/get-tx-by-asset-response.http
|
||||||
|
:language: http
|
||||||
HTTP/1.1 200 OK
|
|
||||||
Content-Type: application/json
|
|
||||||
|
|
||||||
[{
|
|
||||||
"transaction": {
|
|
||||||
"conditions": [
|
|
||||||
{
|
|
||||||
"cid": 0,
|
|
||||||
"condition": {
|
|
||||||
"uri": "cc:4:20:GG-pi3CeIlySZhQoJVBh9O23PzrOuhnYI7OHqIbHjkk:96",
|
|
||||||
"details": {
|
|
||||||
"signature": null,
|
|
||||||
"type": "fulfillment",
|
|
||||||
"type_id": 4,
|
|
||||||
"bitmask": 32,
|
|
||||||
"public_key": "2ePYHfV3yS3xTxF9EE3Xjo8zPwq2RmLPFAJGQqQKc3j6"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"amount": 1,
|
|
||||||
"owners_after": [
|
|
||||||
"2ePYHfV3yS3xTxF9EE3Xjo8zPwq2RmLPFAJGQqQKc3j6"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"operation": "CREATE",
|
|
||||||
"asset": {
|
|
||||||
"divisible": false,
|
|
||||||
"updatable": false,
|
|
||||||
"data": null,
|
|
||||||
"id": "1AAAbbb...ccc",
|
|
||||||
"refillable": false
|
|
||||||
},
|
|
||||||
"metadata": null,
|
|
||||||
"timestamp": "1477578978",
|
|
||||||
"fulfillments": [
|
|
||||||
{
|
|
||||||
"fid": 0,
|
|
||||||
"input": null,
|
|
||||||
"fulfillment": "cf:4:GG-pi3CeIlySZhQoJVBh9O23PzrOuhnYI7OHqIbHjkn2VnQaEWvecO1x82Qr2Va_JjFywLKIOEV1Ob9Ofkeln2K89ny2mB-s7RLNvYAVzWNiQnp18_nQEUsvwACEXTYJ",
|
|
||||||
"owners_before": [
|
|
||||||
"2ePYHfV3yS3xTxF9EE3Xjo8zPwq2RmLPFAJGQqQKc3j6"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"id": "2d431073e1477f3073a4693ac7ff9be5634751de1b8abaa1f4e19548ef0b4b0e",
|
|
||||||
"version": 1
|
|
||||||
}]
|
|
||||||
|
|
||||||
:resheader Content-Type: ``application/json``
|
:resheader Content-Type: ``application/json``
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user