Use APIInfo parser for RemoteBacked wallet config
This commit is contained in:
parent
6c54d2445d
commit
3cd53ad9d9
2
Makefile
2
Makefile
@ -188,7 +188,7 @@ BINS+=lotus-health
|
|||||||
|
|
||||||
lotus-wallet:
|
lotus-wallet:
|
||||||
rm -f lotus-wallet
|
rm -f lotus-wallet
|
||||||
go build -o lotus-stats ./cmd/lotus-wallet
|
go build -o lotus-wallet ./cmd/lotus-wallet
|
||||||
.PHONY: lotus-wallet
|
.PHONY: lotus-wallet
|
||||||
BINS+=lotus-wallet
|
BINS+=lotus-wallet
|
||||||
|
|
||||||
|
@ -2,13 +2,13 @@ package remotewallet
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"go.uber.org/fx"
|
"go.uber.org/fx"
|
||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
"github.com/filecoin-project/lotus/api"
|
"github.com/filecoin-project/lotus/api"
|
||||||
"github.com/filecoin-project/lotus/api/client"
|
"github.com/filecoin-project/lotus/api/client"
|
||||||
|
lcli "github.com/filecoin-project/lotus/cli"
|
||||||
"github.com/filecoin-project/lotus/node/modules/helpers"
|
"github.com/filecoin-project/lotus/node/modules/helpers"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -16,26 +16,16 @@ type RemoteWallet struct {
|
|||||||
api.WalletAPI
|
api.WalletAPI
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetupRemoteWallet(url string) func(mctx helpers.MetricsCtx, lc fx.Lifecycle) (*RemoteWallet, error) {
|
func SetupRemoteWallet(info string) func(mctx helpers.MetricsCtx, lc fx.Lifecycle) (*RemoteWallet, error) {
|
||||||
return func(mctx helpers.MetricsCtx, lc fx.Lifecycle) (*RemoteWallet, error) {
|
return func(mctx helpers.MetricsCtx, lc fx.Lifecycle) (*RemoteWallet, error) {
|
||||||
/*sp := strings.SplitN(env, ":", 2)
|
ai := lcli.ParseApiInfo(info)
|
||||||
if len(sp) != 2 {
|
|
||||||
log.Warnf("invalid env(%s) value, missing token or address", envKey)
|
|
||||||
} else {
|
|
||||||
ma, err := multiaddr.NewMultiaddr(sp[1])
|
|
||||||
if err != nil {
|
|
||||||
return APIInfo{}, xerrors.Errorf("could not parse multiaddr from env(%s): %w", envKey, err)
|
|
||||||
}
|
|
||||||
return APIInfo{
|
|
||||||
Addr: ma,
|
|
||||||
Token: []byte(sp[0]),
|
|
||||||
}, nil
|
|
||||||
}*/
|
|
||||||
|
|
||||||
headers := http.Header{}
|
url, err := ai.DialArgs()
|
||||||
/*headers.Add("Authorization", "Bearer "+token)*/
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
wapi, closer, err := client.NewWalletRPC(mctx, url, headers)
|
wapi, closer, err := client.NewWalletRPC(mctx, url, ai.AuthHeader())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, xerrors.Errorf("creating jsonrpc client: %w", err)
|
return nil, xerrors.Errorf("creating jsonrpc client: %w", err)
|
||||||
}
|
}
|
||||||
|
29
cli/cmd.go
29
cli/cmd.go
@ -7,6 +7,7 @@ import (
|
|||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
@ -153,6 +154,24 @@ func envForRepoDeprecation(t repo.RepoType) string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
infoWithToken = regexp.MustCompile("^[a-zA-Z0-9\\-_]+?\\.[a-zA-Z0-9\\-_]+?\\.([a-zA-Z0-9\\-_]+)?:.+$")
|
||||||
|
)
|
||||||
|
|
||||||
|
func ParseApiInfo(s string) APIInfo {
|
||||||
|
var tok []byte
|
||||||
|
if infoWithToken.Match([]byte(s)) {
|
||||||
|
sp := strings.SplitN(s, ":", 2)
|
||||||
|
tok = []byte(sp[0])
|
||||||
|
s = sp[1]
|
||||||
|
}
|
||||||
|
|
||||||
|
return APIInfo{
|
||||||
|
Addr: s,
|
||||||
|
Token: tok,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func GetAPIInfo(ctx *cli.Context, t repo.RepoType) (APIInfo, error) {
|
func GetAPIInfo(ctx *cli.Context, t repo.RepoType) (APIInfo, error) {
|
||||||
// Check if there was a flag passed with the listen address of the API
|
// Check if there was a flag passed with the listen address of the API
|
||||||
// server (only used by the tests)
|
// server (only used by the tests)
|
||||||
@ -175,15 +194,7 @@ func GetAPIInfo(ctx *cli.Context, t repo.RepoType) (APIInfo, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ok {
|
if ok {
|
||||||
sp := strings.SplitN(env, ":", 2)
|
return ParseApiInfo(env), nil
|
||||||
if len(sp) != 2 {
|
|
||||||
log.Warnf("invalid env(%s) value, missing token or address", envKey)
|
|
||||||
} else {
|
|
||||||
return APIInfo{
|
|
||||||
Addr: sp[1],
|
|
||||||
Token: []byte(sp[0]),
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
repoFlag := flagForRepo(t)
|
repoFlag := flagForRepo(t)
|
||||||
|
Loading…
Reference in New Issue
Block a user