create & update card pin details

This commit is contained in:
Peter Rounce 2023-06-29 19:34:18 +00:00
parent 299ab696cc
commit b76252d6ef
5 changed files with 71 additions and 13 deletions

View file

@ -773,7 +773,7 @@ func Get_card_name_count(card_name string) (card_count int, err error) {
func Insert_card(one_time_code string, k0_auth_key string, k2_cmac_key string, k3 string, k4 string,
tx_limit_sats int, day_limit_sats int, lnurlw_enable bool, card_name string, uid_privacy bool,
allow_neg_bal_ptr bool) error {
allow_neg_bal_ptr bool, pin_enable bool, pin_number string, pin_limit_sats int) error {
lnurlw_enable_yn := "N"
if lnurlw_enable {
@ -790,6 +790,11 @@ func Insert_card(one_time_code string, k0_auth_key string, k2_cmac_key string, k
allow_neg_bal_yn = "Y"
}
pin_enable_yn := "N"
if pin_enable {
pin_enable_yn = "Y"
}
db, err := open()
if err != nil {
return err
@ -811,11 +816,12 @@ func Insert_card(one_time_code string, k0_auth_key string, k2_cmac_key string, k
sqlStatement = `INSERT INTO cards` +
` (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, lnurlw_enable,` +
` one_time_code_used, card_name, uid_privacy, allow_negative_balance)` +
` VALUES ($1, $2, $3, $4, $5, '', 0, 60, $6, $7, $8, 'N', $9, $10, $11);`
` one_time_code_used, card_name, uid_privacy, allow_negative_balance,` +
` pin_enable, pin_number, pin_limit_sats)` +
` VALUES ($1, $2, $3, $4, $5, '', 0, 60, $6, $7, $8, 'N', $9, $10, $11, $12, $13, $14);`
res, err = db.Exec(sqlStatement, one_time_code, k0_auth_key, k2_cmac_key, k3, k4,
tx_limit_sats, day_limit_sats, lnurlw_enable_yn, card_name, uid_privacy_yn,
allow_neg_bal_yn)
allow_neg_bal_yn, pin_enable_yn, pin_number, pin_limit_sats)
if err != nil {
return err
}
@ -871,13 +877,19 @@ func Wipe_card(card_name string) (*Card_wipe_info, error) {
return &card_wipe_info, nil
}
func Update_card(card_name string, lnurlw_enable bool, tx_limit_sats int, day_limit_sats int) error {
func Update_card(card_name string, lnurlw_enable bool, tx_limit_sats int, day_limit_sats int,
pin_enable bool, pin_number string, pin_limit_sats int) error {
lnurlw_enable_yn := "N"
if lnurlw_enable {
lnurlw_enable_yn = "Y"
}
pin_enable_yn := "N"
if pin_enable {
pin_enable_yn = "Y"
}
db, err := open()
if err != nil {
@ -886,10 +898,11 @@ func Update_card(card_name string, lnurlw_enable bool, tx_limit_sats int, day_li
defer db.Close()
sqlStatement := `UPDATE cards SET lnurlw_enable = $2, tx_limit_sats = $3, day_limit_sats = $4 ` +
`WHERE card_name = $1 AND wiped = 'N';`
sqlStatement := `UPDATE cards SET lnurlw_enable = $2, tx_limit_sats = $3, day_limit_sats = $4, ` +
`pin_enable = $5, pin_number = $6, pin_limit_sats = $7 WHERE card_name = $1 AND wiped = 'N';`
res, err := db.Exec(sqlStatement, card_name, lnurlw_enable_yn, tx_limit_sats, day_limit_sats)
res, err := db.Exec(sqlStatement, card_name, lnurlw_enable_yn, tx_limit_sats, day_limit_sats,
pin_enable_yn, pin_number, pin_limit_sats)
if err != nil {
return err