diff --git a/src/farmer.py b/src/farmer.py index 66b422dc32..cdd3e3c4ec 100644 --- a/src/farmer.py +++ b/src/farmer.py @@ -58,14 +58,14 @@ class Farmer: raise RuntimeError(error_str) # This is the farmer configuration - self.wallet_target = decode_puzzle_hash(bytes.fromhex(self.config["xch_target_address"])) + self.wallet_target = decode_puzzle_hash(self.config["xch_target_address"]) self.pool_public_keys = [ G1Element.from_bytes(bytes.fromhex(pk)) for pk in self.config["pool_public_keys"] ] # This is the pool configuration, which should be moved out to the pool once it exists - self.pool_target = decode_puzzle_hash(bytes.fromhex(pool_config["xch_target_address"])) + self.pool_target = decode_puzzle_hash(pool_config["xch_target_address"]) self.pool_sks_map: Dict = {} for key in self._get_private_keys(): self.pool_sks_map[bytes(key.get_g1())] = key diff --git a/src/full_node/blockchain.py b/src/full_node/blockchain.py index 0ecc98fd61..25aba6ab6a 100644 --- a/src/full_node/blockchain.py +++ b/src/full_node/blockchain.py @@ -28,10 +28,10 @@ from src.types.full_block import FullBlock, additions_for_npc from src.types.header import Header from src.types.header_block import HeaderBlock from src.types.sized_bytes import bytes32 -from src.util.blockchain_check_conditions import blockchain_check_conditions_dict +from src.full_node.blockchain_check_conditions import blockchain_check_conditions_dict from src.util.clvm import int_from_bytes from src.util.condition_tools import pkm_pairs_for_conditions_dict -from src.util.cost_calculator import calculate_cost_of_program +from src.full_node.cost_calculator import calculate_cost_of_program from src.util.errors import ConsensusError, Err from src.util.hash import std_hash from src.util.ints import uint32, uint64 diff --git a/src/util/blockchain_check_conditions.py b/src/full_node/blockchain_check_conditions.py similarity index 100% rename from src/util/blockchain_check_conditions.py rename to src/full_node/blockchain_check_conditions.py diff --git a/src/util/bundle_tools.py b/src/full_node/bundle_tools.py similarity index 100% rename from src/util/bundle_tools.py rename to src/full_node/bundle_tools.py diff --git a/src/util/cost_calculator.py b/src/full_node/cost_calculator.py similarity index 97% rename from src/util/cost_calculator.py rename to src/full_node/cost_calculator.py index 3a6d5866c0..3452f393cb 100644 --- a/src/util/cost_calculator.py +++ b/src/full_node/cost_calculator.py @@ -6,7 +6,7 @@ from src.types.program import Program from src.types.name_puzzle_condition import NPC from src.util.errors import Err from src.util.ints import uint64 -from src.util.mempool_check_conditions import get_name_puzzle_conditions +from src.full_node.mempool_check_conditions import get_name_puzzle_conditions def calculate_cost_of_program( diff --git a/src/full_node/full_node.py b/src/full_node/full_node.py index f63b81596f..78c7e0241d 100644 --- a/src/full_node/full_node.py +++ b/src/full_node/full_node.py @@ -48,8 +48,8 @@ from src.types.proof_of_time import ProofOfTime from src.types.sized_bytes import bytes32 from src.types.spend_bundle import SpendBundle from src.util.api_decorators import api_request -from src.util.bundle_tools import best_solution_program -from src.util.cost_calculator import calculate_cost_of_program +from src.full_node.bundle_tools import best_solution_program +from src.full_node.cost_calculator import calculate_cost_of_program from src.util.errors import ConsensusError, Err from src.util.hash import std_hash from src.util.ints import uint32, uint64, uint128 @@ -613,12 +613,11 @@ class FullNode: # Ignore if we have already added this transaction if self.mempool_manager.get_spendbundle(tx.transaction.name()) is not None: return - self.log.warning(f"Adding transaction to mempool: {transaction.transaction_id}") cost, status, error = await self.mempool_manager.add_spendbundle( tx.transaction ) if status == MempoolInclusionStatus.SUCCESS: - self.log.warning(f"Added transaction to mempool: {transaction.transaction_id}") + self.log.info(f"Added transaction to mempool: {tx.transaction.name()}") fees = tx.transaction.fees() assert fees >= 0 assert cost is not None diff --git a/src/util/mempool_check_conditions.py b/src/full_node/mempool_check_conditions.py similarity index 100% rename from src/util/mempool_check_conditions.py rename to src/full_node/mempool_check_conditions.py diff --git a/src/full_node/mempool_manager.py b/src/full_node/mempool_manager.py index cc31bb6c27..058967c71e 100644 --- a/src/full_node/mempool_manager.py +++ b/src/full_node/mempool_manager.py @@ -9,7 +9,7 @@ from blspy import G1Element, G2Element, AugSchemeMPL from src.consensus.constants import ConsensusConstants from src.types.condition_opcodes import ConditionOpcode from src.types.condition_var_pair import ConditionVarPair -from src.util.bundle_tools import best_solution_program +from src.full_node.bundle_tools import best_solution_program from src.types.full_block import FullBlock from src.types.coin import Coin from src.types.spend_bundle import SpendBundle @@ -21,8 +21,8 @@ from src.types.sized_bytes import bytes32 from src.full_node.coin_store import CoinStore from src.util.errors import Err from src.util.clvm import int_from_bytes -from src.util.cost_calculator import calculate_cost_of_program -from src.util.mempool_check_conditions import mempool_check_conditions_dict +from src.full_node.cost_calculator import calculate_cost_of_program +from src.full_node.mempool_check_conditions import mempool_check_conditions_dict from src.util.condition_tools import pkm_pairs_for_conditions_dict from src.util.ints import uint64, uint32 from src.types.mempool_inclusion_status import MempoolInclusionStatus diff --git a/src/rpc/wallet_rpc_client.py b/src/rpc/wallet_rpc_client.py index a70528bb7f..a06a5fa5c5 100644 --- a/src/rpc/wallet_rpc_client.py +++ b/src/rpc/wallet_rpc_client.py @@ -21,9 +21,9 @@ class WalletRpcClient(RpcClient): ======= async def send_transaction( self, wallet_id: str, amount: uint64, address: str, fee: uint64 = uint64(0) - ) -> TransactionRecord: + ) -> Dict: - response = await self.fetch( + res = await self.fetch( "send_transaction", { "wallet_id": wallet_id, @@ -32,24 +32,33 @@ class WalletRpcClient(RpcClient): "fee": fee, }, ) - if response["success"]: - return TransactionRecord.from_json_dict(response["transaction"]) - raise Exception(response["reason"]) + res["transaction"] = TransactionRecord.from_json_dict(res["transaction"]) + return res async def get_next_address(self, wallet_id: str) -> Dict: return await self.fetch("get_next_address", {"wallet_id": wallet_id}) async def get_transaction( self, wallet_id: str, transaction_id: bytes32 - ) -> Optional[TransactionRecord]: + ) -> Dict: - response = await self.fetch( + res = await self.fetch( "get_transaction", {"walled_id": wallet_id, "transaction_id": transaction_id.hex()}, ) - if response["success"]: - return TransactionRecord.from_json_dict(response["transaction"]) - return None + res["transaction"] = TransactionRecord.from_json_dict(res["transaction"]) + return res + + async def get_transactions( + self, wallet_id: str, + ) -> Dict: + res = await self.fetch( + "get_transactions", + {"walled_id": wallet_id}, + ) + parsed = [TransactionRecord.from_json_dict(tx) for tx in res["transactions"]) + res[transactions] = parsed + return res >>>>>>> f1c565a8... More test async def log_in(self, fingerprint) -> Dict: diff --git a/src/simulator/full_node_simulator.py b/src/simulator/full_node_simulator.py index b5da7bca7b..c09db67c38 100644 --- a/src/simulator/full_node_simulator.py +++ b/src/simulator/full_node_simulator.py @@ -7,7 +7,7 @@ from src.protocols import ( wallet_protocol, ) from src.simulator.simulator_protocol import FarmNewBlockProtocol, ReorgProtocol -from src.util.bundle_tools import best_solution_program +from src.full_node.bundle_tools import best_solution_program from src.server.outbound_message import OutboundMessage from src.server.server import ChiaServer from src.types.full_block import FullBlock diff --git a/src/types/full_block.py b/src/types/full_block.py index 65d88cec30..0064af135b 100644 --- a/src/types/full_block.py +++ b/src/types/full_block.py @@ -6,7 +6,7 @@ from src.types.program import Program from src.types.coin import Coin from src.types.header import Header from src.types.sized_bytes import bytes32 -from src.util.mempool_check_conditions import get_name_puzzle_conditions +from src.full_node.mempool_check_conditions import get_name_puzzle_conditions from src.util.condition_tools import created_outputs_for_conditions_dict from src.util.ints import uint32, uint128 from src.util.streamable import Streamable, streamable diff --git a/src/util/block_tools.py b/src/util/block_tools.py index d2cb5df00d..35bdee41bd 100644 --- a/src/util/block_tools.py +++ b/src/util/block_tools.py @@ -39,7 +39,7 @@ from src.util.ints import uint8, uint32, uint64, uint128, int512 from src.util.hash import std_hash from src.util.path import mkdir from src.util.significant_bits import truncate_to_significant_bits -from src.util.mempool_check_conditions import get_name_puzzle_conditions +from src.full_node.mempool_check_conditions import get_name_puzzle_conditions from src.plotting.plot_tools import load_plots from src.util.logging import initialize_logging from src.util.wallet_tools import WalletTool diff --git a/src/wallet/wallet_state_manager.py b/src/wallet/wallet_state_manager.py index 7c25e46bea..961e5c57cf 100644 --- a/src/wallet/wallet_state_manager.py +++ b/src/wallet/wallet_state_manager.py @@ -698,7 +698,7 @@ class WalletStateManager: Full node received our transaction, no need to keep it in queue anymore """ await self.tx_store.increment_sent(spendbundle_id, name, send_status, error) - tx: Optional[TransactionRecord] = self.get_transaction(spendbundle_id) + tx: Optional[TransactionRecord] = await self.get_transaction(spendbundle_id) if tx is not None: self.state_changed("tx_update", tx.wallet_id, {"transaction": tx}) diff --git a/tests/full_node/test_blockchain_transactions.py b/tests/full_node/test_blockchain_transactions.py index 4aa37c2484..88a848c867 100644 --- a/tests/full_node/test_blockchain_transactions.py +++ b/tests/full_node/test_blockchain_transactions.py @@ -9,7 +9,7 @@ from src.types.condition_var_pair import ConditionVarPair from src.types.condition_opcodes import ConditionOpcode from src.types.header import HeaderData, Header from src.types.sized_bytes import bytes32 -from src.util.bundle_tools import best_solution_program +from src.full_node.bundle_tools import best_solution_program from src.server.outbound_message import OutboundMessage from src.protocols import full_node_protocol from src.types.full_block import FullBlock diff --git a/tests/full_node/test_full_node.py b/tests/full_node/test_full_node.py index 1e28111a8c..fef606ec7b 100644 --- a/tests/full_node/test_full_node.py +++ b/tests/full_node/test_full_node.py @@ -16,7 +16,7 @@ from src.types.peer_info import PeerInfo from src.types.full_block import FullBlock from src.types.proof_of_space import ProofOfSpace from src.types.spend_bundle import SpendBundle -from src.util.bundle_tools import best_solution_program +from src.full_node.bundle_tools import best_solution_program from src.util.ints import uint16, uint32, uint64, uint8 from src.util.hash import std_hash from src.full_node.full_node import FullNode diff --git a/tests/rpc/test_wallet_rpc.py b/tests/rpc/test_wallet_rpc.py index 6542cf4df7..73928a4918 100644 --- a/tests/rpc/test_wallet_rpc.py +++ b/tests/rpc/test_wallet_rpc.py @@ -89,12 +89,11 @@ class TestWalletRpc: await wallet_node_2.wallet_state_manager.main_wallet.get_new_puzzlehash() ) tx_amount = 15600000 - tx = await client.send_transaction("1", tx_amount, addr) - assert tx is not None + tx = (await client.send_transaction("1", tx_amount, addr))["transaction"] transaction_id = tx.name() async def tx_in_mempool(): - tx = await client.get_transaction("1", transaction_id) + tx = (await client.get_transaction("1", transaction_id))["transaction"] return tx.is_in_mempool() await time_out_assert(5, tx_in_mempool, True) await time_out_assert(5, wallet.get_unconfirmed_balance, initial_funds - tx_amount) @@ -109,7 +108,11 @@ class TestWalletRpc: await time_out_assert(5, eventual_balance, initial_funds_eventually - tx_amount) - await client.get_next_address() + address = (await client.get_next_address("1"))["address"] + assert len(address) > 10 + + txs = (await client.get_transactions("1"))["transactions"] + except Exception: diff --git a/tests/setup_nodes.py b/tests/setup_nodes.py index f8242103e7..b2661f72d5 100644 --- a/tests/setup_nodes.py +++ b/tests/setup_nodes.py @@ -270,9 +270,9 @@ async def setup_farmer( config = load_config(bt.root_path, "config.yaml", "farmer") config_pool = load_config(bt.root_path, "config.yaml", "pool") - config["xch_target_address"] = encode_puzzle_hash(bt.farmer_ph).hex() + config["xch_target_address"] = encode_puzzle_hash(bt.farmer_ph) config["pool_public_keys"] = [bytes(pk).hex() for pk in bt.pool_pubkeys] - config_pool["xch_target_address"] = encode_puzzle_hash(bt.pool_ph).hex() + config_pool["xch_target_address"] = encode_puzzle_hash(bt.pool_ph) if full_node_port: connect_peers = [PeerInfo(self_hostname, full_node_port)] else: diff --git a/tests/test_cost_calculation.py b/tests/test_cost_calculation.py index d732eefe62..ccec0fe754 100644 --- a/tests/test_cost_calculation.py +++ b/tests/test_cost_calculation.py @@ -2,9 +2,9 @@ import asyncio import pytest -from src.util.bundle_tools import best_solution_program -from src.util.cost_calculator import calculate_cost_of_program -from src.util.mempool_check_conditions import get_name_puzzle_conditions +from src.full_node.bundle_tools import best_solution_program +from src.full_node.cost_calculator import calculate_cost_of_program +from src.full_node.mempool_check_conditions import get_name_puzzle_conditions from tests.setup_nodes import test_constants, bt from src.util.wallet_tools import WalletTool diff --git a/tests/wallet/test_wallet_sync.py b/tests/wallet/test_wallet_sync.py index d6e67aeab8..5a4ff1692d 100644 --- a/tests/wallet/test_wallet_sync.py +++ b/tests/wallet/test_wallet_sync.py @@ -7,7 +7,7 @@ from src.protocols import full_node_protocol from src.util.ints import uint16, uint64, uint32 from tests.setup_nodes import setup_node_and_wallet, test_constants, bt from src.types.spend_bundle import SpendBundle -from src.util.bundle_tools import best_solution_program +from src.full_node.bundle_tools import best_solution_program from src.util.wallet_tools import WalletTool from src.types.coin import Coin from src.consensus.coinbase import create_coinbase_coin