2020-02-09 10:31:52 +00:00
package commands
import (
2020-08-28 10:27:56 +00:00
"fmt"
2020-02-09 10:31:52 +00:00
"github.com/ledgerwatch/turbo-geth/cmd/restapi/rest"
2020-04-04 07:18:10 +00:00
"github.com/spf13/cobra"
2020-02-09 10:31:52 +00:00
)
var (
2020-07-27 12:15:48 +00:00
rpcAddr string
chaindata string
addr string
2020-08-28 10:27:56 +00:00
port uint
2020-02-09 10:31:52 +00:00
)
func init ( ) {
2020-07-30 06:59:42 +00:00
rootCmd . Flags ( ) . StringVar ( & rpcAddr , "private.api.addr" , "127.0.0.1:9090" , "binary RPC network address, for example: 127.0.0.1:9090, empty string means not to start the listener. do not expose to public network. serves remote database interface" )
2020-08-28 10:27:56 +00:00
rootCmd . Flags ( ) . StringVar ( & addr , "http.addr" , "127.0.0.1" , "REST server listening host" )
rootCmd . Flags ( ) . UintVar ( & port , "http.port" , 8080 , "REST server listening port" )
2020-06-28 06:10:27 +00:00
rootCmd . Flags ( ) . StringVar ( & chaindata , "chaindata" , "" , "path to the database" )
2020-02-09 10:31:52 +00:00
}
var rootCmd = & cobra . Command {
Use : "restapi" ,
Short : "restapi exposes read-only blockchain APIs through REST (requires running turbo-geth node)" ,
RunE : func ( cmd * cobra . Command , args [ ] string ) error {
2020-08-28 10:27:56 +00:00
return rest . ServeREST ( cmd . Context ( ) , fmt . Sprintf ( "%s:%d" , addr , port ) , rpcAddr , chaindata )
2020-02-09 10:31:52 +00:00
} ,
}
2020-08-19 11:46:20 +00:00
func RootCommand ( ) * cobra . Command {
return rootCmd
2020-04-04 07:18:10 +00:00
}