Module: Vendi::Monitor

Included in:
Machine
Defined in:
lib/vendi/monitor.rb

Overview

helper methods for monitoring incoming transactions

Instance Method Summary collapse

Instance Method Details

#get_dest_addr(tx, address) ⇒ Object

trying to naively get address to send back NFT, take first address from the output that isn’t our address assuming that it is a change address



24
25
26
27
28
29
# File 'lib/vendi/monitor.rb', line 24

def get_dest_addr(tx, address)
  output_dest_addr = tx['outputs'].map { |o| o['address'] }.reject { |a| a == address }.first

  # if no address in outputs try to get one from inputs
  output_dest_addr || tx['inputs'].map { |o| o['address'] }.reject { |a| a == address }.first
end

#get_incoming_txs(wid) ⇒ Object



6
7
8
# File 'lib/vendi/monitor.rb', line 6

def get_incoming_txs(wid)
  @cw.shelley.transactions.list(wid).select { |t| t['direction'] == 'incoming' }
end

#get_transactions_to_process(txs_new, txs) ⇒ Object



10
11
12
# File 'lib/vendi/monitor.rb', line 10

def get_transactions_to_process(txs_new, txs)
  txs_new[0..(txs_new.size - txs.size - 1)]
end

#incoming_tx_ok?(tx, address, price) ⇒ Boolean

incoming tx is correct when the address is on any of the outputs (means that someone was sending to it) and tx amount is >= price set in the config

Returns:

  • (Boolean)


16
17
18
19
20
# File 'lib/vendi/monitor.rb', line 16

def incoming_tx_ok?(tx, address, price)
  (tx['outputs'].any? { |o| (o['address'] == address) }) &&
    (tx['amount']['quantity'] >= price) &&
    (tx['direction'] == 'incoming')
end