Class: NineteenNinetynine::Utils::CustomAddr

Inherits:
Object
  • Object
show all
Defined in:
lib/nineteen_ninetynine/utils.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(addr = nil) ⇒ CustomAddr

Returns a new instance of CustomAddr.



14
15
16
# File 'lib/nineteen_ninetynine/utils.rb', line 14

def initialize(addr = nil)
  @hrp, @prog = parse_addr(addr) if addr
end

Instance Attribute Details

#hrpObject

human-readable part



11
12
13
# File 'lib/nineteen_ninetynine/utils.rb', line 11

def hrp
  @hrp
end

#progObject

witness program



12
13
14
# File 'lib/nineteen_ninetynine/utils.rb', line 12

def prog
  @prog
end

Instance Method Details

#addrObject



27
28
29
30
# File 'lib/nineteen_ninetynine/utils.rb', line 27

def addr
  spec = Bech32::Encoding::BECH32
  Bech32.encode(hrp, convert_bits(prog, 8, 5), spec)
end

#scriptpubkey=(script) ⇒ Object



22
23
24
25
# File 'lib/nineteen_ninetynine/utils.rb', line 22

def scriptpubkey=(script)
  values = [script].pack("H*").unpack("C*")
  @prog = values
end

#to_scriptpubkeyObject



18
19
20
# File 'lib/nineteen_ninetynine/utils.rb', line 18

def to_scriptpubkey
  prog.map{|p|[p].pack("C")}.join.unpack("H*").first
end