Skip to content

Commit

Permalink
Merge pull request #625 from 0xPolygonID/chore_check_errors_when_regi…
Browse files Browse the repository at this point in the history
…stering_networks

chore: Check error when registering custom did methods.
  • Loading branch information
x1m3 authored Feb 28, 2024
2 parents 388d71d + 1969d58 commit 9bebd8a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
7 changes: 5 additions & 2 deletions cmd/issuer_initializer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,16 @@ func main() {

log.Config(cfg.Log.Level, cfg.Log.Mode, os.Stdout)

services.RegisterCustomDIDMethods(cfg.CustomDIDMethods)

if err := cfg.Sanitize(ctx); err != nil {
log.Error(ctx, "there are errors in the configuration that prevent server to start", "err", err)
return
}

if err := services.RegisterCustomDIDMethods(ctx, cfg.CustomDIDMethods); err != nil {
log.Error(ctx, "cannot register custom DID methods. Server cannot start", "err", err)
return
}

storage, err := db.NewStorage(cfg.Database.URL)
if err != nil {
log.Error(ctx, "cannot connect to database", "err", err)
Expand Down
8 changes: 5 additions & 3 deletions cmd/platform/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,18 @@ func main() {
log.Error(ctx, "cannot load config", "err", err)
return
}

services.RegisterCustomDIDMethods(cfg.CustomDIDMethods)

log.Config(cfg.Log.Level, cfg.Log.Mode, os.Stdout)

if err := cfg.Sanitize(ctx); err != nil {
log.Error(ctx, "there are errors in the configuration that prevent server to start", "err", err)
return
}

if err := services.RegisterCustomDIDMethods(ctx, cfg.CustomDIDMethods); err != nil {
log.Error(ctx, "cannot register custom DID methods. Server cannot start", "err", err)
return
}

storage, err := db.NewStorage(cfg.Database.URL)
if err != nil {
log.Error(ctx, "cannot connect to database", "err", err)
Expand Down
5 changes: 4 additions & 1 deletion cmd/platform_ui/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ func main() {
return
}

services.RegisterCustomDIDMethods(cfg.CustomDIDMethods)
if err := services.RegisterCustomDIDMethods(ctx, cfg.CustomDIDMethods); err != nil {
log.Error(ctx, "cannot register custom DID methods. Server cannot start", "err", err)
return
}

storage, err := db.NewStorage(cfg.Database.URL)
if err != nil {
Expand Down
14 changes: 11 additions & 3 deletions internal/core/services/did_registrator.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
package services

import (
"context"

core "github.com/iden3/go-iden3-core/v2"

"github.com/polygonid/sh-id-platform/internal/config"
"github.com/polygonid/sh-id-platform/internal/log"
)

// RegisterCustomDIDMethods registers custom DID methods
func RegisterCustomDIDMethods(customdDids []config.CustomDIDMethods) {
for _, cdid := range customdDids {
func RegisterCustomDIDMethods(ctx context.Context, customsDis []config.CustomDIDMethods) error {
for _, cdid := range customsDis {
params := core.DIDMethodNetworkParams{
Method: core.DIDMethodPolygonID,
Blockchain: core.Blockchain(cdid.Blockchain),
Network: core.NetworkID(cdid.Network),
NetworkFlag: cdid.NetworkFlag,
}
core.RegisterDIDMethodNetwork(params, core.WithChainID(cdid.ChainID))
if err := core.RegisterDIDMethodNetwork(params, core.WithChainID(cdid.ChainID)); err != nil {
log.Error(ctx, "cannot register custom DID method", "err", err, "customDID", cdid)
return err
}
}
return nil
}

0 comments on commit 9bebd8a

Please sign in to comment.