@vue-solana/core 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +11 -0
- package/dist/index.d.cts +3 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.mjs +2 -0
- package/dist/spl-token.cjs +12 -0
- package/dist/spl-token.d.cts +4 -0
- package/dist/spl-token.d.mts +4 -0
- package/dist/spl-token.d.ts +4 -0
- package/dist/spl-token.mjs +1 -0
- package/dist/token-accounts.cjs +56 -0
- package/dist/token-accounts.d.cts +17 -0
- package/dist/token-accounts.d.mts +17 -0
- package/dist/token-accounts.d.ts +17 -0
- package/dist/token-accounts.mjs +52 -0
- package/package.json +12 -1
package/dist/index.cjs
CHANGED
|
@@ -7,6 +7,8 @@ const errors = require('./errors.cjs');
|
|
|
7
7
|
const adapter = require('./shared/core.BsekSwcZ.cjs');
|
|
8
8
|
const mobileWallet = require('./mobile-wallet.cjs');
|
|
9
9
|
const rpc = require('./rpc.cjs');
|
|
10
|
+
const splToken = require('@solana/spl-token');
|
|
11
|
+
const tokenAccounts = require('./token-accounts.cjs');
|
|
10
12
|
const transaction = require('./transaction.cjs');
|
|
11
13
|
const timeout = require('./timeout.cjs');
|
|
12
14
|
const wallet = require('./wallet.cjs');
|
|
@@ -45,6 +47,15 @@ exports.isSolanaMobileWalletSupported = mobileWallet.isSolanaMobileWalletSupport
|
|
|
45
47
|
exports.registerSolanaMobileWallet = mobileWallet.registerSolanaMobileWallet;
|
|
46
48
|
exports.createSolanaConnection = rpc.createSolanaConnection;
|
|
47
49
|
exports.createSolanaContext = rpc.createSolanaContext;
|
|
50
|
+
exports.AccountState = splToken.AccountState;
|
|
51
|
+
exports.TOKEN_2022_PROGRAM_ID = splToken.TOKEN_2022_PROGRAM_ID;
|
|
52
|
+
exports.TOKEN_PROGRAM_ID = splToken.TOKEN_PROGRAM_ID;
|
|
53
|
+
exports.getAssociatedTokenAddressSync = splToken.getAssociatedTokenAddressSync;
|
|
54
|
+
exports.unpackAccount = splToken.unpackAccount;
|
|
55
|
+
exports.unpackMint = splToken.unpackMint;
|
|
56
|
+
exports.getTokenAccount = tokenAccounts.getTokenAccount;
|
|
57
|
+
exports.getTokenAccountsByOwner = tokenAccounts.getTokenAccountsByOwner;
|
|
58
|
+
exports.getTokenBalance = tokenAccounts.getTokenBalance;
|
|
48
59
|
exports.confirmTransactionSignature = transaction.confirmTransactionSignature;
|
|
49
60
|
exports.signAndSendTransaction = transaction.signAndSendTransaction;
|
|
50
61
|
exports.withSolanaTimeout = timeout.withSolanaTimeout;
|
package/dist/index.d.cts
CHANGED
|
@@ -7,6 +7,8 @@ export { SolanaError, SolanaErrorCode, SolanaErrorOptions, createSolanaError, is
|
|
|
7
7
|
export { AdaptSolanaIosWalletOptions, GetSolanaIosWalletsOptions, IosWalletCallbackResult, IosWalletInfo, IosWalletMethod, SolanaIosWalletAppIdentity, adaptSolanaIosWallet, getDefaultIosWalletAppIdentity, getDefaultIosWalletRedirectUrl, getSolanaIosWallets, handleSolanaIosWalletCallback, isIosBrowser, isSolanaIosBrowserWalletSupported, isSolanaIosWalletInfo } from './ios-wallet.cjs';
|
|
8
8
|
export { RegisterSolanaMobileWalletOptions, SolanaMobileWalletAppIdentity, getDefaultMobileWalletAppIdentity, isSolanaMobileWalletSupported, registerSolanaMobileWallet } from './mobile-wallet.cjs';
|
|
9
9
|
export { createSolanaConnection, createSolanaContext } from './rpc.cjs';
|
|
10
|
+
export { AccountState, Mint, TOKEN_2022_PROGRAM_ID, TOKEN_PROGRAM_ID, Account as TokenAccount, getAssociatedTokenAddressSync, unpackAccount, unpackMint } from '@solana/spl-token';
|
|
11
|
+
export { TokenAccountsByOwnerOptions, TokenBalanceResult, getTokenAccount, getTokenAccountsByOwner, getTokenBalance } from './token-accounts.cjs';
|
|
10
12
|
export { confirmTransactionSignature, signAndSendTransaction } from './transaction.cjs';
|
|
11
13
|
export { withSolanaTimeout, withTimeout } from './timeout.cjs';
|
|
12
14
|
export { ConfirmTransactionOptions, SendTransactionOptions, SolanaChain, SolanaCluster, SolanaConfig, SolanaContext, SolanaSignMessageResult, SolanaTransaction, SolanaWallet, SolanaWalletInfo, TransactionConfirmation } from './types.cjs';
|
|
@@ -14,4 +16,5 @@ export { SolanaWalletError, SolanaWalletErrorCode, assertWalletCanSign, assertWa
|
|
|
14
16
|
export { AdaptSolanaWalletOptions, SOLANA_CHAINS, SOLANA_MOBILE_WALLET_ADAPTER_WALLET_NAME, adaptSolanaStandardWallet, getRegisteredSolanaWallets, getSolanaChain, isSolanaStandardWallet, subscribeSolanaWallets } from './wallet-standard.cjs';
|
|
15
17
|
export { AccountInfo, Commitment, Connection, Keypair, PublicKey, RpcResponseAndContext, SendOptions, SignatureResult, SignatureStatus, SystemProgram, Transaction, TransactionInstruction, TransactionSignature, VersionedTransaction } from '@solana/web3-compat';
|
|
16
18
|
export { Buffer } from 'buffer/';
|
|
19
|
+
import '@vue-solana/core/web3';
|
|
17
20
|
import '@wallet-standard/base';
|
package/dist/index.d.mts
CHANGED
|
@@ -7,6 +7,8 @@ export { SolanaError, SolanaErrorCode, SolanaErrorOptions, createSolanaError, is
|
|
|
7
7
|
export { AdaptSolanaIosWalletOptions, GetSolanaIosWalletsOptions, IosWalletCallbackResult, IosWalletInfo, IosWalletMethod, SolanaIosWalletAppIdentity, adaptSolanaIosWallet, getDefaultIosWalletAppIdentity, getDefaultIosWalletRedirectUrl, getSolanaIosWallets, handleSolanaIosWalletCallback, isIosBrowser, isSolanaIosBrowserWalletSupported, isSolanaIosWalletInfo } from './ios-wallet.mjs';
|
|
8
8
|
export { RegisterSolanaMobileWalletOptions, SolanaMobileWalletAppIdentity, getDefaultMobileWalletAppIdentity, isSolanaMobileWalletSupported, registerSolanaMobileWallet } from './mobile-wallet.mjs';
|
|
9
9
|
export { createSolanaConnection, createSolanaContext } from './rpc.mjs';
|
|
10
|
+
export { AccountState, Mint, TOKEN_2022_PROGRAM_ID, TOKEN_PROGRAM_ID, Account as TokenAccount, getAssociatedTokenAddressSync, unpackAccount, unpackMint } from '@solana/spl-token';
|
|
11
|
+
export { TokenAccountsByOwnerOptions, TokenBalanceResult, getTokenAccount, getTokenAccountsByOwner, getTokenBalance } from './token-accounts.mjs';
|
|
10
12
|
export { confirmTransactionSignature, signAndSendTransaction } from './transaction.mjs';
|
|
11
13
|
export { withSolanaTimeout, withTimeout } from './timeout.mjs';
|
|
12
14
|
export { ConfirmTransactionOptions, SendTransactionOptions, SolanaChain, SolanaCluster, SolanaConfig, SolanaContext, SolanaSignMessageResult, SolanaTransaction, SolanaWallet, SolanaWalletInfo, TransactionConfirmation } from './types.mjs';
|
|
@@ -14,4 +16,5 @@ export { SolanaWalletError, SolanaWalletErrorCode, assertWalletCanSign, assertWa
|
|
|
14
16
|
export { AdaptSolanaWalletOptions, SOLANA_CHAINS, SOLANA_MOBILE_WALLET_ADAPTER_WALLET_NAME, adaptSolanaStandardWallet, getRegisteredSolanaWallets, getSolanaChain, isSolanaStandardWallet, subscribeSolanaWallets } from './wallet-standard.mjs';
|
|
15
17
|
export { AccountInfo, Commitment, Connection, Keypair, PublicKey, RpcResponseAndContext, SendOptions, SignatureResult, SignatureStatus, SystemProgram, Transaction, TransactionInstruction, TransactionSignature, VersionedTransaction } from '@solana/web3-compat';
|
|
16
18
|
export { Buffer } from 'buffer/';
|
|
19
|
+
import '@vue-solana/core/web3';
|
|
17
20
|
import '@wallet-standard/base';
|
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,8 @@ export { SolanaError, SolanaErrorCode, SolanaErrorOptions, createSolanaError, is
|
|
|
7
7
|
export { AdaptSolanaIosWalletOptions, GetSolanaIosWalletsOptions, IosWalletCallbackResult, IosWalletInfo, IosWalletMethod, SolanaIosWalletAppIdentity, adaptSolanaIosWallet, getDefaultIosWalletAppIdentity, getDefaultIosWalletRedirectUrl, getSolanaIosWallets, handleSolanaIosWalletCallback, isIosBrowser, isSolanaIosBrowserWalletSupported, isSolanaIosWalletInfo } from './ios-wallet.js';
|
|
8
8
|
export { RegisterSolanaMobileWalletOptions, SolanaMobileWalletAppIdentity, getDefaultMobileWalletAppIdentity, isSolanaMobileWalletSupported, registerSolanaMobileWallet } from './mobile-wallet.js';
|
|
9
9
|
export { createSolanaConnection, createSolanaContext } from './rpc.js';
|
|
10
|
+
export { AccountState, Mint, TOKEN_2022_PROGRAM_ID, TOKEN_PROGRAM_ID, Account as TokenAccount, getAssociatedTokenAddressSync, unpackAccount, unpackMint } from '@solana/spl-token';
|
|
11
|
+
export { TokenAccountsByOwnerOptions, TokenBalanceResult, getTokenAccount, getTokenAccountsByOwner, getTokenBalance } from './token-accounts.js';
|
|
10
12
|
export { confirmTransactionSignature, signAndSendTransaction } from './transaction.js';
|
|
11
13
|
export { withSolanaTimeout, withTimeout } from './timeout.js';
|
|
12
14
|
export { ConfirmTransactionOptions, SendTransactionOptions, SolanaChain, SolanaCluster, SolanaConfig, SolanaContext, SolanaSignMessageResult, SolanaTransaction, SolanaWallet, SolanaWalletInfo, TransactionConfirmation } from './types.js';
|
|
@@ -14,4 +16,5 @@ export { SolanaWalletError, SolanaWalletErrorCode, assertWalletCanSign, assertWa
|
|
|
14
16
|
export { AdaptSolanaWalletOptions, SOLANA_CHAINS, SOLANA_MOBILE_WALLET_ADAPTER_WALLET_NAME, adaptSolanaStandardWallet, getRegisteredSolanaWallets, getSolanaChain, isSolanaStandardWallet, subscribeSolanaWallets } from './wallet-standard.js';
|
|
15
17
|
export { AccountInfo, Commitment, Connection, Keypair, PublicKey, RpcResponseAndContext, SendOptions, SignatureResult, SignatureStatus, SystemProgram, Transaction, TransactionInstruction, TransactionSignature, VersionedTransaction } from '@solana/web3-compat';
|
|
16
18
|
export { Buffer } from 'buffer/';
|
|
19
|
+
import '@vue-solana/core/web3';
|
|
17
20
|
import '@wallet-standard/base';
|
package/dist/index.mjs
CHANGED
|
@@ -5,6 +5,8 @@ export { SolanaError, createSolanaError, isSolanaError, normalizeSolanaError } f
|
|
|
5
5
|
export { a as adaptSolanaIosWallet, g as getDefaultIosWalletAppIdentity, b as getDefaultIosWalletRedirectUrl, c as getSolanaIosWallets, h as handleSolanaIosWalletCallback, i as isIosBrowser, d as isSolanaIosBrowserWalletSupported, e as isSolanaIosWalletInfo } from './shared/core.Ch_Z7_17.mjs';
|
|
6
6
|
export { getDefaultMobileWalletAppIdentity, isSolanaMobileWalletSupported, registerSolanaMobileWallet } from './mobile-wallet.mjs';
|
|
7
7
|
export { createSolanaConnection, createSolanaContext } from './rpc.mjs';
|
|
8
|
+
export { AccountState, TOKEN_2022_PROGRAM_ID, TOKEN_PROGRAM_ID, getAssociatedTokenAddressSync, unpackAccount, unpackMint } from '@solana/spl-token';
|
|
9
|
+
export { getTokenAccount, getTokenAccountsByOwner, getTokenBalance } from './token-accounts.mjs';
|
|
8
10
|
export { confirmTransactionSignature, signAndSendTransaction } from './transaction.mjs';
|
|
9
11
|
export { withSolanaTimeout, withTimeout } from './timeout.mjs';
|
|
10
12
|
export { SolanaWalletError, assertWalletCanSign, assertWalletCanSignMessage, assertWalletConnected, createNoWalletSelectedError, isWalletConnected } from './wallet.mjs';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const splToken = require('@solana/spl-token');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
exports.AccountState = splToken.AccountState;
|
|
8
|
+
exports.TOKEN_2022_PROGRAM_ID = splToken.TOKEN_2022_PROGRAM_ID;
|
|
9
|
+
exports.TOKEN_PROGRAM_ID = splToken.TOKEN_PROGRAM_ID;
|
|
10
|
+
exports.getAssociatedTokenAddressSync = splToken.getAssociatedTokenAddressSync;
|
|
11
|
+
exports.unpackAccount = splToken.unpackAccount;
|
|
12
|
+
exports.unpackMint = splToken.unpackMint;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/// <reference path="../types/web3-compat.d.ts" />
|
|
2
|
+
/// <reference path="../types/buffer.d.ts" />
|
|
3
|
+
export { AccountState, Mint, TOKEN_2022_PROGRAM_ID, TOKEN_PROGRAM_ID, Account as TokenAccount, getAssociatedTokenAddressSync, unpackAccount, unpackMint } from '@solana/spl-token';
|
|
4
|
+
import '@solana/web3-compat';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/// <reference path="../types/web3-compat.d.ts" />
|
|
2
|
+
/// <reference path="../types/buffer.d.ts" />
|
|
3
|
+
export { AccountState, Mint, TOKEN_2022_PROGRAM_ID, TOKEN_PROGRAM_ID, Account as TokenAccount, getAssociatedTokenAddressSync, unpackAccount, unpackMint } from '@solana/spl-token';
|
|
4
|
+
import '@solana/web3-compat';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/// <reference path="../types/web3-compat.d.ts" />
|
|
2
|
+
/// <reference path="../types/buffer.d.ts" />
|
|
3
|
+
export { AccountState, Mint, TOKEN_2022_PROGRAM_ID, TOKEN_PROGRAM_ID, Account as TokenAccount, getAssociatedTokenAddressSync, unpackAccount, unpackMint } from '@solana/spl-token';
|
|
4
|
+
import '@solana/web3-compat';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { AccountState, TOKEN_2022_PROGRAM_ID, TOKEN_PROGRAM_ID, getAssociatedTokenAddressSync, unpackAccount, unpackMint } from '@solana/spl-token';
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const splToken = require('@solana/spl-token');
|
|
4
|
+
const errors = require('./errors.cjs');
|
|
5
|
+
|
|
6
|
+
async function getTokenAccountsByOwner(connection, owner, options) {
|
|
7
|
+
const commitment = options?.commitment ?? "confirmed";
|
|
8
|
+
const programId = options?.programId;
|
|
9
|
+
const programIds = programId ? [programId] : [splToken.TOKEN_PROGRAM_ID, splToken.TOKEN_2022_PROGRAM_ID];
|
|
10
|
+
try {
|
|
11
|
+
const responses = await Promise.all(
|
|
12
|
+
programIds.map(async (pid) => {
|
|
13
|
+
const resp = await connection.getTokenAccountsByOwner(owner, { programId: pid }, commitment);
|
|
14
|
+
return resp.value.map(
|
|
15
|
+
(info) => splToken.unpackAccount(info.pubkey, { data: info.account.data })
|
|
16
|
+
);
|
|
17
|
+
})
|
|
18
|
+
);
|
|
19
|
+
return responses.flat();
|
|
20
|
+
} catch (cause) {
|
|
21
|
+
throw errors.normalizeSolanaError(cause, "RPC_FAILURE");
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
async function getTokenAccount(connection, address) {
|
|
25
|
+
try {
|
|
26
|
+
const accountInfo = await connection.getAccountInfo(address);
|
|
27
|
+
if (!accountInfo) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
return splToken.unpackAccount(address, accountInfo);
|
|
31
|
+
} catch (cause) {
|
|
32
|
+
throw errors.normalizeSolanaError(cause, "RPC_FAILURE");
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
async function getTokenBalance(connection, mint, owner) {
|
|
36
|
+
try {
|
|
37
|
+
const ata = splToken.getAssociatedTokenAddressSync(mint, owner, true);
|
|
38
|
+
const accountInfo = await connection.getAccountInfo(ata);
|
|
39
|
+
if (!accountInfo) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
const tokenAccount = splToken.unpackAccount(ata, accountInfo);
|
|
43
|
+
const mintAccountInfo = await connection.getAccountInfo(mint);
|
|
44
|
+
if (!mintAccountInfo) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
const mintAccount = splToken.unpackMint(mint, mintAccountInfo);
|
|
48
|
+
return { amount: tokenAccount.amount, decimals: mintAccount.decimals };
|
|
49
|
+
} catch (cause) {
|
|
50
|
+
throw errors.normalizeSolanaError(cause, "RPC_FAILURE");
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
exports.getTokenAccount = getTokenAccount;
|
|
55
|
+
exports.getTokenAccountsByOwner = getTokenAccountsByOwner;
|
|
56
|
+
exports.getTokenBalance = getTokenBalance;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { PublicKey, Connection } from '@vue-solana/core/web3';
|
|
2
|
+
import { Account } from '@solana/spl-token';
|
|
3
|
+
|
|
4
|
+
interface TokenAccountsByOwnerOptions {
|
|
5
|
+
commitment?: "processed" | "confirmed" | "finalized";
|
|
6
|
+
programId?: PublicKey;
|
|
7
|
+
}
|
|
8
|
+
declare function getTokenAccountsByOwner(connection: Connection, owner: PublicKey, options?: TokenAccountsByOwnerOptions): Promise<Account[]>;
|
|
9
|
+
declare function getTokenAccount(connection: Connection, address: PublicKey): Promise<Account | null>;
|
|
10
|
+
interface TokenBalanceResult {
|
|
11
|
+
amount: bigint;
|
|
12
|
+
decimals: number;
|
|
13
|
+
}
|
|
14
|
+
declare function getTokenBalance(connection: Connection, mint: PublicKey, owner: PublicKey): Promise<TokenBalanceResult | null>;
|
|
15
|
+
|
|
16
|
+
export { getTokenAccount, getTokenAccountsByOwner, getTokenBalance };
|
|
17
|
+
export type { TokenAccountsByOwnerOptions, TokenBalanceResult };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { PublicKey, Connection } from '@vue-solana/core/web3';
|
|
2
|
+
import { Account } from '@solana/spl-token';
|
|
3
|
+
|
|
4
|
+
interface TokenAccountsByOwnerOptions {
|
|
5
|
+
commitment?: "processed" | "confirmed" | "finalized";
|
|
6
|
+
programId?: PublicKey;
|
|
7
|
+
}
|
|
8
|
+
declare function getTokenAccountsByOwner(connection: Connection, owner: PublicKey, options?: TokenAccountsByOwnerOptions): Promise<Account[]>;
|
|
9
|
+
declare function getTokenAccount(connection: Connection, address: PublicKey): Promise<Account | null>;
|
|
10
|
+
interface TokenBalanceResult {
|
|
11
|
+
amount: bigint;
|
|
12
|
+
decimals: number;
|
|
13
|
+
}
|
|
14
|
+
declare function getTokenBalance(connection: Connection, mint: PublicKey, owner: PublicKey): Promise<TokenBalanceResult | null>;
|
|
15
|
+
|
|
16
|
+
export { getTokenAccount, getTokenAccountsByOwner, getTokenBalance };
|
|
17
|
+
export type { TokenAccountsByOwnerOptions, TokenBalanceResult };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { PublicKey, Connection } from '@vue-solana/core/web3';
|
|
2
|
+
import { Account } from '@solana/spl-token';
|
|
3
|
+
|
|
4
|
+
interface TokenAccountsByOwnerOptions {
|
|
5
|
+
commitment?: "processed" | "confirmed" | "finalized";
|
|
6
|
+
programId?: PublicKey;
|
|
7
|
+
}
|
|
8
|
+
declare function getTokenAccountsByOwner(connection: Connection, owner: PublicKey, options?: TokenAccountsByOwnerOptions): Promise<Account[]>;
|
|
9
|
+
declare function getTokenAccount(connection: Connection, address: PublicKey): Promise<Account | null>;
|
|
10
|
+
interface TokenBalanceResult {
|
|
11
|
+
amount: bigint;
|
|
12
|
+
decimals: number;
|
|
13
|
+
}
|
|
14
|
+
declare function getTokenBalance(connection: Connection, mint: PublicKey, owner: PublicKey): Promise<TokenBalanceResult | null>;
|
|
15
|
+
|
|
16
|
+
export { getTokenAccount, getTokenAccountsByOwner, getTokenBalance };
|
|
17
|
+
export type { TokenAccountsByOwnerOptions, TokenBalanceResult };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { unpackAccount, TOKEN_PROGRAM_ID, TOKEN_2022_PROGRAM_ID, getAssociatedTokenAddressSync, unpackMint } from '@solana/spl-token';
|
|
2
|
+
import { normalizeSolanaError } from './errors.mjs';
|
|
3
|
+
|
|
4
|
+
async function getTokenAccountsByOwner(connection, owner, options) {
|
|
5
|
+
const commitment = options?.commitment ?? "confirmed";
|
|
6
|
+
const programId = options?.programId;
|
|
7
|
+
const programIds = programId ? [programId] : [TOKEN_PROGRAM_ID, TOKEN_2022_PROGRAM_ID];
|
|
8
|
+
try {
|
|
9
|
+
const responses = await Promise.all(
|
|
10
|
+
programIds.map(async (pid) => {
|
|
11
|
+
const resp = await connection.getTokenAccountsByOwner(owner, { programId: pid }, commitment);
|
|
12
|
+
return resp.value.map(
|
|
13
|
+
(info) => unpackAccount(info.pubkey, { data: info.account.data })
|
|
14
|
+
);
|
|
15
|
+
})
|
|
16
|
+
);
|
|
17
|
+
return responses.flat();
|
|
18
|
+
} catch (cause) {
|
|
19
|
+
throw normalizeSolanaError(cause, "RPC_FAILURE");
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
async function getTokenAccount(connection, address) {
|
|
23
|
+
try {
|
|
24
|
+
const accountInfo = await connection.getAccountInfo(address);
|
|
25
|
+
if (!accountInfo) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
return unpackAccount(address, accountInfo);
|
|
29
|
+
} catch (cause) {
|
|
30
|
+
throw normalizeSolanaError(cause, "RPC_FAILURE");
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
async function getTokenBalance(connection, mint, owner) {
|
|
34
|
+
try {
|
|
35
|
+
const ata = getAssociatedTokenAddressSync(mint, owner, true);
|
|
36
|
+
const accountInfo = await connection.getAccountInfo(ata);
|
|
37
|
+
if (!accountInfo) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
const tokenAccount = unpackAccount(ata, accountInfo);
|
|
41
|
+
const mintAccountInfo = await connection.getAccountInfo(mint);
|
|
42
|
+
if (!mintAccountInfo) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
const mintAccount = unpackMint(mint, mintAccountInfo);
|
|
46
|
+
return { amount: tokenAccount.amount, decimals: mintAccount.decimals };
|
|
47
|
+
} catch (cause) {
|
|
48
|
+
throw normalizeSolanaError(cause, "RPC_FAILURE");
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export { getTokenAccount, getTokenAccountsByOwner, getTokenBalance };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vue-solana/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Framework-agnostic primitives for Vue Solana libraries.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
@@ -94,6 +94,16 @@
|
|
|
94
94
|
"types": "./dist/web3.d.ts",
|
|
95
95
|
"import": "./dist/web3.mjs",
|
|
96
96
|
"require": "./dist/web3.cjs"
|
|
97
|
+
},
|
|
98
|
+
"./spl-token": {
|
|
99
|
+
"types": "./dist/spl-token.d.ts",
|
|
100
|
+
"import": "./dist/spl-token.mjs",
|
|
101
|
+
"require": "./dist/spl-token.cjs"
|
|
102
|
+
},
|
|
103
|
+
"./token-accounts": {
|
|
104
|
+
"types": "./dist/token-accounts.d.ts",
|
|
105
|
+
"import": "./dist/token-accounts.mjs",
|
|
106
|
+
"require": "./dist/token-accounts.cjs"
|
|
97
107
|
}
|
|
98
108
|
},
|
|
99
109
|
"files": [
|
|
@@ -105,6 +115,7 @@
|
|
|
105
115
|
},
|
|
106
116
|
"dependencies": {
|
|
107
117
|
"@solana-mobile/wallet-standard-mobile": "^0.5.3",
|
|
118
|
+
"@solana/spl-token": "^0.4.15",
|
|
108
119
|
"@solana/wallet-standard-features": "^1.3.0",
|
|
109
120
|
"@solana/web3-compat": "^0.0.21",
|
|
110
121
|
"@wallet-standard/app": "^1.1.1",
|