-
Notifications
You must be signed in to change notification settings - Fork 178
/
collection.go
61 lines (50 loc) · 1.45 KB
/
collection.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package models
import (
"fmt"
"github.com/onflow/flow-go/engine/access/rest/util"
"github.com/onflow/flow-go/model/flow"
)
const ExpandsTransactions = "transactions"
func (c *Collection) Build(
collection *flow.LightCollection,
txs []*flow.TransactionBody,
link LinkGenerator,
expand map[string]bool) error {
self, err := SelfLink(collection.ID(), link.CollectionLink)
if err != nil {
return err
}
var expandable CollectionExpandable
var transactions Transactions
if expand[ExpandsTransactions] {
transactions.Build(txs, link)
} else {
expandable.Transactions = make([]string, len(collection.Transactions))
for i, tx := range collection.Transactions {
expandable.Transactions[i], err = link.TransactionLink(tx)
if err != nil {
return err
}
}
}
c.Id = collection.ID().String()
c.Transactions = transactions
c.Links = self
c.Expandable = &expandable
return nil
}
func (c *CollectionGuarantee) Build(guarantee *flow.CollectionGuarantee) {
c.CollectionId = guarantee.CollectionID.String()
c.SignerIndices = fmt.Sprintf("%x", guarantee.SignerIndices)
c.Signature = util.ToBase64(guarantee.Signature.Bytes())
}
type CollectionGuarantees []CollectionGuarantee
func (c *CollectionGuarantees) Build(guarantees []*flow.CollectionGuarantee) {
collGuarantees := make([]CollectionGuarantee, len(guarantees))
for i, g := range guarantees {
var col CollectionGuarantee
col.Build(g)
collGuarantees[i] = col
}
*c = collGuarantees
}