Skip to content

Commit

Permalink
feat(pob-x): fix #34
Browse files Browse the repository at this point in the history
  • Loading branch information
janfabian committed Sep 27, 2023
1 parent 37590c3 commit 8d1d524
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
6 changes: 3 additions & 3 deletions skipper-py/src/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from src.transaction import Transaction
from src.contract import Pool
from src.route import Route
from src.rest_client import FixedTxRestClient

from skip_types.pob import MsgAuctionBid
from skip_utility.tx import TransactionWithTimeout as Tx
Expand Down Expand Up @@ -91,6 +92,7 @@ async def init(self):
staking_denomination=self.fee_denom,
)
self.client = LedgerClient(self.network_config)
self.client.txs = FixedTxRestClient(self.client.txs.rest_client)
self.wallet = self.creator.create_wallet(self.chain_id,
self.mnemonic,
self.address_prefix)
Expand Down Expand Up @@ -188,10 +190,8 @@ async def run(self):
# the bid transaction includes the bundle of transactions
# that will be executed if the bid is successful
tx = self.client.broadcast_tx(tx=bidTx).wait_to_complete()
logging.info(f"Broadcasted bid transaction {tx_hash}")
logging.info(f"Broadcasted bid transaction {tx.tx_hash}")

# log the result of the bid transaction
logging.info(f"Result of bid transaction {tx_hash}: {tx.is_successful()}")

def build_most_profitable_bundle(self,
transaction: Transaction,
Expand Down
35 changes: 35 additions & 0 deletions skipper-py/src/rest_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import json
from google.protobuf.json_format import ParseDict
from cosmpy.tx.rest_client import TxRestClient
from cosmpy.protos.cosmos.tx.v1beta1.service_pb2 import (
GetTxRequest,
GetTxResponse
)

class FixedTxRestClient(TxRestClient):
def GetTx(self, request: GetTxRequest) -> GetTxResponse:
"""
GetTx fetches a tx by hash.
:param request: GetTxRequest
:return: GetTxResponse
"""
response = self.rest_client.get(f"{self.API_URL}/txs/{request.hash}")

# JSON in case of CosmWasm messages workaround
dict_response = json.loads(response)
self._fix_messages(dict_response["tx"]["body"]["messages"])
self._fix_messages(dict_response["tx_response"]["tx"]["body"]["messages"])

self._fix_tip_and_events(dict_response)

return ParseDict(dict_response, GetTxResponse())

@staticmethod
def _fix_tip_and_events(dict_response):
"""
Fix tip and events parsing error
"""
del dict_response['tx']['auth_info']['tip']
del dict_response['tx_response']['tx']['auth_info']['tip']
dict_response['tx_response']['events'] = []

0 comments on commit 8d1d524

Please sign in to comment.