Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: standalone rosetta command #14118

Merged
merged 19 commits into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,6 @@ jobs:
- name: Build Cosmovisor
if: env.GIT_DIFF
run: GOARCH=${{ matrix.go-arch }} LEDGER_ENABLED=false make cosmovisor
- name: Build Rosetta
if: env.GIT_DIFF
run: GOARCH=${{ matrix.go-arch }} LEDGER_ENABLED=false make rosetta
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,10 @@ $(BUILDDIR)/:
cosmovisor:
$(MAKE) -C tools/cosmovisor cosmovisor

.PHONY: build build-linux-amd64 build-linux-arm64 cosmovisor
rosetta:
$(MAKE) -C tools/rosetta rosetta

.PHONY: build build-linux-amd64 build-linux-arm64 cosmovisor rosetta


mocks: $(MOCKS_DIR)
Expand Down
1 change: 1 addition & 0 deletions tools/rosetta/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/rosetta
3 changes: 2 additions & 1 deletion tools/rosetta/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Improvements

* [#14118](https://github.com/cosmos/cosmos-sdk/pull/14118) Let Rosetta be install as a standalone application.
* [#14061](https://github.com/cosmos/cosmos-sdk/pull/14061) Adds openapi specification.
* [#13832](https://github.com/cosmos/cosmos-sdk/pull/13832) Correctly populates rosetta's `/network/status` endpoint response. Rosetta's data api is divided into its own go files (account, block, mempool, network).

### Bug Fixes

* [#13832](https://github.com/cosmos/cosmos-sdk/pull/13832) Wrap tendermint RPC errors to rosetta errors.
* [#13832](https://github.com/cosmos/cosmos-sdk/pull/13832) Wrap tendermint RPC errors to rosetta errors.

## v0.1.0 2022-11-04

Expand Down
5 changes: 4 additions & 1 deletion tools/rosetta/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

all: build

rosetta:
go build -mod=readonly ./cmd/rosetta

build:
go build ./cmd/rosetta.go

test:
go test -mod=readonly -race ./...

.PHONY: all build test
.PHONY: all build rosetta test
22 changes: 18 additions & 4 deletions tools/rosetta/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ The Rosetta API server is a stand-alone server that connects to a node of a chai

To enable Rosetta API support, it's required to add the `RosettaCommand` to your application's root command file (e.g. `simd/cmd/root.go`).

Import the `server` package:
Import the `rosettaCmd` package:

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

Find the following line:
Expand All @@ -28,11 +28,11 @@ After that line, add the following:

```go
rootCmd.AddCommand(
server.RosettaCommand(encodingConfig.InterfaceRegistry, encodingConfig.Codec)
rosettaCmd.RosettaCommand(encodingConfig.InterfaceRegistry, encodingConfig.Codec)
)
```

The `RosettaCommand` function builds the `rosetta` root command and is defined in the `server` package within Cosmos SDK.
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 All @@ -57,6 +57,20 @@ simd rosetta
--addr "rosetta binding address (ex: :8080)"
```

## Use Rosetta Standalone

To use Rosetta standalone, without having to add it in your application, install it with the following command:

```bash
go install cosmossdk.io/tools/rosetta/cmd/rosetta
julienrbrt marked this conversation as resolved.
Show resolved Hide resolved
```

:::warning
This command will fail until https://github.com/coinbase/rosetta-sdk-go/issues/449 is resolved.
:::

Alternatively, for building from source, simply run `make rosetta`. The binary will be located in `tools/rosetta`.

## Extensions

There are two ways in which you can customize and extend the implementation with your custom settings.
Expand Down
1 change: 1 addition & 0 deletions tools/rosetta/cmd/rosetta.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"

"github.com/spf13/cobra"

"cosmossdk.io/tools/rosetta"
Expand Down
23 changes: 23 additions & 0 deletions tools/rosetta/cmd/rosetta/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package main

import (
"os"

rosettaCmd "cosmossdk.io/tools/rosetta/cmd"
"cosmossdk.io/tools/rosetta/lib/logger"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
)

func main() {
var (
logger = logger.NewLogger()
interfaceRegistry = codectypes.NewInterfaceRegistry()
cdc = codec.NewProtoCodec(interfaceRegistry)
)

if err := rosettaCmd.RosettaCommand(interfaceRegistry, cdc).Execute(); err != nil {
logger.Err(err).Msg("failed to run rosetta")
os.Exit(1)
}
}
25 changes: 16 additions & 9 deletions tools/rosetta/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@ require (
cosmossdk.io/math v1.0.0-beta.4
github.com/btcsuite/btcd/btcec/v2 v2.3.2
github.com/coinbase/rosetta-sdk-go v0.8.1
github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20220909113810-4882f933b1a1
github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20221201152010-fb4d964f7ecc
github.com/rs/zerolog v1.28.0
github.com/spf13/cobra v1.6.1
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.1
github.com/tendermint/tendermint v0.37.0-rc1
github.com/tendermint/tendermint v0.37.0-rc2
google.golang.org/grpc v1.51.0
)

require (
cosmossdk.io/api v0.2.5 // indirect
cosmossdk.io/core v0.3.2 // indirect
cosmossdk.io/depinject v1.0.0-alpha.3 // indirect
cosmossdk.io/errors v1.0.0-beta.7 // indirect
filippo.io/edwards25519 v1.0.0-rc.1 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
Expand All @@ -23,22 +27,22 @@ require (
github.com/armon/go-metrics v0.4.1 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bgentry/speakeasy v0.1.0 // indirect
github.com/btcsuite/btcd v0.22.1 // indirect
github.com/btcsuite/btcd v0.22.3 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/confio/ics23/go v0.7.0 // indirect
github.com/confio/ics23/go v0.9.0 // indirect
github.com/cosmos/btcutil v1.0.4 // indirect
github.com/cosmos/cosmos-proto v1.0.0-beta.1 // indirect
github.com/cosmos/go-bip39 v1.0.0 // indirect
github.com/cosmos/gogoproto v1.4.3 // indirect
github.com/cosmos/gorocksdb v1.2.0 // indirect
github.com/cosmos/iavl v0.19.1 // indirect
github.com/cosmos/iavl v0.19.4 // indirect
github.com/cosmos/ledger-cosmos-go v0.12.0 // indirect
github.com/danieljoos/wincred v1.1.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 // indirect
github.com/dgraph-io/badger/v2 v2.2007.4 // indirect
github.com/dgraph-io/ristretto v0.1.0 // indirect
github.com/dgraph-io/ristretto v0.1.1 // indirect
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 // indirect
github.com/dustin/go-humanize v1.0.0 // indirect
github.com/dvsekhvalnov/jose2go v1.5.0 // indirect
Expand All @@ -51,7 +55,7 @@ require (
github.com/golang/glog v1.0.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/btree v1.0.1 // indirect
github.com/google/btree v1.1.2 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
Expand All @@ -63,11 +67,13 @@ require (
github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hdevalence/ed25519consensus v0.0.0-20220222234857-c00d1f31bab3 // indirect
github.com/huandu/skiplist v1.2.0 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/jmhodges/levigo v1.0.0 // indirect
github.com/klauspost/compress v1.15.9 // indirect
github.com/klauspost/compress v1.15.12 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/magiconair/properties v1.8.6 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/mimoo/StrobeGo v0.0.0-20210601165009-122bf33a46e0 // indirect
Expand Down Expand Up @@ -98,7 +104,7 @@ require (
github.com/zondax/ledger-go v0.14.0 // indirect
go.etcd.io/bbolt v1.3.6 // indirect
golang.org/x/crypto v0.3.0 // indirect
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e // indirect
golang.org/x/exp v0.0.0-20221019170559-20944726eadf // indirect
golang.org/x/net v0.2.0 // indirect
golang.org/x/sys v0.2.0 // indirect
golang.org/x/term v0.2.0 // indirect
Expand All @@ -108,6 +114,7 @@ require (
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
pgregory.net/rapid v0.5.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)

Expand Down
Loading