diff options
Diffstat (limited to 'c2ec/postgres.go')
-rw-r--r-- | c2ec/postgres.go | 83 |
1 files changed, 40 insertions, 43 deletions
diff --git a/c2ec/postgres.go b/c2ec/postgres.go index a7264bf..ce9bc9a 100644 --- a/c2ec/postgres.go +++ b/c2ec/postgres.go @@ -2,8 +2,6 @@ package main import ( "context" - "encoding/base32" - "encoding/base64" "errors" "fmt" "math" @@ -23,18 +21,18 @@ const PS_INSERT_WITHDRAWAL = "INSERT INTO " + WITHDRAWAL_TABLE_NAME + " (" + WITHDRAWAL_FIELD_NAME_WOPID + "," + WITHDRAWAL_FIELD_NAME_RESPUBKEY + "," + WITHDRAWAL_FIELD_NAME_STATUS + "," + - WITHDRAWAL_FIELD_NAME_TS + "," + - WITHDRAWAL_FIELD_NAME_TERMINAL_ID + ")" + - " VALUES ($1, $2, $3, $4, $5);" + WITHDRAWAL_FIELD_NAME_TS + ")" + + " VALUES ($1, $2, $3, $4);" const PS_GET_UNCONFIRMED_WITHDRAWALS = "SELECT * FROM " + WITHDRAWAL_TABLE_NAME + " WHERE " + WITHDRAWAL_FIELD_NAME_TRANSACTION_ID + " IS NOT NULL" + " AND " + WITHDRAWAL_FIELD_NAME_STATUS + " = '" + string(SELECTED) + "'" const PS_PAYMENT_NOTIFICATION = "UPDATE " + WITHDRAWAL_TABLE_NAME + " SET (" + - WITHDRAWAL_FIELD_NAME_AMOUNT + "," + WITHDRAWAL_FIELD_NAME_FEES + "," + WITHDRAWAL_FIELD_NAME_TRANSACTION_ID + ")" + - " = (($1, $2, $3),($4, $5, $6),$7)" + - " WHERE " + WITHDRAWAL_FIELD_NAME_WOPID + "=$8" + WITHDRAWAL_FIELD_NAME_AMOUNT + "," + WITHDRAWAL_FIELD_NAME_FEES + "," + + WITHDRAWAL_FIELD_NAME_TRANSACTION_ID + "," + WITHDRAWAL_FIELD_NAME_TERMINAL_ID + ")" + + " = (($1, $2, $3),($4, $5, $6),$7, $8)" + + " WHERE " + WITHDRAWAL_FIELD_NAME_WOPID + "=$9" const PS_FINALISE_PAYMENT = "UPDATE " + WITHDRAWAL_TABLE_NAME + " SET (" + WITHDRAWAL_FIELD_NAME_STATUS + "," + @@ -42,14 +40,12 @@ const PS_FINALISE_PAYMENT = "UPDATE " + WITHDRAWAL_TABLE_NAME + " SET (" + " = ($1, $2)" + " WHERE " + WITHDRAWAL_FIELD_NAME_ID + "=$3" -const PS_SET_LAST_RETRY = "UPDATE " + WITHDRAWAL_TABLE_NAME + " SET (" + - WITHDRAWAL_FIELD_NAME_LAST_RETRY + ")" + - " = ($1)" + +const PS_SET_LAST_RETRY = "UPDATE " + WITHDRAWAL_TABLE_NAME + + " SET " + WITHDRAWAL_FIELD_NAME_LAST_RETRY + "=$1" + " WHERE " + WITHDRAWAL_FIELD_NAME_ID + "=$2" -const PS_SET_RETRY_COUNTER = "UPDATE " + WITHDRAWAL_TABLE_NAME + " SET (" + - WITHDRAWAL_FIELD_NAME_RETRY_COUNTER + ")" + - " = ($1)" + +const PS_SET_RETRY_COUNTER = "UPDATE " + WITHDRAWAL_TABLE_NAME + + " SET " + WITHDRAWAL_FIELD_NAME_RETRY_COUNTER + "=($1)" + " WHERE " + WITHDRAWAL_FIELD_NAME_ID + "=$2" const PS_CONFIRMED_TRANSACTIONS = "SELECT * FROM " + WITHDRAWAL_TABLE_NAME + @@ -84,8 +80,9 @@ const PS_GET_TRANSFER_BY_ID = "SELECT * FROM " + TRANSFER_TABLE_NAME + " WHERE " + TRANSFER_FIELD_NAME_ID + "=$1" const PS_ADD_TRANSFER = "INSERT INTO " + TRANSFER_TABLE_NAME + - " (" + TRANSFER_FIELD_NAME_ID + ", " + TRANSFER_FIELD_NAME_HASH + ")" + - " VALUES ($1, $2)" + " (" + TRANSFER_FIELD_NAME_ID + ", " + TRANSFER_FIELD_NAME_AMOUNT + ", " + + TRANSFER_FIELD_NAME_EXCHANGE_BASE_URL + ", " + TRANSFER_FIELD_NAME_WTID + ", " + + TRANSFER_FIELD_NAME_CREDIT_ACCOUNT + ")" + " VALUES ($1, $2, $3, $4, $5, $6)" // Postgres implementation of the C2ECDatabase type C2ECPostgres struct { @@ -140,17 +137,11 @@ func (db *C2ECPostgres) registerCustomTypesHook(ctx context.Context, conn *pgx.C } func (db *C2ECPostgres) RegisterWithdrawal( - wopid WithdrawalIdentifier, + wopid []byte, resPubKey EddsaPublicKey, - terminalId uint64, ) error { - wopidBytes, err := base64.StdEncoding.DecodeString(string(wopid)) - if err != nil { - return err - } - - resPubKeyBytes, err := base32.HexEncoding.DecodeString(string(resPubKey)) + resPubKeyBytes, err := ParseEddsaPubKey(resPubKey) if err != nil { return err } @@ -159,11 +150,10 @@ func (db *C2ECPostgres) RegisterWithdrawal( res, err := db.pool.Exec( db.ctx, PS_INSERT_WITHDRAWAL, - wopidBytes, + wopid, resPubKeyBytes, SELECTED, ts.Unix(), - terminalId, ) if err != nil { LogError("postgres", err) @@ -201,17 +191,12 @@ func (db *C2ECPostgres) GetWithdrawalById(withdrawalId int) (*Withdrawal, error) } } -func (db *C2ECPostgres) GetWithdrawalByWopid(wopid string) (*Withdrawal, error) { - - wopidBytes, err := base64.StdEncoding.DecodeString(string(wopid)) - if err != nil { - return nil, err - } +func (db *C2ECPostgres) GetWithdrawalByWopid(wopid []byte) (*Withdrawal, error) { if row, err := db.pool.Query( db.ctx, PS_GET_WITHDRAWAL_BY_WOPID, - wopidBytes, + wopid, ); err != nil { LogError("postgres", err) if row != nil { @@ -263,17 +248,13 @@ func (db *C2ECPostgres) GetWithdrawalByProviderTransactionId(tid string) (*Withd } func (db *C2ECPostgres) NotifyPayment( - wopid WithdrawalIdentifier, + wopid []byte, providerTransactionId string, + terminalId int, amount Amount, fees Amount, ) error { - wopidBytes, err := base64.StdEncoding.DecodeString(string(wopid)) - if err != nil { - return err - } - res, err := db.pool.Exec( db.ctx, PS_PAYMENT_NOTIFICATION, @@ -284,7 +265,8 @@ func (db *C2ECPostgres) NotifyPayment( fees.Fraction, fees.Currency, providerTransactionId, - wopidBytes, + terminalId, + wopid, ) if err != nil { LogError("postgres", err) @@ -575,13 +557,28 @@ func (db *C2ECPostgres) GetTransferById(requestUid HashCode) (*Transfer, error) } -func (db *C2ECPostgres) AddTransfer(requestId HashCode, requestHash string) error { +func (db *C2ECPostgres) AddTransfer( + requestUid HashCode, + amount *Amount, + exchangeBaseUrl string, + wtid string, + credit_account string, +) error { + + dbAmount := TalerAmountCurrency{ + Val: int64(amount.Value), + Frac: int32(amount.Fraction), + Curr: amount.Currency, + } res, err := db.pool.Query( db.ctx, PS_ADD_TRANSFER, - requestId, - requestHash, + requestUid, + dbAmount, + exchangeBaseUrl, + wtid, + credit_account, ) if err != nil { LogError("postgres", err) |