invoices: self-contained payout addresses
Crypto options were limited to a hard-coded asset list, with one address per coin in a side table. A payout address now carries everything an invoice needs: ticker, name, QR URI scheme, amount parameter, CoinGecko id, address and an active flag. Any coin can be added, several addresses per ticker are fine, and known tickers fill the QR and rate fields from the built-in templates. The new-invoice form picks a payout address. The invoice snapshots the ticker, address, name, scheme and amount parameter, and the PDF and QR render from that copy, so editing, retiring or deleting a payout entry never changes an issued invoice. "Fetch live" looks up the rate by the payout address's CoinGecko id. Migration 012 keeps the existing rows and backfills both the payout metadata and the snapshots on existing crypto invoices. Assisted-by: Claude:opus-5
This commit is contained in:
parent
78ea9926e7
commit
33ba7650c3
19 changed files with 420 additions and 176 deletions
51
db/migrations/012_payout_addresses_rework.rb
Normal file
51
db/migrations/012_payout_addresses_rework.rb
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
require_relative '../../lib/crypto_asset'
|
||||
|
||||
Sequel.migration do
|
||||
up do
|
||||
# A payout address now carries everything an invoice needs: ticker
|
||||
# (coin), display name, QR URI scheme + amount parameter, CoinGecko id for
|
||||
# the live rate, the address, and an active flag. Several per ticker.
|
||||
alter_table(:payout_addresses) do
|
||||
drop_constraint :payout_addresses_pkey
|
||||
add_primary_key :id
|
||||
add_column :name, String
|
||||
add_column :scheme, String # e.g. litecoin; NULL = bare address
|
||||
add_column :amount_param, String # amount | tx_amount; NULL = none
|
||||
add_column :coingecko, String # NULL = rate typed by hand
|
||||
add_column :active, TrueClass, null: false, default: true
|
||||
end
|
||||
|
||||
# Invoices snapshot the payout metadata at issue (like the address), so
|
||||
# later edits never change an issued PDF or QR.
|
||||
alter_table(:invoices) do
|
||||
add_column :crypto_name, String
|
||||
add_column :crypto_scheme, String
|
||||
add_column :crypto_amount_param, String
|
||||
end
|
||||
|
||||
CryptoAsset::DEFAULTS.each do |code, a|
|
||||
self[:payout_addresses].where(coin: code).update(name: a[:name], scheme: a[:scheme],
|
||||
amount_param: a[:amount_param], coingecko: a[:coingecko])
|
||||
self[:invoices].where(crypto_coin: code).update(crypto_name: a[:name], crypto_scheme: a[:scheme],
|
||||
crypto_amount_param: a[:amount_param])
|
||||
end
|
||||
self[:payout_addresses].where(name: nil).update(name: :coin)
|
||||
end
|
||||
|
||||
down do
|
||||
alter_table(:invoices) do
|
||||
drop_column :crypto_amount_param
|
||||
drop_column :crypto_scheme
|
||||
drop_column :crypto_name
|
||||
end
|
||||
alter_table(:payout_addresses) do
|
||||
drop_column :active
|
||||
drop_column :coingecko
|
||||
drop_column :amount_param
|
||||
drop_column :scheme
|
||||
drop_column :name
|
||||
drop_column :id
|
||||
add_primary_key [:coin]
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue