Class: CustomAddr

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(addr = nil) ⇒ CustomAddr

Returns a new instance of CustomAddr.



6
7
8
# File 'lib/custom_addr.rb', line 6

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

Instance Attribute Details

#hrpObject

human-readable part



3
4
5
# File 'lib/custom_addr.rb', line 3

def hrp
  @hrp
end

#progObject

witness program



4
5
6
# File 'lib/custom_addr.rb', line 4

def prog
  @prog
end

Instance Method Details

#addrObject



19
20
21
22
# File 'lib/custom_addr.rb', line 19

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

#scriptpubkey=(script) ⇒ Object



14
15
16
17
# File 'lib/custom_addr.rb', line 14

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

#to_scriptpubkeyObject



10
11
12
# File 'lib/custom_addr.rb', line 10

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