arnaucube
arnaucube/hermez-nodePublic Self-hosted repository
hermez-node/txselector/mock/mock.go
txselector/mock/mock.goRaw
 1package mock
 2
 3import (
 4	"github.com/hermeznetwork/hermez-node/tx-selector/common"
 5)
 6
 7type MockDB struct {
 8	Txs map[uint64][]common.Tx
 9
10	// AccountDB is the LocalAccountDB copy of the original AccountDB
11	AccountDB map[[36]byte]common.Account // [36]byte is tx.ToEthAddr + tx.TokenID
12
13	PendingRegistersDB map[[36]byte]common.Account // [36]byte is tx.ToEthAddr + tx.TokenID
14}
15
16func New() *MockDB {
17	return &MockDB{
18		Txs:                make(map[uint64][]common.Tx),
19		AccountDB:          make(map[[36]byte]common.Account),
20		PendingRegistersDB: make(map[[36]byte]common.Account),
21	}
22}
23
24func (m *MockDB) AddTx(batchID uint64, tx common.Tx) {
25	if _, ok := m.Txs[batchID]; !ok {
26		m.Txs[batchID] = []common.Tx{}
27	}
28	m.Txs[batchID] = append(m.Txs[batchID], tx)
29}
30
31func (m *MockDB) GetTxs(batchID uint64) []common.Tx {
32	return m.Txs[batchID]
33}