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

fix: misc fixes for cosmos-rosetta #13583

Merged
merged 33 commits into from
Nov 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
24f8cef
hardcode block identifier (#3)
rllola Sep 22, 2022
4eaa2bd
feat: Add go.mod for rosetta server (#4)
raynaudoe Sep 26, 2022
8ff651c
fix: minor fixes (#18)
raynaudoe Sep 29, 2022
fc58c6d
throw an error in case of config conflict (rosetta offline mode) (#20)
rllola Oct 7, 2022
be4facc
Fix blockidentifier not specify (#33)
rllola Oct 12, 2022
d6b9645
Parse base64 encoded events (#38)
raynaudoe Oct 12, 2022
edf20cd
Fix genesis block response (#42)
raynaudoe Oct 18, 2022
0c2779f
remove println
rllola Oct 20, 2022
cee3d9f
Move rosetta to tools dir
raynaudoe Oct 21, 2022
47e0dab
Rename variable
raynaudoe Oct 21, 2022
8aa02d3
Merge branch 'main' into misc/zondax-rosetta
raynaudoe Oct 21, 2022
e07319d
update module name
raynaudoe Oct 25, 2022
83d60a4
Add rosetta entry
raynaudoe Oct 25, 2022
56288da
Add rosetta to go.work.example
raynaudoe Oct 25, 2022
9fd3d15
add comment for coinbase/rosetta-sdk-go replace
rllola Oct 25, 2022
4d778ec
Update cosmos-sdk tag
raynaudoe Oct 27, 2022
ab271ef
Add comment
raynaudoe Oct 27, 2022
d59fc20
Merge branch 'main' into misc/zondax-rosetta
raynaudoe Oct 27, 2022
04dfe49
Add changelog entry
raynaudoe Oct 27, 2022
7f75a36
Run mod tidy
raynaudoe Oct 27, 2022
91882fb
Fix lint errors
raynaudoe Oct 27, 2022
0285cee
Set genesis hash env for rosetta tests
raynaudoe Oct 27, 2022
bdb125f
Update dockerfile to include tools/rosetta
raynaudoe Oct 27, 2022
468b92c
Fix ToRosetta func
raynaudoe Oct 27, 2022
17aecca
Revert decoding events
raynaudoe Oct 28, 2022
527a020
Fix supply pagination
raynaudoe Oct 31, 2022
69f9558
Fix potential int overflow
raynaudoe Oct 31, 2022
ab148f2
Merge branch 'main' into misc/zondax-rosetta
raynaudoe Oct 31, 2022
fdb6613
Merge branch 'main' into misc/zondax-rosetta
raynaudoe Nov 3, 2022
66707bb
fix: use errors.New instead fmt.Error
JulianToledano Nov 3, 2022
709662b
add: logger rosetta server
JulianToledano Nov 3, 2022
22fc835
fix: log %v err
JulianToledano Nov 4, 2022
d23da2f
Merge branch 'main' into misc/zondax-rosetta
raynaudoe Nov 4, 2022
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
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,10 @@ updates:
labels:
- "A:automerge"
- dependencies
- package-ecosystem: gomod
directory: "/tools/rosetta"
schedule:
interval: weekly
labels:
- "A:automerge"
- dependencies
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Bug Fixes

* (rosetta) [#13583](https://github.com/cosmos/cosmos-sdk/pull/13583) Misc fixes for cosmos-rosetta.
* (x/evidence) [#13740](https://github.com/cosmos/cosmos-sdk/pull/13740) Fix evidence query API to decode the hash properly.
* (bank) [#13691](https://github.com/cosmos/cosmos-sdk/issues/13691) Fix unhandled error for vesting account transfers, when total vesting amount exceeds total balance.
* [#13553](https://github.com/cosmos/cosmos-sdk/pull/13553) Ensure all parameter validation for decimal types handles nil decimal values.
Expand Down
1 change: 1 addition & 0 deletions contrib/images/simd-env/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ COPY math/go.mod math/go.sum /work/math/
COPY api/go.mod api/go.sum /work/api/
COPY core/go.mod core/go.sum /work/core/
COPY depinject/go.mod depinject/go.sum /work/depinject/
COPY tools/rosetta/go.mod tools/rosetta/go.sum /work/tools/rosetta/

RUN go mod download
COPY ./ /work
Expand Down
4 changes: 4 additions & 0 deletions contrib/rosetta/rosetta-ci/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ COPY --from=build /simd/simapp/simd/simd /bin/simd

WORKDIR /rosetta
COPY ./contrib/rosetta/configuration ./

# Set GENESIS_HASH env needed for api correctness
ENV GENESIS_HASH "01331100220a94b9acc0ceef697a6db44ba70fc61e9e6c24802974a0b6cba29b"

RUN chmod +x run_tests.sh
RUN chmod +x send_funds.sh
RUN chmod +x faucet.py
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/run-node/04-rosetta.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ import (

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

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

```go
package custom_errors
import crgerrs "github.com/cosmos/cosmos-sdk/server/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
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ require (
cosmossdk.io/depinject v1.0.0-alpha.3
cosmossdk.io/errors v1.0.0-beta.7
cosmossdk.io/math v1.0.0-beta.3
cosmossdk.io/tools/rosetta v0.0.0-00010101000000-000000000000
github.com/99designs/keyring v1.2.1
github.com/armon/go-metrics v0.4.1
github.com/bgentry/speakeasy v0.1.0
github.com/btcsuite/btcd v0.22.3
github.com/btcsuite/btcd/btcec/v2 v2.3.0
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e
github.com/cockroachdb/apd/v2 v2.0.2
github.com/coinbase/rosetta-sdk-go v0.8.1
github.com/confio/ics23/go v0.7.0
github.com/cosmos/btcutil v1.0.4
github.com/cosmos/cosmos-proto v1.0.0-alpha8
Expand Down Expand Up @@ -77,6 +77,7 @@ require (
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/coinbase/rosetta-sdk-go v0.8.1 // indirect
github.com/cosmos/gorocksdb v1.2.0 // indirect
github.com/cosmos/ledger-go v0.9.2 // indirect
github.com/creachadair/taskgroup v0.3.2 // indirect
Expand Down Expand Up @@ -160,7 +161,9 @@ require (
)

replace (
cosmossdk.io/tools/rosetta => ./tools/rosetta
github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0
github.com/coinbase/rosetta-sdk-go => github.com/coinbase/rosetta-sdk-go v0.8.2-0.20221007214527-e03849ba430a
// dragonberry fix
github.com/confio/ics23/go => github.com/cosmos/cosmos-sdk/ics23/go v0.8.0
// dgrijalva/jwt-go is deprecated and doesn't receive security updates.
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,10 @@ github.com/cockroachdb/apd/v2 v2.0.2/go.mod h1:DDxRlzC2lo3/vSlmSoS7JkqbbrARPuFOG
github.com/cockroachdb/apd/v3 v3.1.0 h1:MK3Ow7LH0W8zkd5GMKA1PvS9qG3bWFI95WaVNfyZJ/w=
github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8=
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
github.com/coinbase/rosetta-sdk-go v0.8.1 h1:WE+Temc8iz7Ra7sCpV9ymBJx78vItqFJ2xcSiPet1Pc=
github.com/coinbase/rosetta-sdk-go v0.8.1/go.mod h1:tXPR6AIW9ogsH4tYIaFOKOgfJNanCvcyl7JKLd4DToc=
github.com/coinbase/rosetta-sdk-go v0.8.2-0.20221007214527-e03849ba430a h1:tAQukG4KWS+9jBQs/lkFfKfONI01QJ1YoxnjzHAEh88=
github.com/coinbase/rosetta-sdk-go v0.8.2-0.20221007214527-e03849ba430a/go.mod h1:tXPR6AIW9ogsH4tYIaFOKOgfJNanCvcyl7JKLd4DToc=
github.com/confio/ics23/go v0.7.0 h1:00d2kukk7sPoHWL4zZBZwzxnpA2pec1NPdwbSokJ5w8=
github.com/confio/ics23/go v0.7.0/go.mod h1:E45NqnlpxGnpfTWL/xauN7MRwEE28T4Dd4uraToOaKg=
github.com/containerd/continuity v0.3.0 h1:nisirsYROK15TAMVukJOUyGJjz4BNQJBVsNvAXZJ/eg=
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk=
Expand Down
1 change: 1 addition & 0 deletions go.work.example
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ use (
./tx
./simapp
./tests
./tools/rosetta
)
12 changes: 6 additions & 6 deletions server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package server
// DONTCOVER

import (
"errors"
"fmt"
"net"
"net/http"
Expand All @@ -21,14 +22,14 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"

"cosmossdk.io/tools/rosetta"
crgserver "cosmossdk.io/tools/rosetta/lib/server"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/server/api"
serverconfig "github.com/cosmos/cosmos-sdk/server/config"
servergrpc "github.com/cosmos/cosmos-sdk/server/grpc"
"github.com/cosmos/cosmos-sdk/server/rosetta"
crgserver "github.com/cosmos/cosmos-sdk/server/rosetta/lib/server"
"github.com/cosmos/cosmos-sdk/server/types"
pruningtypes "github.com/cosmos/cosmos-sdk/store/pruning/types"
"github.com/cosmos/cosmos-sdk/telemetry"
Expand Down Expand Up @@ -463,10 +464,9 @@ func startInProcess(ctx *Context, clientCtx client.Context, appCreator types.App
if config.Rosetta.Enable {
offlineMode := config.Rosetta.Offline

// If GRPC is not enabled rosetta cannot work in online mode, so it works in
// offline mode.
if !config.GRPC.Enable {
offlineMode = true
// If GRPC is not enabled rosetta cannot work in online mode, so we throw an error.
if !config.GRPC.Enable && !offlineMode {
return errors.New("'grpc' must be enable in online mode for Rosetta to work")
}

minGasPrices, err := sdktypes.ParseDecCoins(config.MinGasPrices)
Expand Down
5 changes: 4 additions & 1 deletion simapp/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ require (
cosmossdk.io/core v0.3.2
cosmossdk.io/depinject v1.0.0-alpha.3
cosmossdk.io/math v1.0.0-beta.3
github.com/cosmos/cosmos-sdk v0.0.0-00010101000000-000000000000
github.com/cosmos/cosmos-sdk v0.46.1
cosmossdk.io/tools/rosetta v0.0.0-00010101000000-000000000000
github.com/golang/mock v1.6.0
github.com/spf13/cast v1.5.0
github.com/spf13/cobra v1.6.1
Expand Down Expand Up @@ -157,9 +158,11 @@ require (

replace (
github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0
github.com/coinbase/rosetta-sdk-go => github.com/coinbase/rosetta-sdk-go v0.8.2-0.20221007214527-e03849ba430a
// dragonberry fix
github.com/confio/ics23/go => github.com/cosmos/cosmos-sdk/ics23/go v0.8.0
github.com/cosmos/cosmos-sdk => ../.
cosmossdk.io/tools/rosetta => ./../tools/rosetta
// Fix upstream GHSA-h395-qcrw-5vmq vulnerability.
// TODO Remove it: https://github.com/cosmos/cosmos-sdk/issues/10409
github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.8.1
Expand Down
6 changes: 4 additions & 2 deletions simapp/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,10 @@ github.com/cockroachdb/apd/v2 v2.0.2/go.mod h1:DDxRlzC2lo3/vSlmSoS7JkqbbrARPuFOG
github.com/cockroachdb/apd/v3 v3.1.0 h1:MK3Ow7LH0W8zkd5GMKA1PvS9qG3bWFI95WaVNfyZJ/w=
github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8=
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
github.com/coinbase/rosetta-sdk-go v0.8.1 h1:WE+Temc8iz7Ra7sCpV9ymBJx78vItqFJ2xcSiPet1Pc=
github.com/coinbase/rosetta-sdk-go v0.8.1/go.mod h1:tXPR6AIW9ogsH4tYIaFOKOgfJNanCvcyl7JKLd4DToc=
github.com/coinbase/rosetta-sdk-go v0.8.2-0.20221007214527-e03849ba430a h1:tAQukG4KWS+9jBQs/lkFfKfONI01QJ1YoxnjzHAEh88=
github.com/coinbase/rosetta-sdk-go v0.8.2-0.20221007214527-e03849ba430a/go.mod h1:tXPR6AIW9ogsH4tYIaFOKOgfJNanCvcyl7JKLd4DToc=
github.com/confio/ics23/go v0.7.0 h1:00d2kukk7sPoHWL4zZBZwzxnpA2pec1NPdwbSokJ5w8=
github.com/confio/ics23/go v0.7.0/go.mod h1:E45NqnlpxGnpfTWL/xauN7MRwEE28T4Dd4uraToOaKg=
github.com/containerd/continuity v0.3.0 h1:nisirsYROK15TAMVukJOUyGJjz4BNQJBVsNvAXZJ/eg=
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk=
Expand Down
3 changes: 2 additions & 1 deletion simapp/simd/cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
rosettaCmd "cosmossdk.io/tools/rosetta/cmd"
"errors"
"io"
"os"
Expand Down Expand Up @@ -197,7 +198,7 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) {
)

// add rosetta
rootCmd.AddCommand(server.RosettaCommand(encodingConfig.InterfaceRegistry, encodingConfig.Codec))
rootCmd.AddCommand(rosettaCmd.RosettaCommand(encodingConfig.InterfaceRegistry, encodingConfig.Codec))
}

func addModuleInitFlags(startCmd *cobra.Command) {
Expand Down
6 changes: 5 additions & 1 deletion tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
cosmossdk.io/depinject v1.0.0-alpha.3
cosmossdk.io/math v1.0.0-beta.3
cosmossdk.io/simapp v0.0.0-20220908203654-84d4bf5accad
github.com/cosmos/cosmos-sdk v0.0.0-00010101000000-000000000000
github.com/cosmos/cosmos-sdk v0.46.1
github.com/cosmos/gogoproto v1.4.2
github.com/golang/mock v1.6.0
github.com/google/uuid v1.3.0
Expand All @@ -27,6 +27,7 @@ require (
cloud.google.com/go/storage v1.14.0 // indirect
cosmossdk.io/core v0.3.2 // indirect
cosmossdk.io/errors v1.0.0-beta.7 // indirect
cosmossdk.io/tools/rosetta v0.0.0-00010101000000-000000000000 // indirect
filippo.io/edwards25519 v1.0.0-rc.1 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
github.com/99designs/keyring v1.2.1 // indirect
Expand Down Expand Up @@ -162,7 +163,10 @@ require (
replace (
// We always want to test against the latest version of the simapp.
cosmossdk.io/simapp => ../simapp
// We always want to test against the latest version of rosetta.
cosmossdk.io/tools/rosetta => ./../tools/rosetta
github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0
github.com/coinbase/rosetta-sdk-go => github.com/coinbase/rosetta-sdk-go v0.8.2-0.20221007214527-e03849ba430a
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious why we need this import. Can we add a comment here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is linked to this issue : coinbase/mesh-sdk-go#449
I have added a comment. Once coinbase make a release we can do change to version v0.8.2.

It is so I can pass check:spec like mentioned in the issue. It is however not mandatory.

// We always want to test against the latest version of the SDK.
github.com/cosmos/cosmos-sdk => ../.
// Fix upstream GHSA-h395-qcrw-5vmq vulnerability.
Expand Down
4 changes: 2 additions & 2 deletions tests/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ github.com/cockroachdb/apd/v2 v2.0.2/go.mod h1:DDxRlzC2lo3/vSlmSoS7JkqbbrARPuFOG
github.com/cockroachdb/apd/v3 v3.1.0 h1:MK3Ow7LH0W8zkd5GMKA1PvS9qG3bWFI95WaVNfyZJ/w=
github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8=
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
github.com/coinbase/rosetta-sdk-go v0.8.1 h1:WE+Temc8iz7Ra7sCpV9ymBJx78vItqFJ2xcSiPet1Pc=
github.com/coinbase/rosetta-sdk-go v0.8.1/go.mod h1:tXPR6AIW9ogsH4tYIaFOKOgfJNanCvcyl7JKLd4DToc=
github.com/coinbase/rosetta-sdk-go v0.8.2-0.20221007214527-e03849ba430a h1:tAQukG4KWS+9jBQs/lkFfKfONI01QJ1YoxnjzHAEh88=
github.com/coinbase/rosetta-sdk-go v0.8.2-0.20221007214527-e03849ba430a/go.mod h1:tXPR6AIW9ogsH4tYIaFOKOgfJNanCvcyl7JKLd4DToc=
github.com/confio/ics23/go v0.7.0 h1:00d2kukk7sPoHWL4zZBZwzxnpA2pec1NPdwbSokJ5w8=
github.com/confio/ics23/go v0.7.0/go.mod h1:E45NqnlpxGnpfTWL/xauN7MRwEE28T4Dd4uraToOaKg=
github.com/containerd/continuity v0.3.0 h1:nisirsYROK15TAMVukJOUyGJjz4BNQJBVsNvAXZJ/eg=
Expand Down
11 changes: 11 additions & 0 deletions tools/rosetta/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/make -f

all: build

build:
go build ./cmd/rosetta.go

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

.PHONY: all build test
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

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

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

sdk "github.com/cosmos/cosmos-sdk/types"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@ import (
"github.com/tendermint/tendermint/rpc/client/http"
"google.golang.org/grpc"

crgerrs "github.com/cosmos/cosmos-sdk/server/rosetta/lib/errors"
crgtypes "github.com/cosmos/cosmos-sdk/server/rosetta/lib/types"
crgerrs "cosmossdk.io/tools/rosetta/lib/errors"
crgtypes "cosmossdk.io/tools/rosetta/lib/types"

sdk "github.com/cosmos/cosmos-sdk/types"
grpctypes "github.com/cosmos/cosmos-sdk/types/grpc"
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
auth "github.com/cosmos/cosmos-sdk/x/auth/types"
bank "github.com/cosmos/cosmos-sdk/x/bank/types"

"github.com/cosmos/cosmos-sdk/types/query"
tmrpc "github.com/tendermint/tendermint/rpc/client"
)

Expand Down Expand Up @@ -131,9 +132,7 @@ func (c *Client) Ready() error {
return err
}

// to prevent timeout of reading genesis block
var height int64 = -1
_, err = c.BlockByHeight(ctx, &height)
_, err = c.tmRPC.Status(ctx)
if err != nil {
return err
}
Expand Down Expand Up @@ -202,12 +201,13 @@ func (c *Client) BlockByHash(ctx context.Context, hash string) (crgtypes.BlockRe

func (c *Client) BlockByHeight(ctx context.Context, height *int64) (crgtypes.BlockResponse, error) {
height, err := c.getHeight(ctx, height)

if err != nil {
return crgtypes.BlockResponse{}, crgerrs.WrapError(crgerrs.ErrBadGateway, err.Error())
}
block, err := c.tmRPC.Block(ctx, height)
if err != nil {
return crgtypes.BlockResponse{}, crgerrs.WrapError(crgerrs.ErrBadGateway, err.Error())
return crgtypes.BlockResponse{}, crgerrs.WrapError(crgerrs.ErrInternal, err.Error())
}

return c.converter.ToRosetta().BlockResponse(block), nil
Expand Down Expand Up @@ -237,11 +237,31 @@ func (c *Client) BlockTransactionsByHeight(ctx context.Context, height *int64) (

// Coins fetches the existing coins in the application
func (c *Client) coins(ctx context.Context) (sdk.Coins, error) {
var result sdk.Coins

supply, err := c.bank.TotalSupply(ctx, &bank.QueryTotalSupplyRequest{})
if err != nil {
return nil, crgerrs.FromGRPCToRosettaError(err)
}
return supply.Supply, nil

pages := supply.GetPagination().GetTotal()
for i := uint64(0); i < pages; i++ {
// get next key
page := supply.GetPagination()
if page == nil {
return nil, crgerrs.WrapError(crgerrs.ErrCodec, fmt.Sprintf("error pagination"))
}
nextKey := page.GetNextKey()

supply, err = c.bank.TotalSupply(ctx, &bank.QueryTotalSupplyRequest{Pagination: &query.PageRequest{Key: nextKey}})
if err != nil {
return nil, crgerrs.FromGRPCToRosettaError(err)
}

result = append(result[:0], supply.Supply[:]...)
}

return result, nil
}

func (c *Client) TxOperationsAndSignersAccountIdentifiers(signed bool, txBytes []byte) (ops []*rosettatypes.Operation, signers []*rosettatypes.AccountIdentifier, err error) {
Expand Down
6 changes: 3 additions & 3 deletions server/rosetta.go → tools/rosetta/cmd/rosetta.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package server
package cmd

import (
"fmt"

"github.com/spf13/cobra"

"cosmossdk.io/tools/rosetta"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/server/rosetta"
)

// RosettaCommand builds the rosetta root command given
Expand All @@ -30,6 +29,7 @@ func RosettaCommand(ir codectypes.InterfaceRegistry, cdc codec.Codec) *cobra.Com

rosettaSrv, err := rosetta.ServerFromConfig(conf)
if err != nil {
fmt.Printf("[Rosetta]- Error while creating server: %s", err.Error())
return err
}
return rosettaSrv.Start()
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion server/rosetta/config.go → tools/rosetta/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/coinbase/rosetta-sdk-go/types"
"github.com/spf13/pflag"

crg "github.com/cosmos/cosmos-sdk/server/rosetta/lib/server"
crg "cosmossdk.io/tools/rosetta/lib/server"

clientflags "github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/codec"
Expand Down
Loading