bugfix createcard

This commit is contained in:
Peter Rounce 2022-10-09 20:11:45 +00:00
parent 53a02eddd3
commit b9faa49928
3 changed files with 12 additions and 9 deletions

View file

@ -1,7 +1,7 @@
DROP DATABASE IF EXISTS card_db; DROP DATABASE IF EXISTS card_db;
CREATE DATABASE card_db; CREATE DATABASE card_db;
DROP USER cardapp; DROP USER IF EXISTS cardapp;
CREATE USER cardapp WITH PASSWORD 'database_password'; CREATE USER cardapp WITH PASSWORD 'database_password';
\c card_db; \c card_db;

View file

@ -47,12 +47,12 @@ func db_delete_expired() error {
} }
func db_insert_card(one_time_code string, k0_auth_key string, k2_cmac_key string, k3 string, k4 string, func db_insert_card(one_time_code string, k0_auth_key string, k2_cmac_key string, k3 string, k4 string,
tx_max_sats int, day_max_sats int, enable_flag bool, card_name string) error { tx_max_sats int, day_max_sats int, lnurlw_enable bool, card_name string) error {
enable_flag_yn := "N" lnurlw_enable_yn := "N"
if enable_flag == true { if lnurlw_enable == true {
enable_flag_yn = "Y" lnurlw_enable_yn = "Y"
} }
db, err := db_open() db, err := db_open()
@ -65,11 +65,11 @@ func db_insert_card(one_time_code string, k0_auth_key string, k2_cmac_key string
sqlStatement := `INSERT INTO cards` + sqlStatement := `INSERT INTO cards` +
` (one_time_code, k0_auth_key, k2_cmac_key, k3, k4, uid, last_counter_value,` + ` (one_time_code, k0_auth_key, k2_cmac_key, k3, k4, uid, last_counter_value,` +
` lnurlw_request_timeout_sec, tx_limit_sats, day_limit_sats, enable_flag,` + ` lnurlw_request_timeout_sec, tx_limit_sats, day_limit_sats, lnurlw_enable,` +
` one_time_code_used, card_name)` + ` one_time_code_used, card_name)` +
` VALUES ($1, $2, $3, $4, $5, '', 0, 60, $6, $7, $8, 'N', $9);` ` VALUES ($1, $2, $3, $4, $5, '', 0, 60, $6, $7, $8, 'N', $9);`
res, err := db.Exec(sqlStatement, one_time_code, k0_auth_key, k2_cmac_key, k3, k4, res, err := db.Exec(sqlStatement, one_time_code, k0_auth_key, k2_cmac_key, k3, k4,
tx_max_sats, day_max_sats, enable_flag_yn, card_name) tx_max_sats, day_max_sats, lnurlw_enable_yn, card_name)
if err != nil { if err != nil {
return err return err
} }

View file

@ -2,8 +2,11 @@
sudo systemctl stop postgresql sudo systemctl stop postgresql
sudo systemctl start postgresql sudo systemctl start postgresql
echo This will delete all of the data in your database. echo If you have previously created the database
echo Your card keys are part of this data. echo then this will delete it and recreate it.
echo
echo Key values for cards may be in the database data.
echo
echo Continue? "(y or n)" echo Continue? "(y or n)"
read x read x