Module: ScaleRb::ExtrinsicHelper

Defined in:
lib/scale_rb/extrinsic_helper.rb

Class Method Summary collapse

Class Method Details

.decode_extrinsic(bytes, metadata) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/scale_rb/extrinsic_helper.rb', line 6

def decode_extrinsic(bytes, )
  extrinsic_hash = "0x#{Blake2b.hex(bytes, 32)}"

  _, remaining_bytes = ScaleRb::Codec.decode_compact(bytes)
  meta, remaining_bytes = [remaining_bytes[0], remaining_bytes[1..]]
  signed = (meta & 0x80) == 0x80
  version = (meta & 0x7f)

  raise "Unsupported version: #{version}" unless version == 4

  if signed
    # puts "signed"
    signature, remaining_bytes = ScaleRb::Codec.decode(
      .signature_type_id, 
      remaining_bytes, 
      .registry
    )
    call, = ScaleRb::Codec.decode(
      .runtime_call_type_id, 
      remaining_bytes, 
      .registry
    )
    {
      version: 4,
      signature: signature,
      call: call,
      extrinsic_hash: extrinsic_hash
    }
  else
    # puts "unsigned"
    call, = ScaleRb::Codec.decode(
      .runtime_call_type_id, 
      remaining_bytes, 
      .registry
    )
    {
      version: 4,
      call: call,
      extrinsic_hash: extrinsic_hash
    }
  end
end