class Glueby::Internal::Wallet::AR::Utxo
Public Class Methods
create_or_update_for_outputs(tx, status: :finalized)
click to toggle source
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.
@param [Tapyrus::Tx] tx
# File lib/glueby/internal/wallet/active_record/utxo.rb, line 32 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, script_pubkey: output.script_pubkey.to_hex, value: output.value, status: status, key: key ) end end
destroy_for_inputs(tx)
click to toggle source
Delete utxo spent by specified tx.
@param [Tapyrus::Tx] the spending tx
# File lib/glueby/internal/wallet/active_record/utxo.rb, line 22 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
Public Instance Methods
color_id()
click to toggle source
# File lib/glueby/internal/wallet/active_record/utxo.rb, line 14 def color_id script = Tapyrus::Script.parse_from_payload(script_pubkey.htb) script.color_id&.to_hex end