mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
GET /votes examples -> samples
This commit is contained in:
@@ -5,9 +5,11 @@ import os
|
||||
import os.path
|
||||
|
||||
from bigchaindb.common.transaction import Transaction, Input, TransactionLink
|
||||
from bigchaindb.core import Bigchain
|
||||
from bigchaindb.models import Block
|
||||
|
||||
|
||||
|
||||
TPLS = {}
|
||||
|
||||
|
||||
@@ -80,6 +82,7 @@ Host: example.com
|
||||
|
||||
"""
|
||||
|
||||
|
||||
TPLS['get-statuses-tx-invalid-response'] = """\
|
||||
HTTP/1.1 200 OK
|
||||
Content-Type: application/json
|
||||
@@ -107,6 +110,7 @@ Host: example.com
|
||||
|
||||
"""
|
||||
|
||||
|
||||
TPLS['get-block-response'] = """\
|
||||
HTTP/1.1 200 OK
|
||||
Content-Type: application/json
|
||||
@@ -114,12 +118,14 @@ Content-Type: application/json
|
||||
%(block)s
|
||||
"""
|
||||
|
||||
|
||||
TPLS['get-block-txid-request'] = """\
|
||||
GET /blocks?tx_id=%(txid)s HTTP/1.1
|
||||
Host: example.com
|
||||
|
||||
"""
|
||||
|
||||
|
||||
TPLS['get-block-txid-response'] = """\
|
||||
HTTP/1.1 200 OK
|
||||
Content-Type: application/json
|
||||
@@ -128,8 +134,25 @@ Content-Type: application/json
|
||||
"""
|
||||
|
||||
|
||||
TPLS['get-vote-request'] = """\
|
||||
GET /votes?block_id=%(blockid)s HTTP/1.1
|
||||
Host: example.com
|
||||
|
||||
"""
|
||||
|
||||
|
||||
TPLS['get-vote-response'] = """\
|
||||
HTTP/1.1 200 OK
|
||||
Content-Type: application/json
|
||||
|
||||
[%(vote)s]
|
||||
"""
|
||||
|
||||
|
||||
def main():
|
||||
""" Main function """
|
||||
|
||||
# tx create
|
||||
privkey = 'CfdqtD7sS7FgkMoGPXw55MVGGFwQLAoHYTcBhZDtF99Z'
|
||||
pubkey = '4K9sWUMFwTgaDGPfdynrbxWqWS6sWmKbZoTjxLtVUibD'
|
||||
asset = {'msg': 'Hello BigchainDB!'}
|
||||
@@ -137,6 +160,7 @@ def main():
|
||||
tx = tx.sign([privkey])
|
||||
tx_json = json.dumps(tx.to_dict(), indent=2, sort_keys=True)
|
||||
|
||||
# tx transfer
|
||||
privkey_transfer = '3AeWpPdhEZzWLYfkfYHBfMFC2r1f8HEaGS9NtbbKssya'
|
||||
pubkey_transfer = '3yfQPHeWAa1MxTX9Zf9176QqcpcnWcanVZZbaHb8B3h9'
|
||||
|
||||
@@ -159,6 +183,7 @@ def main():
|
||||
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)
|
||||
|
||||
# block
|
||||
node = "ErEeVZt8AfLbMJub25tjNxbpzzTNp3mGidL3GxGdd9bt"
|
||||
signature = "53wxrEQDYk1dXzmvNSytbCfmNVnPqPkDQaTnAe8Jf43s6ssejPxezkCvUnGTnduNUmaLjhaan1iRLi3peu6s5DzA"
|
||||
block = Block(transactions=[tx], node_pubkey=node, voters=[node], signature=signature)
|
||||
@@ -167,6 +192,12 @@ def main():
|
||||
base_path = os.path.join(os.path.dirname(__file__),
|
||||
'source/drivers-clients/samples')
|
||||
|
||||
# vote
|
||||
DUMMY_SHA3 = '0123456789abcdef' * 4
|
||||
b = Bigchain(public_key=node)
|
||||
vote = b.vote(block.id, DUMMY_SHA3, True)
|
||||
vote_json = json.dumps(vote, indent=2, sort_keys=True)
|
||||
|
||||
if not os.path.exists(base_path):
|
||||
os.makedirs(base_path)
|
||||
|
||||
@@ -182,7 +213,8 @@ def main():
|
||||
'public_keys_transfer': tx_transfer.outputs[0].public_keys[0],
|
||||
'public_keys_transfer_last': tx_transfer_last.outputs[0].public_keys[0],
|
||||
'block': block_json,
|
||||
'blockid': block.id}
|
||||
'blockid': block.id,
|
||||
'vote': vote_json}
|
||||
with open(path, 'w') as handle:
|
||||
handle.write(code)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user