@radixdlt/atom
Version:
Container for CRUD instructions known as 'Particles' that are sent to the Radix decentralized ledger
42 lines • 2.35 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Atom = void 0;
const _types_1 = require("./_types");
const atomIdentifier_1 = require("./atomIdentifier");
const particleGroups_1 = require("./particleGroups");
const data_formats_1 = require("@radixdlt/data-formats");
const neverthrow_1 = require("neverthrow");
const euid_1 = require("./euid");
const particleGroup_1 = require("./particleGroup");
const utils_1 = require("./utils");
const isSigned = (signatures) => {
return Object.keys(signatures).length >= 1;
};
// TODO implemented when we have DSON encoding of Atom.
const mockedAtomIdentifier = atomIdentifier_1.AtomIdentifier.create('deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef')._unsafeUnwrap();
const SERIALIZER = 'radix.atom';
// TODO make signature and message DSONCodable and add them here
const serialization = (input) => {
const keyValues = {
particleGroups: input.particleGroups,
};
return Object.assign(Object.assign({}, data_formats_1.DSONEncoding(SERIALIZER)(keyValues)), data_formats_1.JSONEncoding(SERIALIZER)(keyValues));
};
const JSONDecoder = data_formats_1.taggedObjectDecoder(SERIALIZER, _types_1.SERIALIZER_KEY)((input) => neverthrow_1.ok(create(input)));
const jsonDecoding = utils_1.JSONDecoding.withDependencies(particleGroup_1.ParticleGroup)
.withDecoders(JSONDecoder)
.create();
const create = (input) => {
var _a, _b;
const signatures = (_a = input.signatures) !== null && _a !== void 0 ? _a : {};
const particleGroups_ = (_b = input.particleGroups) !== null && _b !== void 0 ? _b : particleGroups_1.particleGroups([]);
const atomExcludingEquals = Object.assign(Object.assign(Object.assign({}, serialization({
particleGroups: particleGroups_.groups,
})), { particleGroups: particleGroups_, signatures: signatures, message: input.message, equals: (_other) => {
throw new Error('implemented below');
}, identifier: () => mockedAtomIdentifier, isSigned: () => isSigned(signatures) }), particleGroups_);
return Object.assign(Object.assign({}, atomExcludingEquals), { equals: (other) => euid_1.equalsDSONHash(atomExcludingEquals, other) });
};
exports.Atom = Object.assign(Object.assign({ SERIALIZER }, jsonDecoding), { create,
JSONDecoder });
//# sourceMappingURL=atom.js.map