From 9c75109b7561e8419fd47ad46cf55e8a92932255 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Wed, 22 Jan 2025 15:35:16 +0300 Subject: [PATCH 1/5] use dev storage service --- remote/http/service.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/remote/http/service.go b/remote/http/service.go index 40aa4a1..15eaa24 100644 --- a/remote/http/service.go +++ b/remote/http/service.go @@ -14,7 +14,7 @@ import ( "git.grassecon.net/grassrootseconomics/sarafu-api/config" "git.grassecon.net/grassrootseconomics/sarafu-api/dev" "git.grassecon.net/grassrootseconomics/sarafu-api/models" - "git.grassecon.net/grassrootseconomics/visedriver/testutil/mocks" + "git.grassecon.net/grassrootseconomics/visedriver/storage" "github.com/grassrootseconomics/eth-custodial/pkg/api" dataserviceapi "github.com/grassrootseconomics/ussd-data-service/pkg/api" ) @@ -24,6 +24,7 @@ var ( ) type HTTPAccountService struct { + ss storage.StorageService } // Parameters: @@ -228,8 +229,7 @@ func (as *HTTPAccountService) CheckAliasAddress(ctx context.Context, alias strin // TODO: Use actual custodial api to request available alias func (as *HTTPAccountService) RequestAlias(ctx context.Context, publicKey string, hint string) (*models.RequestAliasResult, error) { - storageService := mocks.NewMemStorageService(ctx) - svc := dev.NewDevAccountService(ctx, storageService) + svc := dev.NewDevAccountService(ctx, as.ss) return svc.RequestAlias(ctx, publicKey, hint) } From bc7afa50a45852e34de5b841ee83405a0f16107c Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Wed, 22 Jan 2025 15:53:28 +0300 Subject: [PATCH 2/5] dep: downgrade vise-driver --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index f6f00ed..60a6fa2 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.23.4 require ( git.defalsify.org/vise.git v0.2.3-0.20250120121301-10739fb4a8c9 git.grassecon.net/grassrootseconomics/common v0.0.0-20250121134736-ba8cbbccea7d - git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250121134912-f7d31e4e8162 + git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250115003256-c0534ede1b63 github.com/gofrs/uuid v4.4.0+incompatible github.com/grassrootseconomics/eth-custodial v1.3.0-beta github.com/grassrootseconomics/ussd-data-service v1.2.0-beta diff --git a/go.sum b/go.sum index 1da7e56..2840678 100644 --- a/go.sum +++ b/go.sum @@ -2,8 +2,8 @@ git.defalsify.org/vise.git v0.2.3-0.20250120121301-10739fb4a8c9 h1:sPcqXQcywxA8W git.defalsify.org/vise.git v0.2.3-0.20250120121301-10739fb4a8c9/go.mod h1:jyBMe1qTYUz3mmuoC9JQ/TvFeW0vTanCUcPu3H8p4Ck= git.grassecon.net/grassrootseconomics/common v0.0.0-20250121134736-ba8cbbccea7d h1:5mzLas+jxTUtusOKx4XvU+n2QvrV/mH17MnJRy46siQ= git.grassecon.net/grassrootseconomics/common v0.0.0-20250121134736-ba8cbbccea7d/go.mod h1:wgQJZGIS6QuNLHqDhcsvehsbn5PvgV7aziRebMnJi60= -git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250121134912-f7d31e4e8162 h1:NaPbgGQ1Nb+yYF+Qj1LSagpjYeDcSXST8iZwONg4afY= -git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250121134912-f7d31e4e8162/go.mod h1:pjKp9L/ZsWW3kMB0UoIl1yv9TBIuU33mn9Aghxp7vGk= +git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250115003256-c0534ede1b63 h1:bX7klKZpX+ZZu1LKbtOXDAhV/KK0YwExehiIi0jusAM= +git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250115003256-c0534ede1b63/go.mod h1:Syw9TZyigPAM7t9FvicOm36iUnidt45f0SxzT2JniQ8= github.com/barbashov/iso639-3 v0.0.0-20211020172741-1f4ffb2d8d1c h1:H9Nm+I7Cg/YVPpEV1RzU3Wq2pjamPc/UtHDgItcb7lE= github.com/barbashov/iso639-3 v0.0.0-20211020172741-1f4ffb2d8d1c/go.mod h1:rGod7o6KPeJ+hyBpHfhi4v7blx9sf+QsHsA7KAsdN6U= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= From 3f9dc89a40dcb9848cdc1ecd3b1fcc8b972e4e33 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Wed, 22 Jan 2025 17:19:46 +0300 Subject: [PATCH 3/5] resolve alias address based on UseApi field --- remote/http/service.go | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/remote/http/service.go b/remote/http/service.go index 15eaa24..aca8ae0 100644 --- a/remote/http/service.go +++ b/remote/http/service.go @@ -5,6 +5,7 @@ import ( "context" "encoding/json" "errors" + "fmt" "io" "log" "net/http" @@ -24,7 +25,8 @@ var ( ) type HTTPAccountService struct { - ss storage.StorageService + SS storage.StorageService + UseApi bool } // Parameters: @@ -211,25 +213,38 @@ func (as *HTTPAccountService) TokenTransfer(ctx context.Context, amount, from, t // Parameters: // - alias: The alias of the user. func (as *HTTPAccountService) CheckAliasAddress(ctx context.Context, alias string) (*models.AliasAddress, error) { + if as.SS == nil { + return nil, fmt.Errorf("The storage service cannot be nil") + } + svc := dev.NewDevAccountService(ctx, as.SS) + if as.UseApi { + return resolveAliasAddress(ctx, alias) + } else { + return svc.CheckAliasAddress(ctx, alias) + } +} + +func resolveAliasAddress(ctx context.Context, alias string) (*models.AliasAddress, error) { var r models.AliasAddress ep, err := url.JoinPath(config.CheckAliasURL, alias) if err != nil { return nil, err } - req, err := http.NewRequest("GET", ep, nil) if err != nil { return nil, err } - _, err = doRequest(ctx, req, &r) return &r, err } // TODO: Use actual custodial api to request available alias func (as *HTTPAccountService) RequestAlias(ctx context.Context, publicKey string, hint string) (*models.RequestAliasResult, error) { - svc := dev.NewDevAccountService(ctx, as.ss) + if as.SS == nil { + return nil, fmt.Errorf("The storage service cannot be nil") + } + svc := dev.NewDevAccountService(ctx, as.SS) return svc.RequestAlias(ctx, publicKey, hint) } From 4ae0a484f45fb5e01488fa4fe8380a536f62240e Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Thu, 23 Jan 2025 10:43:19 +0300 Subject: [PATCH 4/5] run go mod tidy --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 60a6fa2..0d62c17 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.23.4 require ( git.defalsify.org/vise.git v0.2.3-0.20250120121301-10739fb4a8c9 git.grassecon.net/grassrootseconomics/common v0.0.0-20250121134736-ba8cbbccea7d - git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250115003256-c0534ede1b63 + git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250122123424-6749c632b0a2 github.com/gofrs/uuid v4.4.0+incompatible github.com/grassrootseconomics/eth-custodial v1.3.0-beta github.com/grassrootseconomics/ussd-data-service v1.2.0-beta diff --git a/go.sum b/go.sum index 2840678..c88d977 100644 --- a/go.sum +++ b/go.sum @@ -2,8 +2,8 @@ git.defalsify.org/vise.git v0.2.3-0.20250120121301-10739fb4a8c9 h1:sPcqXQcywxA8W git.defalsify.org/vise.git v0.2.3-0.20250120121301-10739fb4a8c9/go.mod h1:jyBMe1qTYUz3mmuoC9JQ/TvFeW0vTanCUcPu3H8p4Ck= git.grassecon.net/grassrootseconomics/common v0.0.0-20250121134736-ba8cbbccea7d h1:5mzLas+jxTUtusOKx4XvU+n2QvrV/mH17MnJRy46siQ= git.grassecon.net/grassrootseconomics/common v0.0.0-20250121134736-ba8cbbccea7d/go.mod h1:wgQJZGIS6QuNLHqDhcsvehsbn5PvgV7aziRebMnJi60= -git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250115003256-c0534ede1b63 h1:bX7klKZpX+ZZu1LKbtOXDAhV/KK0YwExehiIi0jusAM= -git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250115003256-c0534ede1b63/go.mod h1:Syw9TZyigPAM7t9FvicOm36iUnidt45f0SxzT2JniQ8= +git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250122123424-6749c632b0a2 h1:ON77G5K0JNuwPb5JT/hRfF6G6+xstlBQgEIEzWydnhg= +git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250122123424-6749c632b0a2/go.mod h1:pjKp9L/ZsWW3kMB0UoIl1yv9TBIuU33mn9Aghxp7vGk= github.com/barbashov/iso639-3 v0.0.0-20211020172741-1f4ffb2d8d1c h1:H9Nm+I7Cg/YVPpEV1RzU3Wq2pjamPc/UtHDgItcb7lE= github.com/barbashov/iso639-3 v0.0.0-20211020172741-1f4ffb2d8d1c/go.mod h1:rGod7o6KPeJ+hyBpHfhi4v7blx9sf+QsHsA7KAsdN6U= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= From 448fdffbd0c3aa7044d847c95fd95a74ac5b47b1 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Thu, 23 Jan 2025 12:05:23 +0300 Subject: [PATCH 5/5] untie session id to saved aliases --- dev/api.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/dev/api.go b/dev/api.go index aa5edec..09ab1f2 100644 --- a/dev/api.go +++ b/dev/api.go @@ -346,17 +346,13 @@ func (das *DevAccountService) saveAlias(ctx context.Context, alias map[string]st if das.db == nil { return fmt.Errorf("Db cannot be nil") } - sessionId, ok := ctx.Value("SessionId").(string) - if !ok { - return fmt.Errorf("unresolved session id") - } for k, v := range alias { k_ := das.prefixKeyFor("alias", k) v_, err := json.Marshal(v) if err != nil { return err } - das.db.SetSession(sessionId) + das.db.SetSession("") das.db.SetPrefix(db.DATATYPE_USERDATA) return das.db.Put(ctx, []byte(k_), v_) }