Skip to content

Commit

Permalink
Print MempoolInclusionStatus as string when reporting mempool inclusi…
Browse files Browse the repository at this point in the history
…on status (#11133)
  • Loading branch information
aqk authored and emlowe committed Apr 21, 2022
1 parent a11468f commit ade852c
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 7 deletions.
12 changes: 12 additions & 0 deletions chia/cmds/cmds_util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from chia.types.blockchain_format.sized_bytes import bytes32
from chia.types.mempool_submission_status import MempoolSubmissionStatus
from chia.wallet.transaction_record import TransactionRecord


def transaction_submitted_msg(tx: TransactionRecord) -> str:
sent_to = [MempoolSubmissionStatus(s[0], s[1], s[2]).to_json_dict_convenience() for s in tx.sent_to]
return f"Transaction submitted to nodes: {sent_to}"


def transaction_status_msg(fingerprint: int, tx_id: bytes32) -> str:
return f"Run 'chia wallet get_transaction -f {fingerprint} -tx 0x{tx_id}' to get status"
9 changes: 5 additions & 4 deletions chia/cmds/plotnft_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from chia.util.config import load_config
from chia.util.default_root import DEFAULT_ROOT_PATH
from chia.util.ints import uint16, uint32, uint64
from chia.cmds.cmds_util import transaction_submitted_msg, transaction_status_msg
from chia.wallet.transaction_record import TransactionRecord
from chia.wallet.util.wallet_types import WalletType

Expand Down Expand Up @@ -100,8 +101,8 @@ async def create(args: dict, wallet_client: WalletRpcClient, fingerprint: int) -
await asyncio.sleep(0.1)
tx = await wallet_client.get_transaction(str(1), tx_record.name)
if len(tx.sent_to) > 0:
print(f"Transaction submitted to nodes: {tx.sent_to}")
print(f"Do chia wallet get_transaction -f {fingerprint} -tx 0x{tx_record.name} to get status")
print(transaction_submitted_msg(tx))
print(transaction_status_msg(fingerprint, tx_record.name))
return None
except Exception as e:
print(f"Error creating plot NFT: {e}\n Please start both farmer and wallet with: chia start -r farmer")
Expand Down Expand Up @@ -286,8 +287,8 @@ async def submit_tx_with_confirmation(
await asyncio.sleep(0.1)
tx = await wallet_client.get_transaction(str(1), tx_record.name)
if len(tx.sent_to) > 0:
print(f"Transaction submitted to nodes: {tx.sent_to}")
print(f"Do chia wallet get_transaction -f {fingerprint} -tx 0x{tx_record.name} to get status")
print(transaction_submitted_msg(tx))
print(transaction_status_msg(fingerprint, tx_record.name))
return None
except Exception as e:
print(f"Error performing operation on Plot NFT -f {fingerprint} wallet id: {wallet_id}: {e}")
Expand Down
5 changes: 3 additions & 2 deletions chia/cmds/wallet_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from chia.util.config import load_config
from chia.util.default_root import DEFAULT_ROOT_PATH
from chia.util.ints import uint16, uint32, uint64
from chia.cmds.cmds_util import transaction_submitted_msg, transaction_status_msg
from chia.wallet.trade_record import TradeRecord
from chia.wallet.trading.offer import Offer
from chia.wallet.trading.trade_status import TradeStatus
Expand Down Expand Up @@ -228,8 +229,8 @@ async def send(args: dict, wallet_client: WalletRpcClient, fingerprint: int) ->
await asyncio.sleep(0.1)
tx = await wallet_client.get_transaction(str(wallet_id), tx_id)
if len(tx.sent_to) > 0:
print(f"Transaction submitted to nodes: {tx.sent_to}")
print(f"Do chia wallet get_transaction -f {fingerprint} -tx 0x{tx_id} to get status")
print(transaction_submitted_msg(tx))
print(transaction_status_msg(fingerprint, tx_id))
return None

print("Transaction not yet submitted to nodes")
Expand Down
28 changes: 28 additions & 0 deletions chia/types/mempool_submission_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from dataclasses import dataclass
from typing import Dict, Optional, Union

from chia.types.mempool_inclusion_status import MempoolInclusionStatus
from chia.util.ints import uint8
from chia.util.streamable import Streamable, streamable


@streamable
@dataclass(frozen=True)
class MempoolSubmissionStatus(Streamable):
"""
:sent_to: in `TradeRecord` and `TransactionRecord` are a
Tuple of (peer_id: str, status: MempoolInclusionStatus, error: Optional[str])
MempoolInclusionStatus is represented as a uint8 in those structs so they can be `Streamable`
"""

peer_id: str
inclusion_status: uint8 # MempoolInclusionStatus
error_msg: Optional[str]

def to_json_dict_convenience(self) -> Dict[str, Union[str, MempoolInclusionStatus, Optional[str]]]:
formatted = self.to_json_dict()
formatted["inclusion_status"] = MempoolInclusionStatus(self.inclusion_status).name
return formatted

def __str__(self) -> str:
return f"{self.to_json_dict_convenience()}"
2 changes: 1 addition & 1 deletion chia/wallet/trade_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class TradeRecord(Streamable):
coins_of_interest: List[Coin]
trade_id: bytes32
status: uint32 # TradeStatus, enum not streamable
sent_to: List[Tuple[str, uint8, Optional[str]]]
sent_to: List[Tuple[str, uint8, Optional[str]]] # MempoolSubmissionStatus.status enum not streamable

def to_json_dict_convenience(self) -> Dict[str, Any]:
formatted = self.to_json_dict()
Expand Down

0 comments on commit ade852c

Please sign in to comment.