Skip to content

Commit

Permalink
Revert "Merge branch 'main' into tag47/cli"
Browse files Browse the repository at this point in the history
This reverts commit 87376fe, reversing
changes made to d11650c.
  • Loading branch information
bizk committed Sep 11, 2023
1 parent 12541d8 commit d268485
Show file tree
Hide file tree
Showing 28 changed files with 433 additions and 2,866 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 github.com/cosmos/rosetta
go install cosmossdk.io/tools/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 "github.com/cosmos/rosetta/cmd"
import "cosmossdk.io/tools/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 (`github.com/cosmos/rosetta/cmd`).
The `RosettaCommand` function builds the `rosetta` root command and is defined in the `rosettaCmd` package (`cosmossdk.io/tools/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"
"github.com/cosmos/rosetta/lib"
"cosmossdk.io/tools/rosetta/lib"
)

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

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

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

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

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

sdk "github.com/cosmos/cosmos-sdk/types"
)
Expand Down Expand Up @@ -49,17 +48,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.ErrOffline, fmt.Sprintf("getting unsigned tx %s", err.Error()))
return nil, crgerrs.WrapError(crgerrs.ErrInvalidOperation, err.Error())
}

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

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

return &types.ConstructionPayloadsResponse{
Expand All @@ -76,38 +75,34 @@ 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, crgerrs.WrapError(crgerrs.ErrOffline, fmt.Sprintf("converting unsigned tx %s", err.Error()))
return nil, err
}

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

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

for i, sig := range signers {
addr := sdk.AccAddress(sig)
signersStr[i] = addr.String()
addr := sig.String()
signersStr[i] = addr
accountIdentifiers[i] = &types.AccountIdentifier{
Address: addr.String(),
Address: addr,
}
}
// get the metadata request information
meta := new(ConstructionPreprocessMetadata)
err = meta.FromMetadata(req.Metadata)
if err != nil {
return nil, crgerrs.WrapError(crgerrs.ErrOffline, fmt.Sprintf("parsing metadata %s", err.Error()))
return nil, err
}

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

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

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

metaOptions, err := options.ToMetadata()
if err != nil {
return nil, crgerrs.WrapError(crgerrs.ErrOffline, fmt.Sprintf("parsing metadata %s", err.Error()))
return nil, err
}
return &types.ConstructionPreprocessResponse{
Options: metaOptions,
Expand All @@ -131,7 +126,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, crgerrs.WrapError(crgerrs.ErrConverter, fmt.Sprintf("converting pub key to sdk %s", err.Error()))
return nil, err
}

return &types.AccountIdentifier{
Expand Down
Loading

0 comments on commit d268485

Please sign in to comment.