Merge branch 'master' into pool-swap-endpoints

This commit is contained in:
Alfred Kamanda 2025-05-16 12:43:26 +03:00
commit 3b85167ad8
Signed by: Alfred-mk
GPG Key ID: 7EA3D01708908703
8 changed files with 145 additions and 3 deletions

View File

@ -16,6 +16,7 @@ const (
voucherTransfersPathPrefix = "/api/v1/transfers/last10" voucherTransfersPathPrefix = "/api/v1/transfers/last10"
voucherDataPathPrefix = "/api/v1/token" voucherDataPathPrefix = "/api/v1/token"
aliasPrefix = "api/v1/alias" aliasPrefix = "api/v1/alias"
SendSMSPrefix = "api/v1/external/upsell"
poolDepositPrefix = "/api/v2/pool/deposit" poolDepositPrefix = "/api/v2/pool/deposit"
poolSwapQoutePrefix = "/api/v2/pool/quote" poolSwapQoutePrefix = "/api/v2/pool/quote"
poolSwapPrefix = "/api/v2/pool/swap" poolSwapPrefix = "/api/v2/pool/swap"
@ -23,6 +24,7 @@ const (
retrievePoolDetailsPrefix = "/api/v1/pool/reverse" retrievePoolDetailsPrefix = "/api/v1/pool/reverse"
poolSwappableVouchersPrefix = "/api/v1/pool" poolSwappableVouchersPrefix = "/api/v1/pool"
AliasEnsPrefix = "/api/v1/bypass" AliasEnsPrefix = "/api/v1/bypass"
ExternalSMSPrefix = "/api/v1/external"
) )
var ( var (
@ -30,6 +32,7 @@ var (
dataURLBase string dataURLBase string
BearerToken string BearerToken string
aliasEnsURLBase string aliasEnsURLBase string
externalSMSBase string
) )
var ( var (
@ -48,7 +51,9 @@ var (
TopPoolsURL string TopPoolsURL string
RetrievePoolDetailsURL string RetrievePoolDetailsURL string
PoolSwappableVouchersURL string PoolSwappableVouchersURL string
SendSMSURL string
AliasEnsURL string AliasEnsURL string
ExternalSMSURL string
) )
func setBase() error { func setBase() error {
@ -57,6 +62,7 @@ func setBase() error {
custodialURLBase = env.GetEnv("CUSTODIAL_URL_BASE", "http://localhost:5003") custodialURLBase = env.GetEnv("CUSTODIAL_URL_BASE", "http://localhost:5003")
dataURLBase = env.GetEnv("DATA_URL_BASE", "http://localhost:5006") dataURLBase = env.GetEnv("DATA_URL_BASE", "http://localhost:5006")
aliasEnsURLBase = env.GetEnv("ALIAS_ENS_BASE", "http://localhost:5015") aliasEnsURLBase = env.GetEnv("ALIAS_ENS_BASE", "http://localhost:5015")
externalSMSBase = env.GetEnv("EXTERNAL_SMS_BASE", "http://localhost:5035")
BearerToken = env.GetEnv("BEARER_TOKEN", "") BearerToken = env.GetEnv("BEARER_TOKEN", "")
_, err = url.Parse(custodialURLBase) _, err = url.Parse(custodialURLBase)
@ -85,6 +91,7 @@ func LoadConfig() error {
VoucherTransfersURL, _ = url.JoinPath(dataURLBase, voucherTransfersPathPrefix) VoucherTransfersURL, _ = url.JoinPath(dataURLBase, voucherTransfersPathPrefix)
VoucherDataURL, _ = url.JoinPath(dataURLBase, voucherDataPathPrefix) VoucherDataURL, _ = url.JoinPath(dataURLBase, voucherDataPathPrefix)
CheckAliasURL, _ = url.JoinPath(dataURLBase, aliasPrefix) CheckAliasURL, _ = url.JoinPath(dataURLBase, aliasPrefix)
SendSMSURL, _ = url.JoinPath(dataURLBase, SendSMSPrefix)
PoolDepositURL, _ = url.JoinPath(custodialURLBase, poolDepositPrefix) PoolDepositURL, _ = url.JoinPath(custodialURLBase, poolDepositPrefix)
PoolSwapQuoteURL, _ = url.JoinPath(custodialURLBase, poolSwapQoutePrefix) PoolSwapQuoteURL, _ = url.JoinPath(custodialURLBase, poolSwapQoutePrefix)
PoolSwapURL, _ = url.JoinPath(custodialURLBase, poolSwapPrefix) PoolSwapURL, _ = url.JoinPath(custodialURLBase, poolSwapPrefix)
@ -93,5 +100,7 @@ func LoadConfig() error {
PoolSwappableVouchersURL, _ = url.JoinPath(dataURLBase, poolSwappableVouchersPrefix) PoolSwappableVouchersURL, _ = url.JoinPath(dataURLBase, poolSwappableVouchersPrefix)
AliasEnsURL, _ = url.JoinPath(aliasEnsURLBase, AliasEnsPrefix) AliasEnsURL, _ = url.JoinPath(aliasEnsURLBase, AliasEnsPrefix)
ExternalSMSURL, _ = url.JoinPath(externalSMSBase, ExternalSMSPrefix)
return nil return nil
} }

View File

@ -806,6 +806,21 @@ func (das *DevAccountService) RequestAlias(ctx context.Context, publicKey string
}, nil }, nil
} }
func (das *DevAccountService) SendUpsellSMS(ctx context.Context, inviterPhone, inviteePhone string) (*models.SendSMSResponse, error) {
logg.DebugCtxf(ctx, "sent an SMS", "inviterPhone", inviterPhone, "inviteePhone", inviteePhone)
return &models.SendSMSResponse{
Invitee: inviteePhone,
}, nil
}
func (das *DevAccountService) SendPINResetSMS(ctx context.Context, admin, phone string) error {
return fmt.Errorf("unimplemented")
}
func (das *DevAccountService) SendAddressSMS(ctx context.Context, publicKey, originPhone string) error {
return fmt.Errorf("unimplemented")
}
func (das *DevAccountService) FetchTopPools(ctx context.Context) ([]dataserviceapi.PoolDetails, error) { func (das *DevAccountService) FetchTopPools(ctx context.Context) ([]dataserviceapi.PoolDetails, error) {
var topPools []dataserviceapi.PoolDetails var topPools []dataserviceapi.PoolDetails
for _, p := range das.pools { for _, p := range das.pools {

View File

@ -0,0 +1,5 @@
package models
type SendSMSResponse struct {
Invitee string `json:"invitee"`
}

View File

@ -17,6 +17,9 @@ type AccountService interface {
TokenTransfer(ctx context.Context, amount, from, to, tokenAddress string) (*models.TokenTransferResponse, error) TokenTransfer(ctx context.Context, amount, from, to, tokenAddress string) (*models.TokenTransferResponse, error)
CheckAliasAddress(ctx context.Context, alias string) (*models.AliasAddress, error) CheckAliasAddress(ctx context.Context, alias string) (*models.AliasAddress, error)
RequestAlias(ctx context.Context, hint string, publicKey string) (*models.RequestAliasResult, error) RequestAlias(ctx context.Context, hint string, publicKey string) (*models.RequestAliasResult, error)
SendUpsellSMS(ctx context.Context, inviterPhone, inviteePhone string) (*models.SendSMSResponse, error)
SendAddressSMS(ctx context.Context, publicKey, originPhone string) error
SendPINResetSMS(ctx context.Context, admin, phone string) error
PoolDeposit(ctx context.Context, amount, from, poolAddress, tokenAddress string) (*models.PoolDepositResult, error) PoolDeposit(ctx context.Context, amount, from, poolAddress, tokenAddress string) (*models.PoolDepositResult, error)
FetchTopPools(ctx context.Context) ([]dataserviceapi.PoolDetails, error) FetchTopPools(ctx context.Context) ([]dataserviceapi.PoolDetails, error)
GetPoolSwappableFromVouchers(ctx context.Context, poolAddress, publicKey string) ([]dataserviceapi.TokenHoldings, error) GetPoolSwappableFromVouchers(ctx context.Context, poolAddress, publicKey string) ([]dataserviceapi.TokenHoldings, error)

View File

@ -520,6 +520,87 @@ func requestEnsAlias(ctx context.Context, publicKey string, hint string) (*model
return &r, nil return &r, nil
} }
// SendSMS calls the API to send out an SMS.
// Parameters:
// - inviterPhone: The user initiating the SMS.
// - inviteePhone: The number being invited to Sarafu.
func (as *HTTPAccountService) SendUpsellSMS(ctx context.Context, inviterPhone, inviteePhone string) (*models.SendSMSResponse, error) {
var r models.SendSMSResponse
// Create request payload
payload := map[string]string{
"inviterPhone": inviterPhone,
"inviteePhone": inviteePhone,
}
payloadBytes, err := json.Marshal(payload)
if err != nil {
return nil, err
}
// Create a new request
req, err := http.NewRequest("POST", config.SendSMSURL, bytes.NewBuffer(payloadBytes))
if err != nil {
return nil, err
}
_, err = doRequest(ctx, req, &r)
if err != nil {
return nil, err
}
return &r, nil
}
func (as *HTTPAccountService) SendAddressSMS(ctx context.Context, publicKey, originPhone string) error {
ep, err := url.JoinPath(config.ExternalSMSURL, "address")
if err != nil {
return err
}
logg.InfoCtxf(ctx, "sending an address sms", "endpoint", ep, "address", publicKey, "origin-phone", originPhone)
payload := map[string]string{
"address": publicKey,
"originPhone": originPhone,
}
payloadBytes, err := json.Marshal(payload)
if err != nil {
return err
}
req, err := http.NewRequest("POST", ep, bytes.NewBuffer(payloadBytes))
if err != nil {
return err
}
_, err = doRequest(ctx, req, nil)
if err != nil {
return err
}
return nil
}
func (as *HTTPAccountService) SendPINResetSMS(ctx context.Context, admin, phone string) error {
ep, err := url.JoinPath(config.ExternalSMSURL, "pinreset")
if err != nil {
return err
}
logg.InfoCtxf(ctx, "sending pin reset sms", "endpoint", ep, "admin", admin, "phone", phone)
payload := map[string]string{
"admin": admin,
"phone": phone,
}
payloadBytes, err := json.Marshal(payload)
if err != nil {
return err
}
req, err := http.NewRequest("POST", ep, bytes.NewBuffer(payloadBytes))
if err != nil {
return err
}
_, err = doRequest(ctx, req, nil)
if err != nil {
return err
}
return nil
}
// TODO: remove eth-custodial api dependency // TODO: remove eth-custodial api dependency
func doRequest(ctx context.Context, req *http.Request, rcpt any) (*api.OKResponse, error) { func doRequest(ctx context.Context, req *http.Request, rcpt any) (*api.OKResponse, error) {
var okResponse api.OKResponse var okResponse api.OKResponse

View File

@ -61,3 +61,7 @@ func (m MockApi) RequestAlias(ctx context.Context, publicKey string, hint string
func (m MockApi) TokenTransfer(ctx context.Context, amount, from, to, tokenAddress string) (*models.TokenTransferResponse, error) { func (m MockApi) TokenTransfer(ctx context.Context, amount, from, to, tokenAddress string) (*models.TokenTransferResponse, error) {
return nil, nil return nil, nil
} }
func (m MockApi) SendUpsellSMS(ctx context.Context, inviterPhone, inviteePhone string) (*models.SendSMSResponse, error) {
return nil, nil
}

View File

@ -53,11 +53,24 @@ func (m *MockAccountService) CheckAliasAddress(ctx context.Context, alias string
return args.Get(0).(*models.AliasAddress), args.Error(1) return args.Get(0).(*models.AliasAddress), args.Error(1)
} }
func (m MockAccountService) RequestAlias(ctx context.Context, publicKey string, hint string) (*models.RequestAliasResult, error) { func (m *MockAccountService) RequestAlias(ctx context.Context, publicKey string, hint string) (*models.RequestAliasResult, error) {
args := m.Called(publicKey, hint) args := m.Called(publicKey, hint)
return args.Get(0).(*models.RequestAliasResult), args.Error(1) return args.Get(0).(*models.RequestAliasResult), args.Error(1)
} }
func (m *MockAccountService) SendUpsellSMS(ctx context.Context, inviterPhone, inviteePhone string) (*models.SendSMSResponse, error) {
args := m.Called(inviterPhone, inviteePhone)
return args.Get(0).(*models.SendSMSResponse), args.Error(1)
}
func (m *MockAccountService) SendPINResetSMS(ctx context.Context, admin, phone string) error {
return nil
}
func (m *MockAccountService) SendAddressSMS(ctx context.Context, publicKey, originPhone string) error {
return nil
}
func (m MockAccountService) PoolDeposit(ctx context.Context, amount, from, poolAddress, tokenAddress string) (*models.PoolDepositResult, error) { func (m MockAccountService) PoolDeposit(ctx context.Context, amount, from, poolAddress, tokenAddress string) (*models.PoolDepositResult, error) {
args := m.Called(amount, from, poolAddress, tokenAddress) args := m.Called(amount, from, poolAddress, tokenAddress)
return args.Get(0).(*models.PoolDepositResult), args.Error(1) return args.Get(0).(*models.PoolDepositResult), args.Error(1)

View File

@ -61,14 +61,26 @@ func (m TestAccountService) PoolDeposit(ctx context.Context, amount, from, poolA
return &models.PoolDepositResult{}, nil return &models.PoolDepositResult{}, nil
} }
func (m TestAccountService) CheckAliasAddress(ctx context.Context, alias string) (*models.AliasAddress, error) { func (m *TestAccountService) CheckAliasAddress(ctx context.Context, alias string) (*models.AliasAddress, error) {
return &models.AliasAddress{}, nil return &models.AliasAddress{}, nil
} }
func (m TestAccountService) RequestAlias(ctx context.Context, publicKey string, hint string) (*models.RequestAliasResult, error) { func (m *TestAccountService) RequestAlias(ctx context.Context, publicKey string, hint string) (*models.RequestAliasResult, error) {
return &models.RequestAliasResult{}, nil return &models.RequestAliasResult{}, nil
} }
func (m *TestAccountService) SendUpsellSMS(ctx context.Context, inviterPhone, inviteePhone string) (*models.SendSMSResponse, error) {
return &models.SendSMSResponse{}, nil
}
func (m *TestAccountService) SendAddressSMS(ctx context.Context, publicKey, originPhone string) error {
return nil
}
func (m *TestAccountService) SendPINResetSMS(ctx context.Context, admin, phone string) error {
return nil
}
func (m TestAccountService) FetchTopPools(ctx context.Context) ([]dataserviceapi.PoolDetails, error) { func (m TestAccountService) FetchTopPools(ctx context.Context) ([]dataserviceapi.PoolDetails, error) {
return []dataserviceapi.PoolDetails{}, nil return []dataserviceapi.PoolDetails{}, nil
} }