Type Alias: CairoTypeStrategy
CairoTypeStrategy =
object
Defined in: src/utils/calldata/parser/cairoTypeStrategy.type.ts:38
How to build a Cairo type from an abi type, and how to read one back.
This is the shape the composite classes drive : unlike ParsingStrategy, whose entries go
straight from a value to its felts, a constructor here returns a CairoType instance.
That is what lets a composite hold its elements as a tree and serialize the whole of it at once,
rather than each level having to flatten what it contains.
Every constructor receives the strategy back, because building a composite means building its children : an array of tuples of u8 has to reach this map three times.
Example
const strategy: CairoTypeStrategy = {
constructors: {
[CairoUint8.abiSelector]: (input) => new CairoUint8(input),
},
response: {
[CairoUint8.abiSelector]: (instance) => (instance as CairoUint8).toBigInt(),
},
dynamicSelectors: {},
};
const felts = strategy.constructors['core::integer::u8'](44, strategy).toApiRequest();
// felts = ["44"]
Properties
constructors
constructors:
Record<AbiEntryType, (input,strategy,type?,variant?) =>CairoType>
Defined in: src/utils/calldata/parser/cairoTypeStrategy.type.ts:47
Build a Cairo type, from raw data on the way out or from response felts on the way in.
The two directions share one entry because they build the same thing : input is whatever a
caller passed for a request, and the iterator positioned on this value for a response. type
and variant are given only where the abi key is not enough to know what to build — a
dynamic selector matches a family of types, and an enum has to be told which branch it holds.
response
response:
Record<AbiEntryType, (instance,strategy) =>any>
Defined in: src/utils/calldata/parser/cairoTypeStrategy.type.ts:63
Turn a built Cairo type back into the plain JS value a caller reads.
The strategy comes along for the same reason as above : decomposing a composite means decomposing its elements.
dynamicSelectors
dynamicSelectors:
Record<string, (type) =>boolean>
Defined in: src/utils/calldata/parser/cairoTypeStrategy.type.ts:76
Recognize the types whose abi string is not a fixed key.
An array, a tuple, a fixed array, an Option or a NonZero write their element type into
their own name, so there is no one string to key them by. Each entry here is a predicate on
the abi type, and its key names the constructor to use — which is why a composite class
carries a dynamicSelector telling which one built it.