invoices: payout addresses in the database
All checks were successful
Build and Deploy to Production / test (push) Successful in 26s
Build and Deploy to Production / build (push) Successful in 59s
Build and Deploy to Production / deploy (push) Successful in 38s

Default crypto payout addresses lived in the CRYPTO_ADDRESSES and
LTC_ADDRESS Forgejo secrets, so changing one meant editing a secret and
redeploying. Keep them in a payout_addresses table edited at
/admin/invoices/payout-addresses (read to view, write to change, every
change audited), and prefill the new-invoice form from it.

The old env values are imported once on the first boot with an empty
table, so the current addresses carry over; after that the secrets can
be removed.

Assisted-by: Claude:opus-5
This commit is contained in:
Sergei Poljanski 2026-10-10 08:36:32 +04:00
commit 1dd8f9081f
Signed by: asxpi
GPG key ID: 4F8851660FA4121B
10 changed files with 179 additions and 14 deletions

View file

@ -17,9 +17,9 @@ class CryptoAssetTest < Minitest::Test
refute CryptoAsset.valid?('DOGE')
end
def test_default_addresses_from_json_env
def test_env_addresses_from_json_env
ENV['CRYPTO_ADDRESSES'] = '{"BTC":"bc1qtest","usdt-trc20":"Ttest","DOGE":"ignored"}'
map = CryptoAsset.default_addresses
map = CryptoAsset.env_addresses
assert_equal 'bc1qtest', map['BTC']
assert_equal 'Ttest', map['USDT-TRC20']
refute map.key?('DOGE')
@ -29,14 +29,14 @@ class CryptoAssetTest < Minitest::Test
def test_legacy_ltc_address_env_still_fills_ltc
ENV['LTC_ADDRESS'] = 'ltc1legacy'
assert_equal 'ltc1legacy', CryptoAsset.default_addresses['LTC']
assert_equal 'ltc1legacy', CryptoAsset.env_addresses['LTC']
ensure
ENV.delete('LTC_ADDRESS')
end
def test_default_addresses_survives_bad_json
def test_env_addresses_survives_bad_json
ENV['CRYPTO_ADDRESSES'] = 'not json'
assert_equal({}, CryptoAsset.default_addresses)
assert_equal({}, CryptoAsset.env_addresses)
ensure
ENV.delete('CRYPTO_ADDRESSES')
end