frostfs-node/pkg/morph/client/waiter.go
Evgenii Stratonikov 3d771aa21c
[#1689] morph: Remove frostfsError type
It has no custom methods defined, only adds `frostfs error: `
prefix to the error message. The utility of this prefix is debatable,
failed invocations already have `invocation failed` prefix.

Change-Id: If25ebb3679497f3f10acde43b596c81d52351907
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
2025-04-05 09:16:32 +03:00

51 lines
1.3 KiB
Go

package client
import (
"context"
"fmt"
"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
"github.com/nspcc-dev/neo-go/pkg/rpcclient/waiter"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger"
"github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neo-go/pkg/vm/vmstate"
)
type waiterClient struct {
c *Client
}
func (w *waiterClient) Context() context.Context {
return context.Background()
}
func (w *waiterClient) GetApplicationLog(hash util.Uint256, trig *trigger.Type) (*result.ApplicationLog, error) {
return w.c.GetApplicationLog(hash, trig)
}
func (w *waiterClient) GetBlockCount() (uint32, error) {
return w.c.BlockCount()
}
func (w *waiterClient) GetVersion() (*result.Version, error) {
return w.c.GetVersion()
}
// WaitTxHalt waits until transaction with the specified hash persists on the blockchain.
// It also checks execution result to finish in HALT state.
func (c *Client) WaitTxHalt(ctx context.Context, vub uint32, h util.Uint256) error {
w, err := waiter.NewPollingBased(&waiterClient{c: c})
if err != nil {
return fmt.Errorf("create tx waiter: %w", err)
}
res, err := w.WaitAny(ctx, vub, h)
if err != nil {
return fmt.Errorf("wait until tx persists: %w", err)
}
if res.VMState.HasFlag(vmstate.Halt) {
return nil
}
return &notHaltStateError{state: res.VMState.String(), exception: res.FaultException}
}