diff --git a/go.mod b/go.mod index 9adffcb43685..5d69f427c1ba 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/DataDog/zstd v1.5.2 github.com/NYTimes/gziphandler v1.1.1 github.com/antithesishq/antithesis-sdk-go v0.3.8 - github.com/ava-labs/coreth v0.13.9-rc.2-encapsulate-signer + github.com/ava-labs/coreth v0.14.1-0.20241230191223-351149733d35 github.com/ava-labs/ledger-avalanche/go v0.0.0-20241009183145-e6f90a8a1a60 github.com/btcsuite/btcd/btcutil v1.1.3 github.com/cockroachdb/pebble v0.0.0-20230928194634-aa077af62593 diff --git a/go.sum b/go.sum index fb6007017f8d..a7885b4ceb7f 100644 --- a/go.sum +++ b/go.sum @@ -64,8 +64,8 @@ github.com/antithesishq/antithesis-sdk-go v0.3.8/go.mod h1:IUpT2DPAKh6i/YhSbt6Gl github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= -github.com/ava-labs/coreth v0.13.9-rc.2-encapsulate-signer h1:mRB03tLPUvgNko4nP4VwWQdiHeHaLHtdwsnqwxrsGec= -github.com/ava-labs/coreth v0.13.9-rc.2-encapsulate-signer/go.mod h1:tqRAe+7bGLo2Rq/Ph4iYMSch72ag/Jn0DiDMDz1Xa9E= +github.com/ava-labs/coreth v0.14.1-0.20241230191223-351149733d35 h1:qBNnMleaJ7yWjNiDdV7wIf/e/PxubB+Ww7Mfx4QN4p8= +github.com/ava-labs/coreth v0.14.1-0.20241230191223-351149733d35/go.mod h1:nvQqJem4MuE0pU93aqBPsaEZx9NnXT0lI8d6rrQS5uY= github.com/ava-labs/ledger-avalanche/go v0.0.0-20241009183145-e6f90a8a1a60 h1:EL66gtXOAwR/4KYBjOV03LTWgkEXvLePribLlJNu4g0= github.com/ava-labs/ledger-avalanche/go v0.0.0-20241009183145-e6f90a8a1a60/go.mod h1:/7qKobTfbzBu7eSTVaXMTr56yTYk4j2Px6/8G+idxHo= github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g= diff --git a/tests/e2e/c/dynamic_fees.go b/tests/e2e/c/dynamic_fees.go index eede13eac7e0..89e056f5fcdc 100644 --- a/tests/e2e/c/dynamic_fees.go +++ b/tests/e2e/c/dynamic_fees.go @@ -9,7 +9,6 @@ import ( "github.com/ava-labs/coreth/core/types" "github.com/ava-labs/coreth/params" - "github.com/ava-labs/coreth/plugin/evm" "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/common" "github.com/onsi/ginkgo/v2" @@ -48,7 +47,7 @@ var _ = e2e.DescribeCChain("[Dynamic Fees]", func() { tc.By("allocating a pre-funded key") key := privateNetwork.PreFundedKeys[0] - ethAddress := evm.GetEthAddress(key) + ethAddress := key.EthAddress() tc.By("initializing a coreth client") node := privateNetwork.Nodes[0] @@ -154,7 +153,7 @@ var _ = e2e.DescribeCChain("[Dynamic Fees]", func() { // Create a recipient address var ( recipientKey = e2e.NewPrivateKey(tc) - recipientEthAddress = evm.GetEthAddress(recipientKey) + recipientEthAddress = recipientKey.EthAddress() ) // Create transaction diff --git a/tests/e2e/c/interchain_workflow.go b/tests/e2e/c/interchain_workflow.go index f4b9cc85c544..791d73888f3e 100644 --- a/tests/e2e/c/interchain_workflow.go +++ b/tests/e2e/c/interchain_workflow.go @@ -7,7 +7,6 @@ import ( "math/big" "github.com/ava-labs/coreth/core/types" - "github.com/ava-labs/coreth/plugin/evm" "github.com/onsi/ginkgo/v2" "github.com/stretchr/testify/require" @@ -39,9 +38,9 @@ var _ = e2e.DescribeCChain("[Interchain Workflow]", func() { tc.By("allocating a pre-funded key to send from and a recipient key to deliver to") var ( senderKey = env.PreFundedKey - senderEthAddress = evm.GetEthAddress(senderKey) + senderEthAddress = senderKey.EthAddress() recipientKey = e2e.NewPrivateKey(tc) - recipientEthAddress = evm.GetEthAddress(recipientKey) + recipientEthAddress = recipientKey.EthAddress() ) tc.By("sending funds from one address to another on the C-Chain", func() { diff --git a/tests/e2e/p/interchain_workflow.go b/tests/e2e/p/interchain_workflow.go index a190a5a75131..f3a54399dc72 100644 --- a/tests/e2e/p/interchain_workflow.go +++ b/tests/e2e/p/interchain_workflow.go @@ -7,7 +7,6 @@ import ( "math/big" "time" - "github.com/ava-labs/coreth/plugin/evm" "github.com/onsi/ginkgo/v2" "github.com/spf13/cast" "github.com/stretchr/testify/require" @@ -74,7 +73,7 @@ var _ = e2e.DescribePChain("[Interchain Workflow]", ginkgo.Label(e2e.UsesCChainL ) tc.By("defining common configuration") - recipientEthAddress := evm.GetEthAddress(recipientKey) + recipientEthAddress := recipientKey.EthAddress() // Use the same owner for sending to X-Chain and importing funds to P-Chain recipientOwner := secp256k1fx.OutputOwners{ Threshold: 1, diff --git a/tests/e2e/x/interchain_workflow.go b/tests/e2e/x/interchain_workflow.go index 33f26cbc9bb4..3e201d05c48a 100644 --- a/tests/e2e/x/interchain_workflow.go +++ b/tests/e2e/x/interchain_workflow.go @@ -6,7 +6,6 @@ package x import ( "math/big" - "github.com/ava-labs/coreth/plugin/evm" "github.com/onsi/ginkgo/v2" "github.com/stretchr/testify/require" @@ -41,7 +40,7 @@ var _ = e2e.DescribeXChain("[Interchain Workflow]", ginkgo.Label(e2e.UsesCChainL pWallet := baseWallet.P() tc.By("defining common configuration") - recipientEthAddress := evm.GetEthAddress(recipientKey) + recipientEthAddress := recipientKey.EthAddress() xBuilder := xWallet.Builder() xContext := xBuilder.Context() cBuilder := cWallet.Builder() diff --git a/tests/fixture/tmpnet/genesis.go b/tests/fixture/tmpnet/genesis.go index c914c9b94e9b..1002a917fec9 100644 --- a/tests/fixture/tmpnet/genesis.go +++ b/tests/fixture/tmpnet/genesis.go @@ -12,7 +12,6 @@ import ( "github.com/ava-labs/coreth/core" "github.com/ava-labs/coreth/params" - "github.com/ava-labs/coreth/plugin/evm" "github.com/ava-labs/avalanchego/genesis" "github.com/ava-labs/avalanchego/ids" @@ -117,7 +116,7 @@ func NewTestGenesis( cChainBalances := make(core.GenesisAlloc, len(keysToFund)) for _, key := range keysToFund { xChainBalances[key.Address()] = defaultFundedKeyXChainAmount - cChainBalances[evm.GetEthAddress(key)] = core.GenesisAccount{ + cChainBalances[key.EthAddress()] = core.GenesisAccount{ Balance: defaultFundedKeyCChainAmount, } } diff --git a/utils/crypto/secp256k1/secp256k1.go b/utils/crypto/secp256k1/secp256k1.go index 7dbbf9f84f7d..2d9dbba0e4c8 100644 --- a/utils/crypto/secp256k1/secp256k1.go +++ b/utils/crypto/secp256k1/secp256k1.go @@ -9,6 +9,8 @@ import ( "strings" "github.com/decred/dcrd/dcrec/secp256k1/v4/ecdsa" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/crypto" "github.com/ava-labs/avalanchego/cache" "github.com/ava-labs/avalanchego/ids" @@ -166,6 +168,10 @@ func (k *PublicKey) Address() ids.ShortID { return k.addr } +func (k *PublicKey) EthAddress() common.Address { + return crypto.PubkeyToAddress(*(k.ToECDSA())) +} + func (k *PublicKey) Bytes() []byte { if k.bytes == nil { k.bytes = k.pk.SerializeCompressed() @@ -190,6 +196,10 @@ func (k *PrivateKey) Address() ids.ShortID { return k.PublicKey().Address() } +func (k *PrivateKey) EthAddress() common.Address { + return crypto.PubkeyToAddress(*(k.PublicKey().ToECDSA())) +} + func (k *PrivateKey) Sign(msg []byte) ([]byte, error) { return k.SignHash(hashing.ComputeHash256(msg)) } diff --git a/vms/secp256k1fx/keychain.go b/vms/secp256k1fx/keychain.go index ecb42f209970..1d2849655154 100644 --- a/vms/secp256k1fx/keychain.go +++ b/vms/secp256k1fx/keychain.go @@ -9,7 +9,6 @@ import ( "strings" "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/crypto" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/utils/crypto/keychain" @@ -55,7 +54,7 @@ func (kc *Keychain) Add(key *secp256k1.PrivateKey) { avaxAddr := pk.Address() if _, ok := kc.avaxAddrToKeyIndex[avaxAddr]; !ok { kc.avaxAddrToKeyIndex[avaxAddr] = len(kc.Keys) - ethAddr := publicKeyToEthAddress(pk) + ethAddr := pk.EthAddress() kc.ethAddrToKeyIndex[ethAddr] = len(kc.Keys) kc.Keys = append(kc.Keys, key) kc.Addrs.Add(avaxAddr) @@ -169,7 +168,3 @@ func (kc Keychain) get(id ids.ShortID) (*secp256k1.PrivateKey, bool) { } return nil, false } - -func publicKeyToEthAddress(pk *secp256k1.PublicKey) common.Address { - return crypto.PubkeyToAddress(*(pk.ToECDSA())) -} diff --git a/wallet/chain/c/backend.go b/wallet/chain/c/backend.go index 000e8e095664..512797e9a020 100644 --- a/wallet/chain/c/backend.go +++ b/wallet/chain/c/backend.go @@ -10,7 +10,7 @@ import ( "math/big" "sync" - "github.com/ava-labs/coreth/plugin/evm" + "github.com/ava-labs/coreth/plugin/evm/atomic" "github.com/ava-labs/avalanchego/database" "github.com/ava-labs/avalanchego/utils/math" @@ -32,7 +32,7 @@ type Backend interface { BuilderBackend SignerBackend - AcceptAtomicTx(ctx context.Context, tx *evm.Tx) error + AcceptAtomicTx(ctx context.Context, tx *atomic.Tx) error } type backend struct { @@ -57,9 +57,9 @@ func NewBackend( } } -func (b *backend) AcceptAtomicTx(ctx context.Context, tx *evm.Tx) error { +func (b *backend) AcceptAtomicTx(ctx context.Context, tx *atomic.Tx) error { switch tx := tx.UnsignedAtomicTx.(type) { - case *evm.UnsignedImportTx: + case *atomic.UnsignedImportTx: for _, input := range tx.ImportedInputs { utxoID := input.InputID() if err := b.RemoveUTXO(ctx, tx.SourceChain, utxoID); err != nil { @@ -80,7 +80,7 @@ func (b *backend) AcceptAtomicTx(ctx context.Context, tx *evm.Tx) error { balance.Mul(balance, avaxConversionRate) account.Balance.Add(account.Balance, balance) } - case *evm.UnsignedExportTx: + case *atomic.UnsignedExportTx: txID := tx.ID() for i, out := range tx.ExportedOutputs { err := b.AddUTXO( diff --git a/wallet/chain/c/builder.go b/wallet/chain/c/builder.go index 1628c2002956..61e4ecd58521 100644 --- a/wallet/chain/c/builder.go +++ b/wallet/chain/c/builder.go @@ -8,7 +8,7 @@ import ( "errors" "math/big" - "github.com/ava-labs/coreth/plugin/evm" + "github.com/ava-labs/coreth/plugin/evm/atomic" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/utils" @@ -71,7 +71,7 @@ type Builder interface { to ethcommon.Address, baseFee *big.Int, options ...common.Option, - ) (*evm.UnsignedImportTx, error) + ) (*atomic.UnsignedImportTx, error) // NewExportTx creates an export transaction that attempts to send all the // provided [outputs] to the requested [chainID]. @@ -84,7 +84,7 @@ type Builder interface { outputs []*secp256k1fx.TransferOutput, baseFee *big.Int, options ...common.Option, - ) (*evm.UnsignedExportTx, error) + ) (*atomic.UnsignedExportTx, error) } // BuilderBackend specifies the required information needed to build unsigned @@ -185,7 +185,7 @@ func (b *builder) NewImportTx( to ethcommon.Address, baseFee *big.Int, options ...common.Option, -) (*evm.UnsignedImportTx, error) { +) (*atomic.UnsignedImportTx, error) { ops := common.NewOptions(options) utxos, err := b.backend.UTXOs(ops.Context(), chainID) if err != nil { @@ -226,7 +226,7 @@ func (b *builder) NewImportTx( } utils.Sort(importedInputs) - tx := &evm.UnsignedImportTx{ + tx := &atomic.UnsignedImportTx{ NetworkID: b.context.NetworkID, BlockchainID: b.context.BlockchainID, SourceChain: chainID, @@ -234,8 +234,8 @@ func (b *builder) NewImportTx( } // We must initialize the bytes of the tx to calculate the initial cost - wrappedTx := &evm.Tx{UnsignedAtomicTx: tx} - if err := wrappedTx.Sign(evm.Codec, nil); err != nil { + wrappedTx := &atomic.Tx{UnsignedAtomicTx: tx} + if err := wrappedTx.Sign(atomic.Codec, nil); err != nil { return nil, err } @@ -243,9 +243,9 @@ func (b *builder) NewImportTx( if err != nil { return nil, err } - gasUsedWithOutput := gasUsedWithoutOutput + evm.EVMOutputGas + gasUsedWithOutput := gasUsedWithoutOutput + atomic.EVMOutputGas - txFee, err := evm.CalculateDynamicFee(gasUsedWithOutput, baseFee) + txFee, err := atomic.CalculateDynamicFee(gasUsedWithOutput, baseFee) if err != nil { return nil, err } @@ -254,7 +254,7 @@ func (b *builder) NewImportTx( return nil, errInsufficientFunds } - tx.Outs = []evm.EVMOutput{{ + tx.Outs = []atomic.EVMOutput{{ Address: to, Amount: importedAmount - txFee, AssetID: avaxAssetID, @@ -267,7 +267,7 @@ func (b *builder) NewExportTx( outputs []*secp256k1fx.TransferOutput, baseFee *big.Int, options ...common.Option, -) (*evm.UnsignedExportTx, error) { +) (*atomic.UnsignedExportTx, error) { var ( avaxAssetID = b.context.AVAXAssetID exportedOutputs = make([]*avax.TransferableOutput, len(outputs)) @@ -287,8 +287,8 @@ func (b *builder) NewExportTx( exportedAmount = newExportedAmount } - avax.SortTransferableOutputs(exportedOutputs, evm.Codec) - tx := &evm.UnsignedExportTx{ + avax.SortTransferableOutputs(exportedOutputs, atomic.Codec) + tx := &atomic.UnsignedExportTx{ NetworkID: b.context.NetworkID, BlockchainID: b.context.BlockchainID, DestinationChain: chainID, @@ -296,8 +296,8 @@ func (b *builder) NewExportTx( } // We must initialize the bytes of the tx to calculate the initial cost - wrappedTx := &evm.Tx{UnsignedAtomicTx: tx} - if err := wrappedTx.Sign(evm.Codec, nil); err != nil { + wrappedTx := &atomic.Tx{UnsignedAtomicTx: tx} + if err := wrappedTx.Sign(atomic.Codec, nil); err != nil { return nil, err } @@ -306,7 +306,7 @@ func (b *builder) NewExportTx( return nil, err } - initialFee, err := evm.CalculateDynamicFee(cost, baseFee) + initialFee, err := atomic.CalculateDynamicFee(cost, baseFee) if err != nil { return nil, err } @@ -320,20 +320,20 @@ func (b *builder) NewExportTx( ops = common.NewOptions(options) ctx = ops.Context() addrs = ops.EthAddresses(b.ethAddrs) - inputs = make([]evm.EVMInput, 0, addrs.Len()) + inputs = make([]atomic.EVMInput, 0, addrs.Len()) ) for addr := range addrs { if amountToConsume == 0 { break } - prevFee, err := evm.CalculateDynamicFee(cost, baseFee) + prevFee, err := atomic.CalculateDynamicFee(cost, baseFee) if err != nil { return nil, err } - newCost := cost + evm.EVMInputGas - newFee, err := evm.CalculateDynamicFee(newCost, baseFee) + newCost := cost + atomic.EVMInputGas + newFee, err := atomic.CalculateDynamicFee(newCost, baseFee) if err != nil { return nil, err } @@ -371,7 +371,7 @@ func (b *builder) NewExportTx( } inputAmount := min(amountToConsume, avaxBalance) - inputs = append(inputs, evm.EVMInput{ + inputs = append(inputs, atomic.EVMInput{ Address: addr, Amount: inputAmount, AssetID: avaxAssetID, diff --git a/wallet/chain/c/builder_with_options.go b/wallet/chain/c/builder_with_options.go index c11c41d64471..15f03a1e93f9 100644 --- a/wallet/chain/c/builder_with_options.go +++ b/wallet/chain/c/builder_with_options.go @@ -6,7 +6,7 @@ package c import ( "math/big" - "github.com/ava-labs/coreth/plugin/evm" + "github.com/ava-labs/coreth/plugin/evm/atomic" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/vms/secp256k1fx" @@ -59,7 +59,7 @@ func (b *builderWithOptions) NewImportTx( to ethcommon.Address, baseFee *big.Int, options ...common.Option, -) (*evm.UnsignedImportTx, error) { +) (*atomic.UnsignedImportTx, error) { return b.Builder.NewImportTx( chainID, to, @@ -73,7 +73,7 @@ func (b *builderWithOptions) NewExportTx( outputs []*secp256k1fx.TransferOutput, baseFee *big.Int, options ...common.Option, -) (*evm.UnsignedExportTx, error) { +) (*atomic.UnsignedExportTx, error) { return b.Builder.NewExportTx( chainID, outputs, diff --git a/wallet/chain/c/signer.go b/wallet/chain/c/signer.go index 1e69db75be19..8cb5f1a50f3c 100644 --- a/wallet/chain/c/signer.go +++ b/wallet/chain/c/signer.go @@ -8,7 +8,7 @@ import ( "errors" "fmt" - "github.com/ava-labs/coreth/plugin/evm" + "github.com/ava-labs/coreth/plugin/evm/atomic" "github.com/ethereum/go-ethereum/common" "github.com/ava-labs/avalanchego/database" @@ -44,7 +44,7 @@ type Signer interface { // // If the signer doesn't have the ability to provide a required signature, // the signature slot will be skipped without reporting an error. - SignAtomic(ctx context.Context, tx *evm.Tx) error + SignAtomic(ctx context.Context, tx *atomic.Tx) error } type EthKeychain interface { @@ -73,15 +73,15 @@ func NewSigner(avaxKC keychain.Keychain, ethKC EthKeychain, backend SignerBacken } } -func (s *txSigner) SignAtomic(ctx context.Context, tx *evm.Tx) error { +func (s *txSigner) SignAtomic(ctx context.Context, tx *atomic.Tx) error { switch utx := tx.UnsignedAtomicTx.(type) { - case *evm.UnsignedImportTx: + case *atomic.UnsignedImportTx: signers, err := s.getImportSigners(ctx, utx.SourceChain, utx.ImportedInputs) if err != nil { return err } return sign(tx, true, signers) - case *evm.UnsignedExportTx: + case *atomic.UnsignedExportTx: signers := s.getExportSigners(utx.Ins) return sign(tx, true, signers) default: @@ -134,7 +134,7 @@ func (s *txSigner) getImportSigners(ctx context.Context, sourceChainID ids.ID, i return txSigners, nil } -func (s *txSigner) getExportSigners(ins []evm.EVMInput) [][]keychain.Signer { +func (s *txSigner) getExportSigners(ins []atomic.EVMInput) [][]keychain.Signer { txSigners := make([][]keychain.Signer, len(ins)) for credIndex, input := range ins { inputSigners := make([]keychain.Signer, 1) @@ -151,14 +151,14 @@ func (s *txSigner) getExportSigners(ins []evm.EVMInput) [][]keychain.Signer { return txSigners } -func SignUnsignedAtomic(ctx context.Context, signer Signer, utx evm.UnsignedAtomicTx) (*evm.Tx, error) { - tx := &evm.Tx{UnsignedAtomicTx: utx} +func SignUnsignedAtomic(ctx context.Context, signer Signer, utx atomic.UnsignedAtomicTx) (*atomic.Tx, error) { + tx := &atomic.Tx{UnsignedAtomicTx: utx} return tx, signer.SignAtomic(ctx, tx) } // TODO: remove [signHash] after the ledger supports signing all transactions. -func sign(tx *evm.Tx, signHash bool, txSigners [][]keychain.Signer) error { - unsignedBytes, err := evm.Codec.Marshal(version, &tx.UnsignedAtomicTx) +func sign(tx *atomic.Tx, signHash bool, txSigners [][]keychain.Signer) error { + unsignedBytes, err := atomic.Codec.Marshal(version, &tx.UnsignedAtomicTx) if err != nil { return fmt.Errorf("couldn't marshal unsigned tx: %w", err) } @@ -219,7 +219,7 @@ func sign(tx *evm.Tx, signHash bool, txSigners [][]keychain.Signer) error { } } - signedBytes, err := evm.Codec.Marshal(version, tx) + signedBytes, err := atomic.Codec.Marshal(version, tx) if err != nil { return fmt.Errorf("couldn't marshal tx: %w", err) } diff --git a/wallet/chain/c/wallet.go b/wallet/chain/c/wallet.go index 65c15e6533a0..87b377edcc1b 100644 --- a/wallet/chain/c/wallet.go +++ b/wallet/chain/c/wallet.go @@ -9,7 +9,8 @@ import ( "time" "github.com/ava-labs/coreth/ethclient" - "github.com/ava-labs/coreth/plugin/evm" + "github.com/ava-labs/coreth/plugin/evm/atomic" + "github.com/ava-labs/coreth/plugin/evm/client" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/utils/rpc" @@ -37,7 +38,7 @@ type Wallet interface { chainID ids.ID, to ethcommon.Address, options ...common.Option, - ) (*evm.Tx, error) + ) (*atomic.Tx, error) // IssueExportTx creates, signs, and issues an export transaction that // attempts to send all the provided [outputs] to the requested [chainID]. @@ -48,17 +49,17 @@ type Wallet interface { chainID ids.ID, outputs []*secp256k1fx.TransferOutput, options ...common.Option, - ) (*evm.Tx, error) + ) (*atomic.Tx, error) // IssueUnsignedAtomicTx signs and issues the unsigned tx. IssueUnsignedAtomicTx( - utx evm.UnsignedAtomicTx, + utx atomic.UnsignedAtomicTx, options ...common.Option, - ) (*evm.Tx, error) + ) (*atomic.Tx, error) // IssueAtomicTx issues the signed tx. IssueAtomicTx( - tx *evm.Tx, + tx *atomic.Tx, options ...common.Option, ) error } @@ -66,7 +67,7 @@ type Wallet interface { func NewWallet( builder Builder, signer Signer, - avaxClient evm.Client, + avaxClient client.Client, ethClient ethclient.Client, backend Backend, ) Wallet { @@ -83,7 +84,7 @@ type wallet struct { Backend builder Builder signer Signer - avaxClient evm.Client + avaxClient client.Client ethClient ethclient.Client } @@ -99,7 +100,7 @@ func (w *wallet) IssueImportTx( chainID ids.ID, to ethcommon.Address, options ...common.Option, -) (*evm.Tx, error) { +) (*atomic.Tx, error) { baseFee, err := w.baseFee(options) if err != nil { return nil, err @@ -116,7 +117,7 @@ func (w *wallet) IssueExportTx( chainID ids.ID, outputs []*secp256k1fx.TransferOutput, options ...common.Option, -) (*evm.Tx, error) { +) (*atomic.Tx, error) { baseFee, err := w.baseFee(options) if err != nil { return nil, err @@ -130,9 +131,9 @@ func (w *wallet) IssueExportTx( } func (w *wallet) IssueUnsignedAtomicTx( - utx evm.UnsignedAtomicTx, + utx atomic.UnsignedAtomicTx, options ...common.Option, -) (*evm.Tx, error) { +) (*atomic.Tx, error) { ops := common.NewOptions(options) ctx := ops.Context() tx, err := SignUnsignedAtomic(ctx, w.signer, utx) @@ -144,7 +145,7 @@ func (w *wallet) IssueUnsignedAtomicTx( } func (w *wallet) IssueAtomicTx( - tx *evm.Tx, + tx *atomic.Tx, options ...common.Option, ) error { ops := common.NewOptions(options) @@ -182,7 +183,7 @@ func (w *wallet) baseFee(options []common.Option) (*big.Int, error) { // TODO: Upstream this function into coreth. func awaitTxAccepted( - c evm.Client, + c client.Client, ctx context.Context, txID ids.ID, freq time.Duration, @@ -197,7 +198,7 @@ func awaitTxAccepted( return err } - if status == evm.Accepted { + if status == atomic.Accepted { return nil } diff --git a/wallet/chain/c/wallet_with_options.go b/wallet/chain/c/wallet_with_options.go index 3b5987217d17..2fbfb75c13cf 100644 --- a/wallet/chain/c/wallet_with_options.go +++ b/wallet/chain/c/wallet_with_options.go @@ -4,7 +4,7 @@ package c import ( - "github.com/ava-labs/coreth/plugin/evm" + "github.com/ava-labs/coreth/plugin/evm/atomic" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/vms/secp256k1fx" @@ -41,7 +41,7 @@ func (w *walletWithOptions) IssueImportTx( chainID ids.ID, to ethcommon.Address, options ...common.Option, -) (*evm.Tx, error) { +) (*atomic.Tx, error) { return w.Wallet.IssueImportTx( chainID, to, @@ -53,7 +53,7 @@ func (w *walletWithOptions) IssueExportTx( chainID ids.ID, outputs []*secp256k1fx.TransferOutput, options ...common.Option, -) (*evm.Tx, error) { +) (*atomic.Tx, error) { return w.Wallet.IssueExportTx( chainID, outputs, @@ -62,9 +62,9 @@ func (w *walletWithOptions) IssueExportTx( } func (w *walletWithOptions) IssueUnsignedAtomicTx( - utx evm.UnsignedAtomicTx, + utx atomic.UnsignedAtomicTx, options ...common.Option, -) (*evm.Tx, error) { +) (*atomic.Tx, error) { return w.Wallet.IssueUnsignedAtomicTx( utx, common.UnionOptions(w.options, options)..., @@ -72,7 +72,7 @@ func (w *walletWithOptions) IssueUnsignedAtomicTx( } func (w *walletWithOptions) IssueAtomicTx( - tx *evm.Tx, + tx *atomic.Tx, options ...common.Option, ) error { return w.Wallet.IssueAtomicTx( diff --git a/wallet/subnet/primary/api.go b/wallet/subnet/primary/api.go index dbf7047fafe1..493994b808fb 100644 --- a/wallet/subnet/primary/api.go +++ b/wallet/subnet/primary/api.go @@ -8,9 +8,10 @@ import ( "fmt" "github.com/ava-labs/coreth/ethclient" - "github.com/ava-labs/coreth/plugin/evm" + "github.com/ava-labs/coreth/plugin/evm/client" "github.com/ava-labs/avalanchego/api/info" + "github.com/ava-labs/avalanchego/chains/atomic" "github.com/ava-labs/avalanchego/codec" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/utils/constants" @@ -62,7 +63,7 @@ type AVAXState struct { PCTX *pbuilder.Context XClient avm.Client XCTX *xbuilder.Context - CClient evm.Client + CClient client.Client CCTX *c.Context UTXOs walletcommon.UTXOs } @@ -78,7 +79,7 @@ func FetchState( infoClient := info.NewClient(uri) pClient := platformvm.NewClient(uri) xClient := avm.NewClient(uri, "X") - cClient := evm.NewCChainClient(uri) + cClient := client.NewCChainClient(uri) pCTX, err := p.NewContextFromClients(ctx, infoClient, pClient) if err != nil { @@ -115,7 +116,7 @@ func FetchState( { id: cCTX.BlockchainID, client: cClient, - codec: evm.Codec, + codec: atomic.Codec, }, } for _, destinationChain := range chains { diff --git a/wallet/subnet/primary/examples/c-chain-import/main.go b/wallet/subnet/primary/examples/c-chain-import/main.go index 8b599cd4b742..98f747f2223d 100644 --- a/wallet/subnet/primary/examples/c-chain-import/main.go +++ b/wallet/subnet/primary/examples/c-chain-import/main.go @@ -8,8 +8,6 @@ import ( "log" "time" - "github.com/ava-labs/coreth/plugin/evm" - "github.com/ava-labs/avalanchego/genesis" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/utils/constants" @@ -24,7 +22,7 @@ func main() { uri := primary.LocalAPIURI kc := secp256k1fx.NewKeychain(key) avaxAddr := key.Address() - ethAddr := evm.PublicKeyToEthAddress(key.PublicKey()) + ethAddr := key.PublicKey().EthAddress() ctx := context.Background()