@solana/instructions
Version:
Helpers for creating transaction instructions
76 lines (73 loc) • 2.79 kB
JavaScript
import { SolanaError, SOLANA_ERROR__INSTRUCTION__PROGRAM_ID_MISMATCH, SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_ACCOUNTS, SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_DATA } from '@solana/errors';
// src/instruction.ts
function isInstructionForProgram(instruction, programAddress) {
return instruction.programAddress === programAddress;
}
function assertIsInstructionForProgram(instruction, programAddress) {
if (instruction.programAddress !== programAddress) {
throw new SolanaError(SOLANA_ERROR__INSTRUCTION__PROGRAM_ID_MISMATCH, {
actualProgramAddress: instruction.programAddress,
expectedProgramAddress: programAddress
});
}
}
function isInstructionWithAccounts(instruction) {
return instruction.accounts !== void 0;
}
function assertIsInstructionWithAccounts(instruction) {
if (instruction.accounts === void 0) {
throw new SolanaError(SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_ACCOUNTS, {
data: instruction.data,
programAddress: instruction.programAddress
});
}
}
function isInstructionWithData(instruction) {
return instruction.data !== void 0;
}
function assertIsInstructionWithData(instruction) {
if (instruction.data === void 0) {
throw new SolanaError(SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_DATA, {
accountAddresses: instruction.accounts?.map((a) => a.address),
programAddress: instruction.programAddress
});
}
}
// src/roles.ts
var AccountRole = /* @__PURE__ */ ((AccountRole2) => {
AccountRole2[AccountRole2["WRITABLE_SIGNER"] = /* 3 */
3] = "WRITABLE_SIGNER";
AccountRole2[AccountRole2["READONLY_SIGNER"] = /* 2 */
2] = "READONLY_SIGNER";
AccountRole2[AccountRole2["WRITABLE"] = /* 1 */
1] = "WRITABLE";
AccountRole2[AccountRole2["READONLY"] = /* 0 */
0] = "READONLY";
return AccountRole2;
})(AccountRole || {});
var IS_SIGNER_BITMASK = 2;
var IS_WRITABLE_BITMASK = 1;
function downgradeRoleToNonSigner(role) {
return role & -3;
}
function downgradeRoleToReadonly(role) {
return role & -2;
}
function isSignerRole(role) {
return role >= 2 /* READONLY_SIGNER */;
}
function isWritableRole(role) {
return (role & IS_WRITABLE_BITMASK) !== 0;
}
function mergeRoles(roleA, roleB) {
return roleA | roleB;
}
function upgradeRoleToSigner(role) {
return role | IS_SIGNER_BITMASK;
}
function upgradeRoleToWritable(role) {
return role | IS_WRITABLE_BITMASK;
}
export { AccountRole, assertIsInstructionForProgram, assertIsInstructionWithAccounts, assertIsInstructionWithData, downgradeRoleToNonSigner, downgradeRoleToReadonly, isInstructionForProgram, isInstructionWithAccounts, isInstructionWithData, isSignerRole, isWritableRole, mergeRoles, upgradeRoleToSigner, upgradeRoleToWritable };
//# sourceMappingURL=index.native.mjs.map
//# sourceMappingURL=index.native.mjs.map