github.com/annchain/OG@v0.0.9/og/txmaker/dummy_test.go (about) 1 package txmaker 2 3 import ( 4 "fmt" 5 types2 "github.com/annchain/OG/arefactor/og/types" 6 "github.com/annchain/OG/common" 7 "github.com/annchain/OG/common/math" 8 "github.com/annchain/OG/og/protocol/ogmessage/archive" 9 "github.com/annchain/OG/og/types" 10 11 "github.com/sirupsen/logrus" 12 ) 13 14 type dummyTxPoolRandomTx struct { 15 } 16 17 func (p *dummyTxPoolRandomTx) IsBadSeq(seq *types.Sequencer) error { 18 return nil 19 } 20 21 func (p *dummyTxPoolRandomTx) GetRandomTips(n int) (v []types.Txi) { 22 for i := 0; i < n; i++ { 23 v = append(v, archive.RandomTx()) 24 } 25 return 26 } 27 28 func (P *dummyTxPoolRandomTx) GetByNonce(addr common.Address, nonce uint64) types.Txi { 29 return nil 30 } 31 32 type dummyTxPoolMiniTx struct { 33 poolMap map[types2.Hash]types.Txi 34 tipsMap map[types2.Hash]types.Txi 35 } 36 37 func (d *dummyTxPoolMiniTx) IsBadSeq(seq *types.Sequencer) error { 38 return nil 39 } 40 41 func (d *dummyTxPoolMiniTx) Init() { 42 d.poolMap = make(map[types2.Hash]types.Txi) 43 d.tipsMap = make(map[types2.Hash]types.Txi) 44 } 45 46 func (P *dummyTxPoolMiniTx) GetByNonce(addr common.Address, nonce uint64) types.Txi { 47 return nil 48 } 49 50 func (p *dummyTxPoolMiniTx) GetRandomTips(n int) (v []types.Txi) { 51 indices := math.GenerateRandomIndices(n, len(p.tipsMap)) 52 // slice of keys 53 var keys types2.Hashes 54 for k := range p.tipsMap { 55 keys = append(keys, k) 56 } 57 for i := range indices { 58 v = append(v, p.tipsMap[keys[i]]) 59 } 60 return v 61 } 62 63 func (p *dummyTxPoolMiniTx) Add(v types.Txi) { 64 p.tipsMap[v.GetHash()] = v 65 66 for _, parentHash := range v.GetParents() { 67 if vp, ok := p.tipsMap[parentHash]; ok { 68 delete(p.tipsMap, parentHash) 69 p.poolMap[parentHash] = vp 70 } 71 } 72 logrus.Infof("added tx %s to tip. current pool size: tips: %d pool: %d", 73 v.String(), len(p.tipsMap), len(p.poolMap)) 74 } 75 76 type dummyTxPoolParents struct { 77 poolMap map[types2.Hash]types.Txi 78 } 79 80 func (p *dummyTxPoolParents) IsLocalHash(h types2.Hash) bool { 81 return false 82 } 83 84 func (p *dummyTxPoolParents) IsBadSeq(seq *types.Sequencer) error { 85 return nil 86 } 87 88 func (P *dummyTxPoolParents) GetByNonce(addr common.Address, nonce uint64) types.Txi { 89 return nil 90 } 91 92 func (p *dummyTxPoolParents) GetLatestNonce(addr common.Address) (uint64, error) { 93 return 0, fmt.Errorf("not supported") 94 } 95 96 func (p *dummyTxPoolParents) RegisterOnNewTxReceived(c chan types.Txi, s string, b bool) { 97 return 98 } 99 100 func (p *dummyTxPoolParents) Init() { 101 p.poolMap = make(map[types2.Hash]types.Txi) 102 } 103 104 func (p *dummyTxPoolParents) Get(hash types2.Hash) types.Txi { 105 return p.poolMap[hash] 106 } 107 108 func (p *dummyTxPoolParents) AddRemoteTx(tx types.Txi, b bool) error { 109 p.poolMap[tx.GetHash()] = tx 110 return nil 111 } 112 113 func (p *dummyTxPoolParents) GetMaxWeight() uint64 { 114 return 0 115 }