forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathrosetta.go
42 lines (34 loc) · 963 Bytes
/
rosetta.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package server
import (
"fmt"
"github.com/spf13/cobra"
"github.com/cosmos/cosmos-sdk/server/rosetta"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
)
// RosettaCommand builds the rosetta root command given
// a protocol buffers serializer/deserializer
func RosettaCommand(ir codectypes.InterfaceRegistry, cdc codec.Marshaler) *cobra.Command {
cmd := &cobra.Command{
Use: "rosetta",
Short: "spin up a rosetta server",
RunE: func(cmd *cobra.Command, args []string) error {
conf, err := rosetta.FromFlags(cmd.Flags())
if err != nil {
return err
}
protoCodec, ok := cdc.(*codec.ProtoCodec)
if !ok {
return fmt.Errorf("exoected *codec.ProtoMarshaler, got: %T", cdc)
}
conf.WithCodec(ir, protoCodec)
rosettaSrv, err := rosetta.ServerFromConfig(conf)
if err != nil {
return err
}
return rosettaSrv.Start()
},
}
rosetta.SetFlags(cmd.Flags())
return cmd
}