-
Notifications
You must be signed in to change notification settings - Fork 0
/
registrar.py
51 lines (43 loc) · 2.32 KB
/
registrar.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
#coding=utf-8
import os, json,datetime, pytz
from eth_utils import decode_hex
from settings import *
address = '0x6090A6e47849629b7245Dfa1Ca21D94cd15878Ef'
abi = json.load(open(os.path.join(BASE_DIR, 'abi/registrar.json')))
registrar = web3.eth.contract(abi=abi, address=address)
def lookup(name):
name = decode_hex(web3.sha3(web3.toHex(name)))
return registrar.call().entries(name)
def get_allowed_time2(name):
name = decode_hex(web3.sha3(web3.toHex(name)))
ts = registrar.call().getAllowedTime(name)
return datetime.datetime.fromtimestamp(ts, tz=pytz.UTC)
def get_allowed_time(name):
name = decode_hex(web3.sha3(web3.toHex(name)))
return registrar.call().getAllowedTime(name)
def start_auction(name, account, gas=1000000, gas_price=''):
name = decode_hex(web3.sha3(web3.toHex(name)))
if not gas_price:
return registrar.transact({'from':account, 'gas':gas}).startAuction(name)
return registrar.transact({'from':account, 'gas':gas, 'gasPrice':gas_price}).startAuction(name)
def bid(name, account, price, disguise_price, secret, gas=1000000, gas_price=''):
name = decode_hex(web3.sha3(web3.toHex(name)))
secret = decode_hex(web3.sha3(web3.toHex(secret)))
price = web3.toWei(price, 'ether')
disguise_price = web3.toWei(disguise_price, 'ether')
sb = registrar.call().shaBid(name, account, price, secret)
if not gas_price:
return registrar.transact({'from':account, 'gas':gas, 'value':disguise_price}).newBid(sb)
return registrar.transact({'from':account, 'gas':gas, 'gasPrice':gas_price, 'value':disguise_price}).newBid(sb)
def unseal_bid(name, account, price, secret, gas=1000000, gas_price=''):
name = decode_hex(web3.sha3(web3.toHex(name)))
secret = decode_hex(web3.sha3(web3.toHex(secret)))
price = web3.toWei(price, 'ether')
if not gas_price:
return registrar.transact({'from':account, 'gas':gas}).unsealBid(name, price, secret)
return registrar.transact({'from':account, 'gas':gas, 'gasPrice':gas_price}).unsealBid(name, price, secret)
def finalize(name, account, gas=1000000, gas_price=''):
name = decode_hex(web3.sha3(web3.toHex(name)))
if not gas_price:
return registrar.transact({'from':account, 'gas':gas}).finalizeAuction(name)
return registrar.transact({'from':account, 'gas':gas, 'gasPrice':gas_price}).finalizeAuction(name)