Skip to content
This repository was archived by the owner on Jan 16, 2023. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion pkg/transaction/authorizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"crypto/ed25519"
"github.com/pkg/errors"

"github.com/golang/protobuf/proto"
"github.com/kinecosystem/agora-common/kin"
Expand Down Expand Up @@ -32,6 +33,7 @@ type authorizer struct {
log *logrus.Entry
mapper app.Mapper
configStore app.ConfigStore
blockAnonTxns bool
mint ed25519.PublicKey
subsidizer ed25519.PublicKey
subsidizerKey ed25519.PrivateKey
Expand All @@ -45,6 +47,7 @@ type authorizer struct {
func NewAuthorizer(
mapper app.Mapper,
configStore app.ConfigStore,
blockAnonTxns bool,
webhookClient *webhook.Client,
limiter *Limiter,
subsidizer ed25519.PrivateKey,
Expand All @@ -59,6 +62,7 @@ func NewAuthorizer(
log: logrus.StandardLogger().WithField("type", "transaction/authorizer"),
mapper: mapper,
configStore: configStore,
blockAnonTxns: blockAnonTxns,
webhookClient: webhookClient,
limiter: limiter,
mint: mint,
Expand Down Expand Up @@ -117,7 +121,11 @@ func (s *authorizer) Authorize(ctx context.Context, raw solana.Transaction, il *
}
}
if appIndex == 0 {
appIndex, _ = app.GetAppIndex(ctx)
appIndex, err = app.GetAppIndex(ctx)
if s.blockAnonTxns && (err != nil || appIndex == 0) {
log.Warn("Authorize: blocked anonymous transactions")
return a, errors.New("Authorize: blocked anonymous creations")
}
}

//
Expand Down
13 changes: 13 additions & 0 deletions service/agora/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ const (

// Agora Config
agoraBlockAnonCreates = "AGORA_BLOCK_ANON_CREATES"
agoraBlockAnonTxns = "AGORA_BLOCK_ANON_TXNS"
agoraSdkFilter = "AGORA_SDK_FILTER"

// Events config
Expand Down Expand Up @@ -278,6 +279,17 @@ func (a *app) Init(_ agoraapp.Config) (err error) {
log.Warnf("Anonymous creations: ALLOWED")
}

var blockAnonTxns = false
if len(os.Getenv(agoraBlockAnonTxns)) > 0 {
blockAnonTxns = os.Getenv(agoraBlockAnonTxns) == "true"
}

if blockAnonTxns {
log.Warnf("Anonymous transactions: BLOCKED")
} else {
log.Warnf("Anonymous transactions: ALLOWED")
}

accountAuthorizer := account.NewAuthorizer(
appMapper,
appConfigStore,
Expand All @@ -304,6 +316,7 @@ func (a *app) Init(_ agoraapp.Config) (err error) {
authorizer, err := transaction.NewAuthorizer(
appMapper,
appConfigStore,
blockAnonTxns,
webhookClient,
txLimiter,
subsidizer,
Expand Down