fsl-js-sdk
Version:
sdk for web
41 lines (40 loc) • 1.63 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.deserializeAccount = void 0;
var spl_token_v0_1 = require("@solana/spl-token-v0");
var web3_js_1 = require("@solana/web3.js");
var deserializeAccount = function (data) {
if (data == undefined || data.length == 0) {
return undefined;
}
var accountInfo = spl_token_v0_1.AccountLayout.decode(data);
accountInfo.mint = new web3_js_1.PublicKey(accountInfo.mint);
accountInfo.owner = new web3_js_1.PublicKey(accountInfo.owner);
accountInfo.amount = spl_token_v0_1.u64.fromBuffer(accountInfo.amount);
if (accountInfo.delegateOption === 0) {
accountInfo.delegate = null;
accountInfo.delegatedAmount = new spl_token_v0_1.u64(0);
}
else {
accountInfo.delegate = new web3_js_1.PublicKey(accountInfo.delegate);
accountInfo.delegatedAmount = spl_token_v0_1.u64.fromBuffer(accountInfo.delegatedAmount);
}
accountInfo.isInitialized = accountInfo.state !== 0;
accountInfo.isFrozen = accountInfo.state === 2;
if (accountInfo.isNativeOption === 1) {
accountInfo.rentExemptReserve = spl_token_v0_1.u64.fromBuffer(accountInfo.isNative);
accountInfo.isNative = true;
}
else {
accountInfo.rentExemptReserve = null;
accountInfo.isNative = false;
}
if (accountInfo.closeAuthorityOption === 0) {
accountInfo.closeAuthority = null;
}
else {
accountInfo.closeAuthority = new web3_js_1.PublicKey(accountInfo.closeAuthority);
}
return accountInfo;
};
exports.deserializeAccount = deserializeAccount;