Class: Sibit::Tx
- Inherits:
-
Object
- Object
- Sibit::Tx
- Defined in:
- lib/sibit/tx.rb
Overview
Bitcoin Transaction structure.
- Author
Yegor Bugayenko (yegor256@gmail.com)
- Copyright
Copyright (c) 2019-2026 Yegor Bugayenko
- License
MIT
Defined Under Namespace
Constant Summary collapse
- SIGHASH_ALL =
0x01- VERSION =
1- SEQUENCE =
0xffffffff
Instance Attribute Summary collapse
-
#inputs ⇒ Object
readonly
Returns the value of attribute inputs.
-
#outputs ⇒ Object
readonly
Returns the value of attribute outputs.
Instance Method Summary collapse
- #add_input(hash:, index:, script:, key:, value: 0) ⇒ Object
- #add_output(value, address) ⇒ Object
- #hash ⇒ Object
- #hex ⇒ Object
- #in ⇒ Object
-
#initialize(network: :mainnet) ⇒ Tx
constructor
A new instance of Tx.
- #out ⇒ Object
- #payload ⇒ Object
Constructor Details
#initialize(network: :mainnet) ⇒ Tx
Returns a new instance of Tx.
27 28 29 30 31 |
# File 'lib/sibit/tx.rb', line 27 def initialize(network: :mainnet) @inputs = [] @outputs = [] @network = network end |
Instance Attribute Details
#inputs ⇒ Object (readonly)
Returns the value of attribute inputs.
25 26 27 |
# File 'lib/sibit/tx.rb', line 25 def inputs @inputs end |
#outputs ⇒ Object (readonly)
Returns the value of attribute outputs.
25 26 27 |
# File 'lib/sibit/tx.rb', line 25 def outputs @outputs end |
Instance Method Details
#add_input(hash:, index:, script:, key:, value: 0) ⇒ Object
33 34 35 |
# File 'lib/sibit/tx.rb', line 33 def add_input(hash:, index:, script:, key:, value: 0) @inputs << Input.new(hash, index, script, key, value) end |
#add_output(value, address) ⇒ Object
37 38 39 |
# File 'lib/sibit/tx.rb', line 37 def add_output(value, address) @outputs << Output.new(value, address, @network) end |
#hash ⇒ Object
41 42 43 44 45 46 |
# File 'lib/sibit/tx.rb', line 41 def hash sign_inputs Digest::SHA256.hexdigest( Digest::SHA256.digest(serialize(witness: false)) ).scan(/../).reverse.join end |
#hex ⇒ Object
54 55 56 |
# File 'lib/sibit/tx.rb', line 54 def hex payload.unpack1('H*') end |
#in ⇒ Object
58 59 60 |
# File 'lib/sibit/tx.rb', line 58 def in @inputs end |
#out ⇒ Object
62 63 64 |
# File 'lib/sibit/tx.rb', line 62 def out @outputs end |
#payload ⇒ Object
48 49 50 51 52 |
# File 'lib/sibit/tx.rb', line 48 def payload return @payload if @payload sign_inputs @payload = serialize end |