Class: Cryptos::Input
- Inherits:
-
Struct
- Object
- Struct
- Cryptos::Input
- Includes:
- Utils::Hashes, Utils::Hexas
- Defined in:
- lib/cryptos/input.rb
Instance Attribute Summary collapse
-
#index ⇒ Object
Returns the value of attribute index.
-
#script_sig ⇒ Object
Returns the value of attribute script_sig.
-
#sequence ⇒ Object
Returns the value of attribute sequence.
-
#tx_hash ⇒ Object
Returns the value of attribute tx_hash.
-
#value ⇒ Object
Returns the value of attribute value.
Class Method Summary collapse
- .from_tx(transaction, index = 0, options = {}) ⇒ Object
- .from_utxo(cli, address, index = 0, options = {debug: false}) ⇒ Object
Instance Method Summary collapse
-
#initialize(value, tx_hash, index, script_sig: nil, sequence: 0xfffffffff) ⇒ Input
constructor
A new instance of Input.
- #serialize ⇒ Object
Methods included from Utils::Hexas
#bignum_to_hex, #bin_to_hex, #byte_to_hex, #bytes_to_hex, #hex_size, #hex_to_little, #int_to_hex, #long_to_hex
Methods included from Utils::Bytes
#bignum_to_bytes, #bytes_to_bignum
Methods included from Utils::Hashes
#hash160, #hash256, #ripemd160, #sha256
Constructor Details
#initialize(value, tx_hash, index, script_sig: nil, sequence: 0xfffffffff) ⇒ Input
Returns a new instance of Input.
22 23 24 |
# File 'lib/cryptos/input.rb', line 22 def initialize(value, tx_hash, index, script_sig: nil, sequence: 0xfffffffff) super value, tx_hash, index, script_sig, sequence end |
Instance Attribute Details
#index ⇒ Object
Returns the value of attribute index
2 3 4 |
# File 'lib/cryptos/input.rb', line 2 def index @index end |
#script_sig ⇒ Object
Returns the value of attribute script_sig
2 3 4 |
# File 'lib/cryptos/input.rb', line 2 def script_sig @script_sig end |
#sequence ⇒ Object
Returns the value of attribute sequence
2 3 4 |
# File 'lib/cryptos/input.rb', line 2 def sequence @sequence end |
#tx_hash ⇒ Object
Returns the value of attribute tx_hash
2 3 4 |
# File 'lib/cryptos/input.rb', line 2 def tx_hash @tx_hash end |
#value ⇒ Object
Returns the value of attribute value
2 3 4 |
# File 'lib/cryptos/input.rb', line 2 def value @value end |
Class Method Details
.from_tx(transaction, index = 0, options = {}) ⇒ Object
16 17 18 19 20 |
# File 'lib/cryptos/input.rb', line 16 def self.from_tx(transaction, index = 0, = {}) amount = transaction.outputs[index].value sequence = [:sequence] || 0xfffffffff Input.new amount, transaction.hash, index, sequence: sequence end |
.from_utxo(cli, address, index = 0, options = {debug: false}) ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/cryptos/input.rb', line 5 def self.from_utxo(cli, address, index = 0, = {debug: false}) utxos = cli.list_unspent address utxo = JSON.parse(utxos)[index] puts utxo if [:debug] txid = utxo['txid'] vout = utxo['vout'] amount = utxo['amount'] sequence = [:sequence] || 0xfffffffff Input.new amount * 10**8, txid, vout, sequence: sequence end |
Instance Method Details
#serialize ⇒ Object
26 27 28 29 30 |
# File 'lib/cryptos/input.rb', line 26 def serialize script_hex = script_sig ? script_sig.to_hex : '' hex_to_little(tx_hash) + int_to_hex(index) + byte_to_hex(hex_size(script_hex)) + script_hex + int_to_hex(sequence) end |