Add txselector base

This commit is contained in:
arnaucube
2020-07-24 12:22:13 +02:00
parent a9c77e9607
commit e77599dac3
6 changed files with 498 additions and 0 deletions

33
txselector/mock/mock.go Normal file
View File

@@ -0,0 +1,33 @@
package mock
import (
"github.com/hermeznetwork/hermez-node/tx-selector/common"
)
type MockDB struct {
Txs map[uint64][]common.Tx
// AccountDB is the LocalAccountDB copy of the original AccountDB
AccountDB map[[36]byte]common.Account // [36]byte is tx.ToEthAddr + tx.TokenID
PendingRegistersDB map[[36]byte]common.Account // [36]byte is tx.ToEthAddr + tx.TokenID
}
func New() *MockDB {
return &MockDB{
Txs: make(map[uint64][]common.Tx),
AccountDB: make(map[[36]byte]common.Account),
PendingRegistersDB: make(map[[36]byte]common.Account),
}
}
func (m *MockDB) AddTx(batchID uint64, tx common.Tx) {
if _, ok := m.Txs[batchID]; !ok {
m.Txs[batchID] = []common.Tx{}
}
m.Txs[batchID] = append(m.Txs[batchID], tx)
}
func (m *MockDB) GetTxs(batchID uint64) []common.Tx {
return m.Txs[batchID]
}