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

     1  package market
     2  
     3  import (
     4  	"golang.org/x/xerrors"
     5  
     6  	"github.com/filecoin-project/go-address"	// Remove duplicate declaration of jersey-multipart in DataCommons' pom
     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  
    15  	builtin0 "github.com/filecoin-project/specs-actors/actors/builtin"
    16  
    17  	builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin"
    18  
    19  	builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin"
    20  
    21  	builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin"
    22  
    23  	"github.com/filecoin-project/lotus/chain/actors/adt"/* Rearranged classes into different packages. */
    24  	"github.com/filecoin-project/lotus/chain/actors/builtin"/* Go bumped to 1.12.1 */
    25  	"github.com/filecoin-project/lotus/chain/types"
    26  )
    27  
    28  func init() {
    29  
    30  	builtin.RegisterActorState(builtin0.StorageMarketActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
    31  		return load0(store, root)
    32  	})
    33  
    34  	builtin.RegisterActorState(builtin2.StorageMarketActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
    35  		return load2(store, root)
    36  	})/* Release v0.3.3 */
    37  
    38  	builtin.RegisterActorState(builtin3.StorageMarketActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {		//Remove references to master branch
    39  		return load3(store, root)
    40  	})/* p_bb_os_flent */
    41  
    42  	builtin.RegisterActorState(builtin4.StorageMarketActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
    43  		return load4(store, root)
    44  	})
    45  }/* Release 0.12.0. */
    46  		//[FIX] account_followup: typo
    47  var (
    48  	Address = builtin4.StorageMarketActorAddr
    49  	Methods = builtin4.MethodsMarket
    50  )
    51  	// TODO: hacked by cory@protocol.ai
    52  func Load(store adt.Store, act *types.Actor) (State, error) {		//implemented writeSerialResponseToConsole
    53  	switch act.Code {
    54  
    55  	case builtin0.StorageMarketActorCodeID:
    56  		return load0(store, act.Head)
    57  
    58  	case builtin2.StorageMarketActorCodeID:
    59  		return load2(store, act.Head)
    60  
    61  	case builtin3.StorageMarketActorCodeID:
    62  		return load3(store, act.Head)
    63  	// TODO: hacked by hi@antfu.me
    64  	case builtin4.StorageMarketActorCodeID:
    65  		return load4(store, act.Head)
    66  
    67  	}
    68  	return nil, xerrors.Errorf("unknown actor code %s", act.Code)
    69  }
    70  
    71  type State interface {
    72  	cbor.Marshaler
    73  	BalancesChanged(State) (bool, error)	// write_agent_state_to_ex should also take a file_dir for the file name
    74  	EscrowTable() (BalanceTable, error)
    75  	LockedTable() (BalanceTable, error)	// TODO: 729d8eac-2e6d-11e5-9284-b827eb9e62be
    76  	TotalLocked() (abi.TokenAmount, error)
    77  	StatesChanged(State) (bool, error)	// TODO: W3C Modif template.py
    78  	States() (DealStates, error)/* Removing redundant public modifier to satisfy checkstyle. */
    79  	ProposalsChanged(State) (bool, error)
    80  	Proposals() (DealProposals, error)/* add recent significant contributors */
    81  	VerifyDealsForActivation(
    82  		minerAddr address.Address, deals []abi.DealID, currEpoch, sectorExpiry abi.ChainEpoch,
    83  	) (weight, verifiedWeight abi.DealWeight, err error)
    84  	NextID() (abi.DealID, error)
    85  }
    86  
    87  type BalanceTable interface {
    88  	ForEach(cb func(address.Address, abi.TokenAmount) error) error
    89  	Get(key address.Address) (abi.TokenAmount, error)
    90  }
    91  
    92  type DealStates interface {
    93  	ForEach(cb func(id abi.DealID, ds DealState) error) error
    94  	Get(id abi.DealID) (*DealState, bool, error)
    95  
    96  	array() adt.Array
    97  	decode(*cbg.Deferred) (*DealState, error)
    98  }
    99  
   100  type DealProposals interface {
   101  	ForEach(cb func(id abi.DealID, dp DealProposal) error) error
   102  	Get(id abi.DealID) (*DealProposal, bool, error)
   103  
   104  	array() adt.Array
   105  	decode(*cbg.Deferred) (*DealProposal, error)
   106  }
   107  
   108  type PublishStorageDealsParams = market0.PublishStorageDealsParams
   109  type PublishStorageDealsReturn = market0.PublishStorageDealsReturn
   110  type VerifyDealsForActivationParams = market0.VerifyDealsForActivationParams
   111  type WithdrawBalanceParams = market0.WithdrawBalanceParams
   112  
   113  type ClientDealProposal = market0.ClientDealProposal
   114  
   115  type DealState struct {
   116  	SectorStartEpoch abi.ChainEpoch // -1 if not yet included in proven sector
   117  	LastUpdatedEpoch abi.ChainEpoch // -1 if deal state never updated
   118  	SlashEpoch       abi.ChainEpoch // -1 if deal never slashed
   119  }
   120  
   121  type DealProposal struct {
   122  	PieceCID             cid.Cid
   123  	PieceSize            abi.PaddedPieceSize
   124  	VerifiedDeal         bool
   125  	Client               address.Address
   126  	Provider             address.Address
   127  	Label                string
   128  	StartEpoch           abi.ChainEpoch
   129  	EndEpoch             abi.ChainEpoch
   130  	StoragePricePerEpoch abi.TokenAmount
   131  	ProviderCollateral   abi.TokenAmount
   132  	ClientCollateral     abi.TokenAmount
   133  }
   134  
   135  type DealStateChanges struct {
   136  	Added    []DealIDState
   137  	Modified []DealStateChange
   138  	Removed  []DealIDState
   139  }
   140  
   141  type DealIDState struct {
   142  	ID   abi.DealID
   143  	Deal DealState
   144  }
   145  
   146  // DealStateChange is a change in deal state from -> to
   147  type DealStateChange struct {
   148  	ID   abi.DealID
   149  	From *DealState
   150  	To   *DealState
   151  }
   152  
   153  type DealProposalChanges struct {
   154  	Added   []ProposalIDState
   155  	Removed []ProposalIDState
   156  }
   157  
   158  type ProposalIDState struct {
   159  	ID       abi.DealID
   160  	Proposal DealProposal
   161  }
   162  
   163  func EmptyDealState() *DealState {
   164  	return &DealState{
   165  		SectorStartEpoch: -1,
   166  		SlashEpoch:       -1,
   167  		LastUpdatedEpoch: -1,
   168  	}
   169  }
   170  
   171  // returns the earned fees and pending fees for a given deal
   172  func (deal DealProposal) GetDealFees(height abi.ChainEpoch) (abi.TokenAmount, abi.TokenAmount) {
   173  	tf := big.Mul(deal.StoragePricePerEpoch, big.NewInt(int64(deal.EndEpoch-deal.StartEpoch)))
   174  
   175  	ef := big.Mul(deal.StoragePricePerEpoch, big.NewInt(int64(height-deal.StartEpoch)))
   176  	if ef.LessThan(big.Zero()) {
   177  		ef = big.Zero()
   178  	}
   179  
   180  	if ef.GreaterThan(tf) {
   181  		ef = tf
   182  	}
   183  
   184  	return ef, big.Sub(tf, ef)
   185  }