Documentation ¶
Index ¶
- Constants
- func AddressFromHex(hex string) (common.Address, error)
- func CallAtBlock(fromAddress common.Address, blockNumber *big.Int, value *big.Int, ...) error
- func ConnectClients(url string, urlRPC string) (*celoclient.Client, *rpc.Client, *rpc.Client, error)
- func DecryptKeyFile(keyFile, password string) (*keystore.Key, error)
- func EstimateGas(from common.Address, to common.Address, method string, contractABI *abi.ABI, ...) (uint64, error)
- func NewBlockCounter(client CeloClient) (*ethlike.BlockCounter, error)
- func NewKeyedTransactorWithChainID(key *ecdsa.PrivateKey, chainID *big.Int) (*bind.TransactOpts, error)
- func NewMiningWaiter(client CeloClient, checkInterval time.Duration, maxGasPrice *big.Int) *ethlike.MiningWaiter
- func NewNonceManager(client CeloClient, account common.Address) *ethlike.NonceManager
- func WithResubscription(backoffMax time.Duration, subscribeFn event.ResubscribeFunc, ...) event.Subscription
- type BalanceMonitor
- type BalanceSource
- type CeloClient
- type CeloSigner
- func (cs *CeloSigner) PublicKey() []byte
- func (cs *CeloSigner) PublicKeyBytesToAddress(publicKey []byte) []byte
- func (cs *CeloSigner) PublicKeyToAddress(publicKey ecdsa.PublicKey) []byte
- func (cs *CeloSigner) Sign(message []byte) ([]byte, error)
- func (cs *CeloSigner) Verify(message []byte, signature []byte) (bool, error)
- func (cs *CeloSigner) VerifyWithPublicKey(message []byte, signature []byte, publicKey []byte) (bool, error)
- type ErrorResolver
- type TransactionOptions
Constants ¶
const ( // DefaultSubscribeOptsTick is the default duration with which // past events are pulled from the chain by the subscription monitoring // mechanism if no other value is provided in SubscribeOpts when creating // the subscription. DefaultSubscribeOptsTick = 15 * time.Minute // DefaultSubscribeOptsPastBlocks is the default number of past blocks // pulled from the chain by the subscription monitoring mechanism if no // other value is provided in SubscribeOpts when creating the subscription. DefaultSubscribeOptsPastBlocks = 100 // SubscriptionBackoffMax is the maximum backoff time between event // resubscription attempts. SubscriptionBackoffMax = 2 * time.Minute // SubscriptionAlertThreshold is time threshold below which event // resubscription emits an error to the logs. // WS connection can be dropped at any moment and event resubscription will // follow. However, if WS connection for event subscription is getting // dropped too often, it may indicate something is wrong with Celo // client. This constant defines the minimum lifetime of an event // subscription required before the subscription failure happens and // resubscription follows so that the resubscription does not emit an error // to the logs alerting about potential problems with Celo client // connection. SubscriptionAlertThreshold = 15 * time.Minute )
const SignatureSize = 65
SignatureSize is a byte size of a signature calculated by Celo with recovery-id, V, included. The signature consists of three values (R,S,V) in the following order: R = [0:31] S = [32:63] V = [64]
Variables ¶
This section is empty.
Functions ¶
func AddressFromHex ¶
AddressFromHex converts the passed string to a common.Address and returns it, unless it is not a valid address, in which case it returns an error. Compare to common.HexToAddress, which assumes the address is valid and does not provide for an error return.
func CallAtBlock ¶
func CallAtBlock( fromAddress common.Address, blockNumber *big.Int, value *big.Int, contractABI *abi.ABI, caller bind.ContractCaller, errorResolver *ErrorResolver, contractAddress common.Address, method string, result interface{}, parameters ...interface{}, ) error
CallAtBlock allows the invocation of a particular contract method at a particular block. It papers over the fact that abigen bindings don't directly support calling at a particular block, and is mostly meant for use from generated contract code.
func ConnectClients ¶
func ConnectClients(url string, urlRPC string) ( *celoclient.Client, *rpc.Client, *rpc.Client, error, )
ConnectClients takes HTTP and RPC URLs and returns initialized versions of standard, WebSocket, and RPC clients for the Celo node at that address.
func DecryptKeyFile ¶
DecryptKeyFile reads in a key file and uses the password to decrypt it.
func EstimateGas ¶
func EstimateGas( from common.Address, to common.Address, method string, contractABI *abi.ABI, transactor bind.ContractTransactor, parameters ...interface{}, ) (uint64, error)
EstimateGas tries to estimate the gas needed to execute a specific transaction based on the current pending state of the backend blockchain. There is no guarantee that this is the true gas limit requirement as other transactions may be added or removed by miners, but it should provide a basis for setting a reasonable default.
func NewBlockCounter ¶
func NewBlockCounter(client CeloClient) (*ethlike.BlockCounter, error)
NewBlockCounter creates a new BlockCounter instance for the provided Celo client.
func NewKeyedTransactorWithChainID ¶
func NewKeyedTransactorWithChainID( key *ecdsa.PrivateKey, chainID *big.Int, ) (*bind.TransactOpts, error)
NewKeyedTransactorWithChainID is a utility method to easily create a transaction signer from a single private key. FIXME Remove this function and rely on bind.NewKeyedTransactorWithChainID FIXME when celo-org/celo-blockchain merges in changes from upstream FIXME ethereum/go-ethereum beyond v1.9.25.
func NewMiningWaiter ¶
func NewMiningWaiter( client CeloClient, checkInterval time.Duration, maxGasPrice *big.Int, ) *ethlike.MiningWaiter
NewMiningWaiter creates a new MiningWaiter instance for the provided Celo client. It accepts two parameters setting up monitoring rules of the transaction mining status.
func NewNonceManager ¶
func NewNonceManager( client CeloClient, account common.Address, ) *ethlike.NonceManager
NewNonceManager creates NonceManager instance for the provided account using the provided Celo client.
func WithResubscription ¶
func WithResubscription( backoffMax time.Duration, subscribeFn event.ResubscribeFunc, alertThreshold time.Duration, thresholdViolatedFn func(time.Duration), subscriptionFailedFn func(error), ) event.Subscription
WithResubscription wraps the subscribe function to call it repeatedly to keep a subscription alive. When a subscription is established, it is monitored and in the case of a failure, resubscribe is attempted by calling the subscribe function again.
The mechanism applies backoff between resubscription attempts. The time between calls is adapted based on the error rate, but will never exceed backoffMax.
The mechanism monitors the time elapsed between resubscription attempts and if it is shorter than the specificed alertThreshold, it calls thresholdViolatedFn passing the time elapsed between resubscription attempts. This function alarms about potential problems with the stability of the subscription.
In case of an error returned by the wrapped subscription function, subscriptionFailedFn is called with the underlying error.
thresholdViolatedFn and subscriptionFailedFn calls are executed in a separate goroutine and thus are non-blocking.
Types ¶
type BalanceMonitor ¶
type BalanceMonitor struct {
// contains filtered or unexported fields
}
BalanceMonitor provides the possibility to monitor balances for given accounts.
func NewBalanceMonitor ¶
func NewBalanceMonitor(balanceSource BalanceSource) *BalanceMonitor
NewBalanceMonitor creates a new instance of the balance monitor.
func (*BalanceMonitor) Observe ¶
func (bm *BalanceMonitor) Observe( ctx context.Context, address common.Address, alertThreshold *celo.Wei, tick time.Duration, retryTimeout time.Duration, )
Observe starts a process which checks the address balance with the given tick and triggers an alert in case the balance falls below the alert threshold value. The balance check will be retried in case of an error up to the retry timeout.
type BalanceSource ¶
BalanceSource provides a balance info for the given address.
type CeloClient ¶
type CeloClient interface { bind.ContractBackend celo.ChainReader celo.TransactionReader BalanceAt( ctx context.Context, account common.Address, blockNumber *big.Int, ) (*big.Int, error) }
CeloClient wraps the core `bind.ContractBackend` interface with some other interfaces allowing to expose additional methods provided by client implementations.
func WrapCallLogging ¶
func WrapCallLogging( logger log.EventLogger, client CeloClient, ) CeloClient
WrapCallLogging wraps certain call-related methods on the given `client` with debug logging sent to the given `logger`. Actual functionality is delegated to the passed client.
func WrapRateLimiting ¶
func WrapRateLimiting( client CeloClient, config *rate.LimiterConfig, ) CeloClient
WrapRateLimiting wraps the given contract backend with rate limiting capabilities with respect to the provided configuration. All types of requests to the contract are rate-limited, including view function calls.
type CeloSigner ¶
type CeloSigner struct {
// contains filtered or unexported fields
}
CeloSigner provides functions to sign a message and verify a signature using the Celo-specific signature format. It also provides functions for conversion of a public key to an address.
func NewSigner ¶
func NewSigner(privateKey *ecdsa.PrivateKey) *CeloSigner
NewSigner creates a new CeloSigner instance for the provided ECDSA private key.
func (*CeloSigner) PublicKey ¶
func (cs *CeloSigner) PublicKey() []byte
PublicKey returns byte representation of a public key for the private key signer was created with.
func (*CeloSigner) PublicKeyBytesToAddress ¶
func (cs *CeloSigner) PublicKeyBytesToAddress(publicKey []byte) []byte
PublicKeyBytesToAddress transforms the provided ECDSA public key in a bytes format into Celo address represented in bytes.
func (*CeloSigner) PublicKeyToAddress ¶
func (cs *CeloSigner) PublicKeyToAddress(publicKey ecdsa.PublicKey) []byte
PublicKeyToAddress transforms the provided ECDSA public key into Celo address represented in bytes.
func (*CeloSigner) Sign ¶
func (cs *CeloSigner) Sign(message []byte) ([]byte, error)
Sign signs the provided message using Celo-specific format.
func (*CeloSigner) Verify ¶
func (cs *CeloSigner) Verify(message []byte, signature []byte) (bool, error)
Verify verifies the provided message against a signature using the key CeloSigner was created with. The signature has to be provided in Celo-specific format.
func (*CeloSigner) VerifyWithPublicKey ¶
func (cs *CeloSigner) VerifyWithPublicKey( message []byte, signature []byte, publicKey []byte, ) (bool, error)
VerifyWithPublicKey verifies the provided message against a signature and public key. The signature has to be provided in Celo-specific format.
type ErrorResolver ¶
type ErrorResolver struct {
// contains filtered or unexported fields
}
ErrorResolver bundles up the bits needed to turn errors like "failed to estimate gas needed" that are triggered by contract reverts but don't include revert causes into proper revert error messages from a contract by calling the contract method without trying to commit it.
It has one method, ResolveError, that does the heavy lifting.
func NewErrorResolver ¶
func NewErrorResolver( contractCaller celo.ContractCaller, abi *abi.ABI, address *common.Address, ) *ErrorResolver
NewErrorResolver returns an ErroResolver for the given Celo client, contract ABI, and contract address combination.
func (*ErrorResolver) ResolveError ¶
func (er *ErrorResolver) ResolveError( originalErr error, from common.Address, value *big.Int, methodName string, parameters ...interface{}, ) error
ResolveError resolves the given transaction error to a standard error that, if available, contains the error message the transaction produced when reverting.
ResolveError achieves this by re-calling the transaction (not submitting it for block inclusion, just calling it for its results). `value` is the value in gwei to send along with the simulated call.
type TransactionOptions ¶
type TransactionOptions struct { // GasLimit specifies a gas limit to set on a transaction call; should be // ignored if set to 0. GasLimit uint64 // GasPrice specifies a gas price to set on a transaction call; should be // ignored if set to nil. GasPrice *big.Int }
TransactionOptions represents custom transaction options which can be used while invoking contracts methods.
func (TransactionOptions) Apply ¶
func (to TransactionOptions) Apply(transactorOptions *bind.TransactOpts)
Apply takes a bind.TransactOpts pointer and applies the options described in TransactionOptions to it. Note that a GasLimit of 0 or a GasPrice of nil are not applied to the passed options; these values indicate that the options should remain unchanged.