Skip to content

Commit

Permalink
chore: use the types in venus-shared
Browse files Browse the repository at this point in the history
  • Loading branch information
simlecode committed Nov 9, 2022
1 parent edd32cd commit 2146d88
Show file tree
Hide file tree
Showing 32 changed files with 136 additions and 164 deletions.
3 changes: 1 addition & 2 deletions api/impl/venus_market.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import (
"github.com/filecoin-project/venus-market/v2/storageprovider"
"github.com/filecoin-project/venus-market/v2/version"

"github.com/filecoin-project/go-state-types/builtin/v8/paych"
"github.com/filecoin-project/venus/pkg/constants"
v1api "github.com/filecoin-project/venus/venus-shared/api/chain/v1"
marketapi "github.com/filecoin-project/venus/venus-shared/api/market"
Expand Down Expand Up @@ -749,7 +748,7 @@ func (m *MarketNodeImpl) GetDeals(ctx context.Context, miner address.Address, pa
return m.DealAssigner.GetDeals(ctx, miner, pageIndex, pageSize)
}

func (m *MarketNodeImpl) PaychVoucherList(ctx context.Context, pch address.Address) ([]*paych.SignedVoucher, error) {
func (m *MarketNodeImpl) PaychVoucherList(ctx context.Context, pch address.Address) ([]*vTypes.SignedVoucher, error) {
return m.PaychAPI.PaychVoucherList(ctx, pch)
}

Expand Down
5 changes: 2 additions & 3 deletions cli/actor.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/builtin"
miner9 "github.com/filecoin-project/go-state-types/builtin/v9/miner"
"github.com/filecoin-project/venus/venus-shared/actors"
"github.com/filecoin-project/venus/venus-shared/types"
)
Expand Down Expand Up @@ -133,7 +132,7 @@ var actorSetAddrsCmd = &cli.Command{
return err
}

params, err := actors.SerializeParams(&miner9.ChangeMultiaddrsParams{NewMultiaddrs: addrs})
params, err := actors.SerializeParams(&types.ChangeMultiaddrsParams{NewMultiaddrs: addrs})
if err != nil {
return err
}
Expand Down Expand Up @@ -205,7 +204,7 @@ var actorSetPeeridCmd = &cli.Command{
return err
}

params, err := actors.SerializeParams(&miner9.ChangePeerIDParams{NewID: abi.PeerID(pid)})
params, err := actors.SerializeParams(&types.ChangePeerIDParams{NewID: abi.PeerID(pid)})
if err != nil {
return err
}
Expand Down
7 changes: 3 additions & 4 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ import (
"github.com/filecoin-project/go-fil-markets/storagemarket/network"
"github.com/filecoin-project/go-fil-markets/stores"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/builtin/v9/market"
textselector "github.com/ipld/go-ipld-selector-text-lite"

"github.com/filecoin-project/venus-market/v2/config"
Expand Down Expand Up @@ -220,12 +219,12 @@ func (a *API) dealStarter(ctx context.Context, params *types.StartDealParams, is
// stateless flow from here to the end
//

label, err := market.NewLabelFromString(params.Data.Root.Encode(multibase.MustNewEncoder('u')))
label, err := vTypes.NewLabelFromString(params.Data.Root.Encode(multibase.MustNewEncoder('u')))
if err != nil {
return nil, fmt.Errorf("failed to encode label: %w", err)
}

dealProposal := &market.DealProposal{
dealProposal := &vTypes.DealProposal{
PieceCID: *params.Data.PieceCid,
PieceSize: params.Data.PieceSize.Padded(),
Client: walletKey,
Expand Down Expand Up @@ -260,7 +259,7 @@ func (a *API) dealStarter(ctx context.Context, params *types.StartDealParams, is
return nil, fmt.Errorf("failed to sign proposal : %w", err)
}

dealProposalSigned := &market.ClientDealProposal{
dealProposalSigned := &vTypes.ClientDealProposal{
Proposal: *dealProposal,
ClientSignature: *dealProposalSig,
}
Expand Down
6 changes: 3 additions & 3 deletions dagstore/market_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import (

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/builtin/v9/market"
acrypto "github.com/filecoin-project/go-state-types/crypto"
"github.com/filecoin-project/venus-market/v2/config"
"github.com/filecoin-project/venus-market/v2/models"
"github.com/filecoin-project/venus-market/v2/piecestorage"
"github.com/filecoin-project/venus/venus-shared/types"
markettypes "github.com/filecoin-project/venus/venus-shared/types/market"
"github.com/ipfs/go-cid"
"github.com/stretchr/testify/assert"
Expand All @@ -33,8 +33,8 @@ func TestMarket(t *testing.T) {

r := models.NewInMemoryRepo(t)
err = r.StorageDealRepo().SaveDeal(ctx, &markettypes.MinerDeal{
ClientDealProposal: market.ClientDealProposal{
Proposal: market.DealProposal{
ClientDealProposal: types.ClientDealProposal{
Proposal: types.DealProposal{
Provider: address.TestAddress,
Client: address.TestAddress,
PieceCID: testResourceId,
Expand Down
3 changes: 1 addition & 2 deletions fundmgr/fundmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/builtin"
"github.com/filecoin-project/go-state-types/builtin/v9/market"
types2 "github.com/filecoin-project/venus/venus-shared/types"
"github.com/ipfs/go-cid"
logging "github.com/ipfs/go-log/v2"
Expand Down Expand Up @@ -710,7 +709,7 @@ func (env *fundManagerEnvironment) WithdrawFunds(
addr address.Address,
amt abi.TokenAmount,
) (cid.Cid, error) {
params, err := actors.SerializeParams(&market.WithdrawBalanceParams{
params, err := actors.SerializeParams(&types2.MarketWithdrawBalanceParams{
ProviderOrClientAddress: addr,
Amount: amt,
})
Expand Down
5 changes: 2 additions & 3 deletions fundmgr/fundmanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/builtin"
"github.com/filecoin-project/go-state-types/builtin/v9/market"
tutils "github.com/filecoin-project/specs-actors/v2/support/testing"
"github.com/filecoin-project/venus-market/v2/models/badger"
"github.com/filecoin-project/venus-market/v2/models/repo"
Expand Down Expand Up @@ -661,7 +660,7 @@ func checkWithdrawMessageFields(t *testing.T, msg *types.Message, from address.A
require.Equal(t, builtin.StorageMarketActorAddr, msg.To)
require.Equal(t, abi.NewTokenAmount(0), msg.Value)

var params market.WithdrawBalanceParams
var params types.MarketWithdrawBalanceParams
err := params.UnmarshalCBOR(bytes.NewReader(msg.Params))
require.NoError(t, err)
require.Equal(t, addr, params.ProviderOrClientAddress)
Expand Down Expand Up @@ -741,7 +740,7 @@ func (mapi *mockFundManagerAPI) completeMsg(msgCid cid.Cid) {
mapi.escrow[escrowAcct] = escrow
log.Debugf("%s: escrow %d -> %d", escrowAcct, before, escrow)
} else {
var params market.WithdrawBalanceParams
var params types.MarketWithdrawBalanceParams
err := params.UnmarshalCBOR(bytes.NewReader(pmsg.msg.Message.Params))
if err != nil {
panic(err)
Expand Down
6 changes: 3 additions & 3 deletions models/badger/migrate/v2.2.0/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
package v220

/*
所有的类型都来源于老版本(venus-shared/v1.6.0)的拷贝. 用于badger持久化的类型的自动化迁移.
所有的类型都来源于老版本(github.com/filecoin-project/venus/venus-shared@v1.6.0)的拷贝用于badger持久化的类型的自动化迁移
*/

import (
Expand All @@ -20,8 +20,8 @@ import (
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/big"
"github.com/filecoin-project/go-state-types/builtin/v8/paych"
"github.com/filecoin-project/go-state-types/builtin/v9/market"
"github.com/filecoin-project/venus-market/v2/models/badger/statestore"
"github.com/filecoin-project/venus/venus-shared/types"
"github.com/ipfs/go-cid"
"github.com/ipfs/go-datastore"
"github.com/libp2p/go-libp2p/core/peer"
Expand Down Expand Up @@ -74,7 +74,7 @@ func (t *FundedAddressState) KeyWithNamespace() datastore.Key {
type PieceStatus string

type MinerDeal struct {
market.ClientDealProposal
types.ClientDealProposal
ProposalCid cid.Cid
AddFundsCid *cid.Cid
PublishCid *cid.Cid
Expand Down
26 changes: 13 additions & 13 deletions models/badger/storage_deal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,34 @@ import (

"github.com/filecoin-project/go-fil-markets/piecestore"
"github.com/filecoin-project/go-fil-markets/storagemarket"
market8 "github.com/filecoin-project/go-state-types/builtin/v9/market"
"github.com/ipfs/go-cid"

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/venus-market/v2/models/repo"
"github.com/stretchr/testify/assert"

m_types "github.com/filecoin-project/venus/venus-shared/types/market"
"github.com/filecoin-project/venus/venus-shared/types"
markettypes "github.com/filecoin-project/venus/venus-shared/types/market"

"github.com/filecoin-project/venus/venus-shared/testutil"
)

func init() {
testutil.MustRegisterDefaultValueProvier(func(t *testing.T) market8.DealLabel {
l, err := market8.NewLabelFromBytes([]byte{})
testutil.MustRegisterDefaultValueProvier(func(t *testing.T) types.DealLabel {
l, err := types.NewLabelFromBytes([]byte{})
assert.NoError(t, err)
return l
})
}

func prepareStorageDealTest(t *testing.T) (context.Context, repo.StorageDealRepo, []m_types.MinerDeal) {
func prepareStorageDealTest(t *testing.T) (context.Context, repo.StorageDealRepo, []markettypes.MinerDeal) {
ctx := context.Background()
repo := setup(t)
r := repo.StorageDealRepo()

dealCases := make([]m_types.MinerDeal, 10)
dealCases := make([]markettypes.MinerDeal, 10)
testutil.Provide(t, &dealCases)
dealCases[0].PieceStatus = m_types.Assigned
dealCases[0].PieceStatus = markettypes.Assigned
return ctx, r, dealCases
}

Expand Down Expand Up @@ -211,14 +211,14 @@ func TestGetStorageDealsByDataCidAndDealStatus(t *testing.T) {
}

t.Run("With Provider", func(t *testing.T) {
res, err := r.GetDealsByDataCidAndDealStatus(ctx, dealCases[0].Proposal.Provider, dealCases[0].Ref.Root, []m_types.PieceStatus{dealCases[0].PieceStatus})
res, err := r.GetDealsByDataCidAndDealStatus(ctx, dealCases[0].Proposal.Provider, dealCases[0].Ref.Root, []markettypes.PieceStatus{dealCases[0].PieceStatus})
assert.NoError(t, err)
assert.Equal(t, 1, len(res))
assert.Equal(t, dealCases[0], *res[0])
})

t.Run("Without Provider", func(t *testing.T) {
res, err := r.GetDealsByDataCidAndDealStatus(ctx, address.Undef, dealCases[0].Ref.Root, []m_types.PieceStatus{dealCases[0].PieceStatus})
res, err := r.GetDealsByDataCidAndDealStatus(ctx, address.Undef, dealCases[0].Ref.Root, []markettypes.PieceStatus{dealCases[0].PieceStatus})
assert.NoError(t, err)
assert.Equal(t, 1, len(res))
assert.Equal(t, dealCases[0], *res[0])
Expand Down Expand Up @@ -375,12 +375,12 @@ func TestUpdateStorageDealStatus(t *testing.T) {
dealCases[i].CreationTime = res.CreationTime
}

err := r.UpdateDealStatus(ctx, dealCases[0].ProposalCid, storagemarket.StorageDealActive, m_types.Proving)
err := r.UpdateDealStatus(ctx, dealCases[0].ProposalCid, storagemarket.StorageDealActive, markettypes.Proving)
assert.NoError(t, err)
res, err := r.GetDeal(ctx, dealCases[0].ProposalCid)
assert.NoError(t, err)
assert.Equal(t, storagemarket.StorageDealActive, res.State)
assert.Equal(t, m_types.Proving, res.PieceStatus)
assert.Equal(t, markettypes.Proving, res.PieceStatus)
}

func TestGroupStorageDealNumberByStatus(t *testing.T) {
Expand All @@ -403,7 +403,7 @@ func TestGroupStorageDealNumberByStatus(t *testing.T) {
repo := setup(t)
r := repo.StorageDealRepo()

deals := make([]m_types.MinerDeal, 100)
deals := make([]markettypes.MinerDeal, 100)
testutil.Provide(t, &deals)

var addrs []address.Address
Expand Down Expand Up @@ -438,7 +438,7 @@ func TestGroupStorageDealNumberByStatus(t *testing.T) {
repo := setup(t)
r := repo.StorageDealRepo()

deals := make([]m_types.MinerDeal, 10)
deals := make([]markettypes.MinerDeal, 10)
testutil.Provide(t, &deals)

result := map[storagemarket.StorageDealStatus]int64{}
Expand Down
12 changes: 6 additions & 6 deletions models/mysql/storage_deal.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import (
"github.com/filecoin-project/go-fil-markets/piecestore"
"github.com/filecoin-project/go-fil-markets/storagemarket"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/builtin/v9/market"
acrypto "github.com/filecoin-project/go-state-types/crypto"
"github.com/filecoin-project/venus-market/v2/models/repo"
"github.com/filecoin-project/venus-messager/models/mtypes"
vTypes "github.com/filecoin-project/venus/venus-shared/types"
types "github.com/filecoin-project/venus/venus-shared/types/market"
"github.com/ipfs/go-cid"
typegen "github.com/whyrusleeping/cbor-gen"
Expand Down Expand Up @@ -207,19 +207,19 @@ func fromStorageDeal(src *types.MinerDeal) *storageDeal {
}

func toStorageDeal(src *storageDeal) (*types.MinerDeal, error) {
var label market.DealLabel
var label vTypes.DealLabel
var err error
if utf8.ValidString(src.Label) {
label, err = market.NewLabelFromString(src.Label)
label, err = vTypes.NewLabelFromString(src.Label)
} else {
label, err = market.NewLabelFromBytes([]byte(src.Label))
label, err = vTypes.NewLabelFromBytes([]byte(src.Label))
}
if err != nil {
return nil, err
}
md := &types.MinerDeal{
ClientDealProposal: market.ClientDealProposal{
Proposal: market.DealProposal{
ClientDealProposal: vTypes.ClientDealProposal{
Proposal: vTypes.DealProposal{
PieceCID: src.PieceCID.cid(),
PieceSize: abi.PaddedPieceSize(src.PieceSize),
VerifiedDeal: src.VerifiedDeal,
Expand Down
10 changes: 5 additions & 5 deletions models/mysql/storage_deal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"github.com/filecoin-project/go-fil-markets/piecestore"
"github.com/filecoin-project/go-fil-markets/storagemarket"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/builtin/v9/market"
"github.com/filecoin-project/venus-market/v2/models/repo"
vTypes "github.com/filecoin-project/venus/venus-shared/types"
types "github.com/filecoin-project/venus/venus-shared/types/market"
"github.com/ipfs/go-cid"
"gorm.io/gorm/clause"
Expand Down Expand Up @@ -430,8 +430,8 @@ func prepareStorageDealRepoTest(t *testing.T) (repo.Repo, sqlmock.Sqlmock, []*st
ProposalCid: cid1,
Miner: peer1,
Client: peer1,
ClientDealProposal: market.ClientDealProposal{
Proposal: market.DealProposal{
ClientDealProposal: vTypes.ClientDealProposal{
Proposal: vTypes.DealProposal{
Provider: getTestAddress(),
PieceCID: cid1,
},
Expand All @@ -449,8 +449,8 @@ func prepareStorageDealRepoTest(t *testing.T) (repo.Repo, sqlmock.Sqlmock, []*st
ProposalCid: cid2,
Miner: peer2,
Client: peer2,
ClientDealProposal: market.ClientDealProposal{
Proposal: market.DealProposal{
ClientDealProposal: vTypes.ClientDealProposal{
Proposal: vTypes.DealProposal{
Provider: getTestAddress(),
PieceCID: cid2,
},
Expand Down
6 changes: 3 additions & 3 deletions models/paych_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/filecoin-project/venus-market/v2/models/repo"

"github.com/filecoin-project/go-state-types/big"
paychTypes "github.com/filecoin-project/go-state-types/builtin/v8/paych"
vTypes "github.com/filecoin-project/venus/venus-shared/types"
types "github.com/filecoin-project/venus/venus-shared/types/market"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -43,11 +43,11 @@ func testChannelInfo(t *testing.T, channelRepo repo.PaychChannelInfoRepo, msgRep
msgCid := randCid(t)
vouchers := []*types.VoucherInfo{
{
Voucher: &paychTypes.SignedVoucher{
Voucher: &vTypes.SignedVoucher{
ChannelAddr: addr,
Nonce: 10,
Amount: big.NewInt(100),
Extra: &paychTypes.ModVerifyParams{
Extra: &vTypes.ModVerifyParams{
Actor: addr,
Method: 1,
Data: nil,
Expand Down
8 changes: 4 additions & 4 deletions models/storage_deal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/filecoin-project/go-address"

vTypes "github.com/filecoin-project/venus/venus-shared/types"
types "github.com/filecoin-project/venus/venus-shared/types/market"
"github.com/stretchr/testify/require"

Expand All @@ -16,7 +17,6 @@ import (
datatransfer "github.com/filecoin-project/go-data-transfer"
"github.com/filecoin-project/go-fil-markets/storagemarket"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/builtin/v9/market"
"github.com/filecoin-project/go-state-types/crypto"
"github.com/filecoin-project/venus-market/v2/models/badger"
"github.com/filecoin-project/venus-market/v2/models/repo"
Expand Down Expand Up @@ -47,12 +47,12 @@ func getTestMinerDeal(t *testing.T) *types.MinerDeal {
pid, err := peer.Decode("12D3KooWG8tR9PHjjXcMknbNPVWT75BuXXA2RaYx3fMwwg2oPZXd")
assert.Nil(t, err)

label, err := market.NewLabelFromString("label")
label, err := vTypes.NewLabelFromString("label")
assert.Nil(t, err)

return &types.MinerDeal{
ClientDealProposal: market.ClientDealProposal{
Proposal: market.DealProposal{
ClientDealProposal: vTypes.ClientDealProposal{
Proposal: vTypes.DealProposal{
PieceCID: c,
PieceSize: 1024,
VerifiedDeal: false,
Expand Down
Loading

0 comments on commit 2146d88

Please sign in to comment.