Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FromBase64 ¶
FromBase64 convert input base64 encoded string to decoded bytes
func SelectFilter ¶
SelectFilter selects the specified keys from the given object. The keys are in the json dot notation and must refer to leaf elements e.g. payload.collection_guarantees.signer_ids
Example ¶
package main import ( "encoding/json" "fmt" "time" "github.com/onflow/flow-go/engine/access/rest/models" "github.com/onflow/flow-go/engine/access/rest/util" ) func main() { blocks := make([]models.Block, 2) for i := range blocks { block, err := generateBlock() if err != nil { fmt.Println(err) return } blocks[i] = block } selectKeys := []string{ "header.id", "payload.collection_guarantees.signature", "payload.block_seals.aggregated_approval_signatures.signer_ids", "payload.collection_guarantees.signer_ids", "execution_result.events.event_index", "something.nonexisting", } filteredBlock, err := util.SelectFilter(blocks, selectKeys) if err != nil { fmt.Println(err) return } marshalled, err := json.MarshalIndent(filteredBlock, "", "\t") if err != nil { panic(err.Error()) } fmt.Println(string(marshalled)) } func generateBlock() (models.Block, error) { dummySignature := "abcdef0123456789" multipleDummySignatures := []string{dummySignature, dummySignature} dummyID := "abcd" dateString := "2021-11-20T11:45:26.371Z" t, err := time.Parse(time.RFC3339, dateString) if err != nil { return models.Block{}, err } return models.Block{ Header: &models.BlockHeader{ Id: dummyID, ParentId: dummyID, Height: "100", Timestamp: t, ParentVoterSignature: dummySignature, }, Payload: &models.BlockPayload{ CollectionGuarantees: []models.CollectionGuarantee{ { CollectionId: "abcdef0123456789", SignerIds: multipleDummySignatures, Signature: dummySignature, }, }, BlockSeals: []models.BlockSeal{ { BlockId: dummyID, ResultId: dummyID, FinalState: "final", AggregatedApprovalSignatures: []models.AggregatedSignature{ { VerifierSignatures: multipleDummySignatures, SignerIds: multipleDummySignatures, }, }, }, }, }, ExecutionResult: &models.ExecutionResult{ Id: dummyID, BlockId: dummyID, Events: []models.Event{ { Type_: "type", TransactionId: dummyID, TransactionIndex: "1", EventIndex: "2", Payload: "payload", }, { Type_: "type", TransactionId: dummyID, TransactionIndex: "1", EventIndex: "3", Payload: "payload", }, }, Links: &models.Links{ Self: "link", }, }, }, nil }
Output: [ { "execution_result": { "events": [ { "event_index": "2" }, { "event_index": "3" } ] }, "header": { "id": "abcd" }, "payload": { "block_seals": [ { "aggregated_approval_signatures": [ { "signer_ids": [ "abcdef0123456789", "abcdef0123456789" ] } ] } ], "collection_guarantees": [ { "signature": "abcdef0123456789", "signer_ids": [ "abcdef0123456789", "abcdef0123456789" ] } ] } }, { "execution_result": { "events": [ { "event_index": "2" }, { "event_index": "3" } ] }, "header": { "id": "abcd" }, "payload": { "block_seals": [ { "aggregated_approval_signatures": [ { "signer_ids": [ "abcdef0123456789", "abcdef0123456789" ] } ] } ], "collection_guarantees": [ { "signature": "abcdef0123456789", "signer_ids": [ "abcdef0123456789", "abcdef0123456789" ] } ] } } ]
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.