@solana/spl-governance
Advanced tools
Comparing version 0.3.16 to 0.3.17
@@ -6,3 +6,3 @@ import { Connection, PublicKey } from '@solana/web3.js'; | ||
export declare function getRealm(connection: Connection, realm: PublicKey): Promise<ProgramAccount<Realm>>; | ||
export declare function getRealms(connection: Connection, programId: PublicKey): Promise<ProgramAccount<Realm>[]>; | ||
export declare function getRealms(connection: Connection, programIds: PublicKey | PublicKey[]): Promise<ProgramAccount<Realm>[]>; | ||
export declare function tryGetRealmConfig(connection: Connection, programId: PublicKey, realmPk: PublicKey): Promise<ProgramAccount<RealmConfigAccount> | undefined>; | ||
@@ -9,0 +9,0 @@ export declare function getRealmConfig(connection: Connection, realmConfigPk: PublicKey): Promise<ProgramAccount<RealmConfigAccount>>; |
@@ -11,8 +11,15 @@ "use strict"; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.tryGetGovernanceAccount = exports.getGovernanceAccount = exports.getGovernanceAccounts = exports.getAllProposals = exports.getProposalsByGovernance = exports.getProposal = exports.getAllGovernances = exports.getGovernance = exports.getAllTokenOwnerRecords = exports.getTokenOwnerRecordsByOwner = exports.getTokenOwnerRecord = exports.getTokenOwnerRecordForRealm = exports.getVoteRecordsByVoter = exports.getVoteRecord = exports.getRealmConfig = exports.tryGetRealmConfig = exports.getRealms = exports.getRealm = void 0; | ||
const web3_js_1 = require("@solana/web3.js"); | ||
const serialisation_1 = require("./serialisation"); | ||
const accounts_1 = require("./accounts"); | ||
const api_1 = require("../core/api"); | ||
// Realms | ||
const bs58_1 = __importDefault(require("bs58")); | ||
const axios_1 = __importDefault(require("axios")); | ||
const borsh_1 = require("../tools/borsh"); | ||
const tools_1 = require("../tools"); | ||
function getRealm(connection, realm) { | ||
@@ -24,8 +31,70 @@ return __awaiter(this, void 0, void 0, function* () { | ||
exports.getRealm = getRealm; | ||
function getRealms(connection, programId) { | ||
function getRealms(connection, programIds) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return getGovernanceAccounts(connection, programId, accounts_1.Realm); | ||
if (programIds instanceof web3_js_1.PublicKey) { | ||
return getGovernanceAccounts(connection, programIds, accounts_1.Realm); | ||
} | ||
return _getRealms(connection, programIds); | ||
}); | ||
} | ||
exports.getRealms = getRealms; | ||
function _getRealms(connection, programIds) { | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const accountTypes = (0, accounts_1.getAccountTypes)(accounts_1.Realm); | ||
const rpcEndpoint = connection._rpcEndpoint; | ||
const rawProgramAccounts = []; | ||
for (const accountType of accountTypes) { | ||
const programAccountsJson = yield axios_1.default.request({ | ||
url: rpcEndpoint, | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
data: JSON.stringify([ | ||
...programIds.map(x => { | ||
return { | ||
jsonrpc: '2.0', | ||
id: x.toBase58(), | ||
method: 'getProgramAccounts', | ||
params: [ | ||
x.toBase58(), | ||
{ | ||
commitment: connection.commitment, | ||
encoding: 'base64', | ||
filters: [ | ||
{ | ||
memcmp: { | ||
offset: 0, | ||
bytes: bs58_1.default.encode([accountType]), | ||
}, | ||
}, | ||
], | ||
}, | ||
], | ||
}; | ||
}), | ||
]), | ||
}); | ||
rawProgramAccounts.push(...(_a = programAccountsJson === null || programAccountsJson === void 0 ? void 0 : programAccountsJson.data) === null || _a === void 0 ? void 0 : _a.filter((x) => x.result).flatMap((x) => x.result)); | ||
} | ||
let accounts = []; | ||
for (let rawAccount of rawProgramAccounts) { | ||
try { | ||
const data = Buffer.from(rawAccount.account.data[0], 'base64'); | ||
const accountType = data[0]; | ||
const account = { | ||
pubkey: new web3_js_1.PublicKey(rawAccount.pubkey), | ||
account: (0, borsh_1.deserializeBorsh)((0, serialisation_1.getGovernanceSchemaForAccount)(accountType), accounts_1.Realm, data), | ||
owner: rawAccount.account.owner, | ||
}; | ||
accounts.push(account); | ||
} | ||
catch (ex) { | ||
console.info(`Can't deserialize Realm @ ${rawAccount.pubkey}.`, (0, tools_1.getErrorMessage)(ex)); | ||
} | ||
} | ||
return accounts; | ||
}); | ||
} | ||
// Realm config | ||
@@ -32,0 +101,0 @@ function tryGetRealmConfig(connection, programId, realmPk) { |
@@ -17,6 +17,6 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
// @ts-ignore | ||
transaction.recentBlockhash = yield connection._recentBlockhash( | ||
// @ts-ignore | ||
connection._disableBlockhashCaching); | ||
const latestBlockhash = yield connection.getRecentBlockhash(); | ||
//@ts-ignore | ||
transaction.lastValidBlockHeight = latestBlockhash.lastValidBlockHeight; | ||
transaction.recentBlockhash = latestBlockhash.blockhash; | ||
const signData = transaction.serializeMessage(); | ||
@@ -23,0 +23,0 @@ // @ts-ignore |
{ | ||
"name": "@solana/spl-governance", | ||
"version": "0.3.16", | ||
"version": "0.3.17", | ||
"description": "SPL Governance Client API", | ||
@@ -36,3 +36,4 @@ "author": "Solana Maintainers <maintainers@solana.foundation>", | ||
"bs58": "^4.0.1", | ||
"superstruct": "^0.15.2" | ||
"superstruct": "^0.15.2", | ||
"axios": "^1.1.3" | ||
}, | ||
@@ -39,0 +40,0 @@ "devDependencies": { |
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
498387
7016
7
+ Addedaxios@^1.1.3
+ Addedasynckit@0.4.0(transitive)
+ Addedaxios@1.7.7(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addedfollow-redirects@1.15.9(transitive)
+ Addedform-data@4.0.1(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedproxy-from-env@1.1.0(transitive)