aboutsummaryrefslogtreecommitdiff
path: root/plugin/evm/tx.go
diff options
context:
space:
mode:
authorAaron Buchwald <[email protected]>2020-09-22 16:45:12 -0400
committerAaron Buchwald <[email protected]>2020-09-23 00:33:57 -0400
commita725a6a16c53f508681484e36729ebe65a5b33b1 (patch)
tree23fb875b6f13f3a079c4581a968b46b974b4a153 /plugin/evm/tx.go
parent8cc21e15b96ccbe246bb06bece08c22df786069d (diff)
Add test for ExportTx Verify
Diffstat (limited to 'plugin/evm/tx.go')
-rw-r--r--plugin/evm/tx.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/plugin/evm/tx.go b/plugin/evm/tx.go
index 9580bc0..fd52222 100644
--- a/plugin/evm/tx.go
+++ b/plugin/evm/tx.go
@@ -4,14 +4,17 @@
package evm
import (
+ "bytes"
"errors"
"fmt"
+ "sort"
"github.com/ava-labs/coreth/core/state"
"github.com/ava-labs/avalanchego/database"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow"
+ "github.com/ava-labs/avalanchego/utils"
"github.com/ava-labs/avalanchego/utils/codec"
"github.com/ava-labs/avalanchego/utils/crypto"
"github.com/ava-labs/avalanchego/utils/hashing"
@@ -115,3 +118,31 @@ func (tx *Tx) Sign(c codec.Codec, signers [][]*crypto.PrivateKeySECP256K1R) erro
tx.Initialize(unsignedBytes, signedBytes)
return nil
}
+
+// innerSortInputs implements sort.Interface for EVMInput
+type innerSortInputs struct {
+ inputs []EVMInput
+ signers [][]*crypto.PrivateKeySECP256K1R
+}
+
+func (ins *innerSortInputs) Less(i, j int) bool {
+ return bytes.Compare(ins.inputs[i].Address.Bytes(), ins.inputs[j].Address.Bytes()) < 0
+}
+
+func (ins *innerSortInputs) Len() int { return len(ins.inputs) }
+
+func (ins *innerSortInputs) Swap(i, j int) {
+ ins.inputs[j], ins.inputs[i] = ins.inputs[i], ins.inputs[j]
+ ins.signers[j], ins.signers[i] = ins.signers[i], ins.signers[j]
+}
+
+// SortEVMInputsAndSigners sorts the list of EVMInputs based solely on the address of the input
+func SortEVMInputsAndSigners(inputs []EVMInput, signers [][]*crypto.PrivateKeySECP256K1R) {
+ sort.Sort(&innerSortInputs{inputs: inputs, signers: signers})
+}
+
+// IsSortedAndUniqueEVMInputs returns true if the EVM Inputs are sorted and unique
+// based on the account addresses
+func IsSortedAndUniqueEVMInputs(inputs []EVMInput) bool {
+ return utils.IsSortedAndUnique(&innerSortInputs{inputs: inputs})
+}