gitlab.com/flarenetwork/coreth@v0.1.1/plugin/evm/import_tx.go (about) 1 // (c) 2021, Flare Networks Limited. All rights reserved. 2 // 3 // This file is a derived work, based on the avalanchego library whose original 4 // notice appears below. It is distributed under a license compatible with the 5 // licensing terms of the original code from which it is derived. 6 // Please see the file LICENSE_AVALABS for licensing terms of the original work. 7 // Please see the file LICENSE for licensing terms. 8 // 9 // (c) 2019-2020, Ava Labs, Inc. All rights reserved. 10 11 package evm 12 13 import ( 14 "fmt" 15 "math/big" 16 17 "gitlab.com/flarenetwork/coreth/core/state" 18 "gitlab.com/flarenetwork/coreth/params" 19 20 "github.com/ava-labs/avalanchego/database" 21 "github.com/ava-labs/avalanchego/ids" 22 "github.com/ava-labs/avalanchego/snow" 23 "github.com/ava-labs/avalanchego/utils/crypto" 24 "github.com/ava-labs/avalanchego/vms/components/avax" 25 "github.com/ethereum/go-ethereum/common" 26 ) 27 28 // UnsignedImportTx is an unsigned ImportTx 29 type UnsignedImportTx struct { 30 avax.Metadata 31 // ID of the network on which this tx was issued 32 NetworkID uint32 `serialize:"true" json:"networkID"` 33 // ID of this blockchain. 34 BlockchainID ids.ID `serialize:"true" json:"blockchainID"` 35 // Which chain to consume the funds from 36 SourceChain ids.ID `serialize:"true" json:"sourceChain"` 37 // Inputs that consume UTXOs produced on the chain 38 ImportedInputs []*avax.TransferableInput `serialize:"true" json:"importedInputs"` 39 // Outputs 40 Outs []EVMOutput `serialize:"true" json:"outputs"` 41 } 42 43 // InputUTXOs returns the UTXOIDs of the imported funds 44 func (tx *UnsignedImportTx) InputUTXOs() ids.Set { 45 set := ids.Set{} 46 for _, in := range tx.ImportedInputs { 47 set.Add(in.InputID()) 48 } 49 return set 50 } 51 52 // Verify this transaction is well-formed 53 func (tx *UnsignedImportTx) Verify( 54 avmID ids.ID, 55 ctx *snow.Context, 56 rules params.Rules, 57 ) error { 58 return errWrongChainID 59 } 60 61 func (tx *UnsignedImportTx) Cost() (uint64, error) { 62 return 0, fmt.Errorf("exportTx transactions disabled") 63 } 64 65 // Amount of [assetID] burned by this transaction 66 func (tx *UnsignedImportTx) Burned(assetID ids.ID) (uint64, error) { 67 return 0, fmt.Errorf("exportTx transactions disabled") 68 } 69 70 // SemanticVerify this transaction is valid. 71 func (tx *UnsignedImportTx) SemanticVerify( 72 vm *VM, 73 stx *Tx, 74 parent *Block, 75 baseFee *big.Int, 76 rules params.Rules, 77 ) error { 78 return fmt.Errorf("exportTx transactions disabled") 79 } 80 81 // Accept this transaction and spend imported inputs 82 // We spend imported UTXOs here rather than in semanticVerify because 83 // we don't want to remove an imported UTXO in semanticVerify 84 // only to have the transaction not be Accepted. This would be inconsistent. 85 // Recall that imported UTXOs are not kept in a versionDB. 86 func (tx *UnsignedImportTx) Accept(ctx *snow.Context, batch database.Batch) error { 87 return fmt.Errorf("exportTx transactions disabled") 88 } 89 90 // newImportTx returns a new ImportTx 91 func (vm *VM) newImportTx( 92 chainID ids.ID, // chain to import from 93 to common.Address, // Address of recipient 94 baseFee *big.Int, // fee to use post-AP3 95 keys []*crypto.PrivateKeySECP256K1R, // Keys to import the funds 96 ) (*Tx, error) { 97 return nil, errWrongChainID 98 } 99 100 // EVMStateTransfer performs the state transfer to increase the balances of 101 // accounts accordingly with the imported EVMOutputs 102 func (tx *UnsignedImportTx) EVMStateTransfer(ctx *snow.Context, state *state.StateDB) error { 103 return errInsufficientFunds 104 }