Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support storage deal protocol v2 #435

Merged
merged 1 commit into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ linters-settings:
min-occurrences: 6

run:
skip-dirs-use-default: false
skip-files:
skip-dirs-use-default: false
skip-files:
- testhelper.go
- ".*_gen\\.go$" # skip auto generated go files
2 changes: 1 addition & 1 deletion api/clients/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var log = logging.Logger("clients")
var ClientsOpts = func(server bool, msgCfg config.Messager, signerCfg *config.Signer, authClient jwtclient.IAuthClient) builder.Option {
return builder.Options(
builder.Override(new(IMixMessage), NewMixMsgClient),
builder.Override(new(signer.ISigner), signer.NewISignerClient(server, authClient)),
builder.Override(new(signer.ISigner), signer.NewISignerClientWithLifecycle(server, authClient)),
builder.ApplyIf(
func(s *builder.Settings) bool {
return len(msgCfg.Url) > 0
Expand Down
28 changes: 18 additions & 10 deletions api/clients/signer/sign_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ type ISigner interface {
WalletSign(ctx context.Context, signerAddr address.Address, msg []byte, meta vTypes.MsgMeta) (*vCrypto.Signature, error)
}

func NewISignerClient(isServer bool, authClient jwtclient.IAuthClient) func(metrics.MetricsCtx, fx.Lifecycle, *config.Signer) (ISigner, error) {

return func(mCtx metrics.MetricsCtx, lc fx.Lifecycle, signerCfg *config.Signer) (ISigner, error) {
func NewISignerClient(isServer bool, authClient jwtclient.IAuthClient) func(metrics.MetricsCtx, *config.Signer) (ISigner, jsonrpc.ClientCloser, error) {
return func(mCtx metrics.MetricsCtx, signerCfg *config.Signer) (ISigner, jsonrpc.ClientCloser, error) {
var (
signer ISigner
closer jsonrpc.ClientCloser
Expand All @@ -43,22 +42,31 @@ func NewISignerClient(isServer bool, authClient jwtclient.IAuthClient) func(metr
// Signing through venus chain-service
case config.SignerTypeGateway:
if !isServer {
return nil, fmt.Errorf("signing through the sophon-gateway cannot be used for droplet-clientt")
return nil, nil, fmt.Errorf("signing through the sophon-gateway cannot be used for droplet-clientt")
}
signer, closer, err = newGatewayWalletClient(mCtx, signerCfg, authClient)
default:
return nil, fmt.Errorf("unsupport signer type %s", signerCfg.SignerType)
return nil, nil, fmt.Errorf("unsupport signer type %s", signerCfg.SignerType)
}

return signer, closer, err
}
}

func NewISignerClientWithLifecycle(isServer bool, authClient jwtclient.IAuthClient) func(metrics.MetricsCtx, fx.Lifecycle, *config.Signer) (ISigner, error) {
return func(mc metrics.MetricsCtx, lc fx.Lifecycle, signerCfg *config.Signer) (ISigner, error) {
signer, closer, err := NewISignerClient(isServer, authClient)(mc, signerCfg)
if err != nil {
return nil, err
}

lc.Append(fx.Hook{
OnStop: func(_ context.Context) error {
if closer != nil {
closer()
}
closer()
return nil
},
})
return signer, err
}

return signer, nil
}
}
59 changes: 59 additions & 0 deletions cli/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cli

import (
"context"
"encoding/hex"
"encoding/json"
"fmt"
"io"
Expand All @@ -20,6 +21,8 @@ import (
"github.com/howeyc/gopass"
"github.com/ipfs/go-cid"
"github.com/ipfs/go-cidutil/cidenc"
"github.com/libp2p/go-libp2p"
"github.com/libp2p/go-libp2p/core/host"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/mitchellh/go-homedir"
"github.com/multiformats/go-multibase"
Expand All @@ -33,8 +36,10 @@ import (
"github.com/filecoin-project/go-state-types/big"
"github.com/filecoin-project/go-state-types/builtin/v9/market"
"github.com/filecoin-project/go-state-types/crypto"
crypto2 "github.com/libp2p/go-libp2p/core/crypto"
cbg "github.com/whyrusleeping/cbor-gen"

"github.com/ipfs-force-community/droplet/v2/api/clients/signer"
"github.com/ipfs-force-community/droplet/v2/cli/tablewriter"
"github.com/ipfs-force-community/droplet/v2/config"

Expand Down Expand Up @@ -159,6 +164,60 @@ func NewFullNode(cctx *cli.Context, legacyRepo string) (v1api.FullNode, jsonrpc.
return v1api.NewFullNodeRPC(cctx.Context, addr, apiInfo.AuthHeader())
}

func getMarketClientConfig(cctx *cli.Context, legacyRepo string) (*config.MarketClientConfig, error) {
repoPath, err := GetRepoPath(cctx, "repo", legacyRepo)
if err != nil {
return nil, err
}
cfgPath := path.Join(repoPath, "config.toml")
marketClientCfg := config.DefaultMarketClientConfig
err = config.LoadConfig(cfgPath, marketClientCfg)
if err != nil {
return nil, err
}

return marketClientCfg, nil
}

func NewHost(cctx *cli.Context, legacyRepo string) (host.Host, error) {
cfg, err := getMarketClientConfig(cctx, legacyRepo)
if err != nil {
return nil, err
}

if len(cfg.Libp2p.PrivateKey) == 0 {
return nil, fmt.Errorf("private key is nil")
}

decodePriv, err := hex.DecodeString(cfg.Libp2p.PrivateKey)
if err != nil {
return nil, err
}
peerkey, err := crypto2.UnmarshalPrivateKey(decodePriv)
if err != nil {
return nil, err
}

h, err := libp2p.New(
libp2p.ListenAddrStrings("/ip4/0.0.0.0/tcp/0"),
libp2p.Identity(peerkey),
)
if err != nil {
return nil, err
}

return h, nil
}

func GetSignerFromRepo(cctx *cli.Context, legacyRepo string) (signer.ISigner, jsonrpc.ClientCloser, error) {
cfg, err := getMarketClientConfig(cctx, legacyRepo)
if err != nil {
return nil, nil, err
}

return signer.NewISignerClient(false, nil)(cctx.Context, &cfg.Signer)
}

func WithCategory(cat string, cmd *cli.Command) *cli.Command {
cmd.Category = strings.ToUpper(cat)
return cmd
Expand Down
Loading
Loading