Class: BSV::Wallet::WalletWireProcessor
- Inherits:
-
Object
- Object
- BSV::Wallet::WalletWireProcessor
- Includes:
- WalletWire
- Defined in:
- lib/bsv/wallet/wallet_wire_processor.rb
Overview
Server-side BRC-103 dispatcher.
Takes any Interface::BRC100 implementation and exposes it as a WalletWire. Decodes incoming binary request frames, dispatches to the wallet, serialises the result, and returns a binary result frame.
Error boundary: any Error from the wallet is serialised into an error frame so the client can rehydrate it. Any other StandardError is wrapped in Error (code 1) before framing — the processor never lets a Ruby exception propagate past this boundary.
Instance Method Summary collapse
-
#initialize(wallet) ⇒ WalletWireProcessor
constructor
A new instance of WalletWireProcessor.
-
#transmit_to_wallet(request_bytes) ⇒ String
Process a binary request frame and return a binary result frame.
Constructor Details
#initialize(wallet) ⇒ WalletWireProcessor
Returns a new instance of WalletWireProcessor.
23 24 25 |
# File 'lib/bsv/wallet/wallet_wire_processor.rb', line 23 def initialize(wallet) @wallet = wallet end |
Instance Method Details
#transmit_to_wallet(request_bytes) ⇒ String
Process a binary request frame and return a binary result frame.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/bsv/wallet/wallet_wire_processor.rb', line 31 def transmit_to_wallet(request_bytes) req = Wire::Frame.read_request(request_bytes) call_byte = req[:call] method_name = Wire::Calls::CALL_TO_METHOD.fetch(call_byte) do raise Error.new("unknown call byte: #{call_byte}", code: 1) end serialize_result = Serializer::SERIALIZE_RESULT.fetch(call_byte) do raise Error.new("no result serialiser for call #{call_byte}", code: 1) end args = Serializer::DESERIALIZE_ARGS.fetch(call_byte) do raise Error.new("no args deserialiser for call #{call_byte}", code: 1) end.call(req[:params]) args[:originator] = req[:originator] unless req[:originator].empty? result = @wallet.public_send(method_name, **args) payload = serialize_result.call(result) Wire::Frame.write_result(payload: payload) rescue NotImplementedError => e Wire::Frame.write_error(error: UnsupportedActionError.new(e..to_s)) rescue Error => e Wire::Frame.write_error(error: e) rescue StandardError => e Wire::Frame.write_error(error: Error.new(e..to_s, code: 1)) end |