container: add a delegation iterator
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
|||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"iter"
|
||||||
|
|
||||||
"github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
"github.com/ipld/go-ipld-prime"
|
"github.com/ipld/go-ipld-prime"
|
||||||
@@ -42,6 +43,19 @@ func (ctn Reader) GetDelegation(cid cid.Cid) (*delegation.Token, error) {
|
|||||||
return nil, fmt.Errorf("not a delegation token")
|
return nil, fmt.Errorf("not a delegation token")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetAllDelegations returns all the delegation.Token in the container.
|
||||||
|
func (ctn Reader) GetAllDelegations() iter.Seq2[cid.Cid, *delegation.Token] {
|
||||||
|
return func(yield func(cid.Cid, *delegation.Token) bool) {
|
||||||
|
for c, t := range ctn {
|
||||||
|
if t, ok := t.(*delegation.Token); ok {
|
||||||
|
if !yield(c, t) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// GetInvocation returns the first found invocation.Token.
|
// GetInvocation returns the first found invocation.Token.
|
||||||
// If none are found, ErrNotFound is returned.
|
// If none are found, ErrNotFound is returned.
|
||||||
func (ctn Reader) GetInvocation() (*invocation.Token, error) {
|
func (ctn Reader) GetInvocation() (*invocation.Token, error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user