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
).
Receipt
Helper Methodsβ
export class Receipt {
... // constructor omitted for brevity
get events(): Event[] {}
static fromOutcomeWithReceipt(outcomeWithReceipt: OutcomeWithReceipt): Receipt {}
}
Receipt.events(): Events[]
β
Returns an Array of Events
for the Receipt
, if any. This might be empty if the logs
field is empty or doesnβt contain JSON Events compatible log records.
Event
β
This structure is an ephemeral entity to provide access to the Events Standard structure and keep data about the related Receipt
for convenience.
Interface for Capturing Data About an Event in handleStreamerMessage()
β
The interface to capture data about an event has the following arguments:
standard
: name of standard, e.g. nep171version
: e.g. 1.0.0event
: type of the event, e.g. nft_mintdata
: associate event data. Strictly typed for each set{standard, version, event}
inside corresponding NEP
Event
Structure Definitionβ
export class Event {
constructor(
readonly relatedReceiptId: string,
readonly rawEvent: RawEvent) {
}
... // helper methods omitted for brevity
}
Event
Methodsβ
export class Event {
... // constructor omitted for brevity
static fromLog(log: string): Event {}
}
Transaction
β
A representation of the IndexerTransactionWithOutcome
from near-indexer-primitives
which is an ephemeral structure combining SignedTransactionView
from near-primitives
and IndexerExecutionOutcomeWithOptionalReceipt
from near-indexer-primitives
.
This structure is very similar to Receipt
. Unlike Receipt
, a Transaction
has a few additional fields like signerId
, signature
, and operations
.
Transaction
Structure Definitionβ
export class Transaction {
constructor(
readonly transactionHash: string,
readonly signerId: string,
readonly signerPublicKey: string,
readonly signature: string,
readonly receiverId: string,
readonly status: ExecutionStatus,
readonly executionOutcomeId: string,
readonly operations: Operation[]) {
}
}
Transaction.transactionHash
β
Returns the hash of the Transaction
in CryptoHash
.
Transaction.signerId
β
Returns the signer account id of the Transaction
.
Transaction.signerPublicKey
β
Returns the PublicKey
of the signer of the Transaction
.
Transaction.signature
β
Returns the Signature
the Transaction
was signed with.
Transaction.receiverId
β
Returns the receiver account id of the Transaction
.
Transaction.status
β
Returns the status of the Transaction
as ExecutionStatus
.
Transaction.executionOutcomeId
β
Returns the id of the ExecutionOutcome
for the Transaction
.
Transaction.operations
β
Returns an Array of Operation
for the Transaction
.
StateChange
β
This structure is almost an identical copy of the StateChangeWithCauseView
from near-primitives
with a propagated additional field affectedAccountId
.
StateChange
Structure Definitionβ
export class StateChange {
constructor(
readonly cause: StateChangeCause,
readonly value: StateChangeValue
) {}
get affectedAccountId(): string {}
static fromStateChangeView(stateChangeView: StateChangeWithCauseView) {}
}
StateChange.cause
β
Returns the cause
of the StateChange
.
StateChange.value
β
Returns the value
of the StateChange
.
StateChange.affectedAccountId(): string
β
Returns the account id of the StateChange
.
StateChange.fromStateChangeView(stateChangeView: StateChangeWithCauseView): StateChange
β
Returns the StateChange
from the StateChangeWithCauseView
. Created for backward compatibility.