lotus/daemon/rpc.go

24 lines
567 B
Go
Raw Normal View History

package daemon
import (
"github.com/filecoin-project/go-lotus/lib/auth"
"github.com/gbrlsnchs/jwt/v3"
"net/http"
"github.com/filecoin-project/go-lotus/api"
"github.com/filecoin-project/go-lotus/lib/jsonrpc"
)
func serveRPC(a api.API, addr string, authSecret []byte) error {
2019-07-08 12:46:30 +00:00
rpcServer := jsonrpc.NewServer()
2019-07-18 16:51:21 +00:00
rpcServer.Register("Filecoin", api.Permissioned(a))
authHandler := &auth.Handler{
Secret: jwt.NewHS256(authSecret),
Next: rpcServer.ServeHTTP,
}
http.Handle("/rpc/v0", authHandler)
2019-07-08 20:50:13 +00:00
return http.ListenAndServe(addr, http.DefaultServeMux)
}