Skip to content

Latest commit

 

History

History
43 lines (29 loc) · 1.37 KB

StructTypeNode.md

File metadata and controls

43 lines (29 loc) · 1.37 KB

StructTypeNode

A node representing an object or struct with named fields. Each field is represented by a dedicated StructFieldTypeNode. Each field is encoded and decoded in the order they are defined.

Attributes

Data

Attribute Type Description
kind "structTypeNode" The node discriminator.

Children

Attribute Type Description
fields StructFieldTypeNode[] The fields of the struct.

Functions

structTypeNode(fields)

Helper function that creates a StructTypeNode object from an array of StructFieldTypeNode objects.

const node = structTypeNode([
    structFieldTypeNode({ name: 'authority', type: publicKeyTypeNode() }),
    structFieldTypeNode({ name: 'amount', type: numberTypeNode('u64') }),
]);

Examples

A struct storing a person's name and age

structTypeNode([
    structFieldTypeNode({ name: 'name', type: fixedSizeTypeNode(stringTypeNode('utf8'), 10) }),
    structFieldTypeNode({ name: 'age', type: numberTypeNode('u8') }),
]);

// { name: Alice, age: 42 } => 0x416C69636500000000002A