-
Notifications
You must be signed in to change notification settings - Fork 0
/
Multiple_owners.py
69 lines (53 loc) · 1.73 KB
/
Multiple_owners.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from bigchaindb_driver import BigchainDB
from bigchaindb_driver.crypto import generate_keypair
from bigchaindb_driver.exceptions import MissingPrivateKeyError
bdb_root_url = 'http://127.0.0.1:9984'
bdb = BigchainDB(bdb_root_url)
alice, bob = generate_keypair(), generate_keypair()
car_asset = {
'data': {
'car': {
'vin': '5YJRE11B781000196'
}
}
}
car_creation_tx = bdb.transactions.prepare(
operation='CREATE',
signers=(alice.public_key, bob.public_key),
recipients=(alice.public_key, bob.public_key),
asset=car_asset,
)
signed_car_creation_tx = bdb.transactions.fulfill(
car_creation_tx,
private_keys=[alice.private_key, bob.private_key],
)
sent_car_tx = bdb.transactions.send_commit(signed_car_creation_tx)
carol = generate_keypair()
output_index = 0
output = signed_car_creation_tx['outputs'][output_index]
input_ = {
'fulfillment': output['condition']['details'],
'fulfills': {
'output_index': output_index,
'transaction_id': signed_car_creation_tx['id'],
},
'owners_before': output['public_keys'],
}
print(input_)
transfer_asset = {'id': signed_car_creation_tx['id'], }
car_transfer_tx = bdb.transactions.prepare(
operation='TRANSFER',
recipients=carol.public_key,
asset=transfer_asset,
inputs=input_,
)
signed_car_transfer_tx = bdb.transactions.fulfill(
car_transfer_tx, private_keys=[alice.private_key, bob.private_key]
)
try:
signed_car_transfer_tx = bdb.transactions.fulfill(car_transfer_tx, private_keys=alice.private_key,)
except MissingPrivateKeyError as e:
print(e, e.__cause__, sep='\n')
print(bob.public_key)
sent_car_transfer_tx = bdb.transactions.send_commit(signed_car_transfer_tx)
print(sent_car_transfer_tx)