@elrondnetwork/erdjs
Advanced tools
Comparing version 11.1.1 to 11.1.2
/// <reference types="node" /> | ||
import { EndpointParameterDefinition, TypedValue } from "./typesystem"; | ||
import { EndpointParameterDefinition, Type, TypedValue } from "./typesystem"; | ||
export declare const ArgumentsSeparator = "@"; | ||
interface IArgSerializerOptions { | ||
codec: ICodec; | ||
} | ||
interface ICodec { | ||
decodeTopLevel(buffer: Buffer, type: Type): TypedValue; | ||
encodeTopLevel(typedValue: TypedValue): Buffer; | ||
} | ||
export declare class ArgSerializer { | ||
codec: ICodec; | ||
constructor(options?: IArgSerializerOptions); | ||
/** | ||
@@ -34,1 +43,2 @@ * Reads typed values from an arguments string (e.g. aa@bb@@cc), given parameter definitions. | ||
} | ||
export {}; |
@@ -5,11 +5,16 @@ "use strict"; | ||
const codec_1 = require("./codec"); | ||
const algebraic_1 = require("./typesystem/algebraic"); | ||
const composite_1 = require("./typesystem/composite"); | ||
const variadic_1 = require("./typesystem/variadic"); | ||
const algebraic_1 = require("./typesystem/algebraic"); | ||
exports.ArgumentsSeparator = "@"; | ||
/** | ||
* For the moment, this is the only codec used. | ||
*/ | ||
const Codec = new codec_1.BinaryCodec(); | ||
// TODO: perhaps move default construction options to a factory (ArgSerializerFactory), instead of referencing them in the constructor | ||
// (postpone as much as possible, breaking change) | ||
const defaultArgSerializerrOptions = { | ||
codec: new codec_1.BinaryCodec() | ||
}; | ||
class ArgSerializer { | ||
constructor(options) { | ||
options = Object.assign(Object.assign({}, defaultArgSerializerrOptions), options); | ||
this.codec = options.codec; | ||
} | ||
/** | ||
@@ -35,2 +40,3 @@ * Reads typed values from an arguments string (e.g. aa@bb@@cc), given parameter definitions. | ||
// TODO: Refactor, split (function is quite complex). | ||
const self = this; | ||
buffers = buffers || []; | ||
@@ -79,3 +85,3 @@ let values = []; | ||
let buffer = buffers[bufferIndex++]; | ||
let decodedValue = Codec.decodeTopLevel(buffer, type); | ||
let decodedValue = self.codec.decodeTopLevel(buffer, type); | ||
return decodedValue; | ||
@@ -111,2 +117,3 @@ } | ||
// TODO: Refactor, split (function is quite complex). | ||
const self = this; | ||
let buffers = []; | ||
@@ -140,3 +147,3 @@ for (const value of values) { | ||
// The only branching without a recursive call. | ||
let buffer = Codec.encodeTopLevel(value); | ||
let buffer = self.codec.encodeTopLevel(value); | ||
buffers.push(buffer); | ||
@@ -143,0 +150,0 @@ } |
@@ -104,4 +104,4 @@ "use strict"; | ||
constructor(init) { | ||
this.maxBufferLength = (init === null || init === void 0 ? void 0 : init.maxBufferLength) || 4096; | ||
this.maxListLength = (init === null || init === void 0 ? void 0 : init.maxListLength) || 1024; | ||
this.maxBufferLength = (init === null || init === void 0 ? void 0 : init.maxBufferLength) || 40960; | ||
this.maxListLength = (init === null || init === void 0 ? void 0 : init.maxListLength) || 8192; | ||
} | ||
@@ -108,0 +108,0 @@ checkBufferLength(buffer) { |
@@ -0,5 +1,13 @@ | ||
/// <reference types="node" /> | ||
import { TransactionMetadata } from "@elrondnetwork/transaction-decoder"; | ||
import { IContractQueryResponse, ITransactionOnNetwork } from "../interfaceOfNetwork"; | ||
import { TypedOutcomeBundle, UntypedOutcomeBundle } from "./interface"; | ||
import { EndpointDefinition } from "./typesystem"; | ||
import { EndpointDefinition, EndpointParameterDefinition, TypedValue } from "./typesystem"; | ||
interface IResultsParserOptions { | ||
argsSerializer: IArgsSerializer; | ||
} | ||
interface IArgsSerializer { | ||
buffersToValues(buffers: Buffer[], parameters: EndpointParameterDefinition[]): TypedValue[]; | ||
stringToBuffers(joinedString: string): Buffer[]; | ||
} | ||
/** | ||
@@ -10,2 +18,4 @@ * Parses contract query responses and smart contract results. | ||
export declare class ResultsParser { | ||
private readonly argsSerializer; | ||
constructor(options?: IResultsParserOptions); | ||
parseQueryResponse(queryResponse: IContractQueryResponse, endpoint: EndpointDefinition): TypedOutcomeBundle; | ||
@@ -29,1 +39,2 @@ parseUntypedQueryResponse(queryResponse: IContractQueryResponse): UntypedOutcomeBundle; | ||
} | ||
export {}; |
@@ -20,2 +20,7 @@ "use strict"; | ||
})(WellKnownTopics || (WellKnownTopics = {})); | ||
// TODO: perhaps move default construction options to a factory (ResultsParserFactory), instead of referencing them in the constructor | ||
// (postpone as much as possible, breaking change) | ||
const defaultResultsParserOptions = { | ||
argsSerializer: new argSerializer_1.ArgSerializer() | ||
}; | ||
/** | ||
@@ -26,5 +31,9 @@ * Parses contract query responses and smart contract results. | ||
class ResultsParser { | ||
constructor(options) { | ||
options = Object.assign(Object.assign({}, defaultResultsParserOptions), options); | ||
this.argsSerializer = options.argsSerializer; | ||
} | ||
parseQueryResponse(queryResponse, endpoint) { | ||
let parts = queryResponse.getReturnDataParts(); | ||
let values = new argSerializer_1.ArgSerializer().buffersToValues(parts, endpoint.output); | ||
let values = this.argsSerializer.buffersToValues(parts, endpoint.output); | ||
let returnCode = new returnCode_1.ReturnCode(queryResponse.returnCode.toString()); | ||
@@ -51,3 +60,3 @@ return { | ||
let untypedBundle = this.parseUntypedOutcome(transaction); | ||
let values = new argSerializer_1.ArgSerializer().buffersToValues(untypedBundle.values, endpoint.output); | ||
let values = this.argsSerializer.buffersToValues(untypedBundle.values, endpoint.output); | ||
return { | ||
@@ -236,3 +245,3 @@ returnCode: untypedBundle.returnCode, | ||
} | ||
let parts = new argSerializer_1.ArgSerializer().stringToBuffers(data); | ||
let parts = this.argsSerializer.stringToBuffers(data); | ||
let returnCodePart = parts[startingIndex] || Buffer.from([]); | ||
@@ -239,0 +248,0 @@ let returnDataParts = parts.slice(startingIndex + 1); |
{ | ||
"name": "@elrondnetwork/erdjs", | ||
"version": "11.1.1", | ||
"version": "11.1.2", | ||
"description": "Smart Contracts interaction framework", | ||
@@ -5,0 +5,0 @@ "main": "out/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
614700
10595