@concordium/common-sdk
Advanced tools
Comparing version
@@ -14,2 +14,7 @@ /// <reference types="node" /> | ||
/** | ||
* schema (V0) for a module, which is a | ||
* map of contract names to contract schemas. | ||
*/ | ||
export declare type ModuleV0 = Record<string, ContractV0>; | ||
/** | ||
* schema (V1) for a module, which is a | ||
@@ -29,2 +34,5 @@ * map of contract names to contract schemas. | ||
export declare type VersionedModule = { | ||
v: SchemaVersion.V0; | ||
value: ModuleV0; | ||
} | { | ||
v: SchemaVersion.V1; | ||
@@ -37,5 +45,12 @@ value: ModuleV1; | ||
/** | ||
* Reads the schema (V1) for a contract module from the given {@link Readable}. | ||
* Reads the schema (V0) for a contract module from the given {@link Readable}. | ||
* | ||
* @param source input stream | ||
* @returns schema (V0) of a module (contract map) | ||
*/ | ||
export declare function deserialModuleV0(source: Readable): ModuleV0; | ||
/** | ||
* Reads the schema (V1) for a contract module from the given{@link Readable}. | ||
* | ||
* @param source input stream | ||
* @returns schema (V1) of a module (contract map) | ||
@@ -66,5 +81,5 @@ */ | ||
/** | ||
* schema (V1) for a contract. | ||
* schema (V0) for a contract. | ||
*/ | ||
export declare type ContractV1 = { | ||
export declare type ContractV0 = { | ||
/** Optional schema for the contract state. */ | ||
@@ -78,2 +93,11 @@ state: Type | null; | ||
/** | ||
* schema (V1) for a contract. | ||
*/ | ||
export declare type ContractV1 = { | ||
/** Optional schema for init function. */ | ||
init: ContractFunctionV1 | null; | ||
/** Map of receive function names to schemas for their respective parameters and return values. */ | ||
receive: Record<string, ContractFunctionV1>; | ||
}; | ||
/** | ||
* schema (V2) for a contract. | ||
@@ -83,7 +107,14 @@ */ | ||
/** Optional schema for init function. */ | ||
init: ContractFunction | null; | ||
init: ContractFunctionV2 | null; | ||
/** Map of receive function names to schemas for their respective parameters and return values. */ | ||
receive: Record<string, ContractFunction>; | ||
receive: Record<string, ContractFunctionV2>; | ||
}; | ||
/** | ||
* Reads {@link ContractV0} from the given {@link Readable}. | ||
* | ||
* @param source input stream | ||
* @returns schema (V0) for a contract. | ||
*/ | ||
export declare function deserialContractV0(source: Readable): ContractV0; | ||
/** | ||
* Reads {@link ContractV1} from the given {@link Readable}. | ||
@@ -121,6 +152,11 @@ * | ||
} | PairType | ListType | MapType | ArrayType | StructType | EnumType | StringType | ULeb128Type | ILeb128Type | ByteListType | ByteArrayType; | ||
export declare type ContractFunction = { | ||
export declare type ContractFunctionV1 = { | ||
parameter?: Type; | ||
returnValue?: Type; | ||
}; | ||
export declare type ContractFunctionV2 = { | ||
parameter?: Type; | ||
returnValue?: Type; | ||
error?: Type; | ||
}; | ||
export declare type StringType = { | ||
@@ -211,4 +247,11 @@ typeTag: ParameterType.String | ParameterType.ContractName | ParameterType.ReceiveName; | ||
*/ | ||
export declare function deserialFunction(source: Readable): ContractFunction; | ||
export declare function deserialFunctionV1(source: Readable): ContractFunctionV1; | ||
/** | ||
* Reads {@link ContractFunctionV2} from the given {@link Readable}. | ||
* | ||
* @param source input stream | ||
* @returns Function schema type | ||
*/ | ||
export declare function deserialFunctionV2(source: Readable): ContractFunctionV2; | ||
/** | ||
* Reads {@link Type} from the given {@link Readable}. | ||
@@ -344,2 +387,2 @@ * | ||
export declare function deserialModuleFromBuffer(buffer: Buffer, schemaVersion?: SchemaVersion): VersionedModule; | ||
export declare function getParameterType(schema: ContractFunction | Type | null, schemaVersion: SchemaVersion): Type | null; | ||
export declare function getParameterType(schema: ContractFunctionV1 | ContractFunctionV2 | Type | null, schemaVersion: SchemaVersion): Type | null; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getParameterType = exports.deserialModuleFromBuffer = exports.deserialUint8 = exports.deserialTupleFn = exports.deserialOptionFn = exports.OptionTag = exports.deserialMapFn = exports.deserialArrayFn = exports.deserialString = exports.deserialFields = exports.FieldsTag = exports.deserialType = exports.deserialFunction = exports.SizeLength = exports.deserialContractV2 = exports.deserialContractV1 = exports.deserialVersionedModule = exports.VERSIONED_SCHEMA_PREFIX = exports.deserialModuleV2 = exports.deserialModuleV1 = void 0; | ||
exports.getParameterType = exports.deserialModuleFromBuffer = exports.deserialUint8 = exports.deserialTupleFn = exports.deserialOptionFn = exports.OptionTag = exports.deserialMapFn = exports.deserialArrayFn = exports.deserialString = exports.deserialFields = exports.FieldsTag = exports.deserialType = exports.deserialFunctionV2 = exports.deserialFunctionV1 = exports.SizeLength = exports.deserialContractV2 = exports.deserialContractV1 = exports.deserialContractV0 = exports.deserialVersionedModule = exports.VERSIONED_SCHEMA_PREFIX = exports.deserialModuleV2 = exports.deserialModuleV1 = exports.deserialModuleV0 = void 0; | ||
const stream_1 = require("stream"); | ||
@@ -8,5 +8,15 @@ const types_1 = require("./types"); | ||
/** | ||
* Reads the schema (V1) for a contract module from the given {@link Readable}. | ||
* Reads the schema (V0) for a contract module from the given {@link Readable}. | ||
* | ||
* @param source input stream | ||
* @returns schema (V0) of a module (contract map) | ||
*/ | ||
function deserialModuleV0(source) { | ||
return deserialMapFn(deserialString, deserialContractV0)(source); | ||
} | ||
exports.deserialModuleV0 = deserialModuleV0; | ||
/** | ||
* Reads the schema (V1) for a contract module from the given{@link Readable}. | ||
* | ||
* @param source input stream | ||
* @returns schema (V1) of a module (contract map) | ||
@@ -48,2 +58,7 @@ */ | ||
switch (version) { | ||
case types_1.SchemaVersion.V0: | ||
return { | ||
v: version, | ||
value: deserialModuleV0(source), | ||
}; | ||
case types_1.SchemaVersion.V1: | ||
@@ -65,8 +80,8 @@ return { | ||
/** | ||
* Reads {@link ContractV1} from the given {@link Readable}. | ||
* Reads {@link ContractV0} from the given {@link Readable}. | ||
* | ||
* @param source input stream | ||
* @returns schema (V1) for a contract. | ||
* @returns schema (V0) for a contract. | ||
*/ | ||
function deserialContractV1(source) { | ||
function deserialContractV0(source) { | ||
return { | ||
@@ -78,2 +93,15 @@ state: deserialOptionFn(deserialType)(source), | ||
} | ||
exports.deserialContractV0 = deserialContractV0; | ||
/** | ||
* Reads {@link ContractV1} from the given {@link Readable}. | ||
* | ||
* @param source input stream | ||
* @returns schema (V1) for a contract. | ||
*/ | ||
function deserialContractV1(source) { | ||
return { | ||
init: deserialOptionFn(deserialFunctionV1)(source), | ||
receive: deserialMapFn(deserialString, deserialFunctionV1)(source), | ||
}; | ||
} | ||
exports.deserialContractV1 = deserialContractV1; | ||
@@ -88,4 +116,4 @@ /** | ||
return { | ||
init: deserialOptionFn(deserialFunction)(source), | ||
receive: deserialMapFn(deserialString, deserialFunction)(source), | ||
init: deserialOptionFn(deserialFunctionV2)(source), | ||
receive: deserialMapFn(deserialString, deserialFunctionV2)(source), | ||
}; | ||
@@ -113,5 +141,11 @@ } | ||
(function (FunctionTag) { | ||
FunctionTag[FunctionTag["Parameter"] = 0] = "Parameter"; | ||
FunctionTag[FunctionTag["ReturnValue"] = 1] = "ReturnValue"; | ||
FunctionTag[FunctionTag["Both"] = 2] = "Both"; | ||
// V1 Functions only use the first three tags | ||
FunctionTag[FunctionTag["Param"] = 0] = "Param"; | ||
/// Rv is short for Return value. | ||
FunctionTag[FunctionTag["Rv"] = 1] = "Rv"; | ||
FunctionTag[FunctionTag["ParamRv"] = 2] = "ParamRv"; | ||
FunctionTag[FunctionTag["Error"] = 3] = "Error"; | ||
FunctionTag[FunctionTag["ParamError"] = 4] = "ParamError"; | ||
FunctionTag[FunctionTag["RvError"] = 5] = "RvError"; | ||
FunctionTag[FunctionTag["ParamRvError"] = 6] = "ParamRvError"; | ||
})(FunctionTag || (FunctionTag = {})); | ||
@@ -124,14 +158,14 @@ /** | ||
*/ | ||
function deserialFunction(source) { | ||
function deserialFunctionV1(source) { | ||
const tag = deserialUint8(source); | ||
switch (tag) { | ||
case FunctionTag.Parameter: | ||
case FunctionTag.Param: | ||
return { | ||
parameter: deserialType(source), | ||
}; | ||
case FunctionTag.ReturnValue: | ||
case FunctionTag.Rv: | ||
return { | ||
returnValue: deserialType(source), | ||
}; | ||
case FunctionTag.Both: | ||
case FunctionTag.ParamRv: | ||
return { | ||
@@ -145,4 +179,51 @@ parameter: deserialType(source), | ||
} | ||
exports.deserialFunction = deserialFunction; | ||
exports.deserialFunctionV1 = deserialFunctionV1; | ||
/** | ||
* Reads {@link ContractFunctionV2} from the given {@link Readable}. | ||
* | ||
* @param source input stream | ||
* @returns Function schema type | ||
*/ | ||
function deserialFunctionV2(source) { | ||
const tag = deserialUint8(source); | ||
switch (tag) { | ||
case FunctionTag.Param: | ||
return { | ||
parameter: deserialType(source), | ||
}; | ||
case FunctionTag.Rv: | ||
return { | ||
returnValue: deserialType(source), | ||
}; | ||
case FunctionTag.ParamRv: | ||
return { | ||
parameter: deserialType(source), | ||
returnValue: deserialType(source), | ||
}; | ||
case FunctionTag.Error: | ||
return { | ||
error: deserialType(source), | ||
}; | ||
case FunctionTag.ParamError: | ||
return { | ||
parameter: deserialType(source), | ||
error: deserialType(source), | ||
}; | ||
case FunctionTag.RvError: | ||
return { | ||
returnValue: deserialType(source), | ||
error: deserialType(source), | ||
}; | ||
case FunctionTag.ParamRvError: | ||
return { | ||
parameter: deserialType(source), | ||
returnValue: deserialType(source), | ||
error: deserialType(source), | ||
}; | ||
default: | ||
throw new Error('Incorrect tag for function'); | ||
} | ||
} | ||
exports.deserialFunctionV2 = deserialFunctionV2; | ||
/** | ||
* Reads {@link Type} from the given {@link Readable}. | ||
@@ -443,2 +524,7 @@ * | ||
switch (schemaVersion) { | ||
case types_1.SchemaVersion.V0: | ||
return { | ||
v: types_1.SchemaVersion.V0, | ||
value: deserialModuleV0(bufferStream), | ||
}; | ||
case types_1.SchemaVersion.V1: | ||
@@ -449,7 +535,2 @@ return { | ||
}; | ||
case types_1.SchemaVersion.V2: | ||
return { | ||
v: types_1.SchemaVersion.V2, | ||
value: deserialModuleV2(bufferStream), | ||
}; | ||
default: | ||
@@ -465,4 +546,5 @@ throw new Error('Unsupported module version'); | ||
switch (schemaVersion) { | ||
case types_1.SchemaVersion.V0: | ||
return schema; | ||
case types_1.SchemaVersion.V1: | ||
return schema; | ||
case types_1.SchemaVersion.V2: | ||
@@ -469,0 +551,0 @@ return schema.parameter || null; |
@@ -1107,4 +1107,5 @@ import { AccountAddress } from './types/accountAddress'; | ||
export declare enum SchemaVersion { | ||
V1 = 0, | ||
V2 = 1 | ||
V0 = 0, | ||
V1 = 1, | ||
V2 = 2 | ||
} | ||
@@ -1111,0 +1112,0 @@ export declare type IpArData = { |
@@ -271,4 +271,5 @@ "use strict"; | ||
(function (SchemaVersion) { | ||
SchemaVersion[SchemaVersion["V1"] = 0] = "V1"; | ||
SchemaVersion[SchemaVersion["V2"] = 1] = "V2"; | ||
SchemaVersion[SchemaVersion["V0"] = 0] = "V0"; | ||
SchemaVersion[SchemaVersion["V1"] = 1] = "V1"; | ||
SchemaVersion[SchemaVersion["V2"] = 2] = "V2"; | ||
})(SchemaVersion = exports.SchemaVersion || (exports.SchemaVersion = {})); |
{ | ||
"name": "@concordium/common-sdk", | ||
"version": "2.4.0", | ||
"version": "3.0.0", | ||
"license": "Apache-2.0", | ||
@@ -5,0 +5,0 @@ "engines": { |
@@ -371,3 +371,3 @@ # Common | ||
``` | ||
For V0 contracts the schemaVersion should be `SchemaVersion.V1`. For V1 contracts it should currently be `SchemaVersion.V2`. | ||
For V0 contracts the schemaVersion should be `SchemaVersion.V0`. For V1 contracts it should currently be `SchemaVersion.V1`, unless the contract have been built using cargo-concordium >=2.0.0, which are internally versioned, and then the version does not need to be provided. | ||
@@ -418,3 +418,3 @@ Then the payload and transaction can be constructed, in the same way as the parameterless example: | ||
``` | ||
For V0 contracts the schema version should be `SchemaVersion.V1`. For V1 contracts it should currently be `SchemaVersion.V2`. | ||
For V0 contracts the schema version should be `SchemaVersion.V0`. For V1 contracts it should currently be `SchemaVersion.V1`, unless the contract have been built using cargo-concordium >=2.0.0, which are internally versioned, and then the version does not need to be provided. | ||
@@ -421,0 +421,0 @@ Then we will construct the update payload with parameters obtained |
308239
1.46%6174
2.12%