github.com/hyperledger/burrow@v0.34.5-0.20220512172541-77f09336001d/vent/chain/ethereum/throttle_client.go (about) 1 package ethereum 2 3 import ( 4 "time" 5 6 "github.com/hyperledger/burrow/logging" 7 8 "github.com/hyperledger/burrow/rpc/web3/ethclient" 9 ) 10 11 type ThrottleClient interface { 12 EthClient 13 Throttle() 14 } 15 16 type throttleClient struct { 17 *Throttler 18 client EthClient 19 } 20 21 func NewThrottleClient(client EthClient, maxRequests int, timeBase time.Duration, logger *logging.Logger) *throttleClient { 22 return &throttleClient{ 23 Throttler: NewThrottler(maxRequests, timeBase, timeBase, 24 logger.WithScope("ThrottleClient"). 25 With("max_requests", maxRequests, "time_base", timeBase.String())), 26 client: client, 27 } 28 } 29 30 func (t *throttleClient) GetLogs(filter *ethclient.Filter) ([]*ethclient.EthLog, error) { 31 t.addNow() 32 return t.client.GetLogs(filter) 33 } 34 35 func (t *throttleClient) BlockNumber() (uint64, error) { 36 t.addNow() 37 return t.client.BlockNumber() 38 } 39 40 func (t *throttleClient) GetBlockByNumber(height string) (*ethclient.Block, error) { 41 t.addNow() 42 return t.client.GetBlockByNumber(height) 43 } 44 45 func (t *throttleClient) NetVersion() (string, error) { 46 t.addNow() 47 return t.client.NetVersion() 48 } 49 50 func (t *throttleClient) Web3ClientVersion() (string, error) { 51 t.addNow() 52 return t.client.Web3ClientVersion() 53 } 54 55 func (t *throttleClient) Syncing() (bool, error) { 56 t.addNow() 57 return t.client.Syncing() 58 }