Class: Platon::SegwitAddr
- Inherits:
-
Object
- Object
- Platon::SegwitAddr
- Defined in:
- lib/platon/segwit_addr.rb
Constant Summary collapse
- HRP_MAINNET =
TODO
'lat'
- HRP_TESTNET =
'atp'
- HRP_REGTEST =
'atx'
Instance Attribute Summary collapse
-
#hrp ⇒ Object
human-readable part.
-
#prog ⇒ Object
witness program.
-
#ver ⇒ Object
witness version.
Instance Method Summary collapse
-
#addr ⇒ Object
Returns segwit address string which generated from hrp, witness version and witness program.
-
#initialize(addr = nil) ⇒ SegwitAddr
constructor
A new instance of SegwitAddr.
-
#script_pubkey=(script_pubkey) ⇒ Object
parse script pubkey into witness version and witness program.
-
#to_script_pubkey ⇒ Object
Returns segwit script pubkey which generated from witness version and witness program.
Constructor Details
#initialize(addr = nil) ⇒ SegwitAddr
Returns a new instance of SegwitAddr.
13 14 15 16 |
# File 'lib/platon/segwit_addr.rb', line 13 def initialize(addr = nil) @hrp = HRP_TESTNET ## TODO parse_addr(addr) if addr end |
Instance Attribute Details
#hrp ⇒ Object
human-readable part
9 10 11 |
# File 'lib/platon/segwit_addr.rb', line 9 def hrp @hrp end |
#prog ⇒ Object
witness program
11 12 13 |
# File 'lib/platon/segwit_addr.rb', line 11 def prog @prog end |
#ver ⇒ Object
witness version
10 11 12 |
# File 'lib/platon/segwit_addr.rb', line 10 def ver @ver end |
Instance Method Details
#addr ⇒ Object
Returns segwit address string which generated from hrp, witness version and witness program.
29 30 31 |
# File 'lib/platon/segwit_addr.rb', line 29 def addr Bech32.encode(hrp, convert_bits(prog, 8, 5), 1) end |
#script_pubkey=(script_pubkey) ⇒ Object
parse script pubkey into witness version and witness program
24 25 26 |
# File 'lib/platon/segwit_addr.rb', line 24 def script_pubkey=(script_pubkey) @prog = [script_pubkey].pack('H*').unpack("C*") end |
#to_script_pubkey ⇒ Object
Returns segwit script pubkey which generated from witness version and witness program.
19 20 21 |
# File 'lib/platon/segwit_addr.rb', line 19 def to_script_pubkey (prog.map{|p|[p].pack("C")}.join).unpack('H*').first end |