Class: BSV::Network::ARC
- Inherits:
-
Object
- Object
- BSV::Network::ARC
- Defined in:
- lib/bsv/network/arc.rb
Overview
ARC broadcaster for submitting transactions to the BSV network.
This facade preserves the legacy public API contract while delegating all HTTP logic to Protocols::ARC. It translates Result objects returned by the protocol into BroadcastResponse instances or raised BroadcastError exceptions as required by consumer code.
Any object responding to #broadcast(tx) can serve as a broadcaster; this class implements that contract using the ARC API.
Constant Summary collapse
- REJECTED_STATUSES =
ARC response statuses that indicate the transaction was NOT accepted.
%w[ REJECTED DOUBLE_SPEND_ATTEMPTED INVALID MALFORMED MINED_IN_STALE_BLOCK ].freeze
Class Method Summary collapse
-
.default(testnet: false, api_key: nil, http_client: nil, **opts) ⇒ ARC
Returns an ARC instance pointed at the GorillaPool public ARC endpoint.
Instance Method Summary collapse
-
#broadcast(tx, wait_for: nil, skip_fee_validation: nil, skip_script_validation: nil) ⇒ BroadcastResponse
Submit a transaction to ARC.
-
#broadcast_many(txs, wait_for: nil, skip_fee_validation: nil, skip_script_validation: nil) ⇒ Array<BroadcastResponse, BroadcastError>
Submit multiple transactions to ARC in a single batch request.
-
#initialize(url_or_protocol, api_key: nil, deployment_id: nil, callback_url: nil, callback_token: nil, http_client: nil) ⇒ ARC
constructor
A new instance of ARC.
-
#status(txid) ⇒ BroadcastResponse
Query the status of a previously submitted transaction.
Constructor Details
#initialize(url_or_protocol, api_key: nil, deployment_id: nil, callback_url: nil, callback_token: nil, http_client: nil) ⇒ ARC
Returns a new instance of ARC.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/bsv/network/arc.rb', line 57 def initialize(url_or_protocol, api_key: nil, deployment_id: nil, callback_url: nil, callback_token: nil, http_client: nil) @protocol = if url_or_protocol.is_a?(String) Protocols::ARC.new( base_url: url_or_protocol, api_key: api_key, deployment_id: deployment_id, callback_url: callback_url, callback_token: callback_token, http_client: http_client ) else url_or_protocol end end |
Class Method Details
.default(testnet: false, api_key: nil, http_client: nil, **opts) ⇒ ARC
Returns an ARC instance pointed at the GorillaPool public ARC endpoint.
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/bsv/network/arc.rb', line 23 def self.default(testnet: false, api_key: nil, http_client: nil, **opts) provider = Providers::GorillaPool.default(testnet: testnet) arc_protocol = provider.protocol_for(:broadcast) base_url = arc_protocol.base_url new( base_url, api_key: api_key, http_client: http_client, **opts ) end |
Instance Method Details
#broadcast(tx, wait_for: nil, skip_fee_validation: nil, skip_script_validation: nil) ⇒ BroadcastResponse
Submit a transaction to ARC.
83 84 85 86 87 88 89 90 91 |
# File 'lib/bsv/network/arc.rb', line 83 def broadcast(tx, wait_for: nil, skip_fee_validation: nil, skip_script_validation: nil) result = @protocol.call( :broadcast, tx, wait_for: wait_for, skip_fee_validation: skip_fee_validation, skip_script_validation: skip_script_validation ) result_to_response!(result) end |
#broadcast_many(txs, wait_for: nil, skip_fee_validation: nil, skip_script_validation: nil) ⇒ Array<BroadcastResponse, BroadcastError>
Submit multiple transactions to ARC in a single batch request.
Returns a mixed array of BroadcastResponse and BroadcastError objects. Per-transaction rejections are returned as BroadcastError values rather than raised. Only HTTP-level errors raise a BroadcastError for the whole batch.
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/bsv/network/arc.rb', line 105 def broadcast_many(txs, wait_for: nil, skip_fee_validation: nil, skip_script_validation: nil) result = @protocol.call( :broadcast_many, txs, wait_for: wait_for, skip_fee_validation: skip_fee_validation, skip_script_validation: skip_script_validation ) case result when Result::Success result.data.map { |item| item_to_response_or_error(item) } else raise broadcast_error_from_result(result) end end |
#status(txid) ⇒ BroadcastResponse
Query the status of a previously submitted transaction.
126 127 128 129 |
# File 'lib/bsv/network/arc.rb', line 126 def status(txid) result = @protocol.call(:get_tx_status, txid) result_to_response!(result) end |