simplify market diff
This commit is contained in:
parent
8bd6791e58
commit
daa441b989
@ -8,7 +8,7 @@ import (
|
||||
cbg "github.com/whyrusleeping/cbor-gen"
|
||||
)
|
||||
|
||||
func diffDealProposals(pre, cur DealProposals) (*DealProposalChanges, error) {
|
||||
func DiffDealProposals(pre, cur DealProposals) (*DealProposalChanges, error) {
|
||||
results := new(DealProposalChanges)
|
||||
if err := adt.DiffAdtArray(pre.array(), cur.array(), &marketProposalsDiffer{results, pre, cur}); err != nil {
|
||||
return nil, fmt.Errorf("diffing deal states: %w", err)
|
||||
@ -44,7 +44,7 @@ func (d *marketProposalsDiffer) Remove(key uint64, val *cbg.Deferred) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func diffDealStates(pre, cur DealStates) (*DealStateChanges, error) {
|
||||
func DiffDealStates(pre, cur DealStates) (*DealStateChanges, error) {
|
||||
results := new(DealStateChanges)
|
||||
if err := adt.DiffAdtArray(pre.array(), cur.array(), &marketStatesDiffer{results, pre, cur}); err != nil {
|
||||
return nil, fmt.Errorf("diffing deal states: %w", err)
|
@ -51,7 +51,6 @@ type BalanceTable interface {
|
||||
|
||||
type DealStates interface {
|
||||
Get(id abi.DealID) (*DealState, bool, error)
|
||||
Diff(DealStates) (*DealStateChanges, error)
|
||||
|
||||
array() adt.Array
|
||||
decode(*cbg.Deferred) (*DealState, error)
|
||||
@ -60,7 +59,6 @@ type DealStates interface {
|
||||
type DealProposals interface {
|
||||
ForEach(cb func(id abi.DealID, dp DealProposal) error) error
|
||||
Get(id abi.DealID) (*DealProposal, bool, error)
|
||||
Diff(DealProposals) (*DealProposalChanges, error)
|
||||
|
||||
array() adt.Array
|
||||
decode(*cbg.Deferred) (*DealProposal, error)
|
||||
|
@ -124,10 +124,6 @@ func (s *v0DealStates) Get(dealID abi.DealID) (*DealState, bool, error) {
|
||||
return &deal, true, nil
|
||||
}
|
||||
|
||||
func (s *v0DealStates) Diff(other DealStates) (*DealStateChanges, error) {
|
||||
return diffDealStates(s, other)
|
||||
}
|
||||
|
||||
func (s *v0DealStates) decode(val *cbg.Deferred) (*DealState, error) {
|
||||
var v0ds market.DealState
|
||||
if err := v0ds.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil {
|
||||
@ -149,10 +145,6 @@ type v0DealProposals struct {
|
||||
adt.Array
|
||||
}
|
||||
|
||||
func (s *v0DealProposals) Diff(other DealProposals) (*DealProposalChanges, error) {
|
||||
return diffDealProposals(s, other)
|
||||
}
|
||||
|
||||
func (s *v0DealProposals) Get(dealID abi.DealID) (*DealProposal, bool, error) {
|
||||
var v0proposal market.DealProposal
|
||||
found, err := s.Array.Get(uint64(dealID), &v0proposal)
|
||||
|
@ -175,7 +175,7 @@ func (sp *StatePredicates) OnDealProposalChanged(diffDealProps DiffDealProposals
|
||||
// - Removed Proposals
|
||||
func (sp *StatePredicates) OnDealProposalAmtChanged() DiffDealProposalsFunc {
|
||||
return func(ctx context.Context, oldDealProps, newDealProps market.DealProposals) (changed bool, user UserData, err error) {
|
||||
proposalChanges, err := oldDealProps.Diff(newDealProps)
|
||||
proposalChanges, err := market.DiffDealProposals(oldDealProps, newDealProps)
|
||||
if err != nil {
|
||||
return false, nil, err
|
||||
}
|
||||
@ -194,7 +194,7 @@ func (sp *StatePredicates) OnDealProposalAmtChanged() DiffDealProposalsFunc {
|
||||
// - Removed Deals
|
||||
func (sp *StatePredicates) OnDealStateAmtChanged() DiffDealStatesFunc {
|
||||
return func(ctx context.Context, oldDealStates, newDealStates market.DealStates) (changed bool, user UserData, err error) {
|
||||
dealStateChanges, err := oldDealStates.Diff(newDealStates)
|
||||
dealStateChanges, err := market.DiffDealStates(oldDealStates, newDealStates)
|
||||
if err != nil {
|
||||
return false, nil, err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user