erigon-pulse/cmd/restapi/commands/root.go
ledgerwatch dba3363b52
Fix RestAPI for tx_retrace and make it work for local boltdb (#584)
* Not hash, keep the files

* Calculate savings

* Fix

* Fix

* Fix

* Fix

* RestAPI to support local boltdb

* Not error on read-only db

* Changes so far

* Continue

* More

* Roll back a bit

* Restore newline

* something compiles

* Fix restapi

* Fix block number

* Fix reads

* Use plain writer

* Maps for storage reads and writes

* Clean up coersions

* Fix accounts/abi/bind

* Fix tests

* More fixes

* more fixes

* More fixes

* Fixes

* Fixed core/state

* Fixed eth tests

* Move code, fix linter

* Fix test

* Fix linter

* Fix linter

* Fix linter, badger_db to support AbstractKV

* Increase IdealBatchSize for badger

* Fix linter

* Fix linter
2020-05-27 17:24:34 +01:00

59 lines
1.3 KiB
Go

package commands
import (
"context"
"fmt"
"os"
"os/signal"
"syscall"
"github.com/ledgerwatch/turbo-geth/cmd/restapi/rest"
"github.com/ledgerwatch/turbo-geth/log"
"github.com/spf13/cobra"
)
var (
remoteDbAddress string
boltPath string
listenAddress string
)
func init() {
rootCmd.Flags().StringVar(&remoteDbAddress, "remote-db-addr", "", "address of remote DB listener of a turbo-geth node")
rootCmd.Flags().StringVar(&boltPath, "bolt-path", "", "path to the boltdb database")
rootCmd.Flags().StringVar(&listenAddress, "rpcaddr", "localhost:8080", "REST server listening interface")
}
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 {
return rest.ServeREST(cmd.Context(), listenAddress, remoteDbAddress, boltPath)
},
}
func Execute() {
if err := rootCmd.ExecuteContext(rootContext()); err != nil {
fmt.Println(err)
os.Exit(1)
}
}
func rootContext() context.Context {
ctx, cancel := context.WithCancel(context.Background())
go func() {
ch := make(chan os.Signal, 1)
signal.Notify(ch, os.Interrupt, syscall.SIGTERM)
defer signal.Stop(ch)
select {
case <-ch:
log.Info("Got interrupt, shutting down...")
case <-ctx.Done():
}
cancel()
}()
return ctx
}