Skip to content

Commit

Permalink
Merge branch 'main' into tag47/cli
Browse files Browse the repository at this point in the history
  • Loading branch information
bizk authored Sep 11, 2023
2 parents d11650c + ba60839 commit 87376fe
Show file tree
Hide file tree
Showing 28 changed files with 2,866 additions and 433 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Rosetta can be executed as a standalone service, it connects to the node endpoin
Install Rosetta standalone server with the following command:

```bash
go install cosmossdk.io/tools/rosetta
go install github.com/cosmos/rosetta
```

Alternatively, for building from source, simply run `make rosetta`. The binary will be located in the root folder.
Expand All @@ -27,7 +27,7 @@ To enable Native Rosetta API support, it's required to add the `RosettaCommand`
Import the `rosettaCmd` package:

```go
import "cosmossdk.io/tools/rosetta/cmd"
import "github.com/cosmos/rosetta/cmd"
```

Find the following line:
Expand All @@ -44,7 +44,7 @@ rootCmd.AddCommand(
)
```

The `RosettaCommand` function builds the `rosetta` root command and is defined in the `rosettaCmd` package (`cosmossdk.io/tools/rosetta/cmd`).
The `RosettaCommand` function builds the `rosetta` root command and is defined in the `rosettaCmd` package (`github.com/cosmos/rosetta/cmd`).

Since we’ve updated the Cosmos SDK to work with the Rosetta API, updating the application's root command file is all you need to do.

Expand Down Expand Up @@ -109,7 +109,7 @@ import (

"context"
"github.com/coinbase/rosetta-sdk-go/types"
"cosmossdk.io/tools/rosetta/lib"
"github.com/cosmos/rosetta/lib"
)

// CustomClient embeds the standard cosmos client
Expand All @@ -135,7 +135,7 @@ Example:

```go
package custom_errors
import crgerrs "cosmossdk.io/tools/rosetta/lib/errors"
import crgerrs "github.com/cosmos/rosetta/lib/errors"

var customErrRetriable = true
var CustomError = crgerrs.RegisterError(100, "custom message", customErrRetriable, "description")
Expand Down
33 changes: 19 additions & 14 deletions client_offline.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package rosetta
import (
"context"
"encoding/hex"
"fmt"

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

crgerrs "cosmossdk.io/tools/rosetta/lib/errors"
crgerrs "github.com/cosmos/rosetta/lib/errors"

sdk "github.com/cosmos/cosmos-sdk/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,34 +76,38 @@ 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 := tx.GetSigners()
signers, err := tx.GetSigners()
if err != nil {
return nil, crgerrs.WrapError(crgerrs.ErrOffline, fmt.Sprintf("getting signers from unsigned tx %s", err.Error()))
}

signersStr := make([]string, len(signers))
accountIdentifiers := make([]*types.AccountIdentifier, len(signers))

for i, sig := range signers {
addr := sig.String()
signersStr[i] = addr
addr := sdk.AccAddress(sig)
signersStr[i] = addr.String()
accountIdentifiers[i] = &types.AccountIdentifier{
Address: addr,
Address: addr.String(),
}
}
// get the metadata request information
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 @@ -115,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 @@ -126,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 87376fe

Please sign in to comment.