Module: BSV::Wallet::Serializer::GetNetwork::Result
- Defined in:
- lib/bsv/wallet/serializer/get_network.rb
Constant Summary collapse
- MAINNET_CODE =
0- TESTNET_CODE =
1
Class Method Summary collapse
-
.deserialize(bytes) ⇒ Hash
{ network: :mainnet | :testnet }.
-
.serialize(result) ⇒ String
1-byte binary.
Class Method Details
.deserialize(bytes) ⇒ Hash
Returns { network: :mainnet | :testnet }.
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/bsv/wallet/serializer/get_network.rb', line 48 def deserialize(bytes) data = bytes.b raise BSV::Wallet::InvalidParameterError.new('get_network result', 'exactly 1 byte') unless data.bytesize == 1 case data.getbyte(0) when MAINNET_CODE then { network: :mainnet } when TESTNET_CODE then { network: :testnet } else raise BSV::Wallet::InvalidParameterError.new( 'get_network result', "0x00 (mainnet) or 0x01 (testnet), got 0x#{data.unpack1('H*')}" ) end end |
.serialize(result) ⇒ String
Returns 1-byte binary.
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/bsv/wallet/serializer/get_network.rb', line 33 def serialize(result) code = case result[:network] when :mainnet then MAINNET_CODE when :testnet then TESTNET_CODE else raise BSV::Wallet::InvalidParameterError.new( 'network', ":mainnet or :testnet, got #{result[:network].inspect}" ) end [code].pack('C') end |