Class: BSV::Wallet::Postgres::Action

Inherits:
Sequel::Model
  • Object
show all
Includes:
Fetchable, DisplayTxid
Defined in:
lib/bsv/wallet/postgres/action.rb

Instance Method Summary collapse

Methods included from DisplayTxid

#dtxid

Instance Method Details

#derived_statusSymbol

Derive BRC-100 status from structural state. No status column — the database structure IS the state.

Returns:

  • (Symbol)


24
25
26
27
28
29
30
31
32
# File 'lib/bsv/wallet/postgres/action.rb', line 24

def derived_status
  return :unsigned   if wtxid.nil?
  return :completed  if tx_proof_id
  return :nosend     if values[:broadcast] == 'none'
  return :unproven   unless outputs_dataset.empty?
  return :failed     if broadcast_entry&.tx_status == 'REJECTED'
  return :sending    if broadcast_entry
  :unprocessed
end

#fetch_argsObject



40
41
42
# File 'lib/bsv/wallet/postgres/action.rb', line 40

def fetch_args
  { txid: dtxid }
end

#fetch_commandObject

– Fetchable contract –



36
37
38
# File 'lib/bsv/wallet/postgres/action.rb', line 36

def fetch_command
  :get_tx_status
end

#needs_fetch?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/bsv/wallet/postgres/action.rb', line 44

def needs_fetch?
  outgoing && !wtxid.nil? && tx_proof_id.nil?
end

#write!(response) ⇒ Object

Create a TxProof from the network response when proof data is present. No-op when the transaction is not yet mined (no merkle_path/block_height).

Parameters:

  • response (BSV::Network::ProtocolResponse)

    normalized response



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/bsv/wallet/postgres/action.rb', line 52

def write!(response)
  data = response.data
  return unless data.is_a?(Hash) && data[:merkle_path] && data[:block_height]

  proof_store = ProofStore.new
  proof_id = proof_store.save_proof(
    wtxid: wtxid,
    proof: {
      height: data[:block_height],
      block_hash: decode_hex(data[:block_hash]),
      merkle_path: decode_hex(data[:merkle_path]),
      raw_tx: raw_tx
    }
  )
  update(tx_proof_id: proof_id)
end