UNPKG

@mavrykdynamics/taquito

Version:

High level functionality that builds upon the other packages in the Mavryk Typescript Library Suite.

71 lines (70 loc) 3.28 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.BigMapAbstraction = void 0; const taquito_http_utils_1 = require("@mavrykdynamics/taquito-http-utils"); class BigMapAbstraction { constructor(id, schema, provider) { this.id = id; this.schema = schema; this.provider = provider; } /** * * @description Fetch one value in a big map * * @param keysToEncode Key to query (will be encoded properly according to the schema) * @param block optional block level to fetch the values from (head will be use by default) * @returns Return a well formatted json object of a big map value or undefined if the key is not found in the big map * */ get(keyToEncode, block) { return __awaiter(this, void 0, void 0, function* () { try { const id = yield this.provider.getBigMapKeyByID(this.id.toString(), keyToEncode, this.schema, block); return id; } catch (e) { if (e instanceof taquito_http_utils_1.HttpResponseError && e.status === taquito_http_utils_1.STATUS_CODE.NOT_FOUND) { return undefined; } else { throw e; } } }); } /** * * @description Fetch multiple values in a big map * All values will be fetched on the same block level. If a block is specified in the request, the values will be fetched at it. * Otherwise, a first request will be done to the node to fetch the level of the head and all values will be fetched at this level. * If one of the keys does not exist in the big map, its value will be set to undefined. * * @param keysToEncode Array of keys to query (will be encoded properly according to the schema) * @param block optional block level to fetch the values from * @param batchSize optional batch size representing the number of requests to execute in parallel * @returns A MichelsonMap containing the keys queried in the big map and their value in a well-formatted JSON object format * */ getMultipleValues(keysToEncode, block, batchSize = 5) { return __awaiter(this, void 0, void 0, function* () { return this.provider.getBigMapKeysByID(this.id.toString(), keysToEncode, this.schema, block, batchSize); }); } toJSON() { return this.id.toString(); } toString() { return this.id.toString(); } } exports.BigMapAbstraction = BigMapAbstraction;