bigchaindb / bigchaindb-driver

Official Python driver for BigchainDB
https://www.bigchaindb.com
Apache License 2.0
105 stars 104 forks source link

Handcrafting guide broken for several snippets #314

Closed muawiakh closed 7 years ago

muawiakh commented 7 years ago

Description

Handcrafting guide seems to be broken. I tried to follow the steps but ran into multiple issues one of those is #313.

A lot of code snippets are broken as well and I haven't been able to send prepare, fulfil and send a transaction that turns out to be valid. All the transactions that I try to make after adding workarounds(mentioned in #313) go into the backlog state.

What I Did

Follow the Handcrafting Transactions(from github master))

Also tried the [Handcrafting Transactions(from website)]

One of the snippets that doesn't work is, there are multiple other instances of this captured in #313:

Section: The Fulfilled Transaction

Snippet: In a nutshell

import json

import base58
import sha3
from cryptoconditions import Ed25519Sha256

from bigchaindb_driver.crypto import generate_keypair

alice = generate_keypair()

operation = 'CREATE'

version = '1.0'

asset = {
    'data': {
        'bicycle': {
            'manufacturer': 'bkfab',
            'serial_number': 'abcd1234',
        },
    },
}

metadata = {'planet': 'earth'}

ed25519 = Ed25519Sha256(public_key=base58.b58decode(alice.public_key))

output = {
    'amount': '1',
    'condition': {
        'details': {
            'type': ed25519.TYPE_NAME,
            'public_key': base58.b58encode(ed25519.public_key),
        },
        'uri': ed25519.condition_uri,
    },
    'public_keys': (alice.public_key,),
}
outputs = (output,)

input_ = {
    'fulfillment': None,
    'fulfills': None,
    'owners_before': (alice.public_key,)
}
inputs = (input_,)

handcrafted_creation_tx = {
    'asset': asset,
    'metadata': metadata,
    'operation': operation,
    'outputs': outputs,
    'inputs': inputs,
    'version': version,
}

json_str_tx = json.dumps(
    handcrafted_creation_tx,
    sort_keys=True,
    separators=(',', ':'),
    ensure_ascii=False,
)

creation_txid = sha3.sha3_256(json_str_tx.encode()).hexdigest()

handcrafted_creation_tx['id'] = creation_txid

message = json.dumps(
    handcrafted_creation_tx,
    sort_keys=True,
    separators=(',', ':'),
    ensure_ascii=False,
)

ed25519.sign(message.encode(), base58.b58decode(alice.private_key))

fulfillment_uri = ed25519.serialize_uri()

handcrafted_creation_tx['inputs'][0]['fulfillment'] = fulfillment_uri
muawiakh commented 7 years ago

I verified the guide on two different setups and it seems like I had some packaging/versioning issue with some python modules(on the setup that I was using). The guide works fine with the current set of instructions. Verified it. Closing the ticket.