@taquito/michelson-encoder
Version:
converts michelson data and types into convenient JS/TS objects
74 lines (73 loc) • 3.74 kB
TypeScript
import { MichelsonV1Expression, MichelsonV1ExpressionExtended } from '@taquito/rpc';
import { TokenSchema } from '../schema/types';
import { TaquitoError } from '@taquito/core';
/**
* @category Error
* @description Error that indicates a failure when encoding invalid or incorrect data (e.g. if an address is expected but a number is received)
*/
export declare abstract class TokenValidationError extends TaquitoError {
readonly value: any;
readonly token: Token;
name: string;
constructor(value: any, token: Token, baseMessage: string);
}
export type TokenFactory = (val: any, idx: number, parentTokenType?: 'Or' | 'Pair' | 'Other') => Token;
export interface Semantic {
[key: string]: (value: MichelsonV1Expression, schema: MichelsonV1Expression) => any;
}
export interface SemanticEncoding {
[key: string]: (value: any, type?: MichelsonV1Expression) => MichelsonV1Expression;
}
/**
* @description Possible strategies for mapping between javascript classes and Michelson values
* Legacy: The old behaviour: { annot1: 'some value', annot2: 'other Value', annot3: { 2: 'yet another value', 3: 'also some value' }}
* ResetFieldNumbersInNestedObjects: { annot1: 'some value', annot2: 'other Value', annot3: { 0: 'yet another value', 1: 'also some value' }}
* Latest: This will include new changes as we might implement in the future. This is the suggested value if it does not break your code
*/
export type FieldNumberingStrategy = 'Legacy' | 'ResetFieldNumbersInNestedObjects' | 'Latest';
export declare abstract class Token {
protected val: MichelsonV1ExpressionExtended;
protected idx: number;
protected fac: TokenFactory;
protected parentTokenType?: ("Or" | "Pair" | "Other") | undefined;
private static _fieldNumberingStrategy;
/**
* @description Gets the strategy used for field numbering in Token execute/encode/decode to convert Michelson values to/from javascript objects, returns a value of type {@link FieldNumberingStrategy} that controls how field numbers are calculated
*/
static get fieldNumberingStrategy(): FieldNumberingStrategy;
/**
* @description Sets the strategy used for field numbering in Token execute/encode/decode to convert Michelson values to/from javascript objects, accepts a value of type {@link FieldNumberingStrategy} that controls how field numbers are calculated
*/
static set fieldNumberingStrategy(value: FieldNumberingStrategy);
constructor(val: MichelsonV1ExpressionExtended, idx: number, fac: TokenFactory, parentTokenType?: ("Or" | "Pair" | "Other") | undefined);
protected typeWithoutAnnotations(): Omit<MichelsonV1ExpressionExtended, "annots">;
annot(): string;
hasAnnotations(): number | false;
get tokenVal(): MichelsonV1ExpressionExtended;
createToken: TokenFactory;
/**
* @deprecated ExtractSchema has been deprecated in favor of generateSchema
*
*/
abstract ExtractSchema(): any;
abstract generateSchema(): TokenSchema;
abstract Execute(val: any, semantics?: Semantic): any;
abstract Encode(_args: any[]): any;
abstract EncodeObject(args: any, semantics?: SemanticEncoding): any;
ExtractSignature(): any[][];
abstract findAndReturnTokens(tokenToFind: string, tokens: Array<Token>): Array<Token>;
}
export type BigMapKeyType = string | number | object;
export declare abstract class ComparableToken extends Token {
abstract ToBigMapKey(val: BigMapKeyType): {
key: {
[key: string]: string | object[];
};
type: {
prim: string;
args?: object[];
};
};
abstract ToKey(val: string | MichelsonV1Expression): any;
compare(o1: string, o2: string): number;
}