@aeternity/aepp-sdk
Version:
SDK for the æternity blockchain
36 lines (32 loc) • 1.25 kB
JavaScript
import { Encoding } from '../../../utils/encoder.js';
import { packRecord, unpackRecord } from '../common.js';
import { schemas } from './schema.js';
import { EntryTag } from './constants.js';
const encodingTag = [[EntryTag.CallsMtree, Encoding.CallStateTree], [EntryTag.StateTrees, Encoding.StateTrees], [EntryTag.TreesPoi, Encoding.Poi]];
/**
* Pack entry
* @category entry builder
* @param params - Params of entry
* @returns Encoded entry
*/
export function packEntry(params) {
var _encodingTag$find$;
const encoding = (_encodingTag$find$ = encodingTag.find(([tag]) => tag === params.tag)?.[1]) !== null && _encodingTag$find$ !== void 0 ? _encodingTag$find$ : Encoding.Bytearray;
return packRecord(schemas, EntryTag, params, {
packEntry
}, encoding);
}
/**
* Unpack entry
* @category entry builder
* @param encoded - Encoded entry
* @param expectedTag - Expected entry type
* @returns Params of entry
*/
export function unpackEntry(encoded, expectedTag) {
expectedTag !== null && expectedTag !== void 0 ? expectedTag : expectedTag = encodingTag.find(([, enc]) => encoded.startsWith(enc))?.[0];
return unpackRecord(schemas, EntryTag, encoded, expectedTag, {
unpackEntry
});
}
//# sourceMappingURL=index.js.map