@ledgerhq/coin-elrond
Version:
Ledger MultiversX Coin integration
52 lines • 1.54 kB
JavaScript
import BigNumber from "bignumber.js";
import { isElrondOperationExtraRaw, isElrondOperationExtra, } from "./types";
export function toElrondResourcesRaw(r) {
const { nonce, delegations, isGuarded } = r;
return {
nonce,
delegations,
isGuarded,
};
}
export function fromElrondResourcesRaw(r) {
const { nonce, delegations, isGuarded } = r;
return {
nonce,
delegations,
isGuarded,
};
}
export function assignToAccountRaw(account, accountRaw) {
const elrondAccount = account;
if (elrondAccount.elrondResources) {
accountRaw.elrondResources = toElrondResourcesRaw(elrondAccount.elrondResources);
}
}
export function assignFromAccountRaw(accountRaw, account) {
const elrondResourcesRaw = accountRaw.elrondResources;
if (elrondResourcesRaw)
account.elrondResources = fromElrondResourcesRaw(elrondResourcesRaw);
}
export function fromOperationExtraRaw(extraRaw) {
const extra = {};
if (!isElrondOperationExtraRaw(extraRaw)) {
// All fields might be undefined
return extra;
}
if (extraRaw.amount) {
extra.amount = new BigNumber(extraRaw.amount);
}
return extra;
}
export function toOperationExtraRaw(extra) {
const extraRaw = {};
if (!isElrondOperationExtra(extra)) {
// All fields might be undefined
return extraRaw;
}
if (extra.amount) {
extraRaw.amount = extra.amount.toString();
}
return extraRaw;
}
//# sourceMappingURL=serialization.js.map