Skip to content

Commit 11958d8

Browse files
Merge pull request #163 from InjectiveLabs/f/refactor_examples
F/refactor examples
2 parents 8d487af + aeff5e3 commit 11958d8

34 files changed

+142
-593
lines changed

examples/chain_client/0_LocalOrderHash.py

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,3 @@
1-
# Copyright 2022 Injective Labs
2-
#
3-
# Licensed under the Apache License, Version 2.0 (the "License");
4-
# you may not use this file except in compliance with the License.
5-
# You may obtain a copy of the License at
6-
#
7-
# http://www.apache.org/licenses/LICENSE-2.0
8-
#
9-
# Unless required by applicable law or agreed to in writing, software
10-
# distributed under the License is distributed on an "AS IS" BASIS,
11-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-
# See the License for the specific language governing permissions and
13-
# limitations under the License.
141
import asyncio
152
import logging
163

@@ -31,9 +18,10 @@ async def main() -> None:
3118
await client.sync_timeout_height()
3219

3320
# load account
34-
priv_key = PrivateKey.from_hex("5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e")
21+
priv_key = PrivateKey.from_hex("f9db9bf330e23cb7839039e944adef6e9df447b90b503d5b4464c90bea9022f3")
3522
pub_key = priv_key.to_public_key()
36-
address = await pub_key.to_address().async_init_num_seq(network.lcd_endpoint)
23+
address = pub_key.to_address()
24+
account = await client.get_account(address.to_acc_bech32())
3725
subaccount_id = address.get_subaccount_id(index=0)
3826
subaccount_id_2 = address.get_subaccount_id(index=1)
3927

@@ -44,8 +32,8 @@ async def main() -> None:
4432
)
4533

4634
# prepare trade info
47-
spot_market_id = "0xa508cb32923323679f29a032c70342c147c17d0145625922b0ef22e955c844c0"
48-
deriv_market_id = "0x4ca0f92fc28be0c9761326016b5a1a2177dd6375558365116b5bdda9abc229ce"
35+
spot_market_id = "0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe"
36+
deriv_market_id = "0x90e662193fa29a3a7e6c07be4407c94833e762d9ee82136a2cc712d6b87d7de3"
4937
fee_recipient = "inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r"
5038

5139
spot_orders = [
@@ -113,8 +101,8 @@ async def main() -> None:
113101
tx = (
114102
Transaction()
115103
.with_messages(spot_msg, deriv_msg)
116-
.with_sequence(address.get_sequence())
117-
.with_account_num(address.get_number())
104+
.with_sequence(client.get_sequence())
105+
.with_account_num(client.get_number())
118106
.with_chain_id(network.chain_id)
119107
)
120108
sim_sign_doc = tx.get_sign_doc(pub_key)
@@ -157,8 +145,8 @@ async def main() -> None:
157145
tx = (
158146
Transaction()
159147
.with_messages(spot_msg, deriv_msg)
160-
.with_sequence(address.get_sequence())
161-
.with_account_num(address.get_number())
148+
.with_sequence(client.get_sequence())
149+
.with_account_num(client.get_number())
162150
.with_chain_id(network.chain_id)
163151
)
164152
sim_sign_doc = tx.get_sign_doc(pub_key)
@@ -255,8 +243,8 @@ async def main() -> None:
255243
tx = (
256244
Transaction()
257245
.with_messages(spot_msg, deriv_msg)
258-
.with_sequence(address.get_sequence())
259-
.with_account_num(address.get_number())
246+
.with_sequence(client.get_sequence())
247+
.with_account_num(client.get_number())
260248
.with_chain_id(network.chain_id)
261249
)
262250
sim_sign_doc = tx.get_sign_doc(pub_key)

examples/chain_client/13_MsgIncreasePositionMargin.py

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
1-
# Copyright 2022 Injective Labs
2-
#
3-
# Licensed under the Apache License, Version 2.0 (the "License");
4-
# you may not use this file except in compliance with the License.
5-
# You may obtain a copy of the License at
6-
#
7-
# http://www.apache.org/licenses/LICENSE-2.0
8-
#
9-
# Unless required by applicable law or agreed to in writing, software
10-
# distributed under the License is distributed on an "AS IS" BASIS,
11-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-
# See the License for the specific language governing permissions and
13-
# limitations under the License.
14-
151
import asyncio
162
import logging
173

@@ -34,11 +20,12 @@ async def main() -> None:
3420
# load account
3521
priv_key = PrivateKey.from_hex("f9db9bf330e23cb7839039e944adef6e9df447b90b503d5b4464c90bea9022f3")
3622
pub_key = priv_key.to_public_key()
37-
address = await pub_key.to_address().async_init_num_seq(network.lcd_endpoint)
23+
address = pub_key.to_address()
24+
account = await client.get_account(address.to_acc_bech32())
3825
subaccount_id = address.get_subaccount_id(index=0)
3926

4027
# prepare trade info
41-
market_id = "0x4ca0f92fc28be0c9761326016b5a1a2177dd6375558365116b5bdda9abc229ce"
28+
market_id = "0x90e662193fa29a3a7e6c07be4407c94833e762d9ee82136a2cc712d6b87d7de3"
4229

4330
# prepare tx msg
4431
msg = composer.MsgIncreasePositionMargin(
@@ -53,8 +40,8 @@ async def main() -> None:
5340
tx = (
5441
Transaction()
5542
.with_messages(msg)
56-
.with_sequence(address.get_sequence())
57-
.with_account_num(address.get_number())
43+
.with_sequence(client.get_sequence())
44+
.with_account_num(client.get_number())
5845
.with_chain_id(network.chain_id)
5946
)
6047
sim_sign_doc = tx.get_sign_doc(pub_key)

examples/chain_client/15_MsgWithdraw.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ async def main() -> None:
3434
# load account
3535
priv_key = PrivateKey.from_hex("f9db9bf330e23cb7839039e944adef6e9df447b90b503d5b4464c90bea9022f3")
3636
pub_key = priv_key.to_public_key()
37-
address = await pub_key.to_address().async_init_num_seq(network.lcd_endpoint)
37+
address = pub_key.to_address()
38+
account = await client.get_account(address.to_acc_bech32())
3839
subaccount_id = address.get_subaccount_id(index=0)
3940

4041
# prepare tx msg
@@ -49,8 +50,8 @@ async def main() -> None:
4950
tx = (
5051
Transaction()
5152
.with_messages(msg)
52-
.with_sequence(address.get_sequence())
53-
.with_account_num(address.get_number())
53+
.with_sequence(client.get_sequence())
54+
.with_account_num(client.get_number())
5455
.with_chain_id(network.chain_id)
5556
)
5657
sim_sign_doc = tx.get_sign_doc(pub_key)

examples/chain_client/16_MsgSubaccountTransfer.py

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
1-
# Copyright 2022 Injective Labs
2-
#
3-
# Licensed under the Apache License, Version 2.0 (the "License");
4-
# you may not use this file except in compliance with the License.
5-
# You may obtain a copy of the License at
6-
#
7-
# http://www.apache.org/licenses/LICENSE-2.0
8-
#
9-
# Unless required by applicable law or agreed to in writing, software
10-
# distributed under the License is distributed on an "AS IS" BASIS,
11-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-
# See the License for the specific language governing permissions and
13-
# limitations under the License.
14-
151
import asyncio
162
import logging
173

@@ -34,7 +20,8 @@ async def main() -> None:
3420
# load account
3521
priv_key = PrivateKey.from_hex("f9db9bf330e23cb7839039e944adef6e9df447b90b503d5b4464c90bea9022f3")
3622
pub_key = priv_key.to_public_key()
37-
address = await pub_key.to_address().async_init_num_seq(network.lcd_endpoint)
23+
address = pub_key.to_address()
24+
account = await client.get_account(address.to_acc_bech32())
3825
subaccount_id = address.get_subaccount_id(index=0)
3926
dest_subaccount_id = address.get_subaccount_id(index=1)
4027

@@ -51,8 +38,8 @@ async def main() -> None:
5138
tx = (
5239
Transaction()
5340
.with_messages(msg)
54-
.with_sequence(address.get_sequence())
55-
.with_account_num(address.get_number())
41+
.with_sequence(client.get_sequence())
42+
.with_account_num(client.get_number())
5643
.with_chain_id(network.chain_id)
5744
)
5845
sim_sign_doc = tx.get_sign_doc(pub_key)

examples/chain_client/17_MsgBatchUpdateOrders.py

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
1-
# Copyright 2022 Injective Labs
2-
#
3-
# Licensed under the Apache License, Version 2.0 (the "License");
4-
# you may not use this file except in compliance with the License.
5-
# You may obtain a copy of the License at
6-
#
7-
# http://www.apache.org/licenses/LICENSE-2.0
8-
#
9-
# Unless required by applicable law or agreed to in writing, software
10-
# distributed under the License is distributed on an "AS IS" BASIS,
11-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-
# See the License for the specific language governing permissions and
13-
# limitations under the License.
14-
151
import asyncio
162
import logging
173

@@ -34,22 +20,20 @@ async def main() -> None:
3420
# load account
3521
priv_key = PrivateKey.from_hex("f9db9bf330e23cb7839039e944adef6e9df447b90b503d5b4464c90bea9022f3")
3622
pub_key = priv_key.to_public_key()
37-
address = await pub_key.to_address().async_init_num_seq(network.lcd_endpoint)
23+
address = pub_key.to_address()
24+
account = await client.get_account(address.to_acc_bech32())
3825
subaccount_id = address.get_subaccount_id(index=0)
3926

4027
# prepare trade info
4128
fee_recipient = "inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r"
4229

43-
derivative_market_id_create = "0x4ca0f92fc28be0c9761326016b5a1a2177dd6375558365116b5bdda9abc229ce"
44-
spot_market_id_create = "0xa508cb32923323679f29a032c70342c147c17d0145625922b0ef22e955c844c0"
45-
46-
derivative_market_id_cancel = "0x1f73e21972972c69c03fb105a5864592ac2b47996ffea3c500d1ea2d20138717"
47-
derivative_market_id_cancel_2 = "0x8158e603fb80c4e417696b0e98765b4ca89dcf886d3b9b2b90dc15bfb1aebd51"
48-
spot_market_id_cancel = "0x74b17b0d6855feba39f1f7ab1e8bad0363bd510ee1dcc74e40c2adfe1502f781"
49-
spot_market_id_cancel_2 = "0x01edfab47f124748dc89998eb33144af734484ba07099014594321729a0ca16b"
30+
derivative_market_id_create = "0x90e662193fa29a3a7e6c07be4407c94833e762d9ee82136a2cc712d6b87d7de3"
31+
spot_market_id_create = "0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe"
5032

51-
spot_market_ids_to_cancel_all =['0x28f3c9897e23750bf653889224f93390c467b83c86d736af79431958fff833d1', '0xe8bf0467208c24209c1cf0fd64833fa43eb6e8035869f9d043dbff815ab76d01']
52-
derivative_market_ids_to_cancel_all = ['0x4ca0f92fc28be0c9761326016b5a1a2177dd6375558365116b5bdda9abc229ce', '0x979731deaaf17d26b2e256ad18fecd0ac742b3746b9ea5382bac9bd0b5e58f74']
33+
derivative_market_id_cancel = "0xd5e4b12b19ecf176e4e14b42944731c27677819d2ed93be4104ad7025529c7ff"
34+
derivative_market_id_cancel_2 = "0x90e662193fa29a3a7e6c07be4407c94833e762d9ee82136a2cc712d6b87d7de3"
35+
spot_market_id_cancel = "0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe"
36+
spot_market_id_cancel_2 = "0x7a57e705bb4e09c88aecfc295569481dbf2fe1d5efe364651fbe72385938e9b0"
5337

5438
derivative_orders_to_cancel = [
5539
composer.OrderData(
@@ -124,21 +108,18 @@ async def main() -> None:
124108
# prepare tx msg
125109
msg = composer.MsgBatchUpdateOrders(
126110
sender=address.to_acc_bech32(),
127-
subaccount_id=subaccount_id,
128111
derivative_orders_to_create=derivative_orders_to_create,
129112
spot_orders_to_create=spot_orders_to_create,
130113
derivative_orders_to_cancel=derivative_orders_to_cancel,
131-
spot_orders_to_cancel=spot_orders_to_cancel,
132-
spot_market_ids_to_cancel_all=spot_market_ids_to_cancel_all,
133-
derivative_market_ids_to_cancel_all=derivative_market_ids_to_cancel_all,
114+
spot_orders_to_cancel=spot_orders_to_cancel
134115
)
135116

136117
# build sim tx
137118
tx = (
138119
Transaction()
139120
.with_messages(msg)
140-
.with_sequence(address.get_sequence())
141-
.with_account_num(address.get_number())
121+
.with_sequence(client.get_sequence())
122+
.with_account_num(client.get_number())
142123
.with_chain_id(network.chain_id)
143124
)
144125
sim_sign_doc = tx.get_sign_doc(pub_key)

examples/chain_client/18_MsgBid.py

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
1-
# Copyright 2022 Injective Labs
2-
#
3-
# Licensed under the Apache License, Version 2.0 (the "License");
4-
# you may not use this file except in compliance with the License.
5-
# You may obtain a copy of the License at
6-
#
7-
# http://www.apache.org/licenses/LICENSE-2.0
8-
#
9-
# Unless required by applicable law or agreed to in writing, software
10-
# distributed under the License is distributed on an "AS IS" BASIS,
11-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-
# See the License for the specific language governing permissions and
13-
# limitations under the License.
14-
151
import asyncio
162
import logging
173

@@ -33,7 +19,8 @@ async def main() -> None:
3319
# load account
3420
priv_key = PrivateKey.from_hex("f9db9bf330e23cb7839039e944adef6e9df447b90b503d5b4464c90bea9022f3")
3521
pub_key = priv_key.to_public_key()
36-
address = await pub_key.to_address().async_init_num_seq(network.lcd_endpoint)
22+
address = pub_key.to_address()
23+
account = await client.get_account(address.to_acc_bech32())
3724

3825
# prepare tx msg
3926
msg = composer.MsgBid(
@@ -46,8 +33,8 @@ async def main() -> None:
4633
tx = (
4734
Transaction()
4835
.with_messages(msg)
49-
.with_sequence(address.get_sequence())
50-
.with_account_num(address.get_number())
36+
.with_sequence(client.get_sequence())
37+
.with_account_num(client.get_number())
5138
.with_chain_id(network.chain_id)
5239
)
5340
sim_sign_doc = tx.get_sign_doc(pub_key)

examples/chain_client/19_MsgGrant.py

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
1-
# Copyright 2022 Injective Labs
2-
#
3-
# Licensed under the Apache License, Version 2.0 (the "License");
4-
# you may not use this file except in compliance with the License.
5-
# You may obtain a copy of the License at
6-
#
7-
# http://www.apache.org/licenses/LICENSE-2.0
8-
#
9-
# Unless required by applicable law or agreed to in writing, software
10-
# distributed under the License is distributed on an "AS IS" BASIS,
11-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-
# See the License for the specific language governing permissions and
13-
# limitations under the License.
14-
151
import asyncio
162
import logging
173

@@ -32,9 +18,10 @@ async def main() -> None:
3218
await client.sync_timeout_height()
3319

3420
# load account
35-
priv_key = PrivateKey.from_hex("5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e")
21+
priv_key = PrivateKey.from_hex("f9db9bf330e23cb7839039e944adef6e9df447b90b503d5b4464c90bea9022f3")
3622
pub_key = priv_key.to_public_key()
37-
address = await pub_key.to_address().async_init_num_seq(network.lcd_endpoint)
23+
address = pub_key.to_address()
24+
account = await client.get_account(address.to_acc_bech32())
3825
subaccount_id = address.get_subaccount_id(index=0)
3926
market_ids = ["0x0511ddc4e6586f3bfe1acb2dd905f8b8a82c97e1edaef654b12ca7e6031ca0fa"]
4027

@@ -62,8 +49,8 @@ async def main() -> None:
6249
tx = (
6350
Transaction()
6451
.with_messages(msg)
65-
.with_sequence(address.get_sequence())
66-
.with_account_num(address.get_number())
52+
.with_sequence(client.get_sequence())
53+
.with_account_num(client.get_number())
6754
.with_chain_id(network.chain_id)
6855
)
6956
sim_sign_doc = tx.get_sign_doc(pub_key)

examples/chain_client/1_MsgSend.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
1-
# Copyright 2022 Injective Labs
2-
#
3-
# Licensed under the Apache License, Version 2.0 (the "License");
4-
# you may not use this file except in compliance with the License.
5-
# You may obtain a copy of the License at
6-
#
7-
# http://www.apache.org/licenses/LICENSE-2.0
8-
#
9-
# Unless required by applicable law or agreed to in writing, software
10-
# distributed under the License is distributed on an "AS IS" BASIS,
11-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-
# See the License for the specific language governing permissions and
13-
# limitations under the License.
14-
151
import asyncio
162
import logging
173

examples/chain_client/20_MsgExec.py

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
1-
# Copyright 2022 Injective Labs
2-
#
3-
# Licensed under the Apache License, Version 2.0 (the "License");
4-
# you may not use this file except in compliance with the License.
5-
# You may obtain a copy of the License at
6-
#
7-
# http://www.apache.org/licenses/LICENSE-2.0
8-
#
9-
# Unless required by applicable law or agreed to in writing, software
10-
# distributed under the License is distributed on an "AS IS" BASIS,
11-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-
# See the License for the specific language governing permissions and
13-
# limitations under the License.
14-
151
import asyncio
162
import logging
173

@@ -34,11 +20,11 @@ async def main() -> None:
3420
# load account
3521
priv_key = PrivateKey.from_hex("f9db9bf330e23cb7839039e944adef6e9df447b90b503d5b4464c90bea9022f3")
3622
pub_key = priv_key.to_public_key()
37-
address = await pub_key.to_address().async_init_num_seq(network.lcd_endpoint)
23+
address = pub_key.to_address()
24+
account = await client.get_account(address.to_acc_bech32())
3825

3926
# prepare tx msg
4027
market_id = "0x0511ddc4e6586f3bfe1acb2dd905f8b8a82c97e1edaef654b12ca7e6031ca0fa"
41-
4228
grantee = "inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r"
4329
granter_inj_address = "inj14au322k9munkmx5wrchz9q30juf5wjgz2cfqku"
4430
granter_address = Address.from_acc_bech32(granter_inj_address)
@@ -63,8 +49,8 @@ async def main() -> None:
6349
tx = (
6450
Transaction()
6551
.with_messages(msg)
66-
.with_sequence(address.get_sequence())
67-
.with_account_num(address.get_number())
52+
.with_sequence(client.get_sequence())
53+
.with_account_num(client.get_number())
6854
.with_chain_id(network.chain_id)
6955
)
7056
sim_sign_doc = tx.get_sign_doc(pub_key)

0 commit comments

Comments
 (0)