Class: BSV::Wallet::Substrates::HTTPWalletWire
- Inherits:
-
Object
- Object
- BSV::Wallet::Substrates::HTTPWalletWire
- Includes:
- WalletWire
- Defined in:
- lib/bsv/wallet/substrates/http_wallet_wire.rb
Overview
Concrete WalletWire implementation over HTTP/HTTPS.
Transmits binary BRC-103 request frames via HTTP POST to ‘base_url/wallet` using `Content-Type: application/octet-stream`, and returns the raw binary response body.
The optional ‘http_client:` parameter accepts any object responding to `#request(uri, net_http_request)` — matching the injectable client convention used throughout this SDK. When omitted, `Net::HTTP` is used directly.
Class Method Summary collapse
-
.client(base_url:, http_client: nil, headers: {}) ⇒ WalletWireTransceiver
Convenience factory: wraps a new HTTPWalletWire in a WalletWireTransceiver.
Instance Method Summary collapse
-
#initialize(base_url:, http_client: nil, headers: {}) ⇒ HTTPWalletWire
constructor
A new instance of HTTPWalletWire.
-
#transmit_to_wallet(message) ⇒ String
POST binary frame to ‘base_url/wallet` and return the binary response body.
Constructor Details
#initialize(base_url:, http_client: nil, headers: {}) ⇒ HTTPWalletWire
Returns a new instance of HTTPWalletWire.
35 36 37 38 39 |
# File 'lib/bsv/wallet/substrates/http_wallet_wire.rb', line 35 def initialize(base_url:, http_client: nil, headers: {}) @uri = build_uri(base_url) @http_client = http_client @headers = headers.transform_keys(&:to_s) end |
Class Method Details
.client(base_url:, http_client: nil, headers: {}) ⇒ WalletWireTransceiver
Convenience factory: wraps a new BSV::Wallet::Substrates::HTTPWalletWire in a WalletWireTransceiver.
47 48 49 |
# File 'lib/bsv/wallet/substrates/http_wallet_wire.rb', line 47 def self.client(base_url:, http_client: nil, headers: {}) WalletWireTransceiver.new(new(base_url: base_url, http_client: http_client, headers: headers)) end |
Instance Method Details
#transmit_to_wallet(message) ⇒ String
POST binary frame to ‘base_url/wallet` and return the binary response body.
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/bsv/wallet/substrates/http_wallet_wire.rb', line 56 def transmit_to_wallet() http_post() rescue BSV::Wallet::Error raise rescue SocketError, Errno::ECONNREFUSED, Errno::ETIMEDOUT, Net::OpenTimeout, Net::ReadTimeout, Net::HTTPError => e raise BSV::Wallet::Error.new("wallet connection failed: #{e.}", code: 1) rescue StandardError => e raise BSV::Wallet::Error.new("wallet request failed: #{e.}", code: 1) end |