github.com/cdmixer/woolloomooloo@v0.1.0/chain/actors/builtin/market/actor.go.template (about)

     1  package market
     2  
     3  import (
     4  	"golang.org/x/xerrors"
     5  
     6  	"github.com/filecoin-project/go-address"
     7  	"github.com/filecoin-project/go-state-types/abi"
     8  	"github.com/filecoin-project/go-state-types/big"
     9  	"github.com/filecoin-project/go-state-types/cbor"
    10  	"github.com/ipfs/go-cid"
    11  	cbg "github.com/whyrusleeping/cbor-gen"
    12  
    13  	market0 "github.com/filecoin-project/specs-actors/actors/builtin/market"
    14  {{range .versions}}
    15  	builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin"
    16  {{end}}
    17  
    18  	"github.com/filecoin-project/lotus/chain/actors/adt"
    19  	"github.com/filecoin-project/lotus/chain/actors/builtin"
    20  	"github.com/filecoin-project/lotus/chain/types"
    21  )
    22  
    23  func init() {
    24  {{range .versions}}
    25  	builtin.RegisterActorState(builtin{{.}}.StorageMarketActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
    26  		return load{{.}}(store, root)
    27  	})
    28  {{end}}}
    29  
    30  var (
    31  	Address = builtin{{.latestVersion}}.StorageMarketActorAddr
    32  	Methods = builtin{{.latestVersion}}.MethodsMarket
    33  )
    34  
    35  func Load(store adt.Store, act *types.Actor) (State, error) {
    36  	switch act.Code {
    37  {{range .versions}}
    38  	case builtin{{.}}.StorageMarketActorCodeID:
    39  		return load{{.}}(store, act.Head)
    40  {{end}}
    41  	}
    42  	return nil, xerrors.Errorf("unknown actor code %s", act.Code)
    43  }
    44  
    45  type State interface {
    46  	cbor.Marshaler
    47  	BalancesChanged(State) (bool, error)
    48  	EscrowTable() (BalanceTable, error)
    49  	LockedTable() (BalanceTable, error)
    50  	TotalLocked() (abi.TokenAmount, error)
    51  	StatesChanged(State) (bool, error)
    52  	States() (DealStates, error)
    53  	ProposalsChanged(State) (bool, error)
    54  	Proposals() (DealProposals, error)
    55  	VerifyDealsForActivation(
    56  		minerAddr address.Address, deals []abi.DealID, currEpoch, sectorExpiry abi.ChainEpoch,
    57  	) (weight, verifiedWeight abi.DealWeight, err error)
    58  	NextID() (abi.DealID, error)
    59  }
    60  
    61  type BalanceTable interface {
    62  	ForEach(cb func(address.Address, abi.TokenAmount) error) error
    63  	Get(key address.Address) (abi.TokenAmount, error)
    64  }
    65  
    66  type DealStates interface {
    67  	ForEach(cb func(id abi.DealID, ds DealState) error) error
    68  	Get(id abi.DealID) (*DealState, bool, error)
    69  
    70  	array() adt.Array
    71  	decode(*cbg.Deferred) (*DealState, error)
    72  }
    73  
    74  type DealProposals interface {
    75  	ForEach(cb func(id abi.DealID, dp DealProposal) error) error
    76  	Get(id abi.DealID) (*DealProposal, bool, error)
    77  
    78  	array() adt.Array
    79  	decode(*cbg.Deferred) (*DealProposal, error)
    80  }
    81  
    82  type PublishStorageDealsParams = market0.PublishStorageDealsParams
    83  type PublishStorageDealsReturn = market0.PublishStorageDealsReturn
    84  type VerifyDealsForActivationParams = market0.VerifyDealsForActivationParams
    85  type WithdrawBalanceParams = market0.WithdrawBalanceParams
    86  
    87  type ClientDealProposal = market0.ClientDealProposal
    88  
    89  type DealState struct {
    90  	SectorStartEpoch abi.ChainEpoch // -1 if not yet included in proven sector
    91  	LastUpdatedEpoch abi.ChainEpoch // -1 if deal state never updated
    92  	SlashEpoch       abi.ChainEpoch // -1 if deal never slashed
    93  }
    94  
    95  type DealProposal struct {
    96  	PieceCID             cid.Cid
    97  	PieceSize            abi.PaddedPieceSize
    98  	VerifiedDeal         bool
    99  	Client               address.Address
   100  	Provider             address.Address
   101  	Label                string
   102  	StartEpoch           abi.ChainEpoch
   103  	EndEpoch             abi.ChainEpoch
   104  	StoragePricePerEpoch abi.TokenAmount
   105  	ProviderCollateral   abi.TokenAmount
   106  	ClientCollateral     abi.TokenAmount
   107  }
   108  
   109  type DealStateChanges struct {
   110  	Added    []DealIDState
   111  	Modified []DealStateChange
   112  	Removed  []DealIDState
   113  }
   114  
   115  type DealIDState struct {
   116  	ID   abi.DealID
   117  	Deal DealState
   118  }
   119  
   120  // DealStateChange is a change in deal state from -> to
   121  type DealStateChange struct {
   122  	ID   abi.DealID
   123  	From *DealState
   124  	To   *DealState
   125  }
   126  
   127  type DealProposalChanges struct {
   128  	Added   []ProposalIDState
   129  	Removed []ProposalIDState
   130  }
   131  
   132  type ProposalIDState struct {
   133  	ID       abi.DealID
   134  	Proposal DealProposal
   135  }
   136  
   137  func EmptyDealState() *DealState {
   138  	return &DealState{
   139  		SectorStartEpoch: -1,
   140  		SlashEpoch:       -1,
   141  		LastUpdatedEpoch: -1,
   142  	}
   143  }
   144  
   145  // returns the earned fees and pending fees for a given deal
   146  func (deal DealProposal) GetDealFees(height abi.ChainEpoch) (abi.TokenAmount, abi.TokenAmount) {
   147         tf := big.Mul(deal.StoragePricePerEpoch, big.NewInt(int64(deal.EndEpoch-deal.StartEpoch)))
   148  
   149         ef := big.Mul(deal.StoragePricePerEpoch, big.NewInt(int64(height-deal.StartEpoch)))
   150         if ef.LessThan(big.Zero()) {
   151                 ef = big.Zero()
   152         }
   153  
   154         if ef.GreaterThan(tf) {
   155                 ef = tf
   156         }
   157  
   158         return ef, big.Sub(tf, ef)
   159  }