Skip to content

Commit

Permalink
Move xchain contract bindings into core/contracts (#284)
Browse files Browse the repository at this point in the history
Also drop v3/dev versions
  • Loading branch information
sergekh2 authored Jun 26, 2024
1 parent 1650ec8 commit bb7c46b
Show file tree
Hide file tree
Showing 46 changed files with 425 additions and 11,088 deletions.
14 changes: 6 additions & 8 deletions core/cmd/register_xchain_node_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import (
"os"
"time"

"github.com/river-build/river/core/xchain/contracts"
"github.com/river-build/river/core/xchain/util"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/core/types"
"github.com/spf13/cobra"

"github.com/river-build/river/core/contracts/base"
"github.com/river-build/river/core/node/crypto"
"github.com/river-build/river/core/node/infra"
"github.com/spf13/cobra"
"github.com/river-build/river/core/xchain/util"
)

var (
Expand Down Expand Up @@ -64,7 +64,6 @@ func registerImpl(operatorKeyfile string, userConfirmationMessage string, regist
ctx, cancel = context.WithTimeout(context.Background(), time.Minute)
xchainWallet, xWalletErr = util.LoadWallet(ctx)
operatorWallet, oWalletErr = crypto.LoadWallet(ctx, operatorKeyfile)
entitlementGatedMetaData = contracts.NewEntitlementGatedMetaData(cmdConfig.GetContractVersion())
)
defer cancel()

Expand Down Expand Up @@ -93,13 +92,12 @@ func registerImpl(operatorKeyfile string, userConfirmationMessage string, regist
metrics,
)

checker, err := contracts.NewIEntitlementChecker(
cmdConfig.GetEntitlementContractAddress(), baseChain.Client, cmdConfig.GetContractVersion())
checker, err := base.NewIEntitlementChecker(cmdConfig.GetEntitlementContractAddress(), baseChain.Client)
if err != nil {
return err
}

decoder, err := crypto.NewEVMErrorDecoder(checker.GetMetadata(), entitlementGatedMetaData.GetMetadata())
decoder, err := crypto.NewEVMErrorDecoder(base.IEntitlementCheckerMetaData, base.IEntitlementGatedMetaData)
if err != nil {
return err
}
Expand Down
24 changes: 3 additions & 21 deletions core/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@ import (
. "github.com/river-build/river/core/node/protocol"
)

type ContractVersion string

const (
VersionDev ContractVersion = "dev"
VersionV3 ContractVersion = "v3"
)

func GetDefaultConfig() *Config {
return &Config{
Port: 443,
Expand Down Expand Up @@ -143,10 +136,9 @@ type Config struct {
XChainBlockchains []uint64

// extra xChain configuration
EntitlementContract ContractConfig `mapstructure:"entitlement_contract"`
contractVersion ContractVersion `mapstructure:"contract_version"`
TestEntitlementContract ContractConfig `mapstructure:"test_contract"`
TestCustomEntitlementContract ContractConfig `mapstructure:"test_custom_entitlement_contract"`
EntitlementContract ContractConfig `mapstructure:"entitlement_contract"`
TestEntitlementContract ContractConfig `mapstructure:"test_contract"`
TestCustomEntitlementContract ContractConfig `mapstructure:"test_custom_entitlement_contract"`

// History indicates how far back xchain must look for entitlement check requests after start
History time.Duration
Expand Down Expand Up @@ -248,8 +240,6 @@ type PerformanceTrackingConfig struct {
type ContractConfig struct {
// Address of the contract
Address common.Address
// Version of the contract to use.
Version string
}

type ArchiveConfig struct {
Expand Down Expand Up @@ -355,14 +345,6 @@ func (c *Config) GetGraffiti() string {
return c.Graffiti
}

func (c *Config) GetContractVersion() ContractVersion {
if c.contractVersion == VersionV3 {
return VersionV3
} else {
return VersionDev
}
}

func (c *Config) GetEntitlementContractAddress() common.Address {
return c.EntitlementContract.Address
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

78 changes: 25 additions & 53 deletions core/contracts/base/rule_entitlement.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/node/auth/architect.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func NewArchitect(ctx context.Context, cfg *config.ContractConfig, backend bind.
return nil, WrapRiverError(
Err_CANNOT_CONNECT,
err,
).Tags("address", cfg.Address, "version", cfg.Version).
).Tags("address", cfg.Address).
Func("NewArchitect").
Message("Failed to initialize contract")
}
Expand Down
1 change: 0 additions & 1 deletion core/node/auth/banning.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ func (b *banning) IsBanned(ctx context.Context, wallets []common.Address) (bool,
func NewBanning(
ctx context.Context,
cfg *config.ChainConfig,
version string,
spaceAddress common.Address,
backend bind.ContractBackend,
) (Banning, error) {
Expand Down
3 changes: 1 addition & 2 deletions core/node/auth/channels.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ type Channels interface {

func NewChannels(
ctx context.Context,
version string,
address common.Address,
backend bind.ContractBackend,
) (Channels, error) {
Expand All @@ -31,7 +30,7 @@ func NewChannels(
return nil, WrapRiverError(
Err_CANNOT_CONNECT,
err,
).Tags("address", address, "version", version).
).Tags("address", address).
Func("NewChannels").
Message("Failed to initialize contract")
}
Expand Down
Loading

0 comments on commit bb7c46b

Please sign in to comment.