NEAR Lake Primitive Types
This article contains the primitive types used by the NEAR Lake Framework package. These types are used to define the data structures used by the framework as well as provide some popular helper functions.
Block
β
Block
- All the entities located on different shards were merged into one single list without differentiation.
Block
is not the fairest name for this structure either. NEAR Protocol is a sharded blockchain, so its block is actually an ephemeral structure that represents a collection of real blocks called chunks in NEAR Protocol.
Block
Structure Definitionβ
The Block
type is used to represent a block in the NEAR Lake Framework. It is comprised by the following structure:
export class Block {
constructor(
readonly streamerMessage: StreamerMessage,
private executedReceipts: Receipt[],
readonly postponedReceipts: Receipt[],
readonly transactions: Transaction[],
private _actions: Map<string, Action>,
private _events: Map<string, Event[]>,
private _stateChanges: StateChange[]) {
}
... // helper methods and getters omitted for brevity
}
streamerMessage
β
Low-level structure for backward compatibility. As implemented in previous versions of near-lake-framework
.
postponedReceipts
β
Receipts included on the chain but not executed yet marked as βpostponedβ: they are represented by the same structure Receipt
(see the corresponding section in this doc for more details).
transactions
β
List of included Transactions
, converted into Receipts
.
Note: You might want to know about Transactions
to know where the action chain has begun. Unlike Ethereum, where a Transaction contains everything you may want to know about a particular interaction on the Ethereum blockchain, Near Protocol because of its asynchronous nature converts a Transaction
into a Receipt
before executing it. Thus, On NEAR, Receipts
are more important for figuring out what happened on-chain as a result of a Transaction signed by a user. Read more about Transactions on Near here.
Block
Helper Methodsβ
export class Block {
... // constructor omitted for brevity
get blockHash(): string {}
get prevBlockHash(): string {}
get blockHeight(): number {}
header(): BlockHeader {}
receipts(): Receipt[] {}
actions(): Action[] {}
events(): Event[] {}
stateChanges(): StateChange[] {}
actionByReceiptId(receipt_id: string): Action | undefined {}
eventsByReceiptId(receipt_id: string): Event[] {}
eventsByAccountId(account_id: string): Event[] {}
private buildActionsHashmap() {}
private buildEventsHashmap(): Map<string, Event[]> {}
static fromStreamerMessage(streamerMessage: StreamerMessage): Block {}
}
blockHash
β
Returns the block hash. A shortcut to get the data from the block header.
prevBlockHash
β
Returns the previous block hash. A shortcut to get the data from the block header.
blockHeight
β
Returns the block height. A shortcut to get the data from the block header.
header(): BlockHeader
β
Returns a BlockHeader
structure of the block
See BlockHeader
structure sections for details.
receipts(): Receipt[]
β
Returns a slice of Receipts
executed in the block.
Basically is a getter for the executedReceipts
field.
actions(): Action[]
β
Returns an Array of Actions
executed in the block.
events(): Event[]
β
Returns Events
emitted in the block.
stateChanges(): StateChange[]
β
Returns an Array of StateChange
occurred in the block.
actionByReceiptId(receipt_id: string): Action | undefined
β
Returns Action
s of the provided receipt_id
from the block if any. Returns undefined
if there is no corresponding Action
.
This method uses the internal Block
action
field which is empty by default and will be filled with the blockβs actions on the first call to optimize memory usage.
The result is either Action | undefined
since there might be a request for an Action
by receipt_id
from another block, in which case this method will be unable to find the Action
in the current block. In the other case, the request might be for an Action
for a receipt_id
that belongs to a DataReceipt
where an action does not exist.
eventsByReceiptId(receipt_id: string): Event[]
β
Returns an Array of Events emitted by ExecutionOutcome
for the given receipt_id
. There might be more than one Event
for the Receipt
or there might be none of them. In the latter case, this method returns an empty Array.
eventsByAccountId(account_id: string): Event[]
β
Returns an Array of Events emitted by ExecutionOutcome
for the given account_id
. There might be more than one Event
for the Receipt
or there might be none of them. In the latter case, this method returns an empty Array.
BlockHeader
β
Replacement for BlockHeaderView
from near-primitives
. Shrunken and simplified.
The original BlockHeaderView
is still accessible via the .streamerMessage
attribute.
BlockHeader
Structure Definitionβ
export class BlockHeader {
constructor(
readonly height: number,
readonly hash: string,
readonly prevHash: string,
readonly author: string,
readonly timestampNanosec: string,
readonly epochId: string,
readonly nextEpochId: string,
readonly gasPrice: string,
readonly totalSupply: string,
readonly latestProtocolVersion: number,
readonly randomValue: string,
readonly chunksIncluded: number,
readonly validatorProposals: ValidatorStakeView[]) {
}
... // helper method omitted for brevity
}
Receipt
β
This field is a simplified representation of the ReceiptView
structure from near-primitives
.
Receipt
Structure Definitionβ
export class Receipt implements Events {
constructor(
readonly receiptKind: ReceiptKind,
readonly receiptId: string,
readonly receiverId: string,
readonly predecessorId: string,
readonly status: ExecutionStatus,
readonly executionOutcomeId?: string | undefined,
readonly logs: string[] = []) {
}
... // helper methods omitted for brevity
}
Receipt
Fieldsβ
receiptKind
β
Defined the type of the Receipt
: Action
or Data
representing the ActionReceipt
and DataReceipt
.
receiptId
β
The ID of the Receipt
of the CryptoHash
type.
receiverId
β
The receiver account id of the Receipt
.
predecessorId
β
The predecessor account id of the Receipt
.
status
β
Represents the status of ExecutionOutcome
of the Receipt
.
See the ExecutionStatus
enum section for the details.
executionOutcomeId
β
The id of the ExecutionOutcome
for the Receipt
. Returns null
if the Receipt
isnβt executed yet and has a postponed status.
logs
β
The original logs of the corresponding ExecutionOutcome
of the Receipt
.
Note: not all of the logs might be parsed as JSON Events (Events
).