convert

package
v0.36.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 24, 2024 License: AGPL-3.0 Imports: 18 Imported by: 19

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptyMessage = errors.New("protobuf message is empty")
View Source
var ValidChainIds = map[string]bool{
	flow.Mainnet.String():           true,
	flow.Testnet.String():           true,
	flow.Sandboxnet.String():        true,
	flow.Previewnet.String():        true,
	flow.Benchnet.String():          true,
	flow.Localnet.String():          true,
	flow.Emulator.String():          true,
	flow.BftTestnet.String():        true,
	flow.MonotonicEmulator.String(): true,
}

Functions

func AccountKeyToMessage

func AccountKeyToMessage(a flow.AccountPublicKey) (*entities.AccountKey, error)

AccountKeyToMessage converts a flow.AccountPublicKey to a protobuf message

func AccountToMessage

func AccountToMessage(a *flow.Account) (*entities.Account, error)

AccountToMessage converts a flow.Account to a protobuf message

func Address

func Address(rawAddress []byte, chain flow.Chain) (flow.Address, error)

Address validates the input address and returns a Flow address if valid and error otherwise

func AggregatedSignaturesToMessages added in v0.24.8

func AggregatedSignaturesToMessages(a []flow.AggregatedSignature) []*entities.AggregatedSignature

AggregatedSignaturesToMessages converts a slice of AggregatedSignature structs to a corresponding slice of protobuf messages

func BlockEventsToMessage added in v0.32.0

func BlockEventsToMessage(block flow.BlockEvents) (*accessproto.EventsResponse_Result, error)

func BlockEventsToMessages added in v0.32.0

func BlockEventsToMessages(blocks []flow.BlockEvents) ([]*accessproto.EventsResponse_Result, error)

func BlockExecutionDataEventPayloadsToVersion added in v0.32.7

func BlockExecutionDataEventPayloadsToVersion(
	m *entities.BlockExecutionData,
	to entities.EventEncodingVersion,
) error

BlockExecutionDataEventPayloadsToVersion converts all event payloads to version

func BlockExecutionDataToMessage added in v0.29.0

func BlockExecutionDataToMessage(data *execution_data.BlockExecutionData) (
	*entities.BlockExecutionData,
	error,
)

BlockExecutionDataToMessage converts a BlockExecutionData to a protobuf message

func BlockHeaderToMessage

func BlockHeaderToMessage(
	h *flow.Header,
	signerIDs flow.IdentifierList,
) (*entities.BlockHeader, error)

BlockHeaderToMessage converts a flow.Header to a protobuf message

func BlockID

func BlockID(blockID []byte) (flow.Identifier, error)

func BlockIDs

func BlockIDs(blockIDs [][]byte) ([]flow.Identifier, error)

func BlockSealToMessage added in v0.24.8

func BlockSealToMessage(s *flow.Seal) *entities.BlockSeal

BlockSealToMessage converts a flow.Seal to a protobuf BlockSeal message.

func BlockSealsToMessages added in v0.24.8

func BlockSealsToMessages(b []*flow.Seal) []*entities.BlockSeal

BlockSealsToMessages converts a slice of flow.Seal to a slice of protobuf BlockSeal messages.

func BlockToMessage

func BlockToMessage(h *flow.Block, signerIDs flow.IdentifierList) (
	*entities.Block,
	error,
)

BlockToMessage converts a flow.Block to a protobuf Block message. signerIDs is a precomputed list of signer IDs for the block based on the block's signer indicies.

func BlockToMessageLight added in v0.24.8

func BlockToMessageLight(h *flow.Block) *entities.Block

BlockToMessageLight converts a flow.Block to the light form of a protobuf Block message.

func BytesToInmemSnapshot added in v0.15.0

func BytesToInmemSnapshot(bytes []byte) (*inmem.Snapshot, error)

BytesToInmemSnapshot converts an array of bytes to `inmem.Snapshot`

func CcfEventToJsonEvent added in v0.31.0

func CcfEventToJsonEvent(e flow.Event) (*flow.Event, error)

CcfEventToJsonEvent returns a new event with the payload converted from CCF to JSON

func CcfEventsToJsonEvents added in v0.33.13

func CcfEventsToJsonEvents(events []flow.Event) ([]flow.Event, error)

CcfEventsToJsonEvents returns a new event with the payload converted from CCF to JSON

func CcfPayloadToJsonPayload added in v0.31.0

func CcfPayloadToJsonPayload(p []byte) ([]byte, error)

CcfPayloadToJsonPayload converts a CCF-encoded payload to a JSON-encoded payload

func ChunkExecutionDataToMessage added in v0.29.0

func ChunkExecutionDataToMessage(data *execution_data.ChunkExecutionData) (
	*entities.ChunkExecutionData,
	error,
)

ChunkExecutionDataToMessage converts a ChunkExecutionData to a protobuf message

func ChunkToMessage added in v0.24.8

func ChunkToMessage(chunk *flow.Chunk) *entities.Chunk

ChunkToMessage converts a chunk to a protobuf message

func CollectionGuaranteeToMessage added in v0.24.8

func CollectionGuaranteeToMessage(g *flow.CollectionGuarantee) *entities.CollectionGuarantee

CollectionGuaranteeToMessage converts a collection guarantee to a protobuf message

func CollectionGuaranteesToMessages added in v0.24.8

func CollectionGuaranteesToMessages(c []*flow.CollectionGuarantee) []*entities.CollectionGuarantee

CollectionGuaranteesToMessages converts a slice of collection guarantees to a slice of protobuf messages

func CollectionID

func CollectionID(collectionID []byte) (flow.Identifier, error)

func CollectionToMessage

func CollectionToMessage(c *flow.Collection) (*entities.Collection, error)

CollectionToMessage converts a collection to a protobuf message

func EventToMessage

func EventToMessage(e flow.Event) *entities.Event

EventToMessage converts a flow.Event to a protobuf message Note: this function does not convert the payload encoding

func EventToMessageFromVersion added in v0.31.11

func EventToMessageFromVersion(e flow.Event, version entities.EventEncodingVersion) (*entities.Event, error)

EventToMessageFromVersion converts a flow.Event to a protobuf message, converting the payload encoding from CCF to JSON if the input version is CCF

func EventType

func EventType(eventType string) (string, error)

func EventsToMessages

func EventsToMessages(flowEvents []flow.Event) []*entities.Event

EventsToMessages converts a slice of flow.Events to a slice of protobuf messages Note: this function does not convert the payload encoding

func EventsToMessagesWithEncodingConversion added in v0.32.7

func EventsToMessagesWithEncodingConversion(
	flowEvents []flow.Event,
	from entities.EventEncodingVersion,
	to entities.EventEncodingVersion,
) ([]*entities.Event, error)

EventsToMessagesWithEncodingConversion converts a slice of flow.Events to a slice of protobuf messages, converting the payload encoding from CCF to JSON if the input version is CCF

func ExecutionResultMetaListToMessages added in v0.24.8

func ExecutionResultMetaListToMessages(e flow.ExecutionReceiptMetaList) []*entities.ExecutionReceiptMeta

ExecutionResultMetaListToMessages converts an execution result meta list to a slice of protobuf messages

func ExecutionResultToMessage added in v0.24.8

func ExecutionResultToMessage(er *flow.ExecutionResult) (
	*entities.ExecutionResult,
	error,
)

ExecutionResultToMessage converts an execution result to a protobuf message

func ExecutionResultsToMessages added in v0.24.8

func ExecutionResultsToMessages(e []*flow.ExecutionResult) (
	[]*entities.ExecutionResult,
	error,
)

ExecutionResultsToMessages converts a slice of execution results to a slice of protobuf messages

func FullCollectionToMessage added in v0.33.26

func FullCollectionToMessage(c *flow.Collection) ([]*entities.Transaction, error)

func HexToAddress added in v0.32.10

func HexToAddress(hexAddress string, chain flow.Chain) (flow.Address, error)

func IdentifierToMessage

func IdentifierToMessage(i flow.Identifier) []byte

IdentifierToMessage converts a flow.Identifier to a byte slice for inclusion in a protobuf message

func IdentifiersToMessages

func IdentifiersToMessages(l []flow.Identifier) [][]byte

IdentifiersToMessages converts a slice of flow.Identifiers to a slice of byte slices for inclusion in a protobuf message

func LightCollectionToMessage

func LightCollectionToMessage(c *flow.LightCollection) (*entities.Collection, error)

LightCollectionToMessage converts a light collection to a protobuf message

func MessageToAccount

func MessageToAccount(m *entities.Account) (*flow.Account, error)

MessageToAccount converts a protobuf message to a flow.Account

func MessageToAccountKey

func MessageToAccountKey(m *entities.AccountKey) (*flow.AccountPublicKey, error)

MessageToAccountKey converts a protobuf message to a flow.AccountPublicKey

func MessageToBlock added in v0.24.8

func MessageToBlock(m *entities.Block) (*flow.Block, error)

MessageToBlock converts a protobuf Block message to a flow.Block.

func MessageToBlockEvents added in v0.32.0

func MessageToBlockEvents(blockEvents *accessproto.EventsResponse_Result) flow.BlockEvents

MessageToBlockEvents converts a protobuf EventsResponse_Result message to a flow.BlockEvents.

func MessageToBlockExecutionData added in v0.29.0

func MessageToBlockExecutionData(
	m *entities.BlockExecutionData,
	chain flow.Chain,
) (*execution_data.BlockExecutionData, error)

MessageToBlockExecutionData converts a protobuf message to a BlockExecutionData

func MessageToBlockHeader added in v0.24.8

func MessageToBlockHeader(m *entities.BlockHeader) (*flow.Header, error)

MessageToBlockHeader converts a protobuf message to a flow.Header

func MessageToBlockSeal added in v0.24.8

func MessageToBlockSeal(m *entities.BlockSeal) (*flow.Seal, error)

MessageToBlockSeal converts a protobuf BlockSeal message to a flow.Seal.

func MessageToBlockStatus added in v0.33.30

func MessageToBlockStatus(status entities.BlockStatus) flow.BlockStatus

MessageToBlockStatus converts a protobuf BlockStatus message to a flow.BlockStatus.

func MessageToChainId added in v0.24.8

func MessageToChainId(m string) (*flow.ChainID, error)

MessageToChainId converts the chainID from a protobuf message to a flow.ChainID It returns an error if the value is not a valid chainId

func MessageToChunk added in v0.24.8

func MessageToChunk(m *entities.Chunk) (*flow.Chunk, error)

MessageToChunk converts a protobuf message to a chunk

func MessageToChunkExecutionData added in v0.29.0

func MessageToChunkExecutionData(
	m *entities.ChunkExecutionData,
	chain flow.Chain,
) (*execution_data.ChunkExecutionData, error)

MessageToChunkExecutionData converts a protobuf message to a ChunkExecutionData

func MessageToCollectionGuarantee added in v0.24.8

func MessageToCollectionGuarantee(m *entities.CollectionGuarantee) *flow.CollectionGuarantee

MessageToCollectionGuarantee converts a protobuf message to a collection guarantee

func MessageToEvent

func MessageToEvent(m *entities.Event) flow.Event

MessageToEvent converts a protobuf message to a flow.Event Note: this function does not convert the payload encoding

func MessageToEventFromVersion added in v0.31.0

func MessageToEventFromVersion(m *entities.Event, inputVersion entities.EventEncodingVersion) (*flow.Event, error)

MessageToEventFromVersion converts a protobuf message to a flow.Event, and converts the payload encoding from CCF to JSON if the input version is CCF

func MessageToExecutionResult added in v0.24.8

func MessageToExecutionResult(m *entities.ExecutionResult) (
	*flow.ExecutionResult,
	error,
)

MessageToExecutionResult converts a protobuf message to an execution result

func MessageToFullCollection added in v0.33.26

func MessageToFullCollection(m []*entities.Transaction, chain flow.Chain) (*flow.Collection, error)

func MessageToIdentifier

func MessageToIdentifier(b []byte) flow.Identifier

MessageToIdentifier converts a byte slice from a protobuf message to a flow.Identifier

func MessageToLightCollection added in v0.32.0

func MessageToLightCollection(m *entities.Collection) (*flow.LightCollection, error)

MessageToLightCollection converts a protobuf message to a light collection

func MessageToRegisterID added in v0.32.10

func MessageToRegisterID(m *entities.RegisterID, chain flow.Chain) (flow.RegisterID, error)

func MessageToServiceEvent added in v0.24.8

func MessageToServiceEvent(m *entities.ServiceEvent) (*flow.ServiceEvent, error)

MessageToServiceEvent converts a protobuf message to a flow.ServiceEvent

func MessageToSignature added in v0.24.8

func MessageToSignature(m []byte) crypto.Signature

MessageToSignature converts a byte slice from a protobuf message to a crypto.Signature

func MessageToStateCommitment added in v0.21.0

func MessageToStateCommitment(bytes []byte) (sc flow.StateCommitment, err error)

MessageToStateCommitment converts a byte slice from a protobuf message to a flow.StateCommitment

func MessageToTransaction

func MessageToTransaction(
	m *entities.Transaction,
	chain flow.Chain,
) (flow.TransactionBody, error)

MessageToTransaction converts a protobuf message to a flow.TransactionBody

func MessageToTrieUpdate added in v0.29.12

func MessageToTrieUpdate(m *entities.TrieUpdate) (*ledger.TrieUpdate, error)

MessageToTrieUpdate converts a protobuf message to a TrieUpdate

func MessagesToAggregatedSignatures added in v0.24.8

func MessagesToAggregatedSignatures(m []*entities.AggregatedSignature) []flow.AggregatedSignature

MessagesToAggregatedSignatures converts a slice of protobuf messages to their corresponding AggregatedSignature structs

func MessagesToBlockEvents added in v0.32.0

func MessagesToBlockEvents(blocksEvents []*accessproto.EventsResponse_Result) []flow.BlockEvents

MessagesToBlockEvents converts a protobuf EventsResponse_Result messages to a slice of flow.BlockEvents.

func MessagesToBlockSeals added in v0.24.8

func MessagesToBlockSeals(m []*entities.BlockSeal) ([]*flow.Seal, error)

MessagesToBlockSeals converts a slice of protobuf BlockSeal messages to a slice of flow.Seal.

func MessagesToChunkList added in v0.24.8

func MessagesToChunkList(m []*entities.Chunk) (flow.ChunkList, error)

MessagesToChunkList converts a slice of protobuf messages to a chunk list

func MessagesToCollectionGuarantees added in v0.24.8

func MessagesToCollectionGuarantees(m []*entities.CollectionGuarantee) []*flow.CollectionGuarantee

MessagesToCollectionGuarantees converts a slice of protobuf messages to a slice of collection guarantees

func MessagesToEvents

func MessagesToEvents(l []*entities.Event) []flow.Event

MessagesToEvents converts a slice of protobuf messages to a slice of flow.Events Note: this function does not convert the payload encoding

func MessagesToEventsWithEncodingConversion added in v0.32.7

func MessagesToEventsWithEncodingConversion(
	messageEvents []*entities.Event,
	from entities.EventEncodingVersion,
	to entities.EventEncodingVersion,
) ([]flow.Event, error)

MessagesToEventsWithEncodingConversion converts a slice of protobuf messages to a slice of flow.Events, converting the payload encoding from CCF to JSON if the input version is CCF

func MessagesToExecutionResultMetaList added in v0.24.8

func MessagesToExecutionResultMetaList(m []*entities.ExecutionReceiptMeta) flow.ExecutionReceiptMetaList

MessagesToExecutionResultMetaList converts a slice of protobuf messages to an execution result meta list

func MessagesToExecutionResults added in v0.24.8

func MessagesToExecutionResults(m []*entities.ExecutionResult) (
	[]*flow.ExecutionResult,
	error,
)

MessagesToExecutionResults converts a slice of protobuf messages to a slice of execution results

func MessagesToIdentifiers

func MessagesToIdentifiers(l [][]byte) []flow.Identifier

MessagesToIdentifiers converts a slice of byte slices from a protobuf message to a slice of flow.Identifiers

func MessagesToRegisterIDs added in v0.32.10

func MessagesToRegisterIDs(m []*entities.RegisterID, chain flow.Chain) (flow.RegisterIDs, error)

MessagesToRegisterIDs converts a protobuf message to RegisterIDs

func MessagesToServiceEventList added in v0.24.8

func MessagesToServiceEventList(m []*entities.ServiceEvent) (
	flow.ServiceEventList,
	error,
)

MessagesToServiceEventList converts a slice of flow.ServiceEvents to a slice of protobuf messages

func MessagesToSignatures added in v0.24.8

func MessagesToSignatures(m [][]byte) []crypto.Signature

MessagesToSignatures converts a slice of byte slices from a protobuf message to a slice of crypto.Signatures

func PayloadFromMessage added in v0.24.8

func PayloadFromMessage(m *entities.Block) (*flow.Payload, error)

PayloadFromMessage converts a protobuf Block message to a flow.Payload.

func RegisterIDToMessage added in v0.32.10

func RegisterIDToMessage(id flow.RegisterID) *entities.RegisterID

func ServiceEventListToMessages added in v0.32.0

func ServiceEventListToMessages(list flow.ServiceEventList) (
	[]*entities.ServiceEvent,
	error,
)

ServiceEventListToMessages converts a slice of flow.ServiceEvents to a slice of protobuf messages

func ServiceEventToMessage added in v0.24.8

func ServiceEventToMessage(event flow.ServiceEvent) (*entities.ServiceEvent, error)

ServiceEventToMessage converts a flow.ServiceEvent to a protobuf message

func SignatureToMessage added in v0.24.8

func SignatureToMessage(s crypto.Signature) []byte

SignatureToMessage converts a crypto.Signature to a byte slice for inclusion in a protobuf message

func SignaturesToMessages added in v0.24.8

func SignaturesToMessages(s []crypto.Signature) [][]byte

SignaturesToMessages converts a slice of crypto.Signatures to a slice of byte slices for inclusion in a protobuf message

func SnapshotToBytes added in v0.15.0

func SnapshotToBytes(snapshot protocol.Snapshot) ([]byte, error)

SnapshotToBytes converts a `protocol.Snapshot` to bytes, encoded as JSON

func StateCommitmentToMessage added in v0.21.0

func StateCommitmentToMessage(s flow.StateCommitment) []byte

StateCommitmentToMessage converts a flow.StateCommitment to a byte slice for inclusion in a protobuf message

func TransactionID

func TransactionID(txID []byte) (flow.Identifier, error)

func TransactionToMessage

func TransactionToMessage(tb flow.TransactionBody) *entities.Transaction

TransactionToMessage converts a flow.TransactionBody to a protobuf message

func TransactionsToMessages added in v0.24.11

func TransactionsToMessages(transactions []*flow.TransactionBody) []*entities.Transaction

TransactionsToMessages converts a slice of flow.TransactionBody to a slice of protobuf messages

func TrieUpdateToMessage added in v0.31.14

func TrieUpdateToMessage(t *ledger.TrieUpdate) (*entities.TrieUpdate, error)

TrieUpdateToMessage converts a TrieUpdate to a protobuf message

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL