Class: Glueby::Internal::Wallet::AR::Utxo
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Glueby::Internal::Wallet::AR::Utxo
- Defined in:
- lib/glueby/internal/wallet/active_record/utxo.rb
Class Method Summary collapse
-
.create_or_update_for_outputs(tx, status: :finalized) ⇒ Object
Create utxo or update utxo for tx outputs if there is no key for script pubkey in an output, utxo for the output is not created.
-
.destroy_for_inputs(tx) ⇒ Object
Delete utxo spent by specified tx.
Instance Method Summary collapse
Class Method Details
.create_or_update_for_outputs(tx, status: :finalized) ⇒ Object
Create utxo or update utxo for tx outputs if there is no key for script pubkey in an output, utxo for the output is not created.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/glueby/internal/wallet/active_record/utxo.rb', line 33 def self.create_or_update_for_outputs(tx, status: :finalized) tx.outputs.each.with_index do |output, index| key = Key.key_for_output(output) next unless key utxo = Utxo.find_or_initialize_by(txid: tx.txid, index: index) utxo.update!( label: key.label, color_id: output.script_pubkey.color_id&.to_hex, script_pubkey: output.script_pubkey.to_hex, value: output.value, status: status, key: key ) end end |
.destroy_for_inputs(tx) ⇒ Object
Delete utxo spent by specified tx.
23 24 25 26 27 |
# File 'lib/glueby/internal/wallet/active_record/utxo.rb', line 23 def self.destroy_for_inputs(tx) tx.inputs.each do |input| Utxo.destroy_by(txid: input.out_point.txid, index: input.out_point.index) end end |
Instance Method Details
#color_id ⇒ Object
15 16 17 18 |
# File 'lib/glueby/internal/wallet/active_record/utxo.rb', line 15 def color_id script = Tapyrus::Script.parse_from_payload(script_pubkey.htb) script.color_id&.to_hex end |