UNPKG

@radixdlt/atom

Version:

Container for CRUD instructions known as 'Particles' that are sent to the Radix decentralized ledger

53 lines 3.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FixedSupplyTokenDefinitionParticle = exports.isFixedTokenDefinitionParticle = void 0; const account_1 = require("@radixdlt/account"); const data_formats_1 = require("@radixdlt/data-formats"); const primitives_1 = require("@radixdlt/primitives"); const neverthrow_1 = require("neverthrow"); const resourceIdentifier_1 = require("../resourceIdentifier"); const _types_1 = require("../_types"); const radixParticleTypes_1 = require("./meta/radixParticleTypes"); const tokenDefinitionParticleBase_1 = require("./tokenDefinitionParticleBase"); const utils_1 = require("../utils"); const radixParticleType = radixParticleTypes_1.RadixParticleType.FIXED_SUPPLY_TOKEN_DEFINITION; const SERIALIZER = 'radix.particles.fixed_supply_token_definition'; const JSONDecoder = data_formats_1.taggedObjectDecoder(SERIALIZER, _types_1.SERIALIZER_KEY)((input) => create(input)); const jsonDecoding = utils_1.JSONDecoding.withDependencies(resourceIdentifier_1.ResourceIdentifier, account_1.Address, primitives_1.Amount) .withDecoders(JSONDecoder) .create(); // eslint-disable-next-line max-lines-per-function const create = (input) => { var _a; const fixedTokenSupply = input.supply; const granularity = (_a = input.granularity) !== null && _a !== void 0 ? _a : primitives_1.granularityDefault; if (!fixedTokenSupply.isMultipleOf(granularity)) { return neverthrow_1.err(new Error(`Supply not multiple of granularity (granularity=${granularity.toString()} ∤ supply=${fixedTokenSupply.toString()}).`)); } return tokenDefinitionParticleBase_1.baseTokenDefinitionParticle(Object.assign(Object.assign({}, input), { granularity: granularity, serializer: SERIALIZER, radixParticleType: radixParticleTypes_1.RadixParticleType.FIXED_SUPPLY_TOKEN_DEFINITION, specificEncodableKeyValues: { supply: fixedTokenSupply, }, // eslint-disable-next-line complexity makeEquals: (thisParticle, other) => { if (!exports.isFixedTokenDefinitionParticle(other)) return false; const otherFSTDP = other; const equalsBase = otherFSTDP.name === thisParticle.name && otherFSTDP.description === thisParticle.description && otherFSTDP.granularity.equals(thisParticle.granularity) && otherFSTDP.resourceIdentifier.equals(thisParticle.resourceIdentifier) && otherFSTDP.url === thisParticle.url && otherFSTDP.iconURL === thisParticle.iconURL; return (equalsBase && otherFSTDP.fixedTokenSupply.equals(fixedTokenSupply)); } })).map((base) => (Object.assign(Object.assign({}, base), { fixedTokenSupply: fixedTokenSupply }))); }; const isFixedTokenDefinitionParticle = (something) => { if (!tokenDefinitionParticleBase_1.isTokenDefinitionParticleBase(something)) return false; return something.radixParticleType === radixParticleType; }; exports.isFixedTokenDefinitionParticle = isFixedTokenDefinitionParticle; exports.FixedSupplyTokenDefinitionParticle = Object.assign(Object.assign({ SERIALIZER }, jsonDecoding), { create, JSONDecoder }); //# sourceMappingURL=fixedSupplyTokenDefinitionParticle.js.map