lotus/chain/wallet/remotewallet/remote.go

51 lines
1022 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.Wallet
2020-09-05 19:36:32 +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)
2021-03-23 18:15:44 +00:00
url, err := ai.DialArgs("v0")
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
}
func (w *RemoteWallet) Get() api.Wallet {
if w == nil {
return nil
}
return w
}