From 46fb0e74cd3d23c5fd0c49c2022106839dbb6051 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Tue, 22 Sep 2020 14:09:33 -0700 Subject: [PATCH] add deal state iterator --- chain/actors/builtin/market/market.go | 1 + chain/actors/builtin/market/v0.go | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/chain/actors/builtin/market/market.go b/chain/actors/builtin/market/market.go index fa5f027b3..9cb0ffc13 100644 --- a/chain/actors/builtin/market/market.go +++ b/chain/actors/builtin/market/market.go @@ -50,6 +50,7 @@ type BalanceTable interface { } type DealStates interface { + ForEach(cb func(id abi.DealID, ds DealState) error) error Get(id abi.DealID) (*DealState, bool, error) array() adt.Array diff --git a/chain/actors/builtin/market/v0.go b/chain/actors/builtin/market/v0.go index 433445dab..14b8b7d93 100644 --- a/chain/actors/builtin/market/v0.go +++ b/chain/actors/builtin/market/v0.go @@ -126,6 +126,13 @@ func (s *dealStates0) Get(dealID abi.DealID) (*DealState, bool, error) { return &deal, true, nil } +func (s *dealStates0) ForEach(cb func(dealID abi.DealID, ds DealState) error) error { + var ds0 market.DealState + return s.Array.ForEach(&ds0, func(idx int64) error { + return cb(abi.DealID(idx), fromV0DealState(ds0)) + }) +} + func (s *dealStates0) decode(val *cbg.Deferred) (*DealState, error) { var ds0 market.DealState if err := ds0.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil {