forked from hyperledger/iroha-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
transaction.py
108 lines (92 loc) · 3.69 KB
/
transaction.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
from protos.api_pb2 import Transaction, Asset
from enum import Enum
from datetime import datetime
class TransactionBuilder:
class AssetType(Enum):
ASSET = 1
DOMAIN = 2
ACCOUNT = 3
PEER = 4
SIMPLE_ASSET = 5
NONE = 6
def __init__(self, type, senderPublicKey, receiverPublicKey=""):
self.tx = Transaction()
self.type = type
self.senderPublicKey = senderPublicKey
self.receiverPublicKey = receiverPublicKey
self.txSignatures = []
self.object = {}
self.object_type = TransactionBuilder.AssetType.NONE
# for Transfer
def __init__(self, type, senderPublicKey, receiverPublicKey):
self.tx = Transaction()
self.type = type
self.senderPublicKey = senderPublicKey
self.receiverPublicKey = receiverPublicKey
self.txSignatures = []
self.object = {}
self.object_type = TransactionBuilder.AssetType.NONE
def add_txSignature(self, sig, hash_):
self.txSignatures.append([sig, hash_])
return self
def set_asset(self, asset_):
self.object_type = TransactionBuilder.AssetType.ASSET
self.object[self.object_type] = asset_
return self
def set_domain(self, domain_):
self.object_type = TransactionBuilder.AssetType.DOMAIN
self.object[self.object_type] = domain_
return self
def set_account(self, account_):
self.object_type = TransactionBuilder.AssetType.ACCOUNT
self.object[self.object_type] = account_
return self
def set_peer(self, peer_):
self.object_type = TransactionBuilder.AssetType.PEER
self.object[self.object_type] = peer_
return self
def set_simple_asset(self, simple_asset_):
self.object_type = TransactionBuilder.AssetType.SIMPLE_ASSET
self.object[self.object_type] = simple_asset_
return self
def set_receive_public_key(self, receiver_publicKey_):
self.receiverPublicKey = receiver_publicKey_
return self
# WIP
def build(self):
if self.object_type == TransactionBuilder.AssetType.ASSET:
return Transaction(
type=self.type,
senderPubkey=self.senderPublicKey,
receivePubkey=self.receiverPublicKey,
hash="", # This is WIP!! dangerous
timestamp=int(datetime.now().timestamp()),
asset=self.object[self.object_type]
)
elif self.object_type == TransactionBuilder.AssetType.ACCOUNT:
return Transaction(
type=self.type,
senderPubkey=self.senderPublicKey,
receivePubkey=self.receiverPublicKey,
hash="", # This is WIP!! dangerous
timestamp=int(datetime.now().timestamp()),
account=self.object[self.object_type]
)
elif self.object_type == TransactionBuilder.AssetType.DOMAIN:
return Transaction(
type=self.type,
senderPubkey=self.senderPublicKey,
receivePubkey=self.receiverPublicKey,
hash="", # This is WIP!! dangerous
timestamp=int(datetime.now().timestamp()),
domain=self.object[self.object_type]
)
elif self.object_type == TransactionBuilder.AssetType.SIMPLE_ASSET:
return Transaction(
type=self.type,
senderPubkey=self.senderPublicKey,
receivePubkey=self.receiverPublicKey,
hash="", # This is WIP!! dangerous
timestamp=int(datetime.now().timestamp()),
simpleAsset=self.object[self.object_type]
)