[#905] Make morph client non-panic-prone
All checks were successful
DCO action / DCO (pull_request) Successful in 3m14s
Build / Build Components (1.21) (pull_request) Successful in 4m44s
Build / Build Components (1.20) (pull_request) Successful in 4m51s
Tests and linters / Lint (pull_request) Successful in 6m2s
Vulncheck / Vulncheck (pull_request) Successful in 10m18s
Tests and linters / Staticcheck (pull_request) Successful in 13m26s
Tests and linters / Tests (1.20) (pull_request) Successful in 13m47s
Tests and linters / Tests (1.21) (pull_request) Successful in 13m59s
Tests and linters / Tests with -race (pull_request) Successful in 3m35s
All checks were successful
DCO action / DCO (pull_request) Successful in 3m14s
Build / Build Components (1.21) (pull_request) Successful in 4m44s
Build / Build Components (1.20) (pull_request) Successful in 4m51s
Tests and linters / Lint (pull_request) Successful in 6m2s
Vulncheck / Vulncheck (pull_request) Successful in 10m18s
Tests and linters / Staticcheck (pull_request) Successful in 13m26s
Tests and linters / Tests (1.20) (pull_request) Successful in 13m47s
Tests and linters / Tests (1.21) (pull_request) Successful in 13m59s
Tests and linters / Tests with -race (pull_request) Successful in 3m35s
Morph client returns errors instead. Signed-off-by: Ekaterina Lebedeva <ekaterina.lebedeva@yadro.com>
This commit is contained in:
parent
7b8881b5fb
commit
ff0f029788
3 changed files with 7 additions and 9 deletions
|
@ -76,8 +76,6 @@ func defaultConfig() *cfg {
|
|||
// Notary support should be enabled with EnableNotarySupport client
|
||||
// method separately.
|
||||
//
|
||||
// If private key is nil, it panics.
|
||||
//
|
||||
// Other values are set according to provided options, or by default:
|
||||
// - client context: Background;
|
||||
// - dial timeout: 5s;
|
||||
|
@ -94,7 +92,7 @@ func defaultConfig() *cfg {
|
|||
// If there are no healthy endpoint - returns ErrNoHealthyEndpoint.
|
||||
func New(ctx context.Context, key *keys.PrivateKey, opts ...Option) (*Client, error) {
|
||||
if key == nil {
|
||||
panic("empty private key")
|
||||
return nil, errors.New("empty private key")
|
||||
}
|
||||
|
||||
acc := wallet.NewAccountFromPrivateKey(key)
|
||||
|
|
|
@ -161,7 +161,7 @@ func (c *Client) ProbeNotary() (res bool) {
|
|||
// be called periodically. Notary support should be enabled in client to
|
||||
// use this function.
|
||||
//
|
||||
// This function must be invoked with notary enabled otherwise it throws panic.
|
||||
// This function must be invoked with notary enabled.
|
||||
func (c *Client) DepositNotary(amount fixedn.Fixed8, delta uint32) (res util.Uint256, err error) {
|
||||
c.switchLock.RLock()
|
||||
defer c.switchLock.RUnlock()
|
||||
|
@ -196,7 +196,7 @@ func (c *Client) DepositNotary(amount fixedn.Fixed8, delta uint32) (res util.Uin
|
|||
// this method sets notary deposit till parameter to a maximum possible value.
|
||||
// This allows to avoid ValidAfterDeposit failures.
|
||||
//
|
||||
// This function must be invoked with notary enabled otherwise it throws panic.
|
||||
// This function must be invoked with notary enabled.
|
||||
func (c *Client) DepositEndlessNotary(amount fixedn.Fixed8) (res util.Uint256, err error) {
|
||||
c.switchLock.RLock()
|
||||
defer c.switchLock.RUnlock()
|
||||
|
@ -246,7 +246,7 @@ func (c *Client) depositNotary(amount fixedn.Fixed8, till int64) (res util.Uint2
|
|||
// GetNotaryDeposit returns deposit of client's account in notary contract.
|
||||
// Notary support should be enabled in client to use this function.
|
||||
//
|
||||
// This function must be invoked with notary enabled otherwise it throws panic.
|
||||
// This function must be invoked with notary enabled.
|
||||
func (c *Client) GetNotaryDeposit() (res int64, err error) {
|
||||
c.switchLock.RLock()
|
||||
defer c.switchLock.RUnlock()
|
||||
|
@ -298,7 +298,7 @@ func (u *UpdateNotaryListPrm) SetHash(hash util.Uint256) {
|
|||
// UpdateNotaryList updates list of notary nodes in designate contract. Requires
|
||||
// committee multi signature.
|
||||
//
|
||||
// This function must be invoked with notary enabled otherwise it throws panic.
|
||||
// This function must be invoked with notary enabled.
|
||||
func (c *Client) UpdateNotaryList(prm UpdateNotaryListPrm) error {
|
||||
c.switchLock.RLock()
|
||||
defer c.switchLock.RUnlock()
|
||||
|
@ -346,7 +346,7 @@ func (u *UpdateAlphabetListPrm) SetHash(hash util.Uint256) {
|
|||
// As for sidechain list should contain all inner ring nodes.
|
||||
// Requires committee multi signature.
|
||||
//
|
||||
// This function must be invoked with notary enabled otherwise it throws panic.
|
||||
// This function must be invoked with notary enabled.
|
||||
func (c *Client) UpdateNeoFSAlphabetList(prm UpdateAlphabetListPrm) error {
|
||||
c.switchLock.RLock()
|
||||
defer c.switchLock.RUnlock()
|
||||
|
|
|
@ -63,7 +63,7 @@ func (c *Client) ReceiveBlocks(ch chan<- *block.Block) (string, error) {
|
|||
// connection to any of passed RPC endpoints.
|
||||
func (c *Client) ReceiveNotaryRequests(txSigner util.Uint160, ch chan<- *result.NotaryRequestEvent) (string, error) {
|
||||
if c.notary == nil {
|
||||
panic(notaryDisabledErrMsg)
|
||||
return "", ErrNotaryDisabled
|
||||
}
|
||||
|
||||
c.switchLock.Lock()
|
||||
|
|
Loading…
Reference in a new issue