aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDeterminant <tederminant@gmail.com>2020-08-19 21:20:58 -0400
committerDeterminant <tederminant@gmail.com>2020-08-19 21:20:58 -0400
commit0b934ef60fd652de038a21e6f25691b11cea7121 (patch)
treea034e3e6b2efd527bcfa87883d8f5f29a65b4828
parentb9b9f523b3a745ca0c5809ea2d1c76c80a4134cb (diff)
remove base_tx.go
-rw-r--r--plugin/evm/base_tx.go85
-rw-r--r--plugin/evm/import_tx.go35
-rw-r--r--plugin/evm/tx.go21
3 files changed, 45 insertions, 96 deletions
diff --git a/plugin/evm/base_tx.go b/plugin/evm/base_tx.go
deleted file mode 100644
index b3e85cd..0000000
--- a/plugin/evm/base_tx.go
+++ /dev/null
@@ -1,85 +0,0 @@
-package evm
-
-import (
- "errors"
-
- "github.com/ava-labs/gecko/ids"
- "github.com/ava-labs/gecko/snow"
- "github.com/ava-labs/gecko/vms/components/avax"
- "github.com/ava-labs/go-ethereum/common"
-)
-
-// Max size of memo field
-// Don't change without also changing avm.maxMemoSize
-const maxMemoSize = 256
-
-var (
- errVMNil = errors.New("tx.vm is nil")
- errWrongBlockchainID = errors.New("wrong blockchain ID provided")
- errWrongNetworkID = errors.New("tx was issued with a different network ID")
- errNilTx = errors.New("tx is nil")
- errInvalidID = errors.New("invalid ID")
- errOutputsNotSorted = errors.New("outputs not sorted")
-)
-
-type EVMOutput struct {
- Address common.Address `serialize:"true" json:"address"`
- Amount uint64 `serialize:"true" json:"amount"`
-}
-
-func (out *EVMOutput) Verify() error {
- return nil
-}
-
-// BaseTx contains fields common to many transaction types. It should be
-// embedded in transaction implementations. The serialized fields of this struct
-// should be exactly the same as those of avm.BaseTx. Do not change this
-// struct's serialized fields without doing the same on avm.BaseTx.
-// TODO: Factor out this and avm.BaseTX
-type BaseTx 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. In practice is always the empty ID.
- // This is only here to match avm.BaseTx's format
- BlockchainID ids.ID `serialize:"true" json:"blockchainID"`
- // Outputs
- Outs []EVMOutput `serialize:"true" json:"outputs"`
- // Inputs consumed by this tx
- Ins []*avax.TransferableInput `serialize:"true" json:"inputs"`
- // Memo field contains arbitrary bytes, up to maxMemoSize
- Memo []byte `serialize:"true" json:"memo"`
-}
-
-// Verify returns nil iff this tx is well formed
-func (tx *BaseTx) Verify(ctx *snow.Context) error {
- switch {
- case tx == nil:
- return errNilTx
- case tx.syntacticallyVerified: // already passed syntactic verification
- return nil
- case tx.NetworkID != ctx.NetworkID:
- return errWrongNetworkID
- case !ctx.ChainID.Equals(tx.BlockchainID):
- return errWrongBlockchainID
- }
- for _, out := range tx.Outs {
- if err := out.Verify(); err != nil {
- return err
- }
- }
- for _, in := range tx.Ins {
- if err := in.Verify(); err != nil {
- return err
- }
- }
- switch {
- // TODO: check whether output addreses are sorted?
- case !avax.IsSortedAndUniqueTransferableInputs(tx.Ins):
- return errInputsNotSortedUnique
- default:
- return nil
- }
-}
diff --git a/plugin/evm/import_tx.go b/plugin/evm/import_tx.go
index 0e77efc..2e49493 100644
--- a/plugin/evm/import_tx.go
+++ b/plugin/evm/import_tx.go
@@ -31,7 +31,18 @@ var (
// UnsignedImportTx is an unsigned ImportTx
type UnsignedImportTx struct {
- BaseTx `serialize:"true"`
+ 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. In practice is always the empty ID.
+ // This is only here to match avm.BaseTx's format
+ BlockchainID ids.ID `serialize:"true" json:"blockchainID"`
+ // Outputs
+ Outs []EVMOutput `serialize:"true" json:"outputs"`
+ // Memo field contains arbitrary bytes, up to maxMemoSize
+ Memo []byte `serialize:"true" json:"memo"`
// Which chain to consume the funds from
SourceChain ids.ID `serialize:"true" json:"sourceChain"`
@@ -67,10 +78,16 @@ func (tx *UnsignedImportTx) Verify(
return errWrongChainID
case len(tx.ImportedInputs) == 0:
return errNoImportInputs
+ case tx.NetworkID != ctx.NetworkID:
+ return errWrongNetworkID
+ case !ctx.ChainID.Equals(tx.BlockchainID):
+ return errWrongBlockchainID
}
- if err := tx.BaseTx.Verify(ctx); err != nil {
- return err
+ for _, out := range tx.Outs {
+ if err := out.Verify(); err != nil {
+ return err
+ }
}
for _, in := range tx.ImportedInputs {
@@ -178,7 +195,6 @@ func (vm *VM) newImportTx(
return nil, errNoFunds // No imported UTXOs were spendable
}
- ins := []*avax.TransferableInput{}
outs := []EVMOutput{}
if importedAmount < vm.txFee { // imported amount goes toward paying tx fee
// TODO: spend EVM balance to compensate vm.txFee-importedAmount
@@ -192,14 +208,11 @@ func (vm *VM) newImportTx(
// Create the transaction
utx := &UnsignedImportTx{
- BaseTx: BaseTx{
- NetworkID: vm.ctx.NetworkID,
- BlockchainID: vm.ctx.ChainID,
- Outs: outs,
- Ins: ins,
- },
- SourceChain: chainID,
+ NetworkID: vm.ctx.NetworkID,
+ BlockchainID: vm.ctx.ChainID,
+ Outs: outs,
ImportedInputs: importedInputs,
+ SourceChain: chainID,
}
tx := &Tx{UnsignedTx: utx}
if err := tx.Sign(vm.codec, signers); err != nil {
diff --git a/plugin/evm/tx.go b/plugin/evm/tx.go
index 024e54d..6196eb8 100644
--- a/plugin/evm/tx.go
+++ b/plugin/evm/tx.go
@@ -4,6 +4,7 @@
package evm
import (
+ "errors"
"fmt"
"github.com/ava-labs/gecko/database"
@@ -15,8 +16,28 @@ import (
"github.com/ava-labs/gecko/utils/hashing"
"github.com/ava-labs/gecko/vms/components/verify"
"github.com/ava-labs/gecko/vms/secp256k1fx"
+ "github.com/ava-labs/go-ethereum/common"
)
+// Max size of memo field
+// Don't change without also changing avm.maxMemoSize
+const maxMemoSize = 256
+
+var (
+ errWrongBlockchainID = errors.New("wrong blockchain ID provided")
+ errWrongNetworkID = errors.New("tx was issued with a different network ID")
+ errNilTx = errors.New("tx is nil")
+)
+
+type EVMOutput struct {
+ Address common.Address `serialize:"true" json:"address"`
+ Amount uint64 `serialize:"true" json:"amount"`
+}
+
+func (out *EVMOutput) Verify() error {
+ return nil
+}
+
// UnsignedTx is an unsigned transaction
type UnsignedTx interface {
Initialize(unsignedBytes, signedBytes []byte)