commit 8f10bf0c4cbaa9edd1f3d6287b60dabcee5399a5
parent 3ec772b741f210d5bcf9d63b66cd06f549465df4
Author: nickfarrow <nick@nickfarrow.com>
Date: Wed, 10 Aug 2022 22:16:54 +1000
rename fiat_currency to base_currency
Avoids 'fiat_currency':'BTC'
Co-authored-by: Kristaps Kaupe <kristaps@blogiem.lv>
Diffstat:
5 files changed, 19 insertions(+), 12 deletions(-)
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"],