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