Skip to content

Commit

Permalink
Handle alias event. Tricky because it's a bytes32
Browse files Browse the repository at this point in the history
  • Loading branch information
elffjs committed Nov 1, 2024
1 parent d1f3a82 commit a9b77eb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
25 changes: 25 additions & 0 deletions internal/services/contracts_events_consumer.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package services

import (
"bytes"
"context"
"fmt"
"net/http"
Expand Down Expand Up @@ -79,6 +80,7 @@ const (
RedirectUriDisabled EventName = "RedirectUriDisabled"
SignerEnabled EventName = "SignerEnabled"
SignerDisabled EventName = "SignerDisabled"
LicenseAliasSet EventName = "LicenseAliasSet"
)

func (r EventName) String() string {
Expand Down Expand Up @@ -208,6 +210,8 @@ func (c *ContractsEventsConsumer) Process(ctx context.Context, event *shared.Clo
switch eventName {
case Issued:
return c.handleDevLicenseIssued(ctx, &data)
case LicenseAliasSet:
return c.handleDevLicenseAlias(ctx, &data)
case RedirectUriEnabled:
return c.handleRedirectEnabled(ctx, &data)
case RedirectUriDisabled:
Expand Down Expand Up @@ -832,6 +836,27 @@ func (c *ContractsEventsConsumer) handleDevLicenseIssued(ctx context.Context, e
return nil
}

func (c *ContractsEventsConsumer) handleDevLicenseAlias(ctx context.Context, e *ContractEventData) error {
var args LicenseAliasSetData
if err := json.Unmarshal(e.Arguments, &args); err != nil {
return err
}

alias := string(bytes.Trim(args.LicenseAlias, "\x00"))

dl := models.DeveloperLicense{
ID: int(args.TokenID.Int64()),
Alias: null.StringFrom(alias),
}

_, err := dl.Update(ctx, c.dbs.DBS().Writer, boil.Whitelist(models.DeveloperLicenseColumns.Alias))
if err != nil {
return err
}

return nil
}

func (c *ContractsEventsConsumer) handleRedirectEnabled(ctx context.Context, e *ContractEventData) error {
var args RedirectUriEnabledData
if err := json.Unmarshal(e.Arguments, &args); err != nil {
Expand Down
5 changes: 5 additions & 0 deletions internal/services/event_data_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,8 @@ type SignerDisabledData struct {
TokenID *big.Int
Signer common.Address
}

type LicenseAliasSetData struct {
TokenID *big.Int
LicenseAlias []byte
}

0 comments on commit a9b77eb

Please sign in to comment.