Skip to content

Commit

Permalink
bubble up errors
Browse files Browse the repository at this point in the history
  • Loading branch information
lalexgap committed May 11, 2023
1 parent fa91d1c commit 79d5878
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 20 deletions.
36 changes: 23 additions & 13 deletions client/engine/store/durablestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,26 +306,31 @@ func (ds *DurableStore) GetChannelsByIds(ids []types.Destination) ([]*channel.Ch
}

// GetChannelsByAppDefinition returns any channels that include the given app definition
func (ds *DurableStore) GetChannelsByAppDefinition(appDef types.Address) []*channel.Channel {
func (ds *DurableStore) GetChannelsByAppDefinition(appDef types.Address) ([]*channel.Channel, error) {
toReturn := []*channel.Channel{}
var unmarshErr error
err := ds.channels.View(func(tx *buntdb.Tx) error {
err := tx.Ascend("", func(key, chJSON string) bool {
return tx.Ascend("", func(key, chJSON string) bool {
var ch channel.Channel
err := json.Unmarshal([]byte(chJSON), &ch)
if err != nil {
ds.checkError(err)
unmarshErr = json.Unmarshal([]byte(chJSON), &ch)
if unmarshErr != nil {
return false
}

if ch.AppDefinition == appDef {
toReturn = append(toReturn, &ch)
}

return true // channel not found: continue looking
return true
})
return err
})
ds.checkError(err)
return toReturn
if err != nil {
return []*channel.Channel{}, err
}
if unmarshErr != nil {
return []*channel.Channel{}, unmarshErr
}
return toReturn, nil
}

// GetChannelsByParticipant returns any channels that include the given participant
Expand Down Expand Up @@ -356,21 +361,26 @@ func (ds *DurableStore) GetChannelsByParticipant(participant types.Address) []*c

func (ds *DurableStore) GetAllConsensusChannels() ([]*consensus_channel.ConsensusChannel, error) {
toReturn := []*consensus_channel.ConsensusChannel{}
var unmarshErr error
err := ds.consensusChannels.View(func(tx *buntdb.Tx) error {
return tx.Ascend("", func(key, chJSON string) bool {
var ch consensus_channel.ConsensusChannel

err := json.Unmarshal([]byte(chJSON), &ch)
if err != nil {
ds.checkError(err)
unmarshErr = json.Unmarshal([]byte(chJSON), &ch)
if unmarshErr != nil {
return false
}
toReturn = append(toReturn, &ch)
return true // channel not found: continue looking
return true
})
})
if err != nil {
return []*consensus_channel.ConsensusChannel{}, err
}

if unmarshErr != nil {
return []*consensus_channel.ConsensusChannel{}, unmarshErr
}
return toReturn, nil
}

Expand Down
13 changes: 9 additions & 4 deletions client/engine/store/memstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,14 @@ func (ms *MemStore) GetChannelsByIds(ids []types.Destination) ([]*channel.Channe
}

// GetChannelsByAppDefinition returns any channels that include the given app definition
func (ms *MemStore) GetChannelsByAppDefinition(appDef types.Address) []*channel.Channel {
func (ms *MemStore) GetChannelsByAppDefinition(appDef types.Address) ([]*channel.Channel, error) {
toReturn := []*channel.Channel{}
var err error
ms.channels.Range(func(key string, chJSON []byte) bool {
var ch channel.Channel
err := json.Unmarshal(chJSON, &ch)
err = json.Unmarshal(chJSON, &ch)
if err != nil {
return true // channel not found, continue looking
return false
}
if ch.AppDefinition == appDef {
toReturn = append(toReturn, &ch)
Expand All @@ -226,7 +227,11 @@ func (ms *MemStore) GetChannelsByAppDefinition(appDef types.Address) []*channel.
return true // channel not found: continue looking
})

return toReturn
if err != nil {
return []*channel.Channel{}, err
}

return toReturn, nil
}

// GetChannelsByParticipant returns any channels that include the given participant
Expand Down
4 changes: 2 additions & 2 deletions client/engine/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ type Store interface {
GetChannelsByParticipant(participant types.Address) []*channel.Channel // Returns any channels that includes the given participant
SetChannel(*channel.Channel) error
DestroyChannel(id types.Destination)
GetChannelsByAppDefinition(appDef types.Address) []*channel.Channel // Returns any channels that includes the given app definition
ReleaseChannelFromOwnership(types.Destination) // Release channel from being owned by any objective
GetChannelsByAppDefinition(appDef types.Address) ([]*channel.Channel, error) // Returns any channels that includes the given app definition
ReleaseChannelFromOwnership(types.Destination) // Release channel from being owned by any objective

ConsensusChannelStore
payments.VoucherStore
Expand Down
5 changes: 4 additions & 1 deletion client/query/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ func GetAllLedgerChannels(store store.Store, consensusAppDefinition types.Addres
for _, con := range allConsensus {
toReturn = append(toReturn, ConstructLedgerInfoFromConsensus(con))
}
allChannels := store.GetChannelsByAppDefinition(consensusAppDefinition)
allChannels, err := store.GetChannelsByAppDefinition(consensusAppDefinition)
if err != nil {
return []LedgerChannelInfo{}, err
}
for _, c := range allChannels {
toReturn = append(toReturn, ConstructLedgerInfoFromChannel(c))
}
Expand Down

0 comments on commit 79d5878

Please sign in to comment.