forked from 0rtis/dfktools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquest_example.py
More file actions
61 lines (47 loc) · 2.54 KB
/
quest_example.py
File metadata and controls
61 lines (47 loc) · 2.54 KB
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
import logging
import sys
import time
from web3 import Web3
from quest import foraging
from quest import fishing
from quest import gardening
from quest.quest import Quest
from quest.utils import utils as quest_utils
import dex.master_gardener
ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'
if __name__ == "__main__":
log_format = '%(asctime)s|%(name)s|%(levelname)s: %(message)s'
logger = logging.getLogger("DFK-quest")
logger.setLevel(logging.DEBUG)
logging.basicConfig(level=logging.INFO, format=log_format, stream=sys.stdout)
rpc_server = 'https://api.harmony.one'
logger.info("Using RPC server " + rpc_server)
private_key = None # set private key
gas_price_gwei = 15
tx_timeout = 30
w3 = Web3(Web3.HTTPProvider(rpc_server))
account_address = w3.eth.account.privateKeyToAccount(private_key).address
quest = Quest(rpc_server, logger)
quest_contract = fishing.QUEST_CONTRACT_ADDRESS # foraging.CONTRACT_ADDRESS
my_heroes_id = [1, 2, 3, 4]
quest.start_quest(quest_contract, my_heroes_id, 3, private_key, w3.eth.getTransactionCount(account_address), gas_price_gwei, tx_timeout)
quest_info = quest_utils.human_readable_quest(quest.get_hero_quest(my_heroes_id[0]))
logger.info(
"Waiting " + str(quest_info['completeAtTime'] - time.time()) + " secs to complete quest " + str(quest_info))
while time.time() < quest_info['completeAtTime']:
time.sleep(2)
tx_receipt = quest.complete_quest(my_heroes_id[0], private_key, w3.eth.getTransactionCount(account_address), gas_price_gwei, tx_timeout)
quest_result = quest.parse_complete_quest_receipt(tx_receipt)
logger.info("Rewards: " + str(quest_result))
# gardening quest
pool_id = 0 # See gardens.master_gardener
quest_data = (pool_id, 0, 0, 0, 0, 0, '', '', ZERO_ADDRESS, ZERO_ADDRESS, ZERO_ADDRESS, ZERO_ADDRESS)
my_gardener_heroes_id = [5]
quest.start_quest_with_data(gardening.QUEST_CONTRACT_ADDRESS, quest_data, my_gardener_heroes_id, 1, private_key, w3.eth.getTransactionCount(account_address), gas_price_gwei, tx_timeout)
quest_info = quest_utils.human_readable_quest(quest.get_hero_quest(my_heroes_id[0]))
logger.info(
"Waiting " + str(quest_info['completeAtTime'] - time.time()) + " secs to complete gardening quest " + str(quest_info))
while time.time() < quest_info['completeAtTime']:
time.sleep(2)
quest.complete_quest(my_gardener_heroes_id[0], private_key, w3.eth.getTransactionCount(account_address),
gas_price_gwei, tx_timeout)