Class: BSV::Wallet::Substrates::HTTPWalletWire
- Inherits:
-
Object
- Object
- BSV::Wallet::Substrates::HTTPWalletWire
- Defined in:
- lib/bsv/wallet_interface/substrates/http_wallet_wire.rb
Overview
Binary wire transport that transmits BRC-100 wallet wire messages over HTTP.
Implements the single-method WalletWire interface: given a raw binary frame (as an Array of byte integers), parses the call code, maps it to a URL path, and POSTs the payload to the remote wallet endpoint.
Instance Method Summary collapse
-
#initialize(base_url, originator: nil, http_client: nil) ⇒ HTTPWalletWire
constructor
A new instance of HTTPWalletWire.
-
#transmit_to_wallet(message) ⇒ Array<Integer>
Transmits a binary wallet wire message to the remote wallet.
Constructor Details
#initialize(base_url, originator: nil, http_client: nil) ⇒ HTTPWalletWire
Returns a new instance of HTTPWalletWire.
22 23 24 25 26 |
# File 'lib/bsv/wallet_interface/substrates/http_wallet_wire.rb', line 22 def initialize(base_url, originator: nil, http_client: nil) @base_url = base_url @originator = originator @http_client = http_client end |
Instance Method Details
#transmit_to_wallet(message) ⇒ Array<Integer>
Transmits a binary wallet wire message to the remote wallet.
Parses the call code from byte 0, reads the originator from the header, and POSTs the remaining payload bytes to the appropriate URL path.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/bsv/wallet_interface/substrates/http_wallet_wire.rb', line 37 def transmit_to_wallet() raise ArgumentError, 'message must not be empty' if .nil? || .empty? call_code = [0] call_name = BSV::Wallet::Wire::Serializer::METHODS_BY_CODE[call_code] raise ArgumentError, "unknown call code: #{call_code}" if call_name.nil? originator_length = [1] || 0 originator = [2, originator_length].pack('C*').force_encoding('UTF-8') if originator_length.positive? payload_start = 2 + originator_length payload = [payload_start..] || [] camel_name = BSV::WireFormat.snake_to_camel(call_name.to_s) url = "#{@base_url}/#{camel_name}" response_body = post_binary(url, payload, originator || @originator) response_body.bytes.to_a end |