Class: CoinOp::Bit::Input
- Inherits:
-
Object
- Object
- CoinOp::Bit::Input
- Includes:
- Encodings
- Defined in:
- lib/coin-op/bit/input.rb
Instance Attribute Summary collapse
-
#binary_sig_hash ⇒ Object
Returns the value of attribute binary_sig_hash.
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#native ⇒ Object
readonly
Returns the value of attribute native.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
-
#script_sig ⇒ Object
Returns the value of attribute script_sig.
-
#sig_hash ⇒ Object
readonly
Returns the value of attribute sig_hash.
-
#signatures ⇒ Object
readonly
Returns the value of attribute signatures.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Input
constructor
Takes a Hash containing these fields:.
- #to_json(*a) ⇒ Object
Methods included from Encodings
#base58, #decode_base58, #decode_hex, #hex
Constructor Details
#initialize(options = {}) ⇒ Input
Takes a Hash containing these fields:
-
:transaction - a Transaction instance
-
:index - the index of the input within the transaction
-
:output - a value representing this input’s unspent output
Optionally:
-
script_sig_asm - the string form of the scriptSig for this input
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/coin-op/bit/input.rb', line 21 def initialize(={}) @transaction, @index, @output, @network = .values_at :transaction, :index, :output, :network script_sig_asm = [:script_sig_asm] unless @output.is_a? Output @output = Output.new(@output, network: @network) end @native = Bitcoin::Protocol::TxIn.new # TODO: the reverse is cargo-culted from a function in bitcoin-ruby # that doesn't document the reason. Find the explanation in the bitcoin # wiki or in the reference client source and document here. @native.prev_out = decode_hex(@output.transaction_hash).reverse @native.prev_out_index = @output.index if script_sig_asm self.script_sig = Bitcoin::Script.binary_from_string(script_sig_asm) end @signatures = [] end |
Instance Attribute Details
#binary_sig_hash ⇒ Object
Returns the value of attribute binary_sig_hash.
8 9 10 |
# File 'lib/coin-op/bit/input.rb', line 8 def binary_sig_hash @binary_sig_hash end |
#index ⇒ Object (readonly)
Returns the value of attribute index.
8 9 10 |
# File 'lib/coin-op/bit/input.rb', line 8 def index @index end |
#native ⇒ Object (readonly)
Returns the value of attribute native.
8 9 10 |
# File 'lib/coin-op/bit/input.rb', line 8 def native @native end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
8 9 10 |
# File 'lib/coin-op/bit/input.rb', line 8 def output @output end |
#script_sig ⇒ Object
Returns the value of attribute script_sig.
8 9 10 |
# File 'lib/coin-op/bit/input.rb', line 8 def script_sig @script_sig end |
#sig_hash ⇒ Object (readonly)
Returns the value of attribute sig_hash.
8 9 10 |
# File 'lib/coin-op/bit/input.rb', line 8 def sig_hash @sig_hash end |
#signatures ⇒ Object (readonly)
Returns the value of attribute signatures.
8 9 10 |
# File 'lib/coin-op/bit/input.rb', line 8 def signatures @signatures end |
Instance Method Details
#to_json(*a) ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'lib/coin-op/bit/input.rb', line 64 def to_json(*a) { :output => self.output, :signatures => self.signatures.map {|b| hex(b) }, :sig_hash => self.sig_hash || "", :script_sig => self.script_sig || "" }.to_json(*a) end |