Skip to content

Commit 8d08a22

Browse files
author
abel
committed
(feat) Updated versions of proto files projects dependencies. Added support in Composer for MsgExecuteContractCompat. Added a new example script showing how to use it.
1 parent d7c435d commit 8d08a22

27 files changed

+1284
-281
lines changed

Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,19 @@ clean-all:
2828
$(call clean_repos)
2929

3030
clone-injective-core:
31-
git clone https://github.com/InjectiveLabs/injective-core.git -b v1.12.8-testnet --depth 1 --single-branch
31+
git clone https://github.com/InjectiveLabs/injective-core.git -b v1.12.9-testnet --depth 1 --single-branch
3232

3333
clone-injective-indexer:
34-
git clone https://github.com/InjectiveLabs/injective-indexer.git -b v1.12.67 --depth 1 --single-branch
34+
git clone https://github.com/InjectiveLabs/injective-indexer.git -b v1.12.72 --depth 1 --single-branch
3535

3636
clone-cometbft:
37-
git clone https://github.com/cometbft/cometbft.git -b v0.37.2 --depth 1 --single-branch
37+
git clone https://github.com/InjectiveLabs/cometbft.git -b v0.37.2-inj --depth 1 --single-branch
3838

3939
clone-wasmd:
40-
git clone https://github.com/InjectiveLabs/wasmd.git -b v0.40.2-inj --depth 1 --single-branch
40+
git clone https://github.com/InjectiveLabs/wasmd.git -b v0.45.0-inj --depth 1 --single-branch
4141

4242
clone-cosmos-sdk:
43-
git clone https://github.com/InjectiveLabs/cosmos-sdk.git -b v0.47.3-inj-6 --depth 1 --single-branch
43+
git clone https://github.com/InjectiveLabs/cosmos-sdk.git -b v0.47.3-inj-9 --depth 1 --single-branch
4444

4545
clone-ibc-go:
4646
git clone https://github.com/InjectiveLabs/ibc-go.git -b v7.2.0-inj --depth 1 --single-branch
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import asyncio
2+
import json
3+
4+
from grpc import RpcError
5+
6+
from pyinjective.async_client import AsyncClient
7+
from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT, GAS_PRICE
8+
from pyinjective.core.network import Network
9+
from pyinjective.transaction import Transaction
10+
from pyinjective.wallet import PrivateKey
11+
12+
13+
async def main() -> None:
14+
# select network: local, testnet, mainnet
15+
network = Network.testnet()
16+
17+
client = AsyncClient(network)
18+
composer = await client.composer()
19+
await client.sync_timeout_height()
20+
21+
# load account
22+
priv_key = PrivateKey.from_hex("f9db9bf330e23cb7839039e944adef6e9df447b90b503d5b4464c90bea9022f3")
23+
pub_key = priv_key.to_public_key()
24+
address = pub_key.to_address()
25+
await client.fetch_account(address.to_acc_bech32())
26+
27+
# prepare tx msg
28+
# NOTE: COIN MUST BE SORTED IN ALPHABETICAL ORDER BY DENOMS
29+
funds = (
30+
"69factory/inj1hdvy6tl89llqy3ze8lv6mz5qh66sx9enn0jxg6/inj12ngevx045zpvacus9s6anr258gkwpmthnz80e9,"
31+
"420peggy0x44C21afAaF20c270EBbF5914Cfc3b5022173FEB7,"
32+
"1peggy0x87aB3B4C8661e07D6372361211B96ed4Dc36B1B5"
33+
)
34+
35+
msg = composer.msg_execute_contract_compat(
36+
sender=address.to_acc_bech32(),
37+
contract="inj1ady3s7whq30l4fx8sj3x6muv5mx4dfdlcpv8n7",
38+
msg=json.dumps({"increment": {}}),
39+
funds=funds,
40+
)
41+
42+
# build sim tx
43+
tx = (
44+
Transaction()
45+
.with_messages(msg)
46+
.with_sequence(client.get_sequence())
47+
.with_account_num(client.get_number())
48+
.with_chain_id(network.chain_id)
49+
)
50+
sim_sign_doc = tx.get_sign_doc(pub_key)
51+
sim_sig = priv_key.sign(sim_sign_doc.SerializeToString())
52+
sim_tx_raw_bytes = tx.get_tx_data(sim_sig, pub_key)
53+
54+
# simulate tx
55+
try:
56+
sim_res = await client.simulate(sim_tx_raw_bytes)
57+
except RpcError as ex:
58+
print(ex)
59+
return
60+
61+
# build tx
62+
gas_price = GAS_PRICE
63+
gas_limit = int(sim_res["gasInfo"]["gasUsed"]) + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
64+
gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0")
65+
fee = [
66+
composer.Coin(
67+
amount=gas_price * gas_limit,
68+
denom=network.fee_denom,
69+
)
70+
]
71+
tx = tx.with_gas(gas_limit).with_fee(fee).with_memo("").with_timeout_height(client.timeout_height)
72+
sign_doc = tx.get_sign_doc(pub_key)
73+
sig = priv_key.sign(sign_doc.SerializeToString())
74+
tx_raw_bytes = tx.get_tx_data(sig, pub_key)
75+
76+
# broadcast tx: send_tx_async_mode, send_tx_sync_mode, send_tx_block_mode
77+
res = await client.broadcast_tx_sync_mode(tx_raw_bytes)
78+
print(res)
79+
print("gas wanted: {}".format(gas_limit))
80+
print("gas fee: {} INJ".format(gas_fee))
81+
82+
83+
if __name__ == "__main__":
84+
asyncio.get_event_loop().run_until_complete(main())

pyinjective/composer.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
params_pb2 as token_factory_params_pb,
3333
tx_pb2 as token_factory_tx_pb,
3434
)
35+
from pyinjective.proto.injective.wasmx.v1 import tx_pb2 as wasmx_tx_pb
3536

3637
REQUEST_TO_RESPONSE_TYPE_MAP = {
3738
"MsgCreateSpotLimitOrder": injective_exchange_tx_pb.MsgCreateSpotLimitOrderResponse,
@@ -1050,6 +1051,14 @@ def msg_change_admin(
10501051
new_admin=new_admin,
10511052
)
10521053

1054+
def msg_execute_contract_compat(self, sender: str, contract: str, msg: str, funds: str):
1055+
return wasmx_tx_pb.MsgExecuteContractCompat(
1056+
sender=sender,
1057+
contract=contract,
1058+
msg=msg,
1059+
funds=funds,
1060+
)
1061+
10531062
def chain_stream_bank_balances_filter(
10541063
self, accounts: Optional[List[str]] = None
10551064
) -> chain_stream_query.BankBalancesFilter:

pyinjective/proto/cosmwasm/wasm/v1/authz_pb2.py

Lines changed: 28 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)