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