-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Declared `api.TracerRpcClient` interface with a narrowed method set; * Created `rpcClientDecorator` to wrap all rpc errors into `ErrRpcCallFailed` (which is handled in prover's task handler);
- Loading branch information
Showing
9 changed files
with
70 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
nil/services/synccommittee/prover/tracer/api/tracer_rpc_client.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package api | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/NilFoundation/nil/nil/internal/types" | ||
"github.com/NilFoundation/nil/nil/services/rpc/jsonrpc" | ||
scTypes "github.com/NilFoundation/nil/nil/services/synccommittee/internal/types" | ||
) | ||
|
||
type TracerRpcClient interface { | ||
GetBlock(ctx context.Context, shardId types.ShardId, blockId any, fullTx bool) (*jsonrpc.RPCBlock, error) | ||
|
||
GetDebugBlock(ctx context.Context, shardId types.ShardId, blockId any, fullTx bool) (*jsonrpc.DebugRPCBlock, error) | ||
|
||
GetDebugContract(ctx context.Context, contractAddr types.Address, blockId any) (*jsonrpc.DebugRPCContract, error) | ||
} | ||
|
||
type rpcClientDecorator struct { | ||
inner TracerRpcClient | ||
} | ||
|
||
func NewRpcClientDecorator(inner TracerRpcClient) TracerRpcClient { | ||
return &rpcClientDecorator{ | ||
inner: inner, | ||
} | ||
} | ||
|
||
func (c *rpcClientDecorator) GetBlock(ctx context.Context, shardId types.ShardId, blockId any, fullTx bool) (*jsonrpc.RPCBlock, error) { | ||
block, err := c.inner.GetBlock(ctx, shardId, blockId, fullTx) | ||
return block, c.wrapError(err) | ||
} | ||
|
||
func (c *rpcClientDecorator) GetDebugBlock(ctx context.Context, shardId types.ShardId, blockId any, fullTx bool) (*jsonrpc.DebugRPCBlock, error) { | ||
block, err := c.inner.GetDebugBlock(ctx, shardId, blockId, fullTx) | ||
return block, c.wrapError(err) | ||
} | ||
|
||
func (c *rpcClientDecorator) GetDebugContract(ctx context.Context, contractAddr types.Address, blockId any) (*jsonrpc.DebugRPCContract, error) { | ||
contract, err := c.inner.GetDebugContract(ctx, contractAddr, blockId) | ||
return contract, c.wrapError(err) | ||
} | ||
|
||
func (*rpcClientDecorator) wrapError(cause error) error { | ||
if cause == nil { | ||
return nil | ||
} | ||
|
||
return fmt.Errorf("%w: %w", scTypes.ErrRpcCallFailed, cause) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters