-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactions.py
204 lines (173 loc) · 4.62 KB
/
actions.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
from rpc_call import rpc_call, converBigInt
import json
def send(frm, to, amt, cur):
resp = rpc_call('tx.CreateRawSend', {
"from": frm,
"to": to,
"amount": {
"currency": cur,
"value": converBigInt(amt),
},
"gasPrice": {
"currency": "OLT",
"value": "1000000000",
},
"gas": 40000,
})
return resp["result"]["rawTx"]
def create_domain(name, owner_hex, price):
req = {
"name": name,
"owner": owner_hex,
"account": owner_hex,
"buyingPrice": {
"currency": "OLT",
"value": converBigInt(price),
},
"gasPrice": {
"currency": "OLT",
"value": "1000000000",
},
"gas": 40000,
}
resp = rpc_call('tx.ONS_CreateRawCreate', req)
return resp["result"]["rawTx"]
def send_domain(name, frm, price):
resp = rpc_call('tx.ONS_CreateRawSend', {
"name": name,
"from": frm,
"amount": {
"currency": "OLT",
"value": converBigInt(price),
},
"gasPrice": {
"currency": "OLT",
"value": "1000000000",
},
"gas": 40000,
})
return resp["result"]["rawTx"]
def sell_domain(name, owner_hex, price):
resp = rpc_call('tx.ONS_CreateRawSale', {
"name": name,
"owner": owner_hex,
"price": {
"currency": "OLT",
"value": converBigInt(price),
},
"cancelSale": False,
"gasPrice": {
"currency": "OLT",
"value": "1000000000",
},
"gas": 40000,
})
return resp["result"]["rawTx"]
def cancel_sell_domain(name, owner_hex, price):
resp = rpc_call('tx.ONS_CreateRawSale', {
"name": name,
"owner": owner_hex,
"price": {
"currency": "OLT",
"value": converBigInt(price),
},
"cancelSale": True,
"gasPrice": {
"currency": "OLT",
"value": "1000000000",
},
"gas": 40000,
})
return resp["result"]["rawTx"]
def buy_domain(name, buyer, price):
resp = rpc_call('tx.ONS_CreateRawBuy', {
"name": name,
"buyer": buyer,
"account": buyer,
"offering": {
"currency": "OLT",
"value": converBigInt(price),
},
"gasPrice": {
"currency": "OLT",
"value": "1000000000",
},
"gas": 40000,
})
return resp["result"]["rawTx"]
def get_domain_on_sale():
resp = rpc_call('query.ONS_GetDomainOnSale', {'onSale': True})
return resp
def broadcast_commit(rawTx, signature, pub_key):
resp = rpc_call('broadcast.TxCommit', {
"rawTx": rawTx,
"signature": signature,
"publicKey": pub_key,
})
print resp
return resp["result"]
def broadcast_sync(rawTx, signature, pub_key):
resp = rpc_call('broadcast.TxSync', {
"rawTx": rawTx,
"signature": signature,
"publicKey": pub_key,
})
return resp["result"]
def get_domains(owner_hex, onsale):
req = {
"owner": owner_hex,
"onSale": onsale,
}
resp = rpc_call('query.ONS_GetDomainByOwner', req)
return resp["result"]["domains"]
def print_all_domains(owner_addr):
result = get_domains(owner_addr, False)
print json.dumps(result, indent=4)
print
def create_sub_domain(name, owner_hex, price, uri):
req = {
"owner": owner_hex,
"account": owner_hex,
"name": name,
"buyingprice": {
"currency": "OLT",
"value": converBigInt(price)
},
"uri": uri,
"gasprice": {
"currency": "OLT",
"value": "1000000000",
},
"gas": 400000,
}
resp = rpc_call('tx.ONS_CreateRawCreate', req)
return resp["result"]["rawTx"]
def delete_sub_domain(name, owner_hex):
req = {
"owner": owner_hex,
"name": name,
"gasprice": {
"currency": "OLT",
"value": "1000000000",
},
"gas": 400000,
}
resp = rpc_call('tx.ONS_CreateRawDeleteSub', req)
return resp["result"]["rawTx"]
def renew_domain(name, owner_hex, price):
req = {
"owner": owner_hex,
"name": name,
"account": owner_hex,
"buyingprice": {
"currency": "OLT",
"value": converBigInt(price)
},
"gasprice": {
"currency": "OLT",
"value": "1000000000",
},
"gas": 400000,
}
resp = rpc_call('tx.ONS_CreateRawRenew', req)
return resp["result"]["rawTx"]