Module: BSV::Wallet::Serializer::InternalizeActionArgs

Defined in:
lib/bsv/wallet/serializer/internalize_action.rb

Overview

BRC-103 serialiser for internalize_action (call byte 5).

Wire layout (port of go-sdk/wallet/serializer/internalize_action.go):

[varint + bytes] tx (BEEF) — length-prefixed raw bytes
[varint]         outputs count
For each output:
  [varint]       output_index
  [1 byte]       protocol: 0x01=wallet_payment, 0x02=basket_insertion
  If wallet_payment:
    [33 bytes]   sender_identity_key (compressed pubkey)
    [int_bytes]  derivation_prefix
    [int_bytes]  derivation_suffix
  If basket_insertion:
    [string]     basket
    [optional_string] custom_instructions
    [string_slice] tags
[string_slice]   labels
[string]         description
[optional_bool] seek_permission

Result wire layout: empty (success is implicit from the frame error byte).

Constant Summary collapse

PROTOCOL_WALLET_PAYMENT =
1
PROTOCOL_BASKET_INSERTION =
2
PUBKEY_SIZE =
33

Class Method Summary collapse

Class Method Details

.deserialize(bytes) ⇒ Hash

Parameters:

  • bytes (String)

    binary

Returns:

  • (Hash)


56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/bsv/wallet/serializer/internalize_action.rb', line 56

def deserialize(bytes)
  r = Wire::Reader.new(bytes)

  tx_len = r.read_varint
  tx     = r.read_bytes(tx_len)

  output_count = r.read_varint
  outputs = output_count.times.map { deserialize_output(r) }

  labels         = r.read_string_slice
  description    = r.read_string
  seek_permission = r.read_optional_bool

  result = { tx: tx, outputs: outputs, description: description }
  result[:labels] = labels unless labels.nil?
  result[:seek_permission] = seek_permission unless seek_permission.nil?
  result
end

.serialize(args) ⇒ String

Returns binary.

Parameters:

  • args (Hash)

Returns:

  • (String)

    binary



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/bsv/wallet/serializer/internalize_action.rb', line 36

def serialize(args)
  w = Wire::Writer.new

  tx = (args[:tx] || ''.b).b
  w.write_varint(tx.bytesize)
  w.write_bytes(tx)

  outputs = args[:outputs] || []
  w.write_varint(outputs.length)
  outputs.each { |out| serialize_output(w, out) }

  w.write_string_slice(args[:labels])
  w.write_string(args[:description].to_s)
  w.write_optional_bool(args[:seek_permission])

  w.buf
end