github.com/aergoio/aergo@v1.3.1/mempool/stub.go (about)

     1  /**
     2   *  @file
     3   *  @copyright defined in aergo/LICENSE.txt
     4   */
     5  
     6  package mempool
     7  
     8  import (
     9  	"sync"
    10  
    11  	"github.com/aergoio/aergo/types"
    12  )
    13  
    14  /*
    15  func (mp *MemPool) generateInfiniteTx() {
    16  	SAMPLES := [][]byte{
    17  		{0x01, 0x00, 0x00, 0x00},
    18  		{0x02, 0x00, 0x00, 0x00},
    19  		{0x03, 0x00, 0x00, 0x00},
    20  	}
    21  
    22  	time.Sleep(time.Second * 2)
    23  	sampleSize := len(SAMPLES)
    24  	var nonce []uint64
    25  	for i := 0; i < sampleSize; i++ {
    26  		ns, _ := mp.getAccountState(SAMPLES[i], false)
    27  		nonce = append(nonce, ns.Nonce+1)
    28  	}
    29  
    30  	chunk := 1000
    31  	txs := make([]*types.Tx, chunk)
    32  	for {
    33  		for i := 0; i < chunk; i++ {
    34  			acc := rand.Intn(sampleSize)
    35  			tx := &types.Tx{
    36  				Body: &types.TxBody{
    37  					Nonce:     nonce[acc],
    38  					Account:   SAMPLES[acc],
    39  					Recipient: SAMPLES[0],
    40  					Amount:    1,
    41  				},
    42  			}
    43  			tx.Hash = tx.CalculateTxHash()
    44  			nonce[acc]++
    45  			txs[i] = tx
    46  
    47  		}
    48  		mp.RequestToFuture(message.MemPoolSvc,
    49  			&message.MemPoolPut{Txs: txs}, time.Second*100).Result() // nolint: errcheck
    50  
    51  		//	err := mp.put(tx)
    52  		//mp.Debugf("create temp tx : %s %s", err, tx.GetBody().String())
    53  	}
    54  }
    55  */
    56  const defaultBalance = uint64(10000000)
    57  
    58  var (
    59  	lock        sync.RWMutex
    60  	balance     = map[string]uint64{}
    61  	nonce       = map[string]uint64{}
    62  	bestBlockNo = types.BlockNo(1)
    63  )
    64  
    65  func initStubData() {
    66  	lock.Lock()
    67  	defer lock.Unlock()
    68  	balance = map[string]uint64{}
    69  	nonce = map[string]uint64{}
    70  	bestBlockNo = types.BlockNo(1)
    71  
    72  }
    73  func getNonceByAccMock(acc string) uint64 {
    74  	lock.Lock()
    75  	defer lock.Unlock()
    76  	_, ok := nonce[acc]
    77  	if !ok {
    78  		nonce[acc] = 0
    79  	}
    80  	return nonce[acc]
    81  }
    82  func getBalanceByAccMock(acc string) uint64 {
    83  	lock.Lock()
    84  	defer lock.Unlock()
    85  	_, ok := balance[acc]
    86  	if !ok {
    87  		balance[acc] = defaultBalance
    88  	}
    89  	return balance[acc]
    90  }
    91  
    92  func getCurrentBestBlockNoMock() types.BlockID {
    93  	return types.ToBlockID(nil)
    94  }