blob: d6e03dc1d7e3f03c737f1d46f547ad162a1a2b95 (
plain) (
tree)
|
|
// (c) 2019-2020, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package evm
import (
"errors"
"fmt"
"math/big"
"github.com/ava-labs/coreth/core/state"
"github.com/ava-labs/gecko/database"
"github.com/ava-labs/gecko/ids"
"github.com/ava-labs/gecko/snow"
crypto "github.com/ava-labs/gecko/utils/crypto"
"github.com/ava-labs/gecko/utils/math"
"github.com/ava-labs/gecko/vms/components/avax"
"github.com/ava-labs/gecko/vms/secp256k1fx"
"github.com/ava-labs/go-ethereum/common"
)
var (
errAssetIDMismatch = errors.New("asset IDs in the input don't match the utxo")
errWrongNumberOfCredentials = errors.New("should have the same number of credentials as inputs")
errNoInputs = errors.New("tx has no inputs")
errNoImportInputs = errors.New("tx has no imported inputs")
errInputsNotSortedUnique = errors.New("inputs not sorted and unique")
errPublicKeySignatureMismatch = errors.New("signature doesn't match public key")
errUnknownAsset = errors.New("unknown asset ID")
errNoFunds = errors.New("no spendable funds were found")
errWrongChainID = errors.New("tx has wrong chain ID")
errInsufficientFunds = errors.New("insufficient funds")
)
// UnsignedImportTx is an unsigned ImportTx
type UnsignedImportTx struct {
avax.Metadata
// true iff this transaction has already passed syntactic verification
syntacticallyVerified bool
// ID of the network on which this tx was issued
NetworkID uint32 `serialize:"true" json:"networkID"`
// ID of this blockchain.
BlockchainID ids.ID `serialize:"true" json:"blockchainID"`
// Which chain to consume the funds from
SourceChain ids.ID `serialize:"true" json:"sourceChain"`
// Inputs that consume UTXOs produced on the chain
ImportedInputs []*avax.TransferableInput `serialize:"true" json:"importedInputs"`
// Outputs
Outs []EVMOutput `serialize:"true" json:"outputs"`
// Memo field contains arbitrary bytes, up to maxMemoSize
Memo []byte `serialize:"true" json:"memo"`
}
// InputUTXOs returns the UTXOIDs of the imported funds
func (tx *UnsignedImportTx) InputUTXOs() ids.Set {
set := ids.Set{}
for _, in := range tx.ImportedInputs {
set.Add(in.InputID())
}
return set
}
// Verify this transaction is well-formed
func (tx *UnsignedImportTx) Verify(
avmID ids.ID,
ctx *snow.Context,
feeAmount uint64,
feeAssetID ids.ID,
) error {
switch {
case tx == nil:
return errNilTx
case tx.syntacticallyVerified: // already passed syntactic verification
return nil
case tx.SourceChain.IsZero():
return errWrongChainID
case !tx.SourceChain.Equals(avmID):
return errWrongChainID
case len(tx.ImportedInputs) == 0:
return errNoImportInputs
case tx.NetworkID
|