Skip to content

Commit 0fc29f3

Browse files
committed
Better mint support detection in transaction and messaging services
1 parent 03c41b8 commit 0fc29f3

File tree

4 files changed

+24
-7
lines changed

4 files changed

+24
-7
lines changed

pkg/code/common/mint.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ package common
22

33
import (
44
"bytes"
5+
"context"
6+
"errors"
57

68
commonpb "github.com/code-payments/code-protobuf-api/generated/go/common/v1"
79
"github.com/code-payments/code-server/pkg/code/config"
10+
code_data "github.com/code-payments/code-server/pkg/code/data"
811
"github.com/code-payments/code-server/pkg/solana/currencycreator"
912
"github.com/code-payments/code-server/pkg/usdc"
1013
"github.com/code-payments/code-server/pkg/usdt"
@@ -17,6 +20,8 @@ var (
1720
CoreMintName = config.CoreMintName
1821
CoreMintSymbol = config.CoreMintSymbol
1922

23+
ErrUnsupportedMint = errors.New("unsupported mint")
24+
2025
jeffyMintAccount, _ = NewAccountFromPublicKeyString(config.JeffyMintPublicKey)
2126
knicksNightMintAccount, _ = NewAccountFromPublicKeyString(config.KnicksNightMintPublicKey)
2227
)
@@ -56,3 +61,13 @@ func GetMintQuarksPerUnit(mint *Account) uint64 {
5661
}
5762
return currencycreator.DefaultMintQuarksPerUnit
5863
}
64+
65+
func IsSupportedMint(ctx context.Context, data code_data.Provider, mintAccount *Account) (bool, error) {
66+
_, err := GetVmConfigForMint(ctx, data, mintAccount)
67+
if err == ErrUnsupportedMint {
68+
return false, nil
69+
} else if err != nil {
70+
return false, err
71+
}
72+
return true, nil
73+
}

pkg/code/common/vm.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package common
22

33
import (
44
"context"
5-
"errors"
65

76
"github.com/code-payments/code-server/pkg/code/config"
87
code_data "github.com/code-payments/code-server/pkg/code/data"
@@ -79,6 +78,6 @@ func GetVmConfigForMint(ctx context.Context, data code_data.Provider, mint *Acco
7978
Mint: mint,
8079
}, nil
8180
default:
82-
return nil, errors.New("unsupported mint")
81+
return nil, ErrUnsupportedMint
8382
}
8483
}

pkg/code/server/messaging/message_handler.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,11 @@ func (h *RequestToGiveBillMessageHandler) Validate(ctx context.Context, rendezvo
9090
return err
9191
}
9292

93-
switch mintAccount.PublicKey().ToBase58() {
94-
case common.CoreMintAccount.PublicKey().ToBase58(), "52MNGpgvydSwCtC2H4qeiZXZ1TxEuRVCRGa8LAfk2kSj":
95-
default:
96-
return newMessageValidationError("mint account must be the core mint or a launcpad currency")
93+
isSupportedMint, err := common.IsSupportedMint(ctx, h.data, mintAccount)
94+
if err != nil {
95+
return err
96+
} else if !isSupportedMint {
97+
return newMessageValidationError("mint account must be the core mint or a launchpad currency")
9798
}
9899

99100
return nil

pkg/code/server/transaction/local_simulation.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,9 @@ func LocalSimulation(ctx context.Context, data code_data.Provider, actions []*tr
242242

243243
// Validate authorities and respective derived timelock vault accounts match.
244244
vmConfig, err := common.GetVmConfigForMint(ctx, data, mint)
245-
if err != nil {
245+
if err == common.ErrUnsupportedMint {
246+
return nil, NewActionValidationError(action, "mint account must be the core mint or a launchpad currency")
247+
} else if err != nil {
246248
return nil, err
247249
}
248250
timelockAccounts, err := authority.GetTimelockAccounts(vmConfig)

0 commit comments

Comments
 (0)