Skip to content

Commit

Permalink
chore: improve code after code review
Browse files Browse the repository at this point in the history
  • Loading branch information
martinsaporiti committed Nov 2, 2023
1 parent 7aca6c3 commit 9059f87
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 17 deletions.
4 changes: 2 additions & 2 deletions .env-issuer.sample
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ ISSUER_VAULT_USERPASS_AUTH_ENABLED=false
ISSUER_VAULT_USERPASS_AUTH_PASSWORD=password


ISSUER_CREDENTIAL_STATUS_ONCHAIN_TREE_STORE_SUPPORTED_CONTRACT=234152345
ISSUER_CREDENTIAL_STATUS_ONCHAIN_TREE_STORE_SUPPORTED_CONTRACT=<supported-onchain-revocation-contract>
ISSUER_CREDENTIAL_STATUS_RHS_URL=http://localhost:3001
ISSUER_CREDENTIAL_STATUS_PUBLISHING_KEY_PATH=pbkey
ISSUER_CREDENTIAL_STATUS_RHS_MODE=<None | OffChain | OnChain>
ISSUER_CREDENTIAL_STATUS_RHS_CHAIN_ID=80001
ISSUER_CREDENTIAL_STATUS_RHS_CHAIN_ID=<80001 | 137>
5 changes: 2 additions & 3 deletions cmd/issuer_initializer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,8 @@ func main() {

commonClient, err := ethclient.Dial(cfg.Ethereum.URL)
if err != nil {
log.Info(ctx, "the ethereum rcp is", "url", cfg.Ethereum.URL)
log.Error(ctx, "error dialing with ethclient", "err", err)
panic("Error dialing with ethclient: " + err.Error())
log.Error(ctx, "error dialing with ethclient", "err", err, "rth-url", cfg.Ethereum.URL)
return
}

ethConn := eth.NewClient(commonClient, &eth.ClientConfig{
Expand Down
8 changes: 4 additions & 4 deletions cmd/notifications/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func main() {
}

connectionsService := services.NewConnection(connectionsRepository, storage)
credentialsService, err := newCredentialsService(cfg, storage, cachex, ps, vaultCli)
credentialsService, err := newCredentialsService(ctx, cfg, storage, cachex, ps, vaultCli)
if err != nil {
log.Error(ctx, "cannot initialize the credential service", "err", err)
return
Expand All @@ -122,7 +122,7 @@ func main() {
<-gracefulShutdown
}

func newCredentialsService(cfg *config.Configuration, storage *db.Storage, cachex cache.Cache, ps pubsub.Client, vaultCli *vault.Client) (ports.ClaimsService, error) {
func newCredentialsService(ctx context.Context, cfg *config.Configuration, storage *db.Storage, cachex cache.Cache, ps pubsub.Client, vaultCli *vault.Client) (ports.ClaimsService, error) {
identityRepository := repositories.NewIdentity()
claimsRepository := repositories.NewClaims()
mtRepository := repositories.NewIdentityMerkleTreeRepository()
Expand All @@ -135,7 +135,8 @@ func newCredentialsService(cfg *config.Configuration, storage *db.Storage, cache

commonClient, err := ethclient.Dial(cfg.Ethereum.URL)
if err != nil {
panic("Error dialing with ethclient: " + err.Error())
log.Error(ctx, "error dialing with ethclient", "err", err, "eth-url", cfg.Ethereum.URL)
return nil, err
}

ethConn := eth.NewClient(commonClient, &eth.ClientConfig{
Expand All @@ -158,7 +159,6 @@ func newCredentialsService(cfg *config.Configuration, storage *db.Storage, cache
mtService := services.NewIdentityMerkleTrees(mtRepository)
qrService := services.NewQrStoreService(cachex)

cfg.CredentialStatus.SingleIssuer = true
identityService := services.NewIdentity(keyStore, identityRepository, mtRepository, identityStateRepository, mtService, qrService, claimsRepository, revocationRepository, nil, storage, nil, nil, ps, cfg.CredentialStatus, rhsFactory, revocationStatusResolver)
claimsService := services.NewClaim(claimsRepository, identityService, qrService, mtService, identityStateRepository, schemaLoader, storage, cfg.APIUI.ServerURL, ps, cfg.IPFS.GatewayURL, revocationStatusResolver)

Expand Down
1 change: 0 additions & 1 deletion cmd/pending_publisher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ func main() {
rhsFactory := reverse_hash.NewFactory(cfg.CredentialStatus.RHS.GetURL(), cl, common.HexToAddress(cfg.CredentialStatus.OnchainTreeStore.SupportedTreeStoreContract), reverse_hash.DefaultRHSTimeOut)
revocationStatusResolver := revocation_status.NewRevocationStatusResolver(cfg.CredentialStatus)

cfg.CredentialStatus.SingleIssuer = true
identityService := services.NewIdentity(keyStore, identityRepo, mtRepo, identityStateRepo, mtService, qrService, claimsRepo, revocationRepository, connectionsRepository, storage, nil, nil, pubsub.NewMock(), cfg.CredentialStatus, rhsFactory, revocationStatusResolver)
claimsService := services.NewClaim(claimsRepo, identityService, qrService, mtService, identityStateRepo, schemaLoader, storage, cfg.APIUI.ServerURL, ps, cfg.IPFS.GatewayURL, revocationStatusResolver)

Expand Down
10 changes: 4 additions & 6 deletions internal/common/smart_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@ type SmartContractProof struct {
// SmartContractProofToMtProofAdapter converts SmartContractProof to merkletree.Proof
func SmartContractProofToMtProofAdapter(smtProof SmartContractProof) (*merkletree.Proof, error) {
var (
existence bool
nodeAux *merkletree.NodeAux
err error
nodeAux *merkletree.NodeAux
err error
)

if smtProof.Existence {
existence = true
} else {
existence := true
if !smtProof.Existence {
existence = false
if smtProof.AuxExistence {
nodeAux = &merkletree.NodeAux{}
Expand Down
2 changes: 1 addition & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ func (c *Configuration) SanitizeAPIUI(ctx context.Context) (err error) {
}

func (c *Configuration) sanitizeCredentialStatus(_ context.Context, host string) error {
if c.CredentialStatus.RHSMode != "" && c.CredentialStatus.RHSMode != onChain && c.CredentialStatus.RHSMode != offChain && c.CredentialStatus.RHSMode != none {
if c.CredentialStatus.RHSMode != onChain && c.CredentialStatus.RHSMode != offChain && c.CredentialStatus.RHSMode != none {
return fmt.Errorf("ISSUER_CREDENTIAL_STATUS_RHS_MODE value is not valid")
}

Expand Down

0 comments on commit 9059f87

Please sign in to comment.