UNPKG

cache-typescript-sdk

Version:
84 lines 3.73 kB
"use strict"; /* * The MIT License (MIT) * * Copyright (c) 2017 NEM * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 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) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const MosaicHttp_1 = require("../../infrastructure/MosaicHttp"); const MosaicId_1 = require("./MosaicId"); const MosaicTransferable_1 = require("./MosaicTransferable"); const XEM_1 = require("./XEM"); /** * A mosaic describes an instance of a mosaic definition. Mosaics can be transferred by means of a transfer transaction. */ class Mosaic { /** * constructor * @param mosaicId * @param quantity */ constructor(mosaicId, quantity) { /** * returns mosaic transferable * @returns {Promise<MosaicTransferable>} */ this.getMosaicDetails = () => { return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () { try { if (this.mosaicId.namespaceId === 'nem' && this.mosaicId.name === 'xem') { resolve(new XEM_1.XEM(this.quantity / 1e6)); } else { new MosaicHttp_1.MosaicHttp().getMosaicDefinition(this.mosaicId).subscribe((mosaicDefinition) => { const divisibility = mosaicDefinition.properties.divisibility; const amount = this.quantity / Math.pow(10, divisibility); resolve(MosaicTransferable_1.MosaicTransferable.createWithMosaicDefinition(mosaicDefinition, amount)); }); } } catch (err) { reject(err); } })); }; this.mosaicId = mosaicId; this.quantity = quantity; } /** * @internal * @param dto * @returns {Mosaic} */ static createFromMosaicDTO(dto) { return new Mosaic(MosaicId_1.MosaicId.createFromMosaicIdDTO(dto.mosaicId), dto.quantity); } } exports.Mosaic = Mosaic; //# sourceMappingURL=Mosaic.js.map