Class: String
Instance Method Summary collapse
-
#bth ⇒ Object
binary convert to hex string.
-
#htb ⇒ Object
hex string convert to binary.
-
#opcode ⇒ Object
get opcode.
- #opcode? ⇒ Boolean
- #push_opcode? ⇒ Boolean
-
#pushdata? ⇒ Boolean
whether data push only?.
- #pushed_data ⇒ Object
-
#rhex ⇒ Object
reverse hex string endian.
Instance Method Details
#bth ⇒ Object
binary convert to hex string
104 105 106 |
# File 'lib/bitcoin.rb', line 104 def bth unpack('H*').first end |
#htb ⇒ Object
hex string convert to binary
109 110 111 |
# File 'lib/bitcoin.rb', line 109 def htb [self].pack('H*') end |
#opcode ⇒ Object
get opcode
119 120 121 122 123 124 125 126 127 128 |
# File 'lib/bitcoin.rb', line 119 def opcode case encoding when Encoding::ASCII_8BIT each_byte.next when Encoding::US_ASCII ord else to_i end end |
#opcode? ⇒ Boolean
130 131 132 |
# File 'lib/bitcoin.rb', line 130 def opcode? !pushdata? end |
#push_opcode? ⇒ Boolean
134 135 136 |
# File 'lib/bitcoin.rb', line 134 def push_opcode? [Bitcoin::Opcodes::OP_PUSHDATA1, Bitcoin::Opcodes::OP_PUSHDATA2, Bitcoin::Opcodes::OP_PUSHDATA4].include?(opcode) end |
#pushdata? ⇒ Boolean
whether data push only?
139 140 141 |
# File 'lib/bitcoin.rb', line 139 def pushdata? opcode <= Bitcoin::Opcodes::OP_PUSHDATA4 && opcode > Bitcoin::Opcodes::OP_0 end |
#pushed_data ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/bitcoin.rb', line 143 def pushed_data return nil unless pushdata? offset = 1 case opcode when Bitcoin::Opcodes::OP_PUSHDATA1 offset += 1 when Bitcoin::Opcodes::OP_PUSHDATA2 offset += 2 when Bitcoin::Opcodes::OP_PUSHDATA4 offset += 4 end self[offset..-1] end |
#rhex ⇒ Object
reverse hex string endian
114 115 116 |
# File 'lib/bitcoin.rb', line 114 def rhex htb.reverse.bth end |