Skip to content

Commit 8eaef28

Browse files
fix: Update SUI & Ton to compose ChainMetadata (#116)
The original intention was not to compose ChainMetadata and just use it directly by explicitly implementing the ChainMetadata interface and calling ChainMetadatato avoid breaking existing compatibility with EVM, SOL and APTOS and also the clunky initiation code. However this introduces some duplication across all chains. So the compromise is to still have the duplication in the existing chains but for new chains, they will compose the ChainMetadata and to avoid referencing another package for the ChainMetadata (clunky), the type alias is introduced.
1 parent 3f32425 commit 8eaef28

File tree

10 files changed

+26
-48
lines changed

10 files changed

+26
-48
lines changed

.changeset/ninety-bottles-ring.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"chainlink-deployments-framework": patch
3+
---
4+
5+
chains: update sui & ton to compose ChainMetadata

chain/aptos/aptos_chain.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ type Chain struct {
1717
Confirm func(txHash string, opts ...any) error
1818
}
1919

20+
// Author note: Have to implement the blockhain interface methods explicitly below
21+
// instead of composing the ChainMetadata struct to avoid breaking change since there are existing usage.
22+
2023
// ChainSelector returns the chain selector of the chain
2124
func (c Chain) ChainSelector() uint64 {
2225
return c.Selector

chain/blockchain_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ var evmChain1 = evm.Chain{Selector: chain_selectors.TEST_90000001.Selector}
2020
var evmChain2 = evm.Chain{Selector: chain_selectors.TEST_90000002.Selector}
2121
var solanaChain1 = solana.Chain{Selector: chain_selectors.TEST_22222222222222222222222222222222222222222222.Selector}
2222
var aptosChain1 = aptos.Chain{Selector: chain_selectors.APTOS_LOCALNET.Selector}
23-
var suiChain1 = sui.Chain{Selector: chain_selectors.SUI_LOCALNET.Selector}
24-
var tonChain1 = ton.Chain{Selector: chain_selectors.TON_LOCALNET.Selector}
23+
var suiChain1 = sui.Chain{ChainMetadata: sui.ChainMetadata{Selector: chain_selectors.SUI_LOCALNET.Selector}}
24+
var tonChain1 = ton.Chain{ChainMetadata: ton.ChainMetadata{Selector: chain_selectors.TON_LOCALNET.Selector}}
2525

2626
func TestNewBlockChains(t *testing.T) {
2727
t.Parallel()

chain/evm/evm_chain.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ type Chain struct {
4141
DeployerKeyZkSyncVM *accounts.Wallet
4242
}
4343

44+
// Author note: Have to implement the blockhain interface methods explicitly below
45+
// instead of composing the ChainMetadata struct to avoid breaking change since there are existing usage.
46+
4447
// ChainSelector returns the chain selector of the chain
4548
func (c Chain) ChainSelector() uint64 {
4649
return c.Selector

chain/internal/common/chain_metadata_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/smartcontractkit/chainlink-deployments-framework/chain/internal/common"
1010
)
1111

12-
func TestChainInfoProvider(t *testing.T) {
12+
func TestChainMetadata(t *testing.T) {
1313
t.Parallel()
1414

1515
tests := []struct {

chain/solana/solana_chain.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ func parseProgramID(output string, prefix string) (string, error) {
175175
return output[startIdx : startIdx+endIdx], nil
176176
}
177177

178+
// Author note: Have to implement the blockhain interface methods explicitly below
179+
// instead of composing the ChainMetadata struct to avoid breaking change since there are existing usage.
180+
178181
// ChainSelector returns the chain selector of the chain
179182
func (c Chain) ChainSelector() uint64 {
180183
return c.Selector

chain/sui/sui_chain.go

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,16 @@ import (
88
"github.com/smartcontractkit/chainlink-deployments-framework/chain/internal/common"
99
)
1010

11+
type ChainMetadata = common.ChainMetadata
12+
1113
// Chain represents an Sui chain.
1214
type Chain struct {
13-
Selector uint64
14-
Client *suiclient.ClientImpl
15+
ChainMetadata
16+
Client *suiclient.ClientImpl
1517
// TODO: sui-go currently does not have a working Signer interface, so we
1618
// have the raw private key for now.
1719
DeployerKey ed25519.PrivateKey
1820
URL string
1921

2022
Confirm func(txHash string, opts ...any) error
2123
}
22-
23-
// ChainSelector returns the chain selector of the chain
24-
func (c Chain) ChainSelector() uint64 {
25-
return c.Selector
26-
}
27-
28-
// String returns chain name and selector "<name> (<selector>)"
29-
func (c Chain) String() string {
30-
return common.ChainMetadata{Selector: c.Selector}.String()
31-
}
32-
33-
// Name returns the name of the chain
34-
func (c Chain) Name() string {
35-
return common.ChainMetadata{Selector: c.Selector}.Name()
36-
}
37-
38-
// Family returns the family of the chain
39-
func (c Chain) Family() string {
40-
return common.ChainMetadata{Selector: c.Selector}.Family()
41-
}

chain/sui/sui_chain_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func TestChain_ChainInfot(t *testing.T) {
3333
t.Parallel()
3434

3535
c := sui.Chain{
36-
Selector: tt.selector,
36+
ChainMetadata: sui.ChainMetadata{Selector: tt.selector},
3737
}
3838
assert.Equal(t, tt.selector, c.ChainSelector())
3939
assert.Equal(t, tt.wantString, c.String())

chain/ton/ton_chain.go

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,14 @@ import (
88
"github.com/smartcontractkit/chainlink-deployments-framework/chain/internal/common"
99
)
1010

11+
type ChainMetadata = common.ChainMetadata
12+
1113
// Chain represents a TON chain.
1214
type Chain struct {
13-
Selector uint64 // Canonical chain identifier
15+
ChainMetadata // Contains canonical chain identifier
1416
Client *ton.APIClient // RPC client via Lite Server
1517
Wallet *wallet.Wallet // Wallet abstraction (signing, sending)
1618
WalletAddress *address.Address // Address of deployer wallet
1719
URL string // Liteserver URL
1820
DeployerSeed string // Optional: mnemonic or raw seed
1921
}
20-
21-
// ChainSelector returns the chain selector of the chain
22-
func (c Chain) ChainSelector() uint64 {
23-
return c.Selector
24-
}
25-
26-
// String returns chain name and selector "<name> (<selector>)"
27-
func (c Chain) String() string {
28-
return common.ChainMetadata{Selector: c.Selector}.String()
29-
}
30-
31-
// Name returns the name of the chain
32-
func (c Chain) Name() string {
33-
return common.ChainMetadata{Selector: c.Selector}.Name()
34-
}
35-
36-
// Family returns the family of the chain
37-
func (c Chain) Family() string {
38-
return common.ChainMetadata{Selector: c.Selector}.Family()
39-
}

chain/ton/ton_chain_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func TestChain_ChainInfot(t *testing.T) {
3333
t.Parallel()
3434

3535
c := ton.Chain{
36-
Selector: tt.selector,
36+
ChainMetadata: ton.ChainMetadata{Selector: tt.selector},
3737
}
3838
assert.Equal(t, tt.selector, c.ChainSelector())
3939
assert.Equal(t, tt.wantString, c.String())

0 commit comments

Comments
 (0)