Class: NineteenNinetynine::Utils::CustomAddr
- Inherits:
-
Object
- Object
- NineteenNinetynine::Utils::CustomAddr
- Defined in:
- lib/nineteen_ninetynine/utils.rb
Instance Attribute Summary collapse
-
#hrp ⇒ Object
human-readable part.
-
#prog ⇒ Object
witness program.
Instance Method Summary collapse
- #addr ⇒ Object
-
#initialize(addr = nil) ⇒ CustomAddr
constructor
A new instance of CustomAddr.
- #scriptpubkey=(script) ⇒ Object
- #to_scriptpubkey ⇒ Object
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
#hrp ⇒ Object
human-readable part
11 12 13 |
# File 'lib/nineteen_ninetynine/utils.rb', line 11 def hrp @hrp end |
#prog ⇒ Object
witness program
12 13 14 |
# File 'lib/nineteen_ninetynine/utils.rb', line 12 def prog @prog end |
Instance Method Details
#addr ⇒ Object
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_scriptpubkey ⇒ Object
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 |