commit 403565732b15171e6f02bea696a9e7125e866003
parent a2037a9fe68f64f0d630ba0e55e4d94fda2696b8
Author: Joel-Haeberli <haebu@rubigen.ch>
Date: Sun, 26 May 2024 15:22:21 +0200
fix: rename attestation to confirmation
Diffstat:
11 files changed, 44 insertions(+), 27 deletions(-)
diff --git a/c2ec/api-bank-integration.go b/c2ec/api-bank-integration.go
@@ -68,8 +68,8 @@ func bankIntegrationConfig(res http.ResponseWriter, req *http.Request) {
CurrencySpecification: CurrencySpecification{
Name: CONFIG.Server.Currency,
Currency: CONFIG.Server.Currency,
- NumFractionalInputDigits: 2,
- NumFractionalNormalDigits: 1000000000,
+ NumFractionalInputDigits: CONFIG.Server.CurrencyFractionDigits,
+ NumFractionalNormalDigits: CONFIG.Server.CurrencyFractionDigits,
NumFractionalTrailingZeroDigits: 0,
},
}
diff --git a/c2ec/c2ec-config.conf b/c2ec/c2ec-config.conf
@@ -36,6 +36,11 @@ EXCHANGE_ACCOUNT = payto://iban/CH50030202099498
# reserves with the specified currency.
CURRENCY = CHF
+# How many digits does the currency use by default on displays.
+# Hint provided to wallets. Should be 2 for EUR/USD/CHF,
+# and 0 for JPY.
+CURRENCY_FRACTION_DIGITS = 2
+
# How many retries shall be triggered, when the confirmation
# of a transaction fails (when negative, the process tries forever)
MAX_RETRIES = -1
diff --git a/c2ec/c2ec-config.yaml b/c2ec/c2ec-config.yaml
@@ -8,6 +8,7 @@ c2ec:
fail-on-missing-attestors: false # forced if prod=true
credit-account: "payto://IBAN/CH50030202099498" # this account must be specified at the providers backends as well
currency: "CHF"
+ currency-fraction-digits: 2
max-retries: 100
retry-delay-ms: 1000
wire-gateway:
diff --git a/c2ec/config.go b/c2ec/config.go
@@ -16,18 +16,19 @@ type C2ECConfig struct {
}
type C2ECServerConfig struct {
- IsProd bool `yaml:"prod"`
- Host string `yaml:"host"`
- Port int `yaml:"port"`
- UseUnixDomainSocket bool `yaml:"unix-domain-socket"`
- UnixSocketPath string `yaml:"unix-socket-path"`
- UnixPathMode int `yaml:"unix-path-mode"`
- StrictAttestors bool `yaml:"fail-on-missing-attestors"`
- CreditAccount string `yaml:"credit-account"`
- Currency string `yaml:"currency"`
- MaxRetries int32 `yaml:"max-retries"`
- RetryDelayMs int `yaml:"retry-delay-ms"`
- WireGateway C2ECWireGatewayConfig `yaml:"wire-gateway"`
+ IsProd bool `yaml:"prod"`
+ Host string `yaml:"host"`
+ Port int `yaml:"port"`
+ UseUnixDomainSocket bool `yaml:"unix-domain-socket"`
+ UnixSocketPath string `yaml:"unix-socket-path"`
+ UnixPathMode int `yaml:"unix-path-mode"`
+ StrictAttestors bool `yaml:"fail-on-missing-attestors"`
+ CreditAccount string `yaml:"credit-account"`
+ Currency string `yaml:"currency"`
+ CurrencyFractionDigits int `yaml:"currency-fraction-digits"`
+ MaxRetries int32 `yaml:"max-retries"`
+ RetryDelayMs int `yaml:"retry-delay-ms"`
+ WireGateway C2ECWireGatewayConfig `yaml:"wire-gateway"`
}
type C2ECWireGatewayConfig struct {
@@ -178,12 +179,22 @@ func ParseIni(content []byte) (*C2ECConfig, error) {
}
cfg.Server.Currency = value.String()
+ value, err = s.GetKey("CURRENCY_FRACTION_DIGITS")
+ if err != nil {
+ return nil, err
+ }
+ num, err := value.Int()
+ if err != nil {
+ return nil, err
+ }
+ cfg.Server.CurrencyFractionDigits = num
+
value, err = s.GetKey("MAX_RETRIES")
if err != nil {
return nil, err
}
- num, err := value.Int()
+ num, err = value.Int()
if err != nil {
return nil, err
}
diff --git a/c2ec/db-postgres.go b/c2ec/db-postgres.go
@@ -415,7 +415,7 @@ func (db *C2ECPostgres) NotifyPayment(
return nil
}
-func (db *C2ECPostgres) GetAttestableWithdrawals() ([]*Withdrawal, error) {
+func (db *C2ECPostgres) GetWithdrawalsForConfirmation() ([]*Withdrawal, error) {
if row, err := db.pool.Query(
db.ctx,
diff --git a/c2ec/db.go b/c2ec/db.go
@@ -153,7 +153,7 @@ type C2ECDatabase interface {
// specific transaction id was set and the status is
// 'selected'. The attestor can then attest and finalise
// the payments.
- GetAttestableWithdrawals() ([]*Withdrawal, error)
+ GetWithdrawalsForConfirmation() ([]*Withdrawal, error)
// When an confirmation (or fail message) could be
// retrieved by the provider, the withdrawal can
diff --git a/c2ec/proc-attestor.go b/c2ec/proc-attestor.go
@@ -92,7 +92,7 @@ func finaliseOrSetRetry(
prepareRetryOrAbort(withdrawalRowId, errs)
return
} else {
- if err := transaction.Attest(w); err != nil {
+ if err := transaction.Confirm(w); err != nil {
LogError("proc-attestor", err)
errs <- err
prepareRetryOrAbort(withdrawalRowId, errs)
diff --git a/c2ec/proc-retrier.go b/c2ec/proc-retrier.go
@@ -24,7 +24,7 @@ func RunRetrier(ctx context.Context, errs chan error) {
for {
time.Sleep(time.Duration(1000 * time.Millisecond))
//LogInfo("proc-retrier", "attesting selected withdrawals...")
- withdrawals, err := DB.GetAttestableWithdrawals()
+ withdrawals, err := DB.GetWithdrawalsForConfirmation()
if err != nil {
LogError("proc-retrier", err)
errs <- err
@@ -84,20 +84,20 @@ func attest(withdrawal *Withdrawal, errs chan error) {
return
}
- err = DB.SetRetryCounter(int(withdrawal.WithdrawalRowId), int(withdrawal.RetryCounter)+1)
+ client := PROVIDER_CLIENTS[provider.Name]
+ transaction, err := client.GetTransaction(*withdrawal.ProviderTransactionId)
if err != nil {
LogError("proc-retrier", err)
errs <- err
return
}
- client := PROVIDER_CLIENTS[provider.Name]
- transaction, err := client.GetTransaction(*withdrawal.ProviderTransactionId)
+ finaliseOrSetRetry(transaction, int(withdrawal.WithdrawalRowId), errs)
+
+ err = DB.SetRetryCounter(int(withdrawal.WithdrawalRowId), int(withdrawal.RetryCounter)+1)
if err != nil {
LogError("proc-retrier", err)
errs <- err
return
}
-
- finaliseOrSetRetry(transaction, int(withdrawal.WithdrawalRowId), errs)
}
diff --git a/c2ec/provider.go b/c2ec/provider.go
@@ -3,7 +3,7 @@ package main
type ProviderTransaction interface {
AllowWithdrawal() bool
AbortWithdrawal() bool
- Attest(w *Withdrawal) error
+ Confirm(w *Withdrawal) error
Bytes() []byte
}
diff --git a/c2ec/simulation-client.go b/c2ec/simulation-client.go
@@ -32,7 +32,7 @@ func (st *SimulationTransaction) AbortWithdrawal() bool {
return false
}
-func (st *SimulationTransaction) Attest(w *Withdrawal) error {
+func (st *SimulationTransaction) Confirm(w *Withdrawal) error {
return nil
}
diff --git a/c2ec/wallee-client.go b/c2ec/wallee-client.go
@@ -54,7 +54,7 @@ func (wt *WalleeTransaction) AbortWithdrawal() bool {
strings.EqualFold(string(wt.State), string(StateDecline))
}
-func (wt *WalleeTransaction) Attest(w *Withdrawal) error {
+func (wt *WalleeTransaction) Confirm(w *Withdrawal) error {
if wt.MerchantReference != *w.ProviderTransactionId {