This repository has been archived by the owner on Jul 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathterra_chain.py
62 lines (51 loc) · 1.65 KB
/
terra_chain.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
from terra_sdk.core.auth.data.tx import StdFee
from config import Config
from terra_sdk.client.lcd import AsyncLCDClient
import requests
class TerraChain:
chain = AsyncLCDClient(chain_id=Config._chain_id, url=Config._chain_url)
@staticmethod
async def estimate_fee(wallet_address, msgs, usd_gas_price = None):
fees = None
try:
if usd_gas_price is None:
usd_gas_price = TerraChain.get_gas_price()
fees = await TerraChain.chain.tx.estimate_fee(
wallet_address,
msgs,
"",
None,
gas_prices={"uusd": usd_gas_price},
gas_adjustment=1.8,
fee_denoms=["uusd"],
)
else:
fees = StdFee(
1000000,
{"uusd": int(usd_gas_price * 1000000)},
)
except Exception as e:
Config._log.exception(e)
fees = None
return fees
@staticmethod
def get_trx_url(txhash):
try:
return "{}/{}/tx/{}".format(
Config._finder_base_url,
TerraChain.chain.chain_id,
txhash,
)
except Exception as e:
Config._log.exception(e)
@staticmethod
def get_gas_price():
gas_price = 2
try:
url = "https://fcd.terra.dev/v1/txs/gas_prices"
res = requests.get(url)
gas_price = res.json()["uusd"]
except Exception as e:
Config._log.exception(e)
gas_price = 2
return gas_price