c41777dcd2
* mostly working api proxy gen * api: Consistent api names * fix docsgen * regenerate api struct * api: expand external interfaces * Add missing gen files * apigen: fix perm detection * api: Move perm tags to the interface * gofmt * worker perms * docsgen * docsgen: ignore tag comments * apigen: add codegen warning * gofmt * missing actor type * docsgen * make linter happy * fix lint * apigen: use directives for tags * docsgen * regen openrpc docs
51 lines
1018 B
Go
51 lines
1018 B
Go
package remotewallet
|
|
|
|
import (
|
|
"context"
|
|
|
|
"go.uber.org/fx"
|
|
"golang.org/x/xerrors"
|
|
|
|
"github.com/filecoin-project/lotus/api"
|
|
"github.com/filecoin-project/lotus/api/client"
|
|
cliutil "github.com/filecoin-project/lotus/cli/util"
|
|
"github.com/filecoin-project/lotus/node/modules/helpers"
|
|
)
|
|
|
|
type RemoteWallet struct {
|
|
api.Wallet
|
|
}
|
|
|
|
func SetupRemoteWallet(info string) func(mctx helpers.MetricsCtx, lc fx.Lifecycle) (*RemoteWallet, error) {
|
|
return func(mctx helpers.MetricsCtx, lc fx.Lifecycle) (*RemoteWallet, error) {
|
|
ai := cliutil.ParseApiInfo(info)
|
|
|
|
url, err := ai.DialArgs()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
wapi, closer, err := client.NewWalletRPC(mctx, url, ai.AuthHeader())
|
|
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
|
|
}
|
|
}
|
|
|
|
func (w *RemoteWallet) Get() api.Wallet {
|
|
if w == nil {
|
|
return nil
|
|
}
|
|
|
|
return w
|
|
}
|