Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/add_chain_1_12_updates #139

Merged
merged 5 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
176 changes: 89 additions & 87 deletions source/includes/_account.md

Large diffs are not rendered by default.

37 changes: 18 additions & 19 deletions source/includes/_auction.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,31 @@ Includes the message for placing bids in auctions.

``` python
import asyncio
import logging

from pyinjective.composer import Composer as ProtoMsgComposer
from pyinjective.async_client import AsyncClient
from pyinjective.transaction import Transaction
from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT, GAS_PRICE
from pyinjective.core.network import Network
from pyinjective.transaction import Transaction
from pyinjective.wallet import PrivateKey


async def main() -> None:
# select network: local, testnet, mainnet
network = Network.testnet()
composer = ProtoMsgComposer(network=network.string())

# initialize grpc client
client = AsyncClient(network)
composer = await client.composer()
await client.sync_timeout_height()

# load account
priv_key = PrivateKey.from_hex("f9db9bf330e23cb7839039e944adef6e9df447b90b503d5b4464c90bea9022f3")
pub_key = priv_key.to_public_key()
address = pub_key.to_address()
account = await client.get_account(address.to_acc_bech32())
await client.get_account(address.to_acc_bech32())

# prepare tx msg
msg = composer.MsgBid(
sender=address.to_acc_bech32(),
round=23,
bid_amount=1
)
msg = composer.MsgBid(sender=address.to_acc_bech32(), round=16250, bid_amount=1)

# build sim tx
tx = (
Expand All @@ -61,14 +57,16 @@ async def main() -> None:
return

# build tx
gas_price = 500000000
gas_limit = sim_res.gas_info.gas_used + 25000 # add 25k for gas, fee computation
gas_fee = '{:.18f}'.format((gas_price * gas_limit) / pow(10, 18)).rstrip('0')
fee = [composer.Coin(
amount=gas_price * gas_limit,
denom=network.fee_denom,
)]
tx = tx.with_gas(gas_limit).with_fee(fee).with_memo('').with_timeout_height(client.timeout_height)
gas_price = GAS_PRICE
gas_limit = sim_res.gas_info.gas_used + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0")
fee = [
composer.Coin(
amount=gas_price * gas_limit,
denom=network.fee_denom,
)
]
tx = tx.with_gas(gas_limit).with_fee(fee).with_memo("").with_timeout_height(client.timeout_height)
sign_doc = tx.get_sign_doc(pub_key)
sig = priv_key.sign(sign_doc.SerializeToString())
tx_raw_bytes = tx.get_tx_data(sig, pub_key)
Expand All @@ -79,9 +77,10 @@ async def main() -> None:
print("gas wanted: {}".format(gas_limit))
print("gas fee: {} INJ".format(gas_fee))


if __name__ == "__main__":
logging.basicConfig(level=logging.INFO)
asyncio.get_event_loop().run_until_complete(main())

```

``` go
Expand Down
132 changes: 66 additions & 66 deletions source/includes/_authz.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,43 +13,42 @@ There are two types of authorization, Generic and Typed. Generic authorization w

``` python
import asyncio
import logging

from pyinjective.composer import Composer as ProtoMsgComposer
from pyinjective.async_client import AsyncClient
from pyinjective.transaction import Transaction
from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT, GAS_PRICE
from pyinjective.core.network import Network
from pyinjective.transaction import Transaction
from pyinjective.wallet import PrivateKey


async def main() -> None:
# select network: local, testnet, mainnet
network = Network.testnet()
composer = ProtoMsgComposer(network=network.string())

# initialize grpc client
client = AsyncClient(network)
composer = await client.composer()
await client.sync_timeout_height()

# load account
priv_key = PrivateKey.from_hex("f9db9bf330e23cb7839039e944adef6e9df447b90b503d5b4464c90bea9022f3")
pub_key = priv_key.to_public_key()
address = pub_key.to_address()
account = await client.get_account(address.to_acc_bech32())
subaccount_id = address.get_subaccount_id(index=0)
market_ids = ["0x0511ddc4e6586f3bfe1acb2dd905f8b8a82c97e1edaef654b12ca7e6031ca0fa"]
await client.get_account(address.to_acc_bech32())
# subaccount_id = address.get_subaccount_id(index=0)
# market_ids = ["0x0511ddc4e6586f3bfe1acb2dd905f8b8a82c97e1edaef654b12ca7e6031ca0fa"]

# prepare tx msg

#GENERIC AUTHZ
# GENERIC AUTHZ
msg = composer.MsgGrantGeneric(
granter = "inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r",
grantee = "inj14au322k9munkmx5wrchz9q30juf5wjgz2cfqku",
msg_type = "/injective.exchange.v1beta1.MsgCreateSpotLimitOrder",
expire_in=31536000 # 1 year
granter="inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r",
grantee="inj14au322k9munkmx5wrchz9q30juf5wjgz2cfqku",
msg_type="/injective.exchange.v1beta1.MsgCreateSpotLimitOrder",
expire_in=31536000, # 1 year
)

#TYPED AUTHZ
# TYPED AUTHZ
# msg = composer.MsgGrantTyped(
# granter = "inj14au322k9munkmx5wrchz9q30juf5wjgz2cfqku",
# grantee = "inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r",
Expand Down Expand Up @@ -78,14 +77,16 @@ async def main() -> None:
return

# build tx
gas_price = 500000000
gas_limit = sim_res.gas_info.gas_used + 20000 # add 20k for gas, fee computation
gas_fee = '{:.18f}'.format((gas_price * gas_limit) / pow(10, 18)).rstrip('0')
fee = [composer.Coin(
amount=gas_price * gas_limit,
denom=network.fee_denom,
)]
tx = tx.with_gas(gas_limit).with_fee(fee).with_memo('').with_timeout_height(client.timeout_height)
gas_price = GAS_PRICE
gas_limit = sim_res.gas_info.gas_used + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0")
fee = [
composer.Coin(
amount=gas_price * gas_limit,
denom=network.fee_denom,
)
]
tx = tx.with_gas(gas_limit).with_fee(fee).with_memo("").with_timeout_height(client.timeout_height)
sign_doc = tx.get_sign_doc(pub_key)
sig = priv_key.sign(sign_doc.SerializeToString())
tx_raw_bytes = tx.get_tx_data(sig, pub_key)
Expand All @@ -98,8 +99,8 @@ async def main() -> None:


if __name__ == "__main__":
logging.basicConfig(level=logging.INFO)
asyncio.get_event_loop().run_until_complete(main())

```

``` go
Expand Down Expand Up @@ -262,29 +263,29 @@ gas fee: 0.0000589365 INJ

``` python
import asyncio
import logging
import uuid

from pyinjective.composer import Composer as ProtoMsgComposer
from pyinjective.async_client import AsyncClient
from pyinjective.transaction import Transaction
from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT, GAS_PRICE
from pyinjective.core.network import Network
from pyinjective.wallet import PrivateKey, Address
from pyinjective.transaction import Transaction
from pyinjective.wallet import Address, PrivateKey


async def main() -> None:
# select network: local, testnet, mainnet
network = Network.testnet()
composer = ProtoMsgComposer(network=network.string())

# initialize grpc client
client = AsyncClient(network)
composer = await client.composer()
await client.sync_timeout_height()

# load account
priv_key = PrivateKey.from_hex("5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e")
pub_key = priv_key.to_public_key()
address = pub_key.to_address()
account = await client.get_account(address.to_acc_bech32())
await client.get_account(address.to_acc_bech32())

# prepare tx msg
market_id = "0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe"
Expand All @@ -300,13 +301,11 @@ async def main() -> None:
price=7.523,
quantity=0.01,
is_buy=True,
is_po=False
is_po=False,
cid=str(uuid.uuid4()),
)

msg = composer.MsgExec(
grantee=grantee,
msgs=[msg0]
)
msg = composer.MsgExec(grantee=grantee, msgs=[msg0])

# build sim tx
tx = (
Expand All @@ -326,24 +325,23 @@ async def main() -> None:
print(sim_res)
return

sim_res_msg = ProtoMsgComposer.MsgResponses(sim_res, simulation=True)
data=sim_res_msg[0]
unpacked_msg_res = ProtoMsgComposer.UnpackMsgExecResponse(
msg_type=msg0.__class__.__name__,
data=data
)
sim_res_msg = composer.MsgResponses(sim_res, simulation=True)
data = sim_res_msg[0]
unpacked_msg_res = composer.UnpackMsgExecResponse(msg_type=msg0.__class__.__name__, data=data)
print("simulation msg response")
print(unpacked_msg_res)

# build tx
gas_price = 500000000
gas_limit = sim_res.gas_info.gas_used + 20000 # add 20k for gas, fee computation
gas_fee = '{:.18f}'.format((gas_price * gas_limit) / pow(10, 18)).rstrip('0')
fee = [composer.Coin(
amount=gas_price * gas_limit,
denom=network.fee_denom,
)]
tx = tx.with_gas(gas_limit).with_fee(fee).with_memo('').with_timeout_height(client.timeout_height)
gas_price = GAS_PRICE
gas_limit = sim_res.gas_info.gas_used + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0")
fee = [
composer.Coin(
amount=gas_price * gas_limit,
denom=network.fee_denom,
)
]
tx = tx.with_gas(gas_limit).with_fee(fee).with_memo("").with_timeout_height(client.timeout_height)
sign_doc = tx.get_sign_doc(pub_key)
sig = priv_key.sign(sign_doc.SerializeToString())
tx_raw_bytes = tx.get_tx_data(sig, pub_key)
Expand All @@ -354,9 +352,10 @@ async def main() -> None:
print("gas wanted: {}".format(gas_limit))
print("gas fee: {} INJ".format(gas_fee))


if __name__ == "__main__":
logging.basicConfig(level=logging.INFO)
asyncio.get_event_loop().run_until_complete(main())

```

``` go
Expand Down Expand Up @@ -532,36 +531,34 @@ gas fee: 0.000066986 INJ

``` python
import asyncio
import logging

from pyinjective.composer import Composer as ProtoMsgComposer
from pyinjective.async_client import AsyncClient
from pyinjective.transaction import Transaction
from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT, GAS_PRICE
from pyinjective.core.network import Network
from pyinjective.transaction import Transaction
from pyinjective.wallet import PrivateKey


async def main() -> None:
# select network: local, testnet, mainnet
network = Network.testnet()
composer = ProtoMsgComposer(network=network.string())

# initialize grpc client
client = AsyncClient(network)
composer = await client.composer()
await client.sync_timeout_height()

# load account
priv_key = PrivateKey.from_hex("f9db9bf330e23cb7839039e944adef6e9df447b90b503d5b4464c90bea9022f3")
pub_key = priv_key.to_public_key()
address = pub_key.to_address()
account = await client.get_account(address.to_acc_bech32())
subaccount_id = address.get_subaccount_id(index=0)
await client.get_account(address.to_acc_bech32())

# prepare tx msg
msg = composer.MsgRevoke(
granter = "inj14au322k9munkmx5wrchz9q30juf5wjgz2cfqku",
grantee = "inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r",
msg_type = "/injective.exchange.v1beta1.MsgCreateSpotLimitOrder"
granter="inj14au322k9munkmx5wrchz9q30juf5wjgz2cfqku",
grantee="inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r",
msg_type="/injective.exchange.v1beta1.MsgCreateSpotLimitOrder",
)

# build sim tx
Expand All @@ -583,14 +580,16 @@ async def main() -> None:
return

# build tx
gas_price = 500000000
gas_limit = sim_res.gas_info.gas_used + 20000 # add 20k for gas, fee computation
gas_fee = '{:.18f}'.format((gas_price * gas_limit) / pow(10, 18)).rstrip('0')
fee = [composer.Coin(
amount=gas_price * gas_limit,
denom=network.fee_denom,
)]
tx = tx.with_gas(gas_limit).with_fee(fee).with_memo('').with_timeout_height(client.timeout_height)
gas_price = GAS_PRICE
gas_limit = sim_res.gas_info.gas_used + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0")
fee = [
composer.Coin(
amount=gas_price * gas_limit,
denom=network.fee_denom,
)
]
tx = tx.with_gas(gas_limit).with_fee(fee).with_memo("").with_timeout_height(client.timeout_height)
sign_doc = tx.get_sign_doc(pub_key)
sig = priv_key.sign(sign_doc.SerializeToString())
tx_raw_bytes = tx.get_tx_data(sig, pub_key)
Expand All @@ -601,9 +600,10 @@ async def main() -> None:
print("gas wanted: {}".format(gas_limit))
print("gas fee: {} INJ".format(gas_fee))


if __name__ == "__main__":
logging.basicConfig(level=logging.INFO)
asyncio.get_event_loop().run_until_complete(main())

```

``` go
Expand Down
Loading
Loading