Skip to content

WIP: Add a nitro payment test #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: nitro-integration
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions cmd/booster-http/gateway_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import (
type gatewayHandler struct {
gwh http.Handler
supportedFormats map[string]struct{}
nitroRpcClient *rpc.RpcClient
nitroRpcClient rpc.RpcClientApi
}

func newGatewayHandler(gw *gateway.BlocksBackend, supportedFormats []string, nitroRpcClient *rpc.RpcClient) http.Handler {
func newGatewayHandler(gw *gateway.BlocksBackend, supportedFormats []string, nitroRpcClient rpc.RpcClientApi) http.Handler {
headers := map[string][]string{}
gateway.AddAccessControlHeaders(headers)

Expand Down Expand Up @@ -70,7 +70,6 @@ func (h *gatewayHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}

s, err := h.nitroRpcClient.ReceiveVoucher(v)

if err != nil {
webError(w, fmt.Errorf("error processing voucher %w", err), http.StatusBadRequest)
return
Expand Down
279 changes: 279 additions & 0 deletions cmd/booster-http/mocks/mock_nitro_rpc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 12 additions & 6 deletions cmd/booster-http/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/filecoin-project/lotus/markets/dagstore"
"github.com/ipfs/go-cid"
"github.com/mitchellh/go-homedir"
nrpc "github.com/statechannels/go-nitro/rpc"
"github.com/urfave/cli/v2"
)

Expand Down Expand Up @@ -216,19 +217,24 @@ var runCmd = &cli.Command{
opts.Blockstore = filtered
}

nitroOpts := &NitroOptions{
Enabled: cctx.Bool("nitro-enabled"),
Endpoint: cctx.String("nitro-endpoint"),
sapi := serverApi{ctx: ctx, bapi: bapi, sa: sa}
var nitroAPI nrpc.RpcClientApi

if cctx.Bool("nitro-enabled") {
var err error
nitroAPI, err = nrpc.NewHttpRpcClient(cctx.String("nitro-endpoint"))
if err != nil {
return fmt.Errorf("error creating nitro API client: %w", err)
}
}

sapi := serverApi{ctx: ctx, bapi: bapi, sa: sa}
server := NewHttpServer(
cctx.String("base-path"),
cctx.String("address"),
cctx.Int("port"),
sapi,
nitroAPI,
opts,
nitroOpts,
)

// Start the server
Expand Down Expand Up @@ -315,7 +321,7 @@ func createRepoDir(repoDir string) (string, error) {
if repoDir == "" {
return "", fmt.Errorf("%s is a required flag", FlagRepo.Name)
}
return repoDir, os.MkdirAll(repoDir, 0744)
return repoDir, os.MkdirAll(repoDir, 0o744)
}

type serverApi struct {
Expand Down
18 changes: 5 additions & 13 deletions cmd/booster-http/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
)

//go:generate go run github.com/golang/mock/mockgen -destination=mocks/mock_booster_http.go -package=mocks_booster_http -source=server.go HttpServerApi,serverApi
//go:generate go run github.com/golang/mock/mockgen -destination=mocks/mock_nitro_rpc.go -package=mocks_booster_http -mock_names=RpcClientApi=MockNitroRpcApi github.com/statechannels/go-nitro/rpc RpcClientApi

var ErrNotFound = errors.New("not found")

Expand All @@ -55,7 +56,7 @@ type HttpServer struct {
cancel context.CancelFunc
server *http.Server

nitroRpcClient *nrpc.RpcClient
nitroRpcClient nrpc.RpcClientApi
}

type HttpServerApi interface {
Expand All @@ -75,21 +76,12 @@ type NitroOptions struct {
Endpoint string
}

func NewHttpServer(path string, listenAddr string, port int, api HttpServerApi, opts *HttpServerOptions, nitroOpts *NitroOptions) *HttpServer {
func NewHttpServer(path string, listenAddr string, port int, api HttpServerApi, nitroApi nrpc.RpcClientApi, opts *HttpServerOptions) *HttpServer {
if opts == nil {
opts = &HttpServerOptions{ServePieces: true}
}
var rpcClient *nrpc.RpcClient
var err error
if nitroOpts != nil && nitroOpts.Enabled {

rpcClient, err = nrpc.NewHttpRpcClient(nitroOpts.Endpoint)
if err != nil {
panic(err)
}
}
return &HttpServer{path: path, port: port, api: api, opts: *opts, idxPage: parseTemplate(*opts), nitroRpcClient: rpcClient}

return &HttpServer{path: path, port: port, api: api, opts: *opts, idxPage: parseTemplate(*opts), nitroRpcClient: nitroApi}
}

func (s *HttpServer) pieceBasePath() string {
Expand Down Expand Up @@ -222,7 +214,7 @@ func serveContent(w http.ResponseWriter, r *http.Request, content io.ReadSeeker)
err = e
}}

writer = writeErrWatcher //Need writeErrWatcher to be of type writeErrorWatcher for addCommas()
writer = writeErrWatcher // Need writeErrWatcher to be of type writeErrorWatcher for addCommas()

// Note that the last modified time is a constant value because the data
// in a piece identified by a cid will never change.
Expand Down
Loading