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
|
|
|
|
}
|
|
|
|
|
2020-10-09 00:21:37 +00:00
|
|
|
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)
|
2020-10-09 00:21:37 +00:00
|
|
|
|
|
|
|
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
|
|
|
}
|
2020-10-10 22:08:12 +00:00
|
|
|
|
|
|
|
func (w *RemoteWallet) Get() api.WalletAPI {
|
|
|
|
if w == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return w
|
|
|
|
}
|