Skip to content
This repository has been archived by the owner on Jan 3, 2023. It is now read-only.

Commit

Permalink
Integrate FIP 0027
Browse files Browse the repository at this point in the history
  • Loading branch information
arajasek authored and vyzo committed Apr 14, 2022
1 parent 77613b5 commit 339b7db
Show file tree
Hide file tree
Showing 32 changed files with 322 additions and 126 deletions.
2 changes: 1 addition & 1 deletion api/api_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
datatransfer "github.com/filecoin-project/go-data-transfer"
"github.com/filecoin-project/go-state-types/abi"
abinetwork "github.com/filecoin-project/go-state-types/network"
"github.com/filecoin-project/specs-actors/v2/actors/builtin/market"
"github.com/filecoin-project/specs-actors/v8/actors/builtin/market"
"github.com/filecoin-project/specs-storage/storage"

"github.com/filecoin-project/go-fil-markets/piecestore"
Expand Down
2 changes: 1 addition & 1 deletion api/cbor_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 14 additions & 3 deletions chain/actors/builtin/market/actor.go.template
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package market

import (
"unicode/utf8"

"github.com/filecoin-project/go-state-types/network"
"golang.org/x/xerrors"

Expand All @@ -12,6 +14,7 @@ import (
cbg "github.com/whyrusleeping/cbor-gen"

market0 "github.com/filecoin-project/specs-actors/actors/builtin/market"
market{{.latestVersion}} "github.com/filecoin-project/specs-actors{{import .latestVersion}}actors/builtin/market"
{{range .versions}}
builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin"
{{end}}
Expand Down Expand Up @@ -128,7 +131,7 @@ type DealProposals interface {
decode(*cbg.Deferred) (*DealProposal, error)
}

type PublishStorageDealsParams = market0.PublishStorageDealsParams
type PublishStorageDealsParams = market{{.latestVersion}}.PublishStorageDealsParams

type PublishStorageDealsReturn interface {
DealIDs() ([]abi.DealID, error)
Expand All @@ -154,7 +157,7 @@ func DecodePublishStorageDealsReturn(b []byte, nv network.Version) (PublishStora
type VerifyDealsForActivationParams = market0.VerifyDealsForActivationParams
type WithdrawBalanceParams = market0.WithdrawBalanceParams

type ClientDealProposal = market0.ClientDealProposal
type ClientDealProposal = market{{.latestVersion}}.ClientDealProposal

type DealState struct {
SectorStartEpoch abi.ChainEpoch // -1 if not yet included in proven sector
Expand All @@ -168,7 +171,7 @@ type DealProposal struct {
VerifiedDeal bool
Client address.Address
Provider address.Address
Label string
Label market{{.latestVersion}}.DealLabel
StartEpoch abi.ChainEpoch
EndEpoch abi.ChainEpoch
StoragePricePerEpoch abi.TokenAmount
Expand Down Expand Up @@ -227,3 +230,11 @@ func (deal DealProposal) GetDealFees(height abi.ChainEpoch) (abi.TokenAmount, ab

return ef, big.Sub(tf, ef)
}

func labelFromGoString(s string) (market{{.latestVersion}}.DealLabel, error) {
if utf8.ValidString(s) {
return market{{.latestVersion}}.NewLabelFromString(s)
} else {
return market{{.latestVersion}}.NewLabelFromBytes([]byte(s))
}
}
17 changes: 14 additions & 3 deletions chain/actors/builtin/market/market.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package market

import (
"unicode/utf8"

"github.com/filecoin-project/go-state-types/network"
"golang.org/x/xerrors"

Expand All @@ -12,6 +14,7 @@ import (
cbg "github.com/whyrusleeping/cbor-gen"

market0 "github.com/filecoin-project/specs-actors/actors/builtin/market"
market8 "github.com/filecoin-project/specs-actors/v8/actors/builtin/market"

builtin0 "github.com/filecoin-project/specs-actors/actors/builtin"

Expand Down Expand Up @@ -295,7 +298,7 @@ type DealProposals interface {
decode(*cbg.Deferred) (*DealProposal, error)
}

type PublishStorageDealsParams = market0.PublishStorageDealsParams
type PublishStorageDealsParams = market8.PublishStorageDealsParams

type PublishStorageDealsReturn interface {
DealIDs() ([]abi.DealID, error)
Expand Down Expand Up @@ -342,7 +345,7 @@ func DecodePublishStorageDealsReturn(b []byte, nv network.Version) (PublishStora
type VerifyDealsForActivationParams = market0.VerifyDealsForActivationParams
type WithdrawBalanceParams = market0.WithdrawBalanceParams

type ClientDealProposal = market0.ClientDealProposal
type ClientDealProposal = market8.ClientDealProposal

type DealState struct {
SectorStartEpoch abi.ChainEpoch // -1 if not yet included in proven sector
Expand All @@ -356,7 +359,7 @@ type DealProposal struct {
VerifiedDeal bool
Client address.Address
Provider address.Address
Label string
Label market8.DealLabel
StartEpoch abi.ChainEpoch
EndEpoch abi.ChainEpoch
StoragePricePerEpoch abi.TokenAmount
Expand Down Expand Up @@ -415,3 +418,11 @@ func (deal DealProposal) GetDealFees(height abi.ChainEpoch) (abi.TokenAmount, ab

return ef, big.Sub(tf, ef)
}

func labelFromGoString(s string) (market8.DealLabel, error) {
if utf8.ValidString(s) {
return market8.NewLabelFromString(s)
} else {
return market8.NewLabelFromBytes([]byte(s))
}
}
25 changes: 20 additions & 5 deletions chain/actors/builtin/market/state.go.template
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,24 @@ func (s *dealProposals{{.v}}) Get(dealID abi.DealID) (*DealProposal, bool, error
if !found {
return nil, false, nil
}
proposal := fromV{{.v}}DealProposal(proposal{{.v}})
return &proposal, true, nil

proposal, err := fromV{{.v}}DealProposal(proposal{{.v}})
if err != nil {
return nil, true, xerrors.Errorf("decoding proposal: %w", err)
}

return &proposal, true, nil
}

func (s *dealProposals{{.v}}) ForEach(cb func(dealID abi.DealID, dp DealProposal) error) error {
var dp{{.v}} market{{.v}}.DealProposal
return s.Array.ForEach(&dp{{.v}}, func(idx int64) error {
return cb(abi.DealID(idx), fromV{{.v}}DealProposal(dp{{.v}}))
dp, err := fromV{{.v}}DealProposal(dp{{.v}})
if err != nil {
return xerrors.Errorf("decoding proposal: %w", err)
}

return cb(abi.DealID(idx), dp)
})
}

Expand All @@ -222,8 +232,13 @@ func (s *dealProposals{{.v}}) decode(val *cbg.Deferred) (*DealProposal, error) {
if err := dp{{.v}}.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil {
return nil, err
}
dp := fromV{{.v}}DealProposal(dp{{.v}})
return &dp, nil

dp, err := fromV{{.v}}DealProposal(dp{{.v}})
if err != nil {
return nil, err
}

return &dp, nil
}

func (s *dealProposals{{.v}}) array() adt.Array {
Expand Down
21 changes: 18 additions & 3 deletions chain/actors/builtin/market/v0.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,24 @@ func (s *dealProposals0) Get(dealID abi.DealID) (*DealProposal, bool, error) {
if !found {
return nil, false, nil
}
proposal := fromV0DealProposal(proposal0)

proposal, err := fromV0DealProposal(proposal0)
if err != nil {
return nil, true, xerrors.Errorf("decoding proposal: %w", err)
}

return &proposal, true, nil
}

func (s *dealProposals0) ForEach(cb func(dealID abi.DealID, dp DealProposal) error) error {
var dp0 market0.DealProposal
return s.Array.ForEach(&dp0, func(idx int64) error {
return cb(abi.DealID(idx), fromV0DealProposal(dp0))
dp, err := fromV0DealProposal(dp0)
if err != nil {
return xerrors.Errorf("decoding proposal: %w", err)
}

return cb(abi.DealID(idx), dp)
})
}

Expand All @@ -215,7 +225,12 @@ func (s *dealProposals0) decode(val *cbg.Deferred) (*DealProposal, error) {
if err := dp0.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil {
return nil, err
}
dp := fromV0DealProposal(dp0)

dp, err := fromV0DealProposal(dp0)
if err != nil {
return nil, err
}

return &dp, nil
}

Expand Down
21 changes: 18 additions & 3 deletions chain/actors/builtin/market/v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,24 @@ func (s *dealProposals2) Get(dealID abi.DealID) (*DealProposal, bool, error) {
if !found {
return nil, false, nil
}
proposal := fromV2DealProposal(proposal2)

proposal, err := fromV2DealProposal(proposal2)
if err != nil {
return nil, true, xerrors.Errorf("decoding proposal: %w", err)
}

return &proposal, true, nil
}

func (s *dealProposals2) ForEach(cb func(dealID abi.DealID, dp DealProposal) error) error {
var dp2 market2.DealProposal
return s.Array.ForEach(&dp2, func(idx int64) error {
return cb(abi.DealID(idx), fromV2DealProposal(dp2))
dp, err := fromV2DealProposal(dp2)
if err != nil {
return xerrors.Errorf("decoding proposal: %w", err)
}

return cb(abi.DealID(idx), dp)
})
}

Expand All @@ -215,7 +225,12 @@ func (s *dealProposals2) decode(val *cbg.Deferred) (*DealProposal, error) {
if err := dp2.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil {
return nil, err
}
dp := fromV2DealProposal(dp2)

dp, err := fromV2DealProposal(dp2)
if err != nil {
return nil, err
}

return &dp, nil
}

Expand Down
21 changes: 18 additions & 3 deletions chain/actors/builtin/market/v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,24 @@ func (s *dealProposals3) Get(dealID abi.DealID) (*DealProposal, bool, error) {
if !found {
return nil, false, nil
}
proposal := fromV3DealProposal(proposal3)

proposal, err := fromV3DealProposal(proposal3)
if err != nil {
return nil, true, xerrors.Errorf("decoding proposal: %w", err)
}

return &proposal, true, nil
}

func (s *dealProposals3) ForEach(cb func(dealID abi.DealID, dp DealProposal) error) error {
var dp3 market3.DealProposal
return s.Array.ForEach(&dp3, func(idx int64) error {
return cb(abi.DealID(idx), fromV3DealProposal(dp3))
dp, err := fromV3DealProposal(dp3)
if err != nil {
return xerrors.Errorf("decoding proposal: %w", err)
}

return cb(abi.DealID(idx), dp)
})
}

Expand All @@ -210,7 +220,12 @@ func (s *dealProposals3) decode(val *cbg.Deferred) (*DealProposal, error) {
if err := dp3.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil {
return nil, err
}
dp := fromV3DealProposal(dp3)

dp, err := fromV3DealProposal(dp3)
if err != nil {
return nil, err
}

return &dp, nil
}

Expand Down
21 changes: 18 additions & 3 deletions chain/actors/builtin/market/v4.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,24 @@ func (s *dealProposals4) Get(dealID abi.DealID) (*DealProposal, bool, error) {
if !found {
return nil, false, nil
}
proposal := fromV4DealProposal(proposal4)

proposal, err := fromV4DealProposal(proposal4)
if err != nil {
return nil, true, xerrors.Errorf("decoding proposal: %w", err)
}

return &proposal, true, nil
}

func (s *dealProposals4) ForEach(cb func(dealID abi.DealID, dp DealProposal) error) error {
var dp4 market4.DealProposal
return s.Array.ForEach(&dp4, func(idx int64) error {
return cb(abi.DealID(idx), fromV4DealProposal(dp4))
dp, err := fromV4DealProposal(dp4)
if err != nil {
return xerrors.Errorf("decoding proposal: %w", err)
}

return cb(abi.DealID(idx), dp)
})
}

Expand All @@ -210,7 +220,12 @@ func (s *dealProposals4) decode(val *cbg.Deferred) (*DealProposal, error) {
if err := dp4.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil {
return nil, err
}
dp := fromV4DealProposal(dp4)

dp, err := fromV4DealProposal(dp4)
if err != nil {
return nil, err
}

return &dp, nil
}

Expand Down
21 changes: 18 additions & 3 deletions chain/actors/builtin/market/v5.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,24 @@ func (s *dealProposals5) Get(dealID abi.DealID) (*DealProposal, bool, error) {
if !found {
return nil, false, nil
}
proposal := fromV5DealProposal(proposal5)

proposal, err := fromV5DealProposal(proposal5)
if err != nil {
return nil, true, xerrors.Errorf("decoding proposal: %w", err)
}

return &proposal, true, nil
}

func (s *dealProposals5) ForEach(cb func(dealID abi.DealID, dp DealProposal) error) error {
var dp5 market5.DealProposal
return s.Array.ForEach(&dp5, func(idx int64) error {
return cb(abi.DealID(idx), fromV5DealProposal(dp5))
dp, err := fromV5DealProposal(dp5)
if err != nil {
return xerrors.Errorf("decoding proposal: %w", err)
}

return cb(abi.DealID(idx), dp)
})
}

Expand All @@ -210,7 +220,12 @@ func (s *dealProposals5) decode(val *cbg.Deferred) (*DealProposal, error) {
if err := dp5.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil {
return nil, err
}
dp := fromV5DealProposal(dp5)

dp, err := fromV5DealProposal(dp5)
if err != nil {
return nil, err
}

return &dp, nil
}

Expand Down
Loading

0 comments on commit 339b7db

Please sign in to comment.