UNPKG

@radixdlt/atom

Version:

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

35 lines 2.21 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.UnallocatedTokensParticle = exports.isUnallocatedTokensParticle = exports.unallocatedTokensParticle = void 0; const radixParticleTypes_1 = require("./meta/radixParticleTypes"); const tokenParticle_1 = require("./meta/tokenParticle"); const data_formats_1 = require("@radixdlt/data-formats"); const neverthrow_1 = require("neverthrow"); const primitives_1 = require("@radixdlt/primitives"); const resourceIdentifier_1 = require("../resourceIdentifier"); const _types_1 = require("../_types"); const utils_1 = require("../utils"); const radixParticleType = radixParticleTypes_1.RadixParticleType.UNALLOCATED_TOKENS; const SERIALIZER = 'radix.particles.unallocated_tokens'; const serialization = (input) => { const keyValues = tokenParticle_1.tokenSerializationKeyValues(input); return Object.assign(Object.assign({}, data_formats_1.JSONEncoding(SERIALIZER)(Object.assign({}, keyValues))), data_formats_1.DSONEncoding(SERIALIZER)(Object.assign({}, keyValues))); }; const JSONDecoder = data_formats_1.taggedObjectDecoder(SERIALIZER, _types_1.SERIALIZER_KEY)((input) => neverthrow_1.ok(exports.unallocatedTokensParticle(input))); const jsonDecoding = utils_1.JSONDecoding.withDependencies(primitives_1.Amount, resourceIdentifier_1.ResourceIdentifier) .withDecoders(JSONDecoder) .create(); const unallocatedTokensParticle = (input) => { const props = Object.assign(Object.assign({}, tokenParticle_1.tokenParticleProps(input)), { radixParticleType: radixParticleType }); return Object.assign(Object.assign(Object.assign({}, serialization(props)), tokenParticle_1.withTokenParticleEquals()(props)), props); }; exports.unallocatedTokensParticle = unallocatedTokensParticle; const isUnallocatedTokensParticle = (something) => { if (!radixParticleTypes_1.isRadixParticle(something)) return false; return something.radixParticleType === radixParticleType; }; exports.isUnallocatedTokensParticle = isUnallocatedTokensParticle; exports.UnallocatedTokensParticle = Object.assign(Object.assign({}, jsonDecoding), { JSONDecoder, SERIALIZER }); //# sourceMappingURL=unallocatedTokensParticle.js.map