Module: BSV::Wallet::Serializer::SignActionArgs
- Defined in:
- lib/bsv/wallet/serializer/sign_action_args.rb
Overview
BRC-103 serialiser for sign_action args (call byte 2).
Wire layout (port of go-sdk/wallet/serializer/sign_action_args.go):
[varint] spends count
For each spend (sorted by input_index):
[varint] input_index
[int_bytes] unlocking_script
[optional_uint32] sequence_number
[int_bytes] reference
[1 byte] options present flag (0=absent, 1=present)
If options present:
[optional_bool] accept_delayed_broadcast
[optional_bool] return_txid_only
[optional_bool] no_send
[txid_slice] send_with
Class Method Summary collapse
Class Method Details
.deserialize(bytes) ⇒ Hash
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/bsv/wallet/serializer/sign_action_args.rb', line 56 def deserialize(bytes) r = Wire::Reader.new(bytes) spend_count = r.read_varint spends = {} spend_count.times do idx = r.read_varint script = r.read_int_bytes seq = r.read_optional_uint32 spend = { unlocking_script: script } spend[:sequence_number] = seq unless seq.nil? spends[idx] = spend end reference = r.read_int_bytes = r.read_byte = if == 1 opts = {} v = r.read_optional_bool opts[:accept_delayed_broadcast] = v unless v.nil? v = r.read_optional_bool opts[:return_txid_only] = v unless v.nil? v = r.read_optional_bool opts[:no_send] = v unless v.nil? sw = r.read_txid_slice opts[:send_with] = sw unless sw.nil? opts end result = { spends: spends } result[:reference] = reference unless reference.nil? || reference.empty? result[:options] = unless .nil? result end |
.serialize(args) ⇒ String
Returns binary.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/bsv/wallet/serializer/sign_action_args.rb', line 26 def serialize(args) w = Wire::Writer.new spends = args[:spends] || {} w.write_varint(spends.length) spends.keys.sort.each do |idx| spend = spends[idx] w.write_varint(idx) w.write_int_bytes(spend[:unlocking_script]) w.write_optional_uint32(spend[:sequence_number]) end w.write_int_bytes(args[:reference]) opts = args[:options] if opts w.write_byte(1) w.write_optional_bool(opts[:accept_delayed_broadcast]) w.write_optional_bool(opts[:return_txid_only]) w.write_optional_bool(opts[:no_send]) w.write_txid_slice(opts[:send_with]) else w.write_byte(0) end w.buf end |