Skip to content

Commit

Permalink
wip - update htx
Browse files Browse the repository at this point in the history
  • Loading branch information
sbellem committed Jul 7, 2017
1 parent 52ef82b commit 1e83fed
Showing 1 changed file with 51 additions and 30 deletions.
81 changes: 51 additions & 30 deletions docs/handcraft.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1452,14 +1452,24 @@ Generate the output condition:

In [0]: threshold_sha256.add_subfulfillment(bob_ed25519)

In [0]: unsigned_subfulfillments_dict = threshold_sha256.to_dict()

In [0]: condition_uri = threshold_sha256.condition.serialize_uri()

In [0]: condition_details = {
...: 'subconditions': [
...: {'type': s['body'].TYPE_NAME,
...: 'public_key': base58.b58encode(s['body'].public_key)}
...: for s in threshold_sha256.subconditions
...: if (s['type'] == 'fulfillment' and
...: s['body'].TYPE_NAME == 'ed25519-sha-256')
...: ],
...: 'threshold': threshold_sha256.threshold,
...: 'type': threshold_sha256.TYPE_NAME,
...: }

In [0]: output = {
...: 'amount': '1',
...: 'condition': {
...: 'details': unsigned_subfulfillments_dict,
...: 'details': condition_details,
...: 'uri': condition_uri,
...: },
...: 'public_keys': (alice.public_key, bob.public_key),
Expand All @@ -1479,7 +1489,7 @@ Generate the output condition:

In [0]: alt_threshold_sha256.condition.serialize_uri() == condition_uri

The ``details`` on the other hand holds the associated fulfillments not yet
The ``details`` on the other hand hold the associated fulfillments not yet
fulfilled.

The yet to be fulfilled input:
Expand Down Expand Up @@ -1563,7 +1573,10 @@ The transfer to Carol:

In [0]: carol_ed25519 = Ed25519Sha256(public_key=base58.b58decode(carol.public_key))

In [0]: unsigned_fulfillments_dict = carol_ed25519.to_dict()
In [0]: unsigned_fulfillments_dict = {
...: 'type': carol_ed25519.TYPE_NAME,
...: 'public_key': base58.b58encode(carol_ed25519.public_key),
...: }

In [0]: condition_uri = carol_ed25519.condition.serialize_uri()

Expand All @@ -1584,7 +1597,7 @@ The yet to be fulfilled input:
...: 'fulfillment': None,
...: 'fulfills': {
...: 'transaction_id': handcrafted_car_creation_tx['id'],
...: 'output': 0,
...: 'output_index': 0,
...: },
...: 'owners_before': (alice.public_key, bob.public_key),
...: }
Expand Down Expand Up @@ -1637,18 +1650,16 @@ Sign the transaction:

In [0]: threshold_sha256 = ThresholdSha256(threshold=2)

In [0]: alice_ed25519.sign(message=message.encode(),
private_key=base58.b58decode(alice.private_key))

In [0]: bob_ed25519.sign(message=message.encode(),
private_key=base58.b58decode(bob.private_key))

In [0]: threshold_sha256.add_subfulfillment(alice_ed25519)

In [0]: threshold_sha256.add_subfulfillment(bob_ed25519)

In [102]: alice_condition = threshold_sha256.get_subcondition_from_vk(base58.b58decode(alice.public_key))[0]

In [103]: bob_condition = threshold_sha256.get_subcondition_from_vk(base58.b58decode(bob.public_key))[0]

In [106]: alice_condition.sign(message.encode(), private_key=base58.b58decode(alice.private_key))

In [107]: bob_condition.sign(message.encode(), private_key=base58.b58decode(bob.private_key))

In [0]: fulfillment_uri = threshold_sha256.serialize_uri()

In [0]: handcrafted_car_transfer_tx['inputs'][0]['fulfillment'] = fulfillment_uri
Expand Down Expand Up @@ -1703,17 +1714,27 @@ Handcrafting the ``'CREATE'`` transaction
# CRYPTO-CONDITIONS: add bob ed25519 to the threshold SHA 256 condition
threshold_sha256.add_subfulfillment(bob_ed25519)
# CRYPTO-CONDITIONS: get the unsigned fulfillment dictionary (details)
unsigned_subfulfillments_dict = threshold_sha256.to_dict()
# CRYPTO-CONDITIONS: generate the condition uri
condition_uri = threshold_sha256.condition.serialize_uri()
# CRYPTO-CONDITIONS: get the unsigned fulfillment dictionary (details)
condition_details = {
'subconditions': [
{'type': s['body'].TYPE_NAME,
'public_key': base58.b58encode(s['body'].public_key)}
for s in threshold_sha256.subconditions
if (s['type'] == 'fulfillment' and
s['body'].TYPE_NAME == 'ed25519-sha-256')
],
'threshold': threshold_sha256.threshold,
'type': threshold_sha256.TYPE_NAME,
}
output = {
'amount': '1',
'condition': {
'details': unsigned_subfulfillments_dict,
'details': condition_details,
'uri': threshold_sha256.condition_uri,
},
'public_keys': (alice.public_key, bob.public_key),
Expand Down Expand Up @@ -1801,7 +1822,10 @@ Handcrafting the ``'TRANSFER'`` transaction
carol_ed25519 = Ed25519Sha256(public_key=base58.b58decode(carol.public_key))
unsigned_fulfillments_dict = carol_ed25519.to_dict()
unsigned_fulfillments_dict = {
'type': carol_ed25519.TYPE_NAME,
'public_key': base58.b58encode(carol_ed25519.public_key),
}
condition_uri = carol_ed25519.condition.serialize_uri()
Expand All @@ -1819,15 +1843,15 @@ Handcrafting the ``'TRANSFER'`` transaction
'fulfillment': None,
'fulfills': {
'transaction_id': handcrafted_car_creation_tx['id'],
'output': 0,
'output_index': 0,
},
'owners_before': (alice.public_key, bob.public_key),
}
# Craft the payload:
handcrafted_car_transfer_tx = {
'operation': 'TRANSFER',
'asset': {'id': car_asset['id']},
'asset': {'id': handcrafted_car_creation_tx['id']},
'metadata': None,
'outputs': (output,),
'inputs': (input_,),
Expand Down Expand Up @@ -1857,18 +1881,15 @@ Handcrafting the ``'TRANSFER'`` transaction
threshold_sha256 = ThresholdSha256(threshold=2)
alice_ed25519.sign(message=message.encode(),
private_key=base58.b58decode(alice.private_key))
bob_ed25519.sign(message=message.encode(),
private_key=base58.b58decode(bob.private_key))
threshold_sha256.add_subfulfillment(alice_ed25519)
threshold_sha256.add_subfulfillment(bob_ed25519)
alice_condition = threshold_sha256.get_subcondition_from_vk(base58.b58decode(alice.public_key))[0]
bob_condition = threshold_sha256.get_subcondition_from_vk(base58.b58decode(bob.public_key))[0]
alice_condition.sign(message.encode(), private_key=base58.b58decode(alice.private_key))
bob_condition.sign(message.encode(), private_key=base58.b58decode(bob.private_key))
fulfillment_uri = threshold_sha256.serialize_uri()
handcrafted_car_transfer_tx['inputs'][0]['fulfillment'] = fulfillment_uri
Expand Down

0 comments on commit 1e83fed

Please sign in to comment.