add the UpdateAlias function

This commit is contained in:
Alfred Kamanda 2025-06-26 09:53:26 +03:00
parent 9a6ab7e6e2
commit 49a8184d02
Signed by: Alfred-mk
GPG Key ID: 7EA3D01708908703
2 changed files with 49 additions and 0 deletions

View File

@ -17,6 +17,7 @@ type AccountService interface {
TokenTransfer(ctx context.Context, amount, from, to, tokenAddress string) (*models.TokenTransferResponse, error)
CheckAliasAddress(ctx context.Context, alias string) (*models.AliasAddress, error)
RequestAlias(ctx context.Context, hint string, publicKey string) (*models.RequestAliasResult, error)
UpdateAlias(ctx context.Context, name 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

View File

@ -559,6 +559,54 @@ func requestEnsAlias(ctx context.Context, publicKey string, hint string) (*model
return &r, nil
}
func (as *HTTPAccountService) UpdateAlias(ctx context.Context, publicKey string, name string) (*models.RequestAliasResult, error) {
if as.SS == nil {
return nil, fmt.Errorf("The storage service cannot be nil")
}
if as.UseApi {
if !strings.Contains(name, ".") {
name = as.ToFqdn(name)
}
enr, err := updateEnsAlias(ctx, publicKey, name)
if err != nil {
return nil, err
}
return &models.RequestAliasResult{Alias: enr.Name}, nil
} else {
svc := dev.NewDevAccountService(ctx, as.SS)
return svc.RequestAlias(ctx, publicKey, name)
}
}
func updateEnsAlias(ctx context.Context, publicKey string, name string) (*models.AliasEnsResult, error) {
var r models.AliasEnsResult
endpoint := config.AliasRegistrationURL
logg.InfoCtxf(ctx, "updating alias", "endpoint", endpoint, "name", name)
payload := map[string]string{
"name": name,
"address": publicKey,
}
payloadBytes, err := json.Marshal(payload)
if err != nil {
return nil, err
}
req, err := http.NewRequest("POST", endpoint, bytes.NewBuffer(payloadBytes))
if err != nil {
return nil, err
}
// Log the request body
logg.InfoCtxf(ctx, "request body", "payload", string(payloadBytes))
_, err = doRequest(ctx, req, &r)
if err != nil {
return nil, err
}
logg.InfoCtxf(ctx, "alias successfully updated", "alias", r.Name)
return &r, nil
}
// SendSMS calls the API to send out an SMS.
// Parameters:
// - inviterPhone: The user initiating the SMS.