Class: BSV::MCP::Tools::FetchTx
- Inherits:
-
MCP::Tool
- Object
- MCP::Tool
- BSV::MCP::Tools::FetchTx
- Defined in:
- lib/bsv/mcp/tools/fetch_tx.rb
Overview
Fetches a transaction from the BSV network by its txid using the WhatsOnChain API, returning both the raw hex and decoded structure.
Class Method Summary collapse
Class Method Details
.call(txid:, network: nil, server_context: nil) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/bsv/mcp/tools/fetch_tx.rb', line 50 def self.call(txid:, network: nil, server_context: nil) net_sym = Helpers.resolve_network_sym(network, server_context) provider = BSV::Network::Providers::WhatsOnChain.default(network: net_sym) fetch_result = provider.call(:get_tx, txid) unless fetch_result.success? code = fetch_result.[:status_code] msg = fetch_result. msg = "#{msg} (HTTP #{code})" if code return Helpers.error_response(msg) end tx = BSV::Transaction::Transaction.from_hex(fetch_result.data) result = { hex: tx.to_hex, network: net_sym.to_s }.merge(Helpers.transaction_to_h(tx)) ::MCP::Tool::Response.new( [::MCP::Content::Text.new(result.to_json)], structured_content: result ) rescue ArgumentError => e Helpers.error_response(e.) end |