2021-01-21 01:33:02 -08:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
|
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
|
|
|
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
2021-05-14 15:18:59 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/server/rosetta"
|
2021-01-21 01:33:02 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
// RosettaCommand builds the rosetta root command given
|
|
|
|
// a protocol buffers serializer/deserializer
|
2021-04-29 03:46:22 -07:00
|
|
|
func RosettaCommand(ir codectypes.InterfaceRegistry, cdc codec.Codec) *cobra.Command {
|
2021-01-21 01:33:02 -08:00
|
|
|
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
|
|
|
|
}
|