lotus/chain/wallet/remotewallet/remote.go

43 lines
934 B
Go
Raw Normal View History

2020-09-05 19:36:32 +00:00
package remotewallet
import (
"context"
2020-10-08 23:53:12 +00:00
2020-09-05 19:36:32 +00:00
"go.uber.org/fx"
"golang.org/x/xerrors"
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/api/client"
2020-10-09 00:57:41 +00:00
cliutil "github.com/filecoin-project/lotus/cli/util"
2020-09-05 19:36:32 +00:00
"github.com/filecoin-project/lotus/node/modules/helpers"
)
type RemoteWallet struct {
api.WalletAPI
}
func SetupRemoteWallet(info string) func(mctx helpers.MetricsCtx, lc fx.Lifecycle) (*RemoteWallet, error) {
2020-09-05 19:36:32 +00:00
return func(mctx helpers.MetricsCtx, lc fx.Lifecycle) (*RemoteWallet, error) {
2020-10-09 00:57:41 +00:00
ai := cliutil.ParseApiInfo(info)
url, err := ai.DialArgs()
if err != nil {
return nil, err
}
wapi, closer, err := client.NewWalletRPC(mctx, url, ai.AuthHeader())
2020-09-05 19:36:32 +00:00
if err != nil {
return nil, xerrors.Errorf("creating jsonrpc client: %w", err)
}
lc.Append(fx.Hook{
OnStop: func(ctx context.Context) error {
closer()
return nil
},
})
return &RemoteWallet{wapi}, nil
}
2020-10-08 23:27:49 +00:00
}