From bf037f27122dcc96849b4dd3d9f9f76c9bb26292 Mon Sep 17 00:00:00 2001 From: Determinant Date: Sat, 19 Sep 2020 13:52:35 -0400 Subject: fix the use of ids.ID --- plugin/evm/export_tx.go | 6 +++--- plugin/evm/import_tx.go | 15 ++++++++++----- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/plugin/evm/export_tx.go b/plugin/evm/export_tx.go index ad70855..9cfd5ba 100644 --- a/plugin/evm/export_tx.go +++ b/plugin/evm/export_tx.go @@ -174,7 +174,7 @@ func (vm *VM) newExportTx( var toBurn uint64 var err error - if assetID == vm.ctx.AVAXAssetID { + if assetID.Equals(vm.ctx.AVAXAssetID) { toBurn, err = safemath.Add64(amount, vm.txFee) if err != nil { return nil, errOverflowExport @@ -189,7 +189,7 @@ func (vm *VM) newExportTx( } // burn non-AVAX - if assetID != vm.ctx.AVAXAssetID { + if !assetID.Equals(vm.ctx.AVAXAssetID) { ins2, signers2, err := vm.GetSpendableCanonical(keys, assetID, amount) if err != nil { return nil, fmt.Errorf("couldn't generate tx inputs/outputs: %w", err) @@ -228,7 +228,7 @@ func (tx *UnsignedExportTx) EVMStateTransfer(vm *VM, state *state.StateDB) error log.Info("crosschain C->X", "addr", from.Address, "amount", from.Amount) amount := new(big.Int).Mul( new(big.Int).SetUint64(from.Amount), x2cRate) - if from.AssetID == vm.ctx.AVAXAssetID { + if from.AssetID.Equals(vm.ctx.AVAXAssetID) { if state.GetBalance(from.Address).Cmp(amount) < 0 { return errInsufficientFunds } diff --git a/plugin/evm/import_tx.go b/plugin/evm/import_tx.go index 1736067..1297f7c 100644 --- a/plugin/evm/import_tx.go +++ b/plugin/evm/import_tx.go @@ -179,6 +179,7 @@ func (vm *VM) newImportTx( to common.Address, // Address of recipient keys []*crypto.PrivateKeySECP256K1R, // Keys to import the funds ) (*Tx, error) { + log.Info("here0") if !vm.ctx.XChainID.Equals(chainID) { return nil, errWrongChainID } @@ -196,7 +197,7 @@ func (vm *VM) newImportTx( importedInputs := []*avax.TransferableInput{} signers := [][]*crypto.PrivateKeySECP256K1R{} - importedAmount := make(map[ids.ID]uint64) + importedAmount := make(map[[32]byte]uint64) now := vm.clock.Unix() for _, utxo := range atomicUTXOs { inputIntf, utxoSigners, err := kc.Spend(utxo.Out, now) @@ -208,7 +209,8 @@ func (vm *VM) newImportTx( continue } aid := utxo.AssetID() - importedAmount[aid], err = math.Add64(importedAmount[aid], input.Amount()) + aidKey := aid.Key() + importedAmount[aidKey], err = math.Add64(importedAmount[aidKey], input.Amount()) if err != nil { return nil, err } @@ -220,9 +222,10 @@ func (vm *VM) newImportTx( signers = append(signers, utxoSigners) } avax.SortTransferableInputsWithSigners(importedInputs, signers) - importedAVAXAmount := importedAmount[vm.ctx.AVAXAssetID] + importedAVAXAmount := importedAmount[vm.ctx.AVAXAssetID.Key()] if importedAVAXAmount == 0 { + log.Info("here1") return nil, errNoFunds // No imported UTXOs were spendable } @@ -230,6 +233,7 @@ func (vm *VM) newImportTx( // AVAX output if importedAVAXAmount < vm.txFee { // imported amount goes toward paying tx fee + log.Info("here2") // TODO: spend EVM balance to compensate vm.txFee-importedAmount return nil, errNoFunds } else if importedAVAXAmount > vm.txFee { @@ -241,7 +245,8 @@ func (vm *VM) newImportTx( } // non-AVAX asset outputs - for aid, amount := range importedAmount { + for aidKey, amount := range importedAmount { + aid := ids.NewID(aidKey) if aid.Equals(vm.ctx.AVAXAssetID) || amount == 0 { continue } @@ -272,7 +277,7 @@ func (tx *UnsignedImportTx) EVMStateTransfer(vm *VM, state *state.StateDB) error log.Info("crosschain X->C", "addr", to.Address, "amount", to.Amount) amount := new(big.Int).Mul( new(big.Int).SetUint64(to.Amount), x2cRate) - if to.AssetID == vm.ctx.AVAXAssetID { + if to.AssetID.Equals(vm.ctx.AVAXAssetID) { state.AddBalance(to.Address, amount) } else { state.AddBalanceMultiCoin(to.Address, to.AssetID.Key(), amount) -- cgit v1.2.3-70-g09d2