Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BeginTemporalRo/Rw defer rules (#13136)
example run: ``` // BalanceAt returns the wei balance of a certain account in the blockchain. func (b *SimulatedBackend) BalanceAt(ctx context.Context, contract libcommon.Address, blockNumber *big.Int) (*uint256.Int, error) { b.mu.Lock() defer b.mu.Unlock() // tx, err := b.m.DB.BeginTemporalRo(context.Background()) // if err != nil { // return nil, err // } // defer tx.Rollback() // stateDB := b.stateByBlockNumber(tx, blockNumber) tx2, err := b.m.DB.BeginTemporalRo(context.Background()) if err != nil { return nil, err } stateDb := b.stateByBlockNumber(tx2, blockNumber) return stateDb.GetBalance(contract) } ``` linter run: ``` >> make lint ^ accounts/abi/bind/backends/simulated.go:224:2: ruleguard: Add "defer tx2.Rollback()" right after transaction creation error check. If you are in the loop - consider use "b.m.DB.View" or "b.m.DB.Update" or extract whole transaction to function. ```
- Loading branch information