Class: Coloredcoins::Transaction
- Inherits:
-
Object
- Object
- Coloredcoins::Transaction
- Defined in:
- lib/coloredcoins/transaction.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#tx ⇒ Object
readonly
Returns the value of attribute tx.
Class Method Summary collapse
Instance Method Summary collapse
- #broadcast ⇒ Object
-
#initialize(hex) ⇒ Transaction
constructor
A new instance of Transaction.
- #new_tx ⇒ Object
- #to_hex ⇒ Object
Constructor Details
#initialize(hex) ⇒ Transaction
Returns a new instance of Transaction.
18 19 20 |
# File 'lib/coloredcoins/transaction.rb', line 18 def initialize(hex) @tx = Bitcoin::P::Tx.new([hex].pack('H*')) end |
Instance Attribute Details
#tx ⇒ Object (readonly)
Returns the value of attribute tx.
3 4 5 |
# File 'lib/coloredcoins/transaction.rb', line 3 def tx @tx end |
Class Method Details
.build_key(key) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/coloredcoins/transaction.rb', line 5 def self.build_key(key) return key if key.is_a?(Array) key = Bitcoin::Key.from_base58(key) unless key.is_a?(Bitcoin::Key) key rescue RuntimeError => e raise InvalidKeyError, 'Invalid key' if e. == 'Invalid version' end |
.build_sigs(key, sig_hash) ⇒ Object
13 14 15 16 |
# File 'lib/coloredcoins/transaction.rb', line 13 def self.build_sigs(key, sig_hash) key = [key] unless key.is_a?(Array) key.map { |k| k.sign(sig_hash) } end |
Instance Method Details
#broadcast ⇒ Object
36 37 38 39 40 41 |
# File 'lib/coloredcoins/transaction.rb', line 36 def broadcast response = Coloredcoins.broadcast(to_hex) return response unless response[:txid] txid = response[:txid] txid.is_a?(Array) ? txid.first[:txid] : txid end |
#new_tx ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/coloredcoins/transaction.rb', line 27 def new_tx @new_tx = Bitcoin::P::Tx.new @new_tx.ver = tx.ver @new_tx.lock_time = tx.lock_time tx.in.each { |input| @new_tx.add_in(input) } tx.out.each { |output| @new_tx.add_out(output) } @new_tx end |
#to_hex ⇒ Object
22 23 24 25 |
# File 'lib/coloredcoins/transaction.rb', line 22 def to_hex raw_tx = Bitcoin::P::Tx.binary_from_json(new_tx.to_json) raw_tx.unpack('H*').first end |