AllBefore returns a batch of transactions added before the given time. this will update the updateTime of the transaction with time.Now
(t time.Time)
| 238 | // AllBefore returns a batch of transactions added before the given time. |
| 239 | // this will update the updateTime of the transaction with time.Now |
| 240 | func (m *txSortedMap) AllBefore(t time.Time) (results []types.Transactions) { |
| 241 | var result types.Transactions |
| 242 | |
| 243 | // filter txs before given time |
| 244 | for _, nonce := range *m.index { |
| 245 | |
| 246 | // get a tx ordered by nonce |
| 247 | if tx, ok := m.items[nonce]; tx != nil && ok { |
| 248 | |
| 249 | // add to result |
| 250 | if tx.updateTime.Before(t) { |
| 251 | result = append(result, tx.Tx()) |
| 252 | tx.updateTime = time.Now() |
| 253 | } |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | // split result with batch size |
| 258 | lengthOfResult := len(result) |
| 259 | batchNumber := lengthOfResult / rebroadcastBatchSize |
| 260 | for i := 0; i < batchNumber; i++ { |
| 261 | results = append(results, result[i*rebroadcastBatchSize:i*rebroadcastBatchSize+rebroadcastBatchSize]) |
| 262 | } |
| 263 | |
| 264 | // add the remained |
| 265 | results = append(results, result[batchNumber*rebroadcastBatchSize:lengthOfResult]) |
| 266 | return |
| 267 | } |
| 268 | |
| 269 | // txList is a "list" of transactions belonging to an account, sorted by account |
| 270 | // nonce. The same type can be used both for storing contiguous transactions for |