aboutsummaryrefslogtreecommitdiff
path: root/plugin/evm/tx.go
diff options
context:
space:
mode:
authorAaron Buchwald <[email protected]>2020-09-23 01:35:28 -0400
committerAaron Buchwald <[email protected]>2020-09-23 01:35:28 -0400
commit6cc9d3c61ee803f37cbc6e65799797c0dc51e9e5 (patch)
tree19fb96d229e75e599301ecdccf7013da576bbb90 /plugin/evm/tx.go
parent332dc311e9a21f21f141cfb262c7c23f5ea61ecb (diff)
Sort evm outputs of import tx
Diffstat (limited to 'plugin/evm/tx.go')
-rw-r--r--plugin/evm/tx.go39
1 files changed, 37 insertions, 2 deletions
diff --git a/plugin/evm/tx.go b/plugin/evm/tx.go
index db49980..7dcebc8 100644
--- a/plugin/evm/tx.go
+++ b/plugin/evm/tx.go
@@ -126,7 +126,11 @@ type innerSortInputsAndSigners struct {
}
func (ins *innerSortInputsAndSigners) Less(i, j int) bool {
- return bytes.Compare(ins.inputs[i].Address.Bytes(), ins.inputs[j].Address.Bytes()) < 0
+ addrComp := bytes.Compare(ins.inputs[i].Address.Bytes(), ins.inputs[j].Address.Bytes())
+ if addrComp != 0 {
+ return addrComp < 0
+ }
+ return bytes.Compare(ins.inputs[i].AssetID.Bytes(), ins.inputs[j].AssetID.Bytes()) < 0
}
func (ins *innerSortInputsAndSigners) Len() int { return len(ins.inputs) }
@@ -136,7 +140,7 @@ func (ins *innerSortInputsAndSigners) Swap(i, j int) {
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
+// SortEVMInputsAndSigners sorts the list of EVMInputs based on the addresses and assetIDs
func SortEVMInputsAndSigners(inputs []EVMInput, signers [][]*crypto.PrivateKeySECP256K1R) {
sort.Sort(&innerSortInputsAndSigners{inputs: inputs, signers: signers})
}
@@ -146,3 +150,34 @@ func SortEVMInputsAndSigners(inputs []EVMInput, signers [][]*crypto.PrivateKeySE
func IsSortedAndUniqueEVMInputs(inputs []EVMInput) bool {
return utils.IsSortedAndUnique(&innerSortInputsAndSigners{inputs: inputs})
}
+
+// innerSortEVMOutputs implements sort.Interface for EVMOutput
+type innerSortEVMOutputs struct {
+ outputs []EVMOutput
+}
+
+func (outs *innerSortEVMOutputs) Less(i, j int) bool {
+ addrComp := bytes.Compare(outs.outputs[i].Address.Bytes(), outs.outputs[j].Address.Bytes())
+ if addrComp != 0 {
+ return addrComp < 0
+ }
+ return bytes.Compare(outs.outputs[i].AssetID.Bytes(), outs.outputs[j].AssetID.Bytes()) < 0
+}
+
+func (outs *innerSortEVMOutputs) Len() int { return len(outs.outputs) }
+
+func (outs *innerSortEVMOutputs) Swap(i, j int) {
+ outs.outputs[j], outs.outputs[i] = outs.outputs[i], outs.outputs[j]
+}
+
+// SortEVMOutputs sorts the list of EVMOutputs based on the addresses and assetIDs
+// of the outputs
+func SortEVMOutputs(outputs []EVMOutput) {
+ sort.Sort(&innerSortEVMOutputs{outputs: outputs})
+}
+
+// IsSortedAndUniqueEVMOutputs returns true if the EVMOutputs are sorted and unique
+// based on the account addresses and assetIDs
+func IsSortedAndUniqueEVMOutputs(outputs []EVMOutput) bool {
+ return utils.IsSortedAndUnique(&innerSortEVMOutputs{outputs: outputs})
+}