Class: BSV::MCP::Tools::FetchTx

Inherits:
MCP::Tool
  • Object
show all
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
# 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)
  woc = BSV::Network::WhatsOnChain.new(network: net_sym)
  tx = woc.fetch_transaction(txid)

  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 BSV::Network::ChainProviderError => e
  Helpers.error_response("#{e.message} (HTTP #{e.status_code})")
rescue ArgumentError => e
  Helpers.error_response(e.message)
end