UNPKG

cache-typescript-sdk

Version:
85 lines 3.33 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. */ Object.defineProperty(exports, "__esModule", { value: true }); const Observable_1 = require("rxjs/Observable"); const MosaicDefinition_1 = require("../models/mosaic/MosaicDefinition"); const MosaicLevy_1 = require("../models/mosaic/MosaicLevy"); const XEM_1 = require("../models/mosaic/XEM"); /** * Mosaic service */ class MosaicService { /** * constructor * @param mosaicHttp */ constructor(mosaicHttp) { this.mosaicHttp = mosaicHttp; } /** * Calculate levy for a given mosaicTransferable * @param mosaicTransferable * @returns {any} */ calculateLevy(mosaicTransferable) { if (mosaicTransferable.levy == undefined) return Observable_1.Observable.of(0); if (mosaicTransferable.levy.mosaicId.equals(XEM_1.XEM.MOSAICID)) { return Observable_1.Observable.of(this.levyFee(mosaicTransferable, new MosaicDefinition_1.MosaicProperties(XEM_1.XEM.DIVISIBILITY, XEM_1.XEM.INITIALSUPPLY, XEM_1.XEM.TRANSFERABLE, XEM_1.XEM.SUPPLYMUTABLE))); } else { return this.mosaicHttp.getMosaicDefinition(mosaicTransferable.levy.mosaicId).map((levyMosaicDefinition) => { return this.levyFee(mosaicTransferable, levyMosaicDefinition.properties); }); } } /** * @internal * @param mosaic * @param levy * @returns {any} */ levyFee(mosaicTransferable, levyProperties) { let levyValue; if (mosaicTransferable.levy.type == MosaicLevy_1.MosaicLevyType.Absolute) { levyValue = mosaicTransferable.levy.fee; } else { levyValue = mosaicTransferable.quantity() * mosaicTransferable.levy.fee / 10000; } const o = parseInt(levyValue, 10); if (!o) { if (levyProperties.divisibility === 0) { return 0; } else { return parseFloat("0." + o.toFixed(levyProperties.divisibility).split(".")[1]); } } return o / Math.pow(10, levyProperties.divisibility); } } exports.MosaicService = MosaicService; //# sourceMappingURL=MosaicService.js.map