Skip to content

Commit

Permalink
refactor: Improvements on error handling (#29)
Browse files Browse the repository at this point in the history
* feat: multi zone - plugin & reflection  (#5)

* added plugins feature and reflection features

* fixed minor sdkTx variables issue

* Roll back some changes on config.go

* fixed makefile build command

* improvements over lint

* Added nolint ant changed variable name

* fix .gitworkflow build

* fix .gitworkflow build

* Added makefile build plugin steps

* added nolint on staticcheck on load.go

* added nolint on staticcheck on load.go

* added nolint on staticcheck on load.go

* added nolint on staticcheck on load.go

* gofumpt on project

* skiped a test due to reliance on an experimental feature of cosmos v0.46.0-beta

* build plugin before test

* build plugin before test

* fixed failing test

* fix make test

* added docs

* small refactor on variable names

* Zondax/feature/multi zone fix

* added plugins feature and reflection features

* fixed minor sdkTx variables issue

* Roll back some changes on config.go

* fixed makefile build command

* improvements over lint

* Added nolint ant changed variable name

* fix .gitworkflow build

* fix .gitworkflow build

* Added makefile build plugin steps

* added nolint on staticcheck on load.go

* added nolint on staticcheck on load.go

* added nolint on staticcheck on load.go

* added nolint on staticcheck on load.go

* gofumpt on project

* skiped a test due to reliance on an experimental feature of cosmos v0.46.0-beta

* build plugin before test

* build plugin before test

* fixed failing test

* fix make test

* added docs

* small refactor on variable names

* Updated documentation and added --plugin flag

* updated install step on README

* lint fix

* updated docs

* updated go.sum (#8)

* refactor: Upgrade rosetta to cosmos-sdk v0.50.0 (#7)

* changed go.mod name, renamed dependencies on rosetta, adapted methods and uses of cosmos-sdk, upgraded dependencies

* fixed all code errors

* improvements over parsing

* fees and gas parsing

* remmoved validation on message due to deprecation (it should be validated on the server side)

* solved issue on missing tx tipper

* added codec types

* fixed interface registre addr issue

* improvements

* fixed converter tests

* commented plugin_test.go due to some modules not being available at v0.50 yet

* improved code, moved parsing functions to utils.go

* solved comments, fixed lint and added utils.go for parsing

* fixed comment on cast variables

* lint comments

* Commented ibc-go dependdency until upgrade

* added type assertion error handlinhg

* updated go.sum

* rename module for vanity url

* update go.mod and go.sum

* refactor: error handling improvements (#9)

* issue on load.go

* fixed tests

* added client offline

* client_online.go

* added error handling on utils.go and unified both files

* added plugins.go

* added config, converter and libraries

* linted and fixed issues

* fixed some issues
  • Loading branch information
bizk authored Sep 4, 2023
1 parent f4f74b4 commit 3c104b2
Show file tree
Hide file tree
Showing 11 changed files with 182 additions and 176 deletions.
21 changes: 11 additions & 10 deletions client_offline.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package rosetta
import (
"context"
"encoding/hex"
"fmt"

"github.com/coinbase/rosetta-sdk-go/types"

Expand Down Expand Up @@ -48,17 +49,17 @@ func (c *Client) ConstructionPayload(_ context.Context, request *types.Construct

tx, err := c.converter.ToSDK().UnsignedTx(request.Operations)
if err != nil {
return nil, crgerrs.WrapError(crgerrs.ErrInvalidOperation, err.Error())
return nil, crgerrs.WrapError(crgerrs.ErrOffline, fmt.Sprintf("getting unsigned tx %s", err.Error()))
}

metadata := new(ConstructionMetadata)
if err = metadata.FromMetadata(request.Metadata); err != nil {
return nil, err
return nil, crgerrs.WrapError(crgerrs.ErrOffline, fmt.Sprintf("getting metadata from request %s", err.Error()))
}

txBytes, payloads, err := c.converter.ToRosetta().SigningComponents(tx, metadata, request.PublicKeys)
if err != nil {
return nil, err
return nil, crgerrs.WrapError(crgerrs.ErrOffline, fmt.Sprintf("getting signed components %s", err.Error()))
}

return &types.ConstructionPayloadsResponse{
Expand All @@ -75,13 +76,13 @@ func (c *Client) PreprocessOperationsToOptions(_ context.Context, req *types.Con
// now we need to parse the operations to cosmos sdk messages
tx, err := c.converter.ToSDK().UnsignedTx(req.Operations)
if err != nil {
return nil, err
return nil, crgerrs.WrapError(crgerrs.ErrOffline, fmt.Sprintf("converting unsigned tx %s", err.Error()))
}

// get the signers
signers, err := tx.GetSigners()
if err != nil {
return nil, err
return nil, crgerrs.WrapError(crgerrs.ErrOffline, fmt.Sprintf("getting signers from unsigned tx %s", err.Error()))
}

signersStr := make([]string, len(signers))
Expand All @@ -98,15 +99,15 @@ func (c *Client) PreprocessOperationsToOptions(_ context.Context, req *types.Con
meta := new(ConstructionPreprocessMetadata)
err = meta.FromMetadata(req.Metadata)
if err != nil {
return nil, err
return nil, crgerrs.WrapError(crgerrs.ErrOffline, fmt.Sprintf("parsing metadata %s", err.Error()))
}

if meta.GasPrice == "" {
return nil, crgerrs.WrapError(crgerrs.ErrBadArgument, "no gas prices")
return nil, crgerrs.WrapError(crgerrs.ErrOffline, "no gas price")
}

if meta.GasLimit == 0 {
return nil, crgerrs.WrapError(crgerrs.ErrBadArgument, "no gas limit")
return nil, crgerrs.WrapError(crgerrs.ErrOffline, "no gas limit")
}

// prepare the options to return
Expand All @@ -119,7 +120,7 @@ func (c *Client) PreprocessOperationsToOptions(_ context.Context, req *types.Con

metaOptions, err := options.ToMetadata()
if err != nil {
return nil, err
return nil, crgerrs.WrapError(crgerrs.ErrOffline, fmt.Sprintf("parsing metadata %s", err.Error()))
}
return &types.ConstructionPreprocessResponse{
Options: metaOptions,
Expand All @@ -130,7 +131,7 @@ func (c *Client) PreprocessOperationsToOptions(_ context.Context, req *types.Con
func (c *Client) AccountIdentifierFromPublicKey(pubKey *types.PublicKey) (*types.AccountIdentifier, error) {
pk, err := c.converter.ToSDK().PubKey(pubKey)
if err != nil {
return nil, err
return nil, crgerrs.WrapError(crgerrs.ErrConverter, fmt.Sprintf("converting pub key to sdk %s", err.Error()))
}

return &types.AccountIdentifier{
Expand Down
Loading

0 comments on commit 3c104b2

Please sign in to comment.