commit 4afb7375e791ad8c1a43ab35af69251ffea78897
parent 8432d087573a2176e44747144c8c336b3336681e
Author: Joel-Haeberli <haebu@rubigen.ch>
Date: Fri, 31 May 2024 14:00:58 +0200
fix: simulation checks fees
Diffstat:
7 files changed, 32 insertions(+), 10 deletions(-)
diff --git a/c2ec/api-bank-integration.go b/c2ec/api-bank-integration.go
@@ -114,11 +114,18 @@ func handleParameterRegistration(res http.ResponseWriter, req *http.Request) {
return
}
- if _, err = DB.GetWithdrawalByWopid(wpd); err != nil {
+ if w, err := DB.GetWithdrawalByWopid(wpd); err != nil {
LogError("bank-integration-api", err)
setLastResponseCodeForLogger(HTTP_NOT_FOUND)
res.WriteHeader(HTTP_NOT_FOUND)
return
+ } else {
+ if w.ReservePubKey != nil || len(w.ReservePubKey) > 0 {
+ LogWarn("bank-integration-api", "tried registering a withdrawal-operation with already existing wopid")
+ setLastResponseCodeForLogger(HTTP_CONFLICT)
+ res.WriteHeader(HTTP_CONFLICT)
+ return
+ }
}
if err = DB.RegisterWithdrawalParameters(
diff --git a/c2ec/c2ec-config.yaml b/c2ec/c2ec-config.yaml
@@ -9,7 +9,7 @@ c2ec:
credit-account: "payto://IBAN/CH50030202099498" # this account must be specified at the providers backends as well
currency: "CHF"
currency-fraction-digits: 2
- withdrawal-fees: "CHF:0.00"
+ withdrawal-fees: "CHF:0.05"
max-retries: 100
retry-delay-ms: 1000
wire-gateway:
diff --git a/simulation/c2ec-simulation b/simulation/c2ec-simulation
Binary files differ.
diff --git a/simulation/config.yaml b/simulation/config.yaml
@@ -3,7 +3,6 @@ c2ec-base-url: "http://localhost:8080"
parallel-withdrawals: 1
provider-backend-payment-delay: 1000
amount: "CHF:10.05"
-fees: "CHF:0.05"
terminal-accept-card-delay: 4000
terminal-provider: "Simulation"
terminal-id: "1"
diff --git a/simulation/model.go b/simulation/model.go
@@ -56,7 +56,11 @@ type C2ECWithdrawRegistration struct {
type C2ECWithdrawalStatus struct {
Status WithdrawalOperationStatus `json:"status"`
Amount string `json:"amount"`
+ CardFees string `json:"card_fees"`
SenderWire string `json:"sender_wire"`
WireTypes []string `json:"wire_types"`
ReservePubKey EddsaPublicKey `json:"selected_reserve_pub"`
+ Aborted bool `json:"aborted"`
+ SelectionDone bool `json:"selection_done"`
+ TransferDone bool `json:"transfer_done"`
}
diff --git a/simulation/sim-terminal.go b/simulation/sim-terminal.go
@@ -13,6 +13,8 @@ import (
// retrieved from the cli tool when added the terminal
var TERMINAL_USER_ID string
+var EXCHANGE_FEES string
+
func Terminal(in chan *SimulatedPhysicalInteraction, out chan *SimulatedPhysicalInteraction, kill chan error) {
var C2EC_TERMINAL_CONFIG_API = CONFIG.C2ecBaseUrl + "/config"
@@ -39,7 +41,10 @@ func Terminal(in chan *SimulatedPhysicalInteraction, out chan *SimulatedPhysical
kill <- errors.New("terminal api configuration failed with status " + strconv.Itoa(status))
return
}
- fmt.Println("TERMINAL: API config loaded.", terminalApiCfg.Name, terminalApiCfg.Version, terminalApiCfg.ProviderName, terminalApiCfg.WireType)
+
+ EXCHANGE_FEES = terminalApiCfg.WithdrawalFees
+
+ fmt.Println("TERMINAL: API config loaded.", terminalApiCfg.Name, terminalApiCfg.Version, terminalApiCfg.ProviderName, terminalApiCfg.WireType, EXCHANGE_FEES)
fmt.Println("TERMINAL: Sim-Wallet ready, intiating withdrawal...")
@@ -53,7 +58,7 @@ func Terminal(in chan *SimulatedPhysicalInteraction, out chan *SimulatedPhysical
Amount: CONFIG.Amount,
SuggestedAmount: "",
ProviderTransactionId: "",
- TerminalFees: CONFIG.Fees,
+ TerminalFees: EXCHANGE_FEES,
RequestUid: uuid.String(),
UserUuid: "",
Lock: "",
@@ -158,7 +163,7 @@ func Terminal(in chan *SimulatedPhysicalInteraction, out chan *SimulatedPhysical
fmt.Println("TERMINAL: payment was processed at the provider backend. sending check notification.")
checkNotification := &TerminalWithdrawalConfirmationRequest{
ProviderTransactionId: "simulation-transaction-id-0",
- TerminalFees: "CHF:10",
+ TerminalFees: EXCHANGE_FEES,
}
checkurl := FormatUrl(
C2EC_TERMINAL_CHECK_WITHDRAWAL_API,
@@ -198,10 +203,12 @@ func TerminalAuth() string {
// Structs copied from c2ec
type TerminalConfig struct {
- Name string `json:"name"`
- Version string `json:"version"`
- ProviderName string `json:"provider_name"`
- WireType string `json:"wire_type"`
+ Name string `json:"name"`
+ Version string `json:"version"`
+ ProviderName string `json:"provider_name"`
+ Currency string `json:"currency"`
+ WithdrawalFees string `json:"withdrawal_fees"`
+ WireType string `json:"wire_type"`
}
type TerminalWithdrawalSetup struct {
diff --git a/simulation/sim-wallet.go b/simulation/sim-wallet.go
@@ -95,6 +95,11 @@ func Wallet(in chan *SimulatedPhysicalInteraction, out chan *SimulatedPhysicalIn
longPollFailed <- errors.New("status of withdrawal status response was " + strconv.Itoa(status))
return
}
+ if response.CardFees != EXCHANGE_FEES {
+ fmt.Printf("WALLET : ATTENTION -> fees do not match expected=%s, got=%s (can be ok but can also indicate a problem, especially when the fees are lower than the expected, it indicates problems.)\n", EXCHANGE_FEES, response.CardFees)
+ } else {
+ fmt.Printf("WALLET : Fees expected=%s, got=%s\n", EXCHANGE_FEES, response.CardFees)
+ }
awaitConfirmationOrAbortion <- response
}()