@solana/spl-token
Advanced tools
Comparing version 0.3.0 to 0.3.1
@@ -12,3 +12,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getMinimumBalanceForRentExemptAccountWithExtensions = exports.getMinimumBalanceForRentExemptAccount = exports.getMultipleAccounts = exports.getAccount = exports.ACCOUNT_SIZE = exports.AccountLayout = exports.AccountState = void 0; | ||
exports.unpackAccount = exports.getMinimumBalanceForRentExemptAccountWithExtensions = exports.getMinimumBalanceForRentExemptAccount = exports.getMultipleAccounts = exports.getAccount = exports.ACCOUNT_SIZE = exports.AccountLayout = exports.AccountState = void 0; | ||
const buffer_layout_1 = require("@solana/buffer-layout"); | ||
@@ -57,3 +57,3 @@ const buffer_layout_utils_1 = require("@solana/buffer-layout-utils"); | ||
const info = yield connection.getAccountInfo(address, commitment); | ||
return unpackAccount(info, address, programId); | ||
return unpackAccount(address, info, programId); | ||
}); | ||
@@ -75,8 +75,3 @@ } | ||
const infos = yield connection.getMultipleAccountsInfo(addresses, commitment); | ||
const accounts = []; | ||
for (let i = 0; i < infos.length; i++) { | ||
const account = unpackAccount(infos[i], addresses[i], programId); | ||
accounts.push(account); | ||
} | ||
return accounts; | ||
return addresses.map((address, i) => unpackAccount(address, infos[i], programId)); | ||
}); | ||
@@ -112,3 +107,12 @@ } | ||
exports.getMinimumBalanceForRentExemptAccountWithExtensions = getMinimumBalanceForRentExemptAccountWithExtensions; | ||
function unpackAccount(info, address, programId) { | ||
/** | ||
* Unpack a token account | ||
* | ||
* @param address Token account | ||
* @param info Token account data | ||
* @param programId SPL Token program account | ||
* | ||
* @return Unpacked token account | ||
*/ | ||
function unpackAccount(address, info, programId = constants_1.TOKEN_PROGRAM_ID) { | ||
if (!info) | ||
@@ -144,2 +148,3 @@ throw new errors_1.TokenAccountNotFoundError(); | ||
} | ||
exports.unpackAccount = unpackAccount; | ||
//# sourceMappingURL=account.js.map |
@@ -12,3 +12,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getAssociatedTokenAddressSync = exports.getAssociatedTokenAddress = exports.getMinimumBalanceForRentExemptMintWithExtensions = exports.getMinimumBalanceForRentExemptMint = exports.getMint = exports.MINT_SIZE = exports.MintLayout = void 0; | ||
exports.getAssociatedTokenAddressSync = exports.getAssociatedTokenAddress = exports.getMinimumBalanceForRentExemptMintWithExtensions = exports.getMinimumBalanceForRentExemptMint = exports.unpackMint = exports.getMint = exports.MINT_SIZE = exports.MintLayout = void 0; | ||
const buffer_layout_1 = require("@solana/buffer-layout"); | ||
@@ -48,31 +48,44 @@ const buffer_layout_utils_1 = require("@solana/buffer-layout-utils"); | ||
const info = yield connection.getAccountInfo(address, commitment); | ||
if (!info) | ||
throw new errors_1.TokenAccountNotFoundError(); | ||
if (!info.owner.equals(programId)) | ||
throw new errors_1.TokenInvalidAccountOwnerError(); | ||
if (info.data.length < exports.MINT_SIZE) | ||
throw new errors_1.TokenInvalidAccountSizeError(); | ||
const rawMint = exports.MintLayout.decode(info.data.slice(0, exports.MINT_SIZE)); | ||
let tlvData = Buffer.alloc(0); | ||
if (info.data.length > exports.MINT_SIZE) { | ||
if (info.data.length <= account_1.ACCOUNT_SIZE) | ||
throw new errors_1.TokenInvalidAccountSizeError(); | ||
if (info.data.length === multisig_1.MULTISIG_SIZE) | ||
throw new errors_1.TokenInvalidAccountSizeError(); | ||
if (info.data[account_1.ACCOUNT_SIZE] != accountType_1.AccountType.Mint) | ||
throw new errors_1.TokenInvalidMintError(); | ||
tlvData = info.data.slice(account_1.ACCOUNT_SIZE + accountType_1.ACCOUNT_TYPE_SIZE); | ||
} | ||
return { | ||
address, | ||
mintAuthority: rawMint.mintAuthorityOption ? rawMint.mintAuthority : null, | ||
supply: rawMint.supply, | ||
decimals: rawMint.decimals, | ||
isInitialized: rawMint.isInitialized, | ||
freezeAuthority: rawMint.freezeAuthorityOption ? rawMint.freezeAuthority : null, | ||
tlvData, | ||
}; | ||
return unpackMint(address, info, programId); | ||
}); | ||
} | ||
exports.getMint = getMint; | ||
/** | ||
* Unpack a mint | ||
* | ||
* @param address Mint account | ||
* @param info Mint account data | ||
* @param programId SPL Token program account | ||
* | ||
* @return Unpacked mint | ||
*/ | ||
function unpackMint(address, info, programId = constants_1.TOKEN_PROGRAM_ID) { | ||
if (!info) | ||
throw new errors_1.TokenAccountNotFoundError(); | ||
if (!info.owner.equals(programId)) | ||
throw new errors_1.TokenInvalidAccountOwnerError(); | ||
if (info.data.length < exports.MINT_SIZE) | ||
throw new errors_1.TokenInvalidAccountSizeError(); | ||
const rawMint = exports.MintLayout.decode(info.data.slice(0, exports.MINT_SIZE)); | ||
let tlvData = Buffer.alloc(0); | ||
if (info.data.length > exports.MINT_SIZE) { | ||
if (info.data.length <= account_1.ACCOUNT_SIZE) | ||
throw new errors_1.TokenInvalidAccountSizeError(); | ||
if (info.data.length === multisig_1.MULTISIG_SIZE) | ||
throw new errors_1.TokenInvalidAccountSizeError(); | ||
if (info.data[account_1.ACCOUNT_SIZE] != accountType_1.AccountType.Mint) | ||
throw new errors_1.TokenInvalidMintError(); | ||
tlvData = info.data.slice(account_1.ACCOUNT_SIZE + accountType_1.ACCOUNT_TYPE_SIZE); | ||
} | ||
return { | ||
address, | ||
mintAuthority: rawMint.mintAuthorityOption ? rawMint.mintAuthority : null, | ||
supply: rawMint.supply, | ||
decimals: rawMint.decimals, | ||
isInitialized: rawMint.isInitialized, | ||
freezeAuthority: rawMint.freezeAuthorityOption ? rawMint.freezeAuthority : null, | ||
tlvData, | ||
}; | ||
} | ||
exports.unpackMint = unpackMint; | ||
/** Get the minimum lamport balance for a mint to be rent exempt | ||
@@ -79,0 +92,0 @@ * |
@@ -12,3 +12,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getMinimumBalanceForRentExemptMultisig = exports.getMultisig = exports.MULTISIG_SIZE = exports.MultisigLayout = void 0; | ||
exports.getMinimumBalanceForRentExemptMultisig = exports.unpackMultisig = exports.getMultisig = exports.MULTISIG_SIZE = exports.MultisigLayout = void 0; | ||
const buffer_layout_1 = require("@solana/buffer-layout"); | ||
@@ -50,12 +50,26 @@ const buffer_layout_utils_1 = require("@solana/buffer-layout-utils"); | ||
const info = yield connection.getAccountInfo(address, commitment); | ||
if (!info) | ||
throw new errors_1.TokenAccountNotFoundError(); | ||
if (!info.owner.equals(programId)) | ||
throw new errors_1.TokenInvalidAccountOwnerError(); | ||
if (info.data.length != exports.MULTISIG_SIZE) | ||
throw new errors_1.TokenInvalidAccountSizeError(); | ||
return Object.assign({ address }, exports.MultisigLayout.decode(info.data)); | ||
return unpackMultisig(address, info, programId); | ||
}); | ||
} | ||
exports.getMultisig = getMultisig; | ||
/** | ||
* Unpack a multisig | ||
* | ||
* @param address Multisig account | ||
* @param info Multisig account data | ||
* @param programId SPL Token program account | ||
* | ||
* @return Unpacked multisig | ||
*/ | ||
function unpackMultisig(address, info, programId = constants_1.TOKEN_PROGRAM_ID) { | ||
if (!info) | ||
throw new errors_1.TokenAccountNotFoundError(); | ||
if (!info.owner.equals(programId)) | ||
throw new errors_1.TokenInvalidAccountOwnerError(); | ||
if (info.data.length != exports.MULTISIG_SIZE) | ||
throw new errors_1.TokenInvalidAccountSizeError(); | ||
const multisig = exports.MultisigLayout.decode(info.data); | ||
return Object.assign({ address }, multisig); | ||
} | ||
exports.unpackMultisig = unpackMultisig; | ||
/** Get the minimum lamport balance for a multisig to be rent exempt | ||
@@ -62,0 +76,0 @@ * |
/// <reference types="node" /> | ||
import { Commitment, Connection, PublicKey } from '@solana/web3.js'; | ||
import { Commitment, Connection, PublicKey, AccountInfo } from '@solana/web3.js'; | ||
import { ExtensionType } from '../extensions/extensionType'; | ||
@@ -95,1 +95,11 @@ /** Information about a token account */ | ||
export declare function getMinimumBalanceForRentExemptAccountWithExtensions(connection: Connection, extensions: ExtensionType[], commitment?: Commitment): Promise<number>; | ||
/** | ||
* Unpack a token account | ||
* | ||
* @param address Token account | ||
* @param info Token account data | ||
* @param programId SPL Token program account | ||
* | ||
* @return Unpacked token account | ||
*/ | ||
export declare function unpackAccount(address: PublicKey, info: AccountInfo<Buffer> | null, programId?: PublicKey): Account; |
/// <reference types="node" /> | ||
import { Commitment, Connection, PublicKey } from '@solana/web3.js'; | ||
import { AccountInfo, Commitment, Connection, PublicKey } from '@solana/web3.js'; | ||
import { ExtensionType } from '../extensions/extensionType'; | ||
@@ -49,2 +49,12 @@ /** Information about a mint */ | ||
export declare function getMint(connection: Connection, address: PublicKey, commitment?: Commitment, programId?: PublicKey): Promise<Mint>; | ||
/** | ||
* Unpack a mint | ||
* | ||
* @param address Mint account | ||
* @param info Mint account data | ||
* @param programId SPL Token program account | ||
* | ||
* @return Unpacked mint | ||
*/ | ||
export declare function unpackMint(address: PublicKey, info: AccountInfo<Buffer> | null, programId?: PublicKey): Mint; | ||
/** Get the minimum lamport balance for a mint to be rent exempt | ||
@@ -51,0 +61,0 @@ * |
@@ -1,2 +0,3 @@ | ||
import { Commitment, Connection, PublicKey } from '@solana/web3.js'; | ||
/// <reference types="node" /> | ||
import { AccountInfo, Commitment, Connection, PublicKey } from '@solana/web3.js'; | ||
/** Information about a multisig */ | ||
@@ -42,2 +43,12 @@ export interface Multisig { | ||
export declare function getMultisig(connection: Connection, address: PublicKey, commitment?: Commitment, programId?: PublicKey): Promise<Multisig>; | ||
/** | ||
* Unpack a multisig | ||
* | ||
* @param address Multisig account | ||
* @param info Multisig account data | ||
* @param programId SPL Token program account | ||
* | ||
* @return Unpacked multisig | ||
*/ | ||
export declare function unpackMultisig(address: PublicKey, info: AccountInfo<Buffer> | null, programId?: PublicKey): Multisig; | ||
/** Get the minimum lamport balance for a multisig to be rent exempt | ||
@@ -44,0 +55,0 @@ * |
{ | ||
"name": "@solana/spl-token", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"author": "Solana Maintainers <maintainers@solana.foundation>", | ||
@@ -30,3 +30,3 @@ "repository": "https://github.com/solana-labs/solana-program-library", | ||
"deploy": "yarn docs && gh-pages --dist docs --dest token/js --dotfiles", | ||
"example": "node --experimental-specifier-resolution=node --loader ts-node/esm examples/create_mint_and_transfer_tokens.ts", | ||
"example": "node --experimental-specifier-resolution=node --loader ts-node/esm examples/createMintAndTransferTokens.ts", | ||
"test": "yarn test:unit && yarn test:e2e-built && yarn test:e2e-native && yarn test:e2e-2022", | ||
@@ -50,3 +50,3 @@ "test:unit": "mocha test/unit", | ||
"devDependencies": { | ||
"@solana/spl-memo": "^0.1.0", | ||
"@solana/spl-memo": "^0.2.0", | ||
"@types/chai-as-promised": "^7.1.4", | ||
@@ -53,0 +53,0 @@ "@types/eslint": "^8.4.0", |
@@ -102,3 +102,3 @@ import { struct, u32, u8 } from '@solana/buffer-layout'; | ||
const info = await connection.getAccountInfo(address, commitment); | ||
return unpackAccount(info, address, programId); | ||
return unpackAccount(address, info, programId); | ||
} | ||
@@ -123,8 +123,3 @@ | ||
const infos = await connection.getMultipleAccountsInfo(addresses, commitment); | ||
const accounts = []; | ||
for (let i = 0; i < infos.length; i++) { | ||
const account = unpackAccount(infos[i], addresses[i], programId); | ||
accounts.push(account); | ||
} | ||
return accounts; | ||
return addresses.map((address, i) => unpackAccount(address, infos[i], programId)); | ||
} | ||
@@ -162,3 +157,16 @@ | ||
function unpackAccount(info: AccountInfo<Buffer> | null, address: PublicKey, programId: PublicKey) { | ||
/** | ||
* Unpack a token account | ||
* | ||
* @param address Token account | ||
* @param info Token account data | ||
* @param programId SPL Token program account | ||
* | ||
* @return Unpacked token account | ||
*/ | ||
export function unpackAccount( | ||
address: PublicKey, | ||
info: AccountInfo<Buffer> | null, | ||
programId = TOKEN_PROGRAM_ID | ||
): Account { | ||
if (!info) throw new TokenAccountNotFoundError(); | ||
@@ -165,0 +173,0 @@ if (!info.owner.equals(programId)) throw new TokenInvalidAccountOwnerError(); |
import { struct, u32, u8 } from '@solana/buffer-layout'; | ||
import { bool, publicKey, u64 } from '@solana/buffer-layout-utils'; | ||
import { Commitment, Connection, PublicKey } from '@solana/web3.js'; | ||
import { AccountInfo, Commitment, Connection, PublicKey } from '@solana/web3.js'; | ||
import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID } from '../constants'; | ||
@@ -80,2 +80,15 @@ import { | ||
const info = await connection.getAccountInfo(address, commitment); | ||
return unpackMint(address, info, programId); | ||
} | ||
/** | ||
* Unpack a mint | ||
* | ||
* @param address Mint account | ||
* @param info Mint account data | ||
* @param programId SPL Token program account | ||
* | ||
* @return Unpacked mint | ||
*/ | ||
export function unpackMint(address: PublicKey, info: AccountInfo<Buffer> | null, programId = TOKEN_PROGRAM_ID): Mint { | ||
if (!info) throw new TokenAccountNotFoundError(); | ||
@@ -82,0 +95,0 @@ if (!info.owner.equals(programId)) throw new TokenInvalidAccountOwnerError(); |
import { struct, u8 } from '@solana/buffer-layout'; | ||
import { bool, publicKey } from '@solana/buffer-layout-utils'; | ||
import { Commitment, Connection, PublicKey } from '@solana/web3.js'; | ||
import { AccountInfo, Commitment, Connection, PublicKey } from '@solana/web3.js'; | ||
import { TOKEN_PROGRAM_ID } from '../constants'; | ||
@@ -72,2 +72,19 @@ import { TokenAccountNotFoundError, TokenInvalidAccountOwnerError, TokenInvalidAccountSizeError } from '../errors'; | ||
const info = await connection.getAccountInfo(address, commitment); | ||
return unpackMultisig(address, info, programId); | ||
} | ||
/** | ||
* Unpack a multisig | ||
* | ||
* @param address Multisig account | ||
* @param info Multisig account data | ||
* @param programId SPL Token program account | ||
* | ||
* @return Unpacked multisig | ||
*/ | ||
export function unpackMultisig( | ||
address: PublicKey, | ||
info: AccountInfo<Buffer> | null, | ||
programId = TOKEN_PROGRAM_ID | ||
): Multisig { | ||
if (!info) throw new TokenAccountNotFoundError(); | ||
@@ -77,3 +94,5 @@ if (!info.owner.equals(programId)) throw new TokenInvalidAccountOwnerError(); | ||
return { address, ...MultisigLayout.decode(info.data) }; | ||
const multisig = MultisigLayout.decode(info.data); | ||
return { address, ...multisig }; | ||
} | ||
@@ -80,0 +99,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1070450
19065