Skip to content

Commit

Permalink
Merge pull request #24 from GenesysGo/typescript-client
Browse files Browse the repository at this point in the history
Typescript client
  • Loading branch information
tracy-codes authored Aug 22, 2023
2 parents 0d92121 + 2fa12ad commit c12f9ca
Show file tree
Hide file tree
Showing 5 changed files with 422 additions and 505 deletions.
15 changes: 9 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
{
"name": "@shadow-drive/cli",
"version": "0.5.3",
"version": "0.6.0",
"main": "shdw-drive.js",
"bin": {
"shdw-drive": "./dist/shdw-drive.js"
"shdw-drive": "./dist/src/shdw-drive.js"
},
"license": "MIT",
"publishConfig": {
"access": "public"
},
"scripts": {
"build": "tsc"
"clean": "rimraf dist",
"build": "npm run clean && tsc",
"prepublishOnly": "npm run build"
},
"dependencies": {
"@coral-xyz/anchor": "^0.27.0",
"@shadow-drive/sdk": "^4.0.2",
"@shadow-drive/sdk": "^5.0.0",
"@solana/spl-token": "^0.2.0",
"@solana/web3.js": "^1.41.0",
"bigint-conversion": "^2.2.1",
"bottleneck": "^2.19.5",
"bs58": "^5.0.0",
"cli-progress": "^3.11.2",
"commander": "^9.2.0",
"commander": "^11.0.0",
"form-data": "^4.0.0",
"loglevel": "^1.8.0",
"mime-types": "^2.1.35",
Expand All @@ -37,6 +39,7 @@
"@types/node-fetch": "^2.6.1",
"@types/prompts": "^2.0.14",
"@types/typescript": "^2.0.0",
"pkg": "^5.6.0"
"pkg": "^5.6.0",
"rimraf": "^5.0.1"
}
}
28 changes: 9 additions & 19 deletions src/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { Program } from "@coral-xyz/anchor";
import { SHDW_DRIVE_ENDPOINT, programId } from "../constants";
import fetch from "node-fetch";
import Bottleneck from "bottleneck";
import { StorageAccount, StorageAccountV2 } from "@shadow-drive/sdk";

export function loadWalletKey(keypair: string): Keypair {
if (!keypair || keypair == "") {
Expand Down Expand Up @@ -115,32 +116,21 @@ export function bytesToHuman(bytes: any, si = false, dp = 1) {
* @returns
*/
export async function getFormattedStorageAccounts(
key: anchor.web3.PublicKey,
totalAccounts: number
rawAccounts: Array<{
publicKey: anchor.web3.PublicKey;
account: StorageAccountV2;
}>
): Promise<[Array<any>, Array<anchor.web3.PublicKey>]> {
const limiter = new Bottleneck({
minTime: 50,
maxConcurrent: 10,
});
let accountsToFetch: anchor.web3.PublicKey[] = [];

for (let i = 0; i <= totalAccounts; i++) {
let [acc] = await anchor.web3.PublicKey.findProgramAddress(
[
Buffer.from("storage-account"),
key.toBytes(),
new anchor.BN(i).toTwos(0).toArrayLike(Buffer, "le", 4),
],
programId
);
accountsToFetch.push(acc);
}

log.debug(`Accounts to Fetch length: ${accountsToFetch.length}`);
let accountKeys = [...rawAccounts.map((account) => account.publicKey)];
log.debug(`Accounts to Fetch length: ${rawAccounts.length}`);
let accounts: any = [];

await Promise.all(
accountsToFetch.map(async (account) => {
accountKeys.map(async (account) => {
try {
const storageAccountDetails = await limiter.schedule(() =>
fetch(`${SHDW_DRIVE_ENDPOINT}/storage-account-info`, {
Expand Down Expand Up @@ -202,7 +192,7 @@ export async function getFormattedStorageAccounts(
return acc;
}
});
return [formattedAccounts, accountsToFetch];
return [formattedAccounts, accountKeys];
}
export function getAnchorEnvironment(
keypair: anchor.web3.Keypair,
Expand Down
Loading

0 comments on commit c12f9ca

Please sign in to comment.