Skip to content

Conversation

@Gerson2102
Copy link
Contributor

Feature: Core Ethereum Blockchain Data Retrieval Functions

This pull request introduces several new functions, each designed to retrieve specific blockchain information, and utilizes a structured request format.

Key Implemented Features:

  • EthereumNodeRequest Structure:

    • Defines the input parameters for service calls, including:
      • node_url: String (Target Ethereum node)
      • block_number: Option<u64> (Optional block number, used by get_block, get_block_transactions, and get_account_balance)
      • transaction_hash: String (Used by get_transaction)
      • account_address: String (Used by get_account_balance)
    • The block_number is Option<u64>, allowing flexibility for functions like get_account_balance to default to the latest block if no number is provided.
  • Service Functions Added:

    • get_block():
      • Retrieves and formats details for a specific block identified by request.block_number.
      • (Note: Currently uses request.block_number.unwrap(), assuming a block number will always be provided for this call.)
    • get_transaction():
      • Fetches detailed information for a transaction specified by request.transaction_hash.
      • Includes parsing the string hash to H256.
      • Formats output to show hash, sender, receiver, value, block number (or "Pending"), gas price, and gas limit.
    • get_block_transactions():
      • Lists transactions within a block specified by request.block_number.
      • Uses provider.get_block_with_txs() to retrieve full transaction objects.
      • Currently displays the first 10 transactions (.take(10)) from the block.
      • (Note: Currently uses request.block_number.unwrap(), assuming a block number will always be provided.)
    • get_account_balance():
      • Retrieves the ETH balance for request.account_address.
      • If request.block_number is Some(bn), fetches the balance at that specific block.
      • If request.block_number is None, fetches the balance at the latest block.
      • Converts the balance from Wei to ETH using ethers::utils::format_ether.
      • Parses the string address to ethers::types::Address.

How to Test:

The implemented functionalities can be invoked via the rmcp service layer:

  • Call get_latest_block with a node URL.
  • Call get_block with a node URL and a block number.
  • Call get_transaction with a node URL and a transaction hash.
  • Call get_block_transactions with a node URL and a block number.
  • Call get_account_balance with a node URL, an account address, and optionally a block number.

@Gerson2102
Copy link
Contributor Author

cc: @therustmonk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant