Run prettier

This commit is contained in:
armaniferrante 2021-01-04 23:59:52 -08:00
parent b4a2b52416
commit ce6d647fdf
No known key found for this signature in database
GPG Key ID: 58BEF301E91F7828
3 changed files with 69 additions and 64 deletions

View File

@ -3,7 +3,7 @@ import * as web3 from "@solana/web3.js";
import { Provider } from "@project-serum/common";
import { Program } from "./program";
import Coder from "./coder";
import workspace from './workspace';
import workspace from "./workspace";
let _provider: Provider | null = null;
@ -15,4 +15,13 @@ function getProvider(): Provider {
return _provider;
}
export { workspace, Program, Coder, setProvider, getProvider, Provider, BN, web3 };
export {
workspace,
Program,
Coder,
setProvider,
getProvider,
Provider,
BN,
web3,
};

View File

@ -105,24 +105,24 @@ export class RpcFactory {
ixFns[name] = ix;
});
if (idl.accounts) {
idl.accounts.forEach((idlAccount) => {
// todo
const accountFn = async (address: PublicKey): Promise<any> => {
const provider = getProvider();
if (provider === null) {
throw new Error("Provider not set");
}
const accountInfo = await provider.connection.getAccountInfo(address);
if (accountInfo === null) {
throw new Error(`Entity does not exist ${address}`);
}
return coder.accounts.decode(idlAccount.name, accountInfo.data);
};
const name = camelCase(idlAccount.name);
accountFns[name] = accountFn;
});
}
if (idl.accounts) {
idl.accounts.forEach((idlAccount) => {
// todo
const accountFn = async (address: PublicKey): Promise<any> => {
const provider = getProvider();
if (provider === null) {
throw new Error("Provider not set");
}
const accountInfo = await provider.connection.getAccountInfo(address);
if (accountInfo === null) {
throw new Error(`Entity does not exist ${address}`);
}
return coder.accounts.decode(idlAccount.name, accountInfo.data);
};
const name = camelCase(idlAccount.name);
accountFns[name] = accountFn;
});
}
return [rpcs, ixFns, accountFns];
}

View File

@ -1,58 +1,54 @@
import camelCase from "camelcase";
import { PublicKey } from '@solana/web3.js';
import { Program } from './program';
import { PublicKey } from "@solana/web3.js";
import { Program } from "./program";
let _populatedWorkspace = false;
// Workspace program discovery only works for node environments.
export default new Proxy({} as any, {
get(
workspaceCache: { [key: string]: Program },
programName: string
) {
const find = require('find');
const fs = require('fs');
const process = require('process');
get(workspaceCache: { [key: string]: Program }, programName: string) {
const find = require("find");
const fs = require("fs");
const process = require("process");
if (typeof window !== 'undefined') {
if (typeof window !== "undefined") {
throw new Error("`anchor.workspace` is not available in the browser");
}
if (!_populatedWorkspace) {
const path = require("path");
let projectRoot = process.cwd();
while (!fs.existsSync(path.join(projectRoot, "Anchor.toml"))) {
const parentDir = path.dirname(projectRoot);
if (parentDir === projectRoot) {
projectRoot = undefined;
}
projectRoot = parentDir;
}
if (projectRoot === undefined) {
throw new Error(
'`anchor.workspace` is not available in the browser'
"Could not find workspace root. Perhaps set the `OASIS_WORKSPACE` env var?"
);
}
if (!_populatedWorkspace) {
const path = require('path');
let projectRoot = process.cwd();
while (!fs.existsSync(path.join(projectRoot, 'Anchor.toml'))) {
const parentDir = path.dirname(projectRoot);
if (parentDir === projectRoot) {
projectRoot = undefined;
}
projectRoot = parentDir;
}
if (projectRoot === undefined) {
throw new Error(
'Could not find workspace root. Perhaps set the `OASIS_WORKSPACE` env var?'
find
.fileSync(/target\/idl\/.*\.json/, projectRoot)
.reduce((programs: any, path: string) => {
const idlStr = fs.readFileSync(path);
const idl = JSON.parse(idlStr);
const name = camelCase(idl.name, { pascalCase: true });
programs[name] = new Program(
idl,
new PublicKey(idl.metadata.address)
);
}
return programs;
}, workspaceCache);
find
.fileSync(/target\/idl\/.*\.json/, projectRoot)
.reduce((programs: any, path: string) => {
const idlStr = fs.readFileSync(path);
const idl = JSON.parse(idlStr);
const name = camelCase(idl.name, { pascalCase: true });
programs[name] = new Program(idl, new PublicKey(idl.metadata.address));
return programs;
}, workspaceCache);
_populatedWorkspace = true;
}
_populatedWorkspace = true;
}
return workspaceCache[programName];
},
}
);
return workspaceCache[programName];
},
});