Skip to content

Commit

Permalink
Merge pull request #3 from Snedashkovsky/add_graphql
Browse files Browse the repository at this point in the history
Add an unsigned contract execution transaction
  • Loading branch information
Snedashkovsky authored May 12, 2023
2 parents 7fad59c + d63dc0c commit f18ac37
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 18 deletions.
49 changes: 36 additions & 13 deletions cyberutils/contract/execution.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,64 @@
from typing import Optional
from typing import Optional, Union

from cyber_sdk.client.lcd.api.tx import CreateTxOptions, BlockTxBroadcastResult
from cyber_sdk.client.lcd import LCDClient
from cyber_sdk.core.fee import Fee
from cyber_sdk.client.lcd.api.tx import CreateTxOptions, BlockTxBroadcastResult, SignerOptions
from cyber_sdk.client.lcd.wallet import Wallet
from cyber_sdk.core import Coin, Coins, AccAddress
from cyber_sdk.exceptions import LCDResponseError
from cyber_sdk.core.fee import Fee
from cyber_sdk.core.tx import Tx
from cyber_sdk.core.wasm import MsgExecuteContract
from cyber_sdk.client.lcd.wallet import Wallet
from cyber_sdk.exceptions import LCDResponseError


def execute_contract(execute_msgs: list[dict], wallet: Wallet, contract_address: str, lcd_client: LCDClient, gas: int,
fee_amount: int, fee_denom: str, memo: Optional[str] = None) -> Optional[BlockTxBroadcastResult]:
def execute_contract(execute_msgs: list[dict],
contract_address: str,
lcd_client: LCDClient,
fee_denom: str,
fee_amount: int = 0,
gas: int = 300_000,
wallet: Optional[Wallet] = None,
sender: Optional[Union[str, AccAddress]] = None,
sign_and_broadcast_tx: bool = True,
memo: Optional[str] = None) -> Optional[Union[BlockTxBroadcastResult, Tx]]:
"""
Execute contract list of messages for a contract in a transaction
Execute contract list of messages for a contract in a transaction or get an unsigned transaction
:param execute_msgs: list of execute messages
:param wallet: executable wallet
:param contract_address: contract address
:param lcd_client: network LCD client
:param gas: amount of gas
:param fee_amount: fee amount
:param fee_denom: fee denom
:param wallet: executable wallet
:param sender: transaction sender address
:param sign_and_broadcast_tx: sign and broadcast a transaction if true, otherwise return an unsigned transaction
:param memo: note(memo) of a transaction
:return: transaction result
:return: a transaction result or an unsigned transaction
"""

assert ((wallet or sender) and not sign_and_broadcast_tx) or (wallet and sign_and_broadcast_tx)
_sender = wallet.key.acc_address if sender is None else AccAddress(sender)
_msgs = \
[MsgExecuteContract(
sender=wallet.key.acc_address,
sender=_sender,
contract=AccAddress(contract_address),
execute_msg=execute_msg) for execute_msg in execute_msgs]

if sign_and_broadcast_tx is False:
return lcd_client.tx.create(
signers=[SignerOptions(address=_sender)],
options=CreateTxOptions(
msgs=_msgs,
memo=memo,
fee=Fee(gas, Coins([Coin(amount=fee_amount, denom=fee_denom)]))
)
)

_tx_signed = wallet.create_and_sign_tx(
CreateTxOptions(
msgs=_msgs,
memo=memo,
fee=Fee(gas, Coins([Coin(amount=fee_amount, denom=fee_denom)]))
))
)
)

try:
_tx_broadcasted = lcd_client.tx.broadcast(_tx_signed)
Expand Down
10 changes: 7 additions & 3 deletions cyberutils/graphql/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@ async def get_messages_by_address_and_type(address: str,
message_involved_addresses: involved_accounts_addresses
transaction_hash
transaction {
success
memo
signer_infos
success
memo
signer_infos
block {
height
timestamp
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ classifiers = [
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
]
description = "The Toolset for cyber protocol and cosmos ecosystem"
description = "the toolset for cyber protocol and cosmos ecosystem"
documentation = "https://github.com/Snedashkovsky/cyberutils"
homepage = "https://github.com/Snedashkovsky/cyberutils"
keywords = ["bostrom", "cyber", "knowledge-graph", "dex", "swap", "defi", "crypto", "blockchain", ]
license = "MIT"
packages = [{ include = "cyberutils" }]
readme = "README.md"
repository = "https://github.com/Snedashkovsky/cyberutils.git"
version = "0.0.3"
version = "0.0.4"

[tool.poetry.dependencies]
pandas = "^1.0.0"
Expand Down

0 comments on commit f18ac37

Please sign in to comment.