From c105ca7528265c89b9d54a6d258a7f6c906f9d07 Mon Sep 17 00:00:00 2001 From: Tiance <1033935631@qq.com> Date: Wed, 8 Feb 2023 17:41:55 +0800 Subject: [PATCH] feat: upgrade market-event api --- venus-devtool/api-gen/example.go | 5 +++ venus-shared/api/gateway/v2/market_event.go | 9 +++--- venus-shared/api/gateway/v2/method.md | 21 ++++--------- .../api/gateway/v2/mock/mock_igateway.go | 6 ++-- venus-shared/api/gateway/v2/proxy_gen.go | 12 +++---- venus-shared/types/gateway/market_event.go | 14 ++++++--- venus-shared/types/market/piece_transfer.go | 31 +++++++++++++++++++ 7 files changed, 64 insertions(+), 34 deletions(-) create mode 100644 venus-shared/types/market/piece_transfer.go diff --git a/venus-devtool/api-gen/example.go b/venus-devtool/api-gen/example.go index 721219a26a..99444ed345 100644 --- a/venus-devtool/api-gen/example.go +++ b/venus-devtool/api-gen/example.go @@ -260,6 +260,11 @@ func init() { // used in market addExample(filestore.Path("/some/path")) + params, _ := json.Marshal(&market.FsTransfer{Path: "/path"}) + addExample(&market.Transfer{ + Type: market.PiecesTransferFs, + Params: params, + }) clientDataSelector := client.DataSelector("/ipld/a/b/c") addExample(clientDataSelector) diff --git a/venus-shared/api/gateway/v2/market_event.go b/venus-shared/api/gateway/v2/market_event.go index e01af80b2c..72cf51d334 100644 --- a/venus-shared/api/gateway/v2/market_event.go +++ b/venus-shared/api/gateway/v2/market_event.go @@ -5,12 +5,11 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/specs-storage/storage" - "github.com/ipfs/go-cid" "github.com/filecoin-project/venus/venus-shared/types" gtypes "github.com/filecoin-project/venus/venus-shared/types/gateway" + mktypes "github.com/filecoin-project/venus/venus-shared/types/market" ) type IMarketEvent interface { @@ -19,9 +18,9 @@ type IMarketEvent interface { } type IMarketClient interface { - ListMarketConnectionsState(ctx context.Context) ([]gtypes.MarketConnectionState, error) //perm:admin - IsUnsealed(ctx context.Context, miner address.Address, pieceCid cid.Cid, sector storage.SectorRef, offset types.PaddedByteIndex, size abi.PaddedPieceSize) (bool, error) //perm:admin - SectorsUnsealPiece(ctx context.Context, miner address.Address, pieceCid cid.Cid, sector storage.SectorRef, offset types.PaddedByteIndex, size abi.PaddedPieceSize, dest string) error //perm:admin + ListMarketConnectionsState(ctx context.Context) ([]gtypes.MarketConnectionState, error) //perm:admin + IsUnsealed(ctx context.Context, miner address.Address, pieceCid cid.Cid, sid abi.SectorNumber, offset types.PaddedByteIndex, size abi.PaddedPieceSize) (bool, error) //perm:admin + SectorsUnsealPiece(ctx context.Context, miner address.Address, pieceCid cid.Cid, sid abi.SectorNumber, offset types.PaddedByteIndex, size abi.PaddedPieceSize, transfer *mktypes.Transfer) error //perm:admin } type IMarketServiceProvider interface { diff --git a/venus-shared/api/gateway/v2/method.md b/venus-shared/api/gateway/v2/method.md index eefff0b99d..a3c71901ab 100644 --- a/venus-shared/api/gateway/v2/method.md +++ b/venus-shared/api/gateway/v2/method.md @@ -66,13 +66,7 @@ Inputs: { "/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4" }, - { - "ID": { - "Miner": 1000, - "Number": 9 - }, - "ProofType": 8 - }, + 9, 10, 1032 ] @@ -122,16 +116,13 @@ Inputs: { "/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4" }, - { - "ID": { - "Miner": 1000, - "Number": 9 - }, - "ProofType": 8 - }, + 9, 10, 1032, - "string value" + { + "Type": "fs", + "Params": "eyJQYXRoIjoiL3BhdGgifQ==" + } ] ``` diff --git a/venus-shared/api/gateway/v2/mock/mock_igateway.go b/venus-shared/api/gateway/v2/mock/mock_igateway.go index 4e4391e9e4..a89a6f0b1d 100644 --- a/venus-shared/api/gateway/v2/mock/mock_igateway.go +++ b/venus-shared/api/gateway/v2/mock/mock_igateway.go @@ -13,9 +13,9 @@ import ( crypto "github.com/filecoin-project/go-state-types/crypto" network "github.com/filecoin-project/go-state-types/network" proof "github.com/filecoin-project/go-state-types/proof" - storage "github.com/filecoin-project/specs-storage/storage" types "github.com/filecoin-project/venus/venus-shared/types" gateway "github.com/filecoin-project/venus/venus-shared/types/gateway" + market "github.com/filecoin-project/venus/venus-shared/types/market" gomock "github.com/golang/mock/gomock" cid "github.com/ipfs/go-cid" ) @@ -73,7 +73,7 @@ func (mr *MockIGatewayMockRecorder) ComputeProof(arg0, arg1, arg2, arg3, arg4, a } // IsUnsealed mocks base method. -func (m *MockIGateway) IsUnsealed(arg0 context.Context, arg1 address.Address, arg2 cid.Cid, arg3 storage.SectorRef, arg4 types.PaddedByteIndex, arg5 abi.PaddedPieceSize) (bool, error) { +func (m *MockIGateway) IsUnsealed(arg0 context.Context, arg1 address.Address, arg2 cid.Cid, arg3 abi.SectorNumber, arg4 types.PaddedByteIndex, arg5 abi.PaddedPieceSize) (bool, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "IsUnsealed", arg0, arg1, arg2, arg3, arg4, arg5) ret0, _ := ret[0].(bool) @@ -264,7 +264,7 @@ func (mr *MockIGatewayMockRecorder) ResponseWalletEvent(arg0, arg1 interface{}) } // SectorsUnsealPiece mocks base method. -func (m *MockIGateway) SectorsUnsealPiece(arg0 context.Context, arg1 address.Address, arg2 cid.Cid, arg3 storage.SectorRef, arg4 types.PaddedByteIndex, arg5 abi.PaddedPieceSize, arg6 string) error { +func (m *MockIGateway) SectorsUnsealPiece(arg0 context.Context, arg1 address.Address, arg2 cid.Cid, arg3 abi.SectorNumber, arg4 types.PaddedByteIndex, arg5 abi.PaddedPieceSize, arg6 *market.Transfer) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "SectorsUnsealPiece", arg0, arg1, arg2, arg3, arg4, arg5, arg6) ret0, _ := ret[0].(error) diff --git a/venus-shared/api/gateway/v2/proxy_gen.go b/venus-shared/api/gateway/v2/proxy_gen.go index b89a4087c0..6c0802368f 100644 --- a/venus-shared/api/gateway/v2/proxy_gen.go +++ b/venus-shared/api/gateway/v2/proxy_gen.go @@ -8,12 +8,12 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/crypto" "github.com/filecoin-project/go-state-types/network" - "github.com/filecoin-project/specs-storage/storage" cid "github.com/ipfs/go-cid" "github.com/filecoin-project/venus/venus-shared/actors/builtin" "github.com/filecoin-project/venus/venus-shared/types" gtypes "github.com/filecoin-project/venus/venus-shared/types/gateway" + mktypes "github.com/filecoin-project/venus/venus-shared/types/market" ) type IProofClientStruct struct { @@ -108,19 +108,19 @@ type IWalletEventStruct struct { type IMarketClientStruct struct { Internal struct { - IsUnsealed func(ctx context.Context, miner address.Address, pieceCid cid.Cid, sector storage.SectorRef, offset types.PaddedByteIndex, size abi.PaddedPieceSize) (bool, error) `perm:"admin"` - ListMarketConnectionsState func(ctx context.Context) ([]gtypes.MarketConnectionState, error) `perm:"admin"` - SectorsUnsealPiece func(ctx context.Context, miner address.Address, pieceCid cid.Cid, sector storage.SectorRef, offset types.PaddedByteIndex, size abi.PaddedPieceSize, dest string) error `perm:"admin"` + IsUnsealed func(ctx context.Context, miner address.Address, pieceCid cid.Cid, sid abi.SectorNumber, offset types.PaddedByteIndex, size abi.PaddedPieceSize) (bool, error) `perm:"admin"` + ListMarketConnectionsState func(ctx context.Context) ([]gtypes.MarketConnectionState, error) `perm:"admin"` + SectorsUnsealPiece func(ctx context.Context, miner address.Address, pieceCid cid.Cid, sid abi.SectorNumber, offset types.PaddedByteIndex, size abi.PaddedPieceSize, transfer *mktypes.Transfer) error `perm:"admin"` } } -func (s *IMarketClientStruct) IsUnsealed(p0 context.Context, p1 address.Address, p2 cid.Cid, p3 storage.SectorRef, p4 types.PaddedByteIndex, p5 abi.PaddedPieceSize) (bool, error) { +func (s *IMarketClientStruct) IsUnsealed(p0 context.Context, p1 address.Address, p2 cid.Cid, p3 abi.SectorNumber, p4 types.PaddedByteIndex, p5 abi.PaddedPieceSize) (bool, error) { return s.Internal.IsUnsealed(p0, p1, p2, p3, p4, p5) } func (s *IMarketClientStruct) ListMarketConnectionsState(p0 context.Context) ([]gtypes.MarketConnectionState, error) { return s.Internal.ListMarketConnectionsState(p0) } -func (s *IMarketClientStruct) SectorsUnsealPiece(p0 context.Context, p1 address.Address, p2 cid.Cid, p3 storage.SectorRef, p4 types.PaddedByteIndex, p5 abi.PaddedPieceSize, p6 string) error { +func (s *IMarketClientStruct) SectorsUnsealPiece(p0 context.Context, p1 address.Address, p2 cid.Cid, p3 abi.SectorNumber, p4 types.PaddedByteIndex, p5 abi.PaddedPieceSize, p6 *mktypes.Transfer) error { return s.Internal.SectorsUnsealPiece(p0, p1, p2, p3, p4, p5, p6) } diff --git a/venus-shared/types/gateway/market_event.go b/venus-shared/types/gateway/market_event.go index 2e5aeecfa2..1bbf9e38ac 100644 --- a/venus-shared/types/gateway/market_event.go +++ b/venus-shared/types/gateway/market_event.go @@ -1,11 +1,13 @@ package gateway import ( + "github.com/filecoin-project/venus/venus-shared/types/market" + "github.com/ipfs/go-cid" + "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/specs-storage/storage" + "github.com/filecoin-project/venus/venus-shared/types" - "github.com/ipfs/go-cid" ) type MarketRegisterPolicy struct { @@ -14,7 +16,8 @@ type MarketRegisterPolicy struct { type IsUnsealRequest struct { PieceCid cid.Cid - Sector storage.SectorRef + Miner address.Address + Sid abi.SectorNumber Offset types.PaddedByteIndex Size abi.PaddedPieceSize } @@ -23,10 +26,11 @@ type IsUnsealResponse struct{} type UnsealRequest struct { PieceCid cid.Cid - Sector storage.SectorRef + Miner address.Address + Sid abi.SectorNumber Offset types.PaddedByteIndex Size abi.PaddedPieceSize - Dest string + Transfer market.Transfer } type UnsealResponse struct{} diff --git a/venus-shared/types/market/piece_transfer.go b/venus-shared/types/market/piece_transfer.go new file mode 100644 index 0000000000..0d3065f7ed --- /dev/null +++ b/venus-shared/types/market/piece_transfer.go @@ -0,0 +1,31 @@ +package market + +const ( + PiecesTransferS3 = "s3" + PiecesTransferFs = "fs" +) + +type FsTransfer struct { + Path string +} + +type S3Transfer struct { + EndPoint string + Bucket string + SubDir string + + AccessKey string + SecretKey string + Token string + + Key string +} + +// Transfer has the parameters for a data transfer +type Transfer struct { + // The type of transfer eg "http" + Type string + // A byte array containing marshalled data specific to the transfer type + // eg a JSON encoded struct { URL: "", Headers: {...} } + Params []byte +}