UNPKG

@ledgerhq/coin-celo

Version:
94 lines 3.72 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.toCeloResourcesRaw = toCeloResourcesRaw; exports.fromCeloResourcesRaw = fromCeloResourcesRaw; exports.assignToAccountRaw = assignToAccountRaw; exports.assignFromAccountRaw = assignFromAccountRaw; exports.fromOperationExtraRaw = fromOperationExtraRaw; exports.toOperationExtraRaw = toOperationExtraRaw; const types_1 = require("../types"); const bignumber_js_1 = require("bignumber.js"); function toCeloResourcesRaw(r) { const { registrationStatus, lockedBalance, nonvotingLockedBalance, pendingWithdrawals, votes, electionAddress, lockedGoldAddress, maxNumGroupsVotedFor, } = r ?? {}; return { registrationStatus, lockedBalance: lockedBalance?.toString(), nonvotingLockedBalance: nonvotingLockedBalance?.toString(), pendingWithdrawals: pendingWithdrawals?.map(withdrawal => ({ value: withdrawal.value.toString(), time: withdrawal.time.toString(), index: withdrawal.index.toString(), })), votes: votes?.map(vote => ({ validatorGroup: vote.validatorGroup.toString(), amount: vote.amount.toString(), activatable: vote.activatable, revokable: vote.revokable, type: vote.type, index: vote.index, })), electionAddress, lockedGoldAddress, maxNumGroupsVotedFor: maxNumGroupsVotedFor?.toString(), }; } function fromCeloResourcesRaw(r) { return { registrationStatus: r.registrationStatus, lockedBalance: new bignumber_js_1.BigNumber(r.lockedBalance), nonvotingLockedBalance: new bignumber_js_1.BigNumber(r.nonvotingLockedBalance), pendingWithdrawals: r.pendingWithdrawals?.map(u => ({ value: new bignumber_js_1.BigNumber(u.value), time: new bignumber_js_1.BigNumber(u.time), index: Number(u.index), })), votes: r.votes?.map(vote => ({ validatorGroup: vote.validatorGroup, amount: new bignumber_js_1.BigNumber(vote.amount), activatable: vote.activatable, revokable: vote.revokable, type: vote.type, index: vote.index, })), electionAddress: r.electionAddress, lockedGoldAddress: r.lockedGoldAddress, maxNumGroupsVotedFor: new bignumber_js_1.BigNumber(r.maxNumGroupsVotedFor), }; } function assignToAccountRaw(account, accountRaw) { const celoAccount = account; if (celoAccount.celoResources) accountRaw.celoResources = toCeloResourcesRaw(celoAccount.celoResources); } function assignFromAccountRaw(accountRaw, account) { const celoResourcesRaw = accountRaw.celoResources; if (celoResourcesRaw) account.celoResources = fromCeloResourcesRaw(celoResourcesRaw); } function fromOperationExtraRaw(extraRaw) { const extra = {}; if (!(0, types_1.isCeloOperationExtraRaw)(extraRaw)) { return extra; } if (extraRaw.celoOperationValue) { extra.celoOperationValue = (0, bignumber_js_1.BigNumber)(extraRaw.celoOperationValue); } if (extraRaw.celoSourceValidator) { extra.celoSourceValidator = extraRaw.celoSourceValidator; } return extra; } function toOperationExtraRaw(extra) { const extraRaw = {}; if (!(0, types_1.isCeloOperationExtra)(extra)) { return extraRaw; } if (extra.celoOperationValue) { extraRaw.celoOperationValue = extra.celoOperationValue.toString(); } if (extra.celoSourceValidator) { extraRaw.celoSourceValidator = extra.celoSourceValidator; } return extraRaw; } //# sourceMappingURL=serialization.js.map