Class: CustomAddr
- Inherits:
-
Object
- Object
- CustomAddr
- Defined in:
- lib/custom_addr.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.
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
#hrp ⇒ Object
human-readable part
3 4 5 |
# File 'lib/custom_addr.rb', line 3 def hrp @hrp end |
#prog ⇒ Object
witness program
4 5 6 |
# File 'lib/custom_addr.rb', line 4 def prog @prog end |
Instance Method Details
#addr ⇒ Object
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_scriptpubkey ⇒ Object
10 11 12 |
# File 'lib/custom_addr.rb', line 10 def to_scriptpubkey prog.map{|p|[p].pack("C")}.join.unpack('H*').first end |