From 5b12d3fa21635145cb8a752b56477e22fca77a5b Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Fri, 30 Oct 2020 12:55:53 -0400 Subject: remove these ID calls: Key(), Bytes(), Equals(), NewID(), IsZero() --- plugin/evm/export_tx.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'plugin/evm/export_tx.go') diff --git a/plugin/evm/export_tx.go b/plugin/evm/export_tx.go index d099eb2..74e36b6 100644 --- a/plugin/evm/export_tx.go +++ b/plugin/evm/export_tx.go @@ -17,6 +17,7 @@ import ( safemath "github.com/ava-labs/avalanchego/utils/math" "github.com/ava-labs/avalanchego/vms/components/avax" "github.com/ava-labs/avalanchego/vms/secp256k1fx" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/log" ) @@ -52,15 +53,15 @@ func (tx *UnsignedExportTx) Verify( return errNilTx case tx.syntacticallyVerified: // already passed syntactic verification return nil - case tx.DestinationChain.IsZero(): + case tx.DestinationChain == ids.Empty: return errWrongChainID - case !tx.DestinationChain.Equals(avmID): + case tx.DestinationChain != avmID: return errWrongChainID case len(tx.ExportedOutputs) == 0: return errNoExportOutputs case tx.NetworkID != ctx.NetworkID: return errWrongNetworkID - case !ctx.ChainID.Equals(tx.BlockchainID): + case ctx.ChainID != tx.BlockchainID: return errWrongBlockchainID } @@ -177,13 +178,13 @@ func (vm *VM) newExportTx( to ids.ShortID, // Address of chain recipient keys []*crypto.PrivateKeySECP256K1R, // Pay the fee and provide the tokens ) (*Tx, error) { - if !vm.ctx.XChainID.Equals(chainID) { + if vm.ctx.XChainID != chainID { return nil, errWrongChainID } var toBurn uint64 var err error - if assetID.Equals(vm.ctx.AVAXAssetID) { + if assetID == vm.ctx.AVAXAssetID { toBurn, err = safemath.Add64(amount, vm.txFee) if err != nil { return nil, errOverflowExport @@ -198,7 +199,7 @@ func (vm *VM) newExportTx( } // burn non-AVAX - if !assetID.Equals(vm.ctx.AVAXAssetID) { + if assetID != vm.ctx.AVAXAssetID { ins2, signers2, err := vm.GetSpendableFunds(keys, assetID, amount) if err != nil { return nil, fmt.Errorf("couldn't generate tx inputs/outputs: %w", err) @@ -242,7 +243,7 @@ func (tx *UnsignedExportTx) EVMStateTransfer(vm *VM, state *state.StateDB) error addrs := map[[20]byte]uint64{} for _, from := range tx.Ins { log.Info("crosschain C->X", "addr", from.Address, "amount", from.Amount) - if from.AssetID.Equals(vm.ctx.AVAXAssetID) { + if from.AssetID == vm.ctx.AVAXAssetID { amount := new(big.Int).Mul( new(big.Int).SetUint64(from.Amount), x2cRate) if state.GetBalance(from.Address).Cmp(amount) < 0 { @@ -251,11 +252,10 @@ func (tx *UnsignedExportTx) EVMStateTransfer(vm *VM, state *state.StateDB) error state.SubBalance(from.Address, amount) } else { amount := new(big.Int).SetUint64(from.Amount) - assetID := from.AssetID.Key() - if state.GetBalanceMultiCoin(from.Address, assetID).Cmp(amount) < 0 { + if state.GetBalanceMultiCoin(from.Address, common.Hash(from.AssetID)).Cmp(amount) < 0 { return errInsufficientFunds } - state.SubBalanceMultiCoin(from.Address, assetID, amount) + state.SubBalanceMultiCoin(from.Address, common.Hash(from.AssetID), amount) } if state.GetNonce(from.Address) != from.Nonce { return errInvalidNonce -- cgit v1.2.3 From c6fcd057903dc5ccc785b3a34fef534a4cb39d0a Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Sun, 1 Nov 2020 18:24:33 -0500 Subject: remove id.Bytes() and ids.NewID --- plugin/evm/export_tx.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'plugin/evm/export_tx.go') diff --git a/plugin/evm/export_tx.go b/plugin/evm/export_tx.go index 74e36b6..0778d0a 100644 --- a/plugin/evm/export_tx.go +++ b/plugin/evm/export_tx.go @@ -155,9 +155,9 @@ func (tx *UnsignedExportTx) Accept(ctx *snow.Context, _ database.Batch) error { if err != nil { return err } - + utxoID := utxo.InputID() elem := &atomic.Element{ - Key: utxo.InputID().Bytes(), + Key: utxoID[:], Value: utxoBytes, } if out, ok := utxo.Out.(avax.Addressable); ok { -- cgit v1.2.3 From d7f430c196e0856eaaeedbfe1fcc30c1c472cd43 Mon Sep 17 00:00:00 2001 From: Aaron Buchwald Date: Mon, 9 Nov 2020 13:46:28 -0500 Subject: Clean up usage of ids.ID --- plugin/evm/export_tx.go | 2 -- 1 file changed, 2 deletions(-) (limited to 'plugin/evm/export_tx.go') diff --git a/plugin/evm/export_tx.go b/plugin/evm/export_tx.go index 0778d0a..ed069d4 100644 --- a/plugin/evm/export_tx.go +++ b/plugin/evm/export_tx.go @@ -53,8 +53,6 @@ func (tx *UnsignedExportTx) Verify( return errNilTx case tx.syntacticallyVerified: // already passed syntactic verification return nil - case tx.DestinationChain == ids.Empty: - return errWrongChainID case tx.DestinationChain != avmID: return errWrongChainID case len(tx.ExportedOutputs) == 0: -- cgit v1.2.3