commit fa269936dee76de07dfed35de82f61f599aa8f92
parent 0c657b35fa8e406604f5629ea56f175e38257045
Author: Nick <nick@nickfarrow.com>
Date: Mon, 29 Aug 2022 14:01:26 +0800
Make sats the standard
Default to sats as base currency
Diffstat:
6 files changed, 21 insertions(+), 14 deletions(-)
diff --git a/config.toml b/config.toml
@@ -91,8 +91,8 @@ loglevel = "DEBUG"
redirect = "https://github.com/nickfarrow/satsale"
# Currency and exchange rate provider
-supported_currencies = ["BTC", "USD"] # Currencies to display on donation dropdown
-base_currency = "USD" # Selection default for that dropdown
+supported_currencies = ["BTC"] # Currencies to display on donation dropdown
+base_currency = "sats" # Selection default for that dropdown
currency_provider = "COINGECKO" # Supported: COINDESK | COINGECKO
# Multiplier added on top of BTC / fiat exchange rate. Allows to give discount or add extra commission.
diff --git a/gateways/woo_webhook.py b/gateways/woo_webhook.py
@@ -12,7 +12,7 @@ def hook(satsale_secret, invoice, order_id):
# Calculate a secret that is required to send back to the
# woocommerce gateway, proving we did not modify id nor amount.
- secret_seed = str(int(100 * float(invoice["fiat_value"]))).encode("utf-8")
+ secret_seed = str(int(100 * float(invoice["base_value"]))).encode("utf-8")
logging.info("Secret seed: {}".format(secret_seed))
secret = hmac.new(key, secret_seed, hashlib.sha256).hexdigest()
diff --git a/payments/database.py b/payments/database.py
@@ -50,12 +50,19 @@ def migrate_database(name="database.db"):
_set_database_schema_version(2)
if schema_version < 3:
- _log_migrate_database(2, 3, "Adding fiat currency column to payments table")
+ _log_migrate_database(2, 3, "Adding base currency column to payments table")
with sqlite3.connect(name) as conn:
conn.execute("ALTER TABLE payments ADD fiat_currency TEXT")
_set_database_schema_version(3)
- #if schema_version < 4:
+ if schema_version < 4:
+ _log_migrate_database(3, 4, "Renaming fiat to base in payments table")
+ with sqlite3.connect(name) as conn:
+ conn.execute("ALTER TABLE payments RENAME fiat_value TO base_value")
+ conn.execute("ALTER TABLE payments RENAME fiat_currency TO base_currency")
+ _set_database_schema_version(4)
+
+ #if schema_version < 5:
# do next migration
new_version = _get_database_schema_version(name)
@@ -71,11 +78,11 @@ def write_to_database(invoice, name="database.db"):
with sqlite3.connect(name) as conn:
cur = conn.cursor()
cur.execute(
- "INSERT INTO payments (uuid,fiat_currency,fiat_value,btc_value,method,address,time,webhook,rhash) VALUES (?,?,?,?,?,?,?,?,?)",
+ "INSERT INTO payments (uuid,base_currency,base_value,btc_value,method,address,time,webhook,rhash) VALUES (?,?,?,?,?,?,?,?,?)",
(
invoice["uuid"],
- invoice["fiat_currency"],
- invoice["fiat_value"],
+ invoice["base_currency"],
+ invoice["base_value"],
invoice["btc_value"],
invoice["method"],
invoice["address"],
diff --git a/payments/price_feed.py b/payments/price_feed.py
@@ -73,4 +73,4 @@ def get_btc_value(base_amount, currency):
return float_value
- raise Exception("Failed to get fiat value.")
+ raise Exception("Failed to get base currency value.")
diff --git a/satsale.py b/satsale.py
@@ -93,8 +93,8 @@ invoice_model = api.model(
"invoice",
{
"uuid": fields.String(),
- "fiat_currency": fields.String(),
- "fiat_value": fields.Float(),
+ "base_currency": fields.String(),
+ "base_value": fields.Float(),
"btc_value": fields.Float(),
"method": fields.String(),
"address": fields.String(),
@@ -165,8 +165,8 @@ class create_payment(Resource):
invoice = {
"uuid": str(uuid.uuid4().hex),
- "fiat_currency": currency,
- "fiat_value": base_amount,
+ "base_currency": currency,
+ "base_value": base_amount,
"btc_value": btc_amount_format(btc_value),
"method": payment_method,
"time": time.time(),
diff --git a/scripts/generate_payment_report.py b/scripts/generate_payment_report.py
@@ -88,7 +88,7 @@ def main():
datetime.utcfromtimestamp(
int(invoice["time"])).strftime("%Y-%m-%d"),
invoice["uuid"],
- invoice["fiat_value"],
+ invoice["base_value"],
"%.8f" % float(invoice["btc_value"]),
"%.8f" % float(conf_paid),
invoice["method"],