Skip to content

Commit

Permalink
Added prettier to dev deps and ran it on project.
Browse files Browse the repository at this point in the history
  • Loading branch information
thekevinbrown committed May 6, 2019
1 parent d9d3312 commit 9a6b7b3
Show file tree
Hide file tree
Showing 15 changed files with 230 additions and 170 deletions.
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"@types/text-encoding": "0.0.35",
"eosjs": "20.0.0",
"eosjs-ecc": "4.0.4",
"prettier": "1.17.0",
"ts-node": "8.1.0",
"typedoc": "0.14.2",
"typescript": "3.4.5"
Expand Down
13 changes: 11 additions & 2 deletions src/accounts/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Contract } from '../contracts';
import { AccountManager } from './accountManager';

export class Account {

/** EOSIO account name */
public name: string;
/** EOSIO account public key */
Expand All @@ -18,7 +17,17 @@ export class Account {
// Store references
this.name = name;
this.privateKey = privateKey;
this.publicKey = publicKey || ecc.privateToPublic(privateKey);

this.publicKey = ecc.privateToPublic(privateKey);

if (publicKey && publicKey !== this.publicKey) {
throw new Error(
`Supplied public key does not match private key. Supplied key: ${publicKey} Expected key: ${ecc.privateToPublic(
privateKey
)} This is usually caused by using the legacy key format vs the new style key format.`
);
}

// Set default permissions
this.permissions = {
active: {
Expand Down
14 changes: 6 additions & 8 deletions src/accounts/accountManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ interface AccountCreationOptions {
}

export class AccountManager {

/**
* Generates a new random account
* @note Shorthand method for [[AccountManager.createAccounts]]
Expand Down Expand Up @@ -136,7 +135,7 @@ export class AccountManager {
// Execute the transaction
return await EOSManager.transact({ actions }, eos);
};

/**
* Grants `eosio.code` permission to the specified account's `active` key
* @note Should be moved to the `contracts/contract.ts` I think?
Expand All @@ -148,19 +147,18 @@ export class AccountManager {
static addCodePermission = async (account: Account) => {
// We need to get their existing permissions, then add in a new eosio.code permission for this contract.
const { permissions } = await EOSManager.rpc.get_account(account.name);
const { required_auth } = permissions.find((permission: any) => permission.perm_name == 'active');
const { required_auth } = permissions.find(
(permission: any) => permission.perm_name == 'active'
);
// Check if `eosio.code` has already been set
const existingPermission = required_auth.accounts.find(
(account: any) =>
account.permission.actor === account.name &&
account.permission.permission === 'eosio.code'
account.permission.actor === account.name && account.permission.permission === 'eosio.code'
);
// Throw if permission exists
if (existingPermission) {
throw new Error(
`Code permission is already present on account ${account.name} for contract ${
account.name
}`
`Code permission is already present on account ${account.name} for contract ${account.name}`
);
}
// Append the `eosio.code` permission to existing
Expand Down
4 changes: 2 additions & 2 deletions src/cli/lamington-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ const run = async () => {
// Initialize configuration
await ConfigManager.initWithDefaults();
// Stop container if running
if (!ConfigManager.keepAlive && await eosIsReady()) {
if (!ConfigManager.keepAlive && (await eosIsReady())) {
await stopContainer();
}
// This ensures we have our .gitignore inside the .lamington directory
await GitIgnoreManager.createIfMissing();
// Start the EOSIO container image
if (!await eosIsReady()) {
if (!(await eosIsReady())) {
await startEos();
}
// Build all smart contracts
Expand Down
6 changes: 3 additions & 3 deletions src/cli/lamington-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const run = async () => {
// Ensures we have our .gitignore inside the .lamington directory
await GitIgnoreManager.createIfMissing();
// Start an EOSIO instance if not running
if (!await eosIsReady()) {
if (!(await eosIsReady())) {
await startEos();
}
// Start compiling smart contracts
Expand All @@ -31,13 +31,13 @@ const run = async () => {
}
};

run().catch(async (error) => {
run().catch(async error => {
if (await eosIsReady()) {
stopContainer().then(() => {
//console.log(error)
process.exit(1);
});
} else {
console.log(error)
console.log(error);
}
});
56 changes: 28 additions & 28 deletions src/cli/logIndicator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,50 @@ import ora, { Ora } from 'ora';
import * as colors from 'colors';

/** Holds spinner instances */
const cache:{ spinner?:Ora } = {};
const cache: { spinner?: Ora } = {};

/**
* Creates a new spinner instance with the specified message
* @author Mitch Pierias <github.com/MitchPierias>
* @param text Output display message
*/
export const create = (text:string) => {
// Cleanup existing spinner
if (cache.spinner) {
cache.spinner.succeed();
delete cache.spinner;
}
// Create and cache spinner
cache.spinner = ora({
text:colors.white(text),
color: 'magenta'
}).start();
}
export const create = (text: string) => {
// Cleanup existing spinner
if (cache.spinner) {
cache.spinner.succeed();
delete cache.spinner;
}
// Create and cache spinner
cache.spinner = ora({
text: colors.white(text),
color: 'magenta',
}).start();
};

/**
* Terminates the current spinner with the specified output message
* @author Mitch Pierias <github.com/MitchPierias>
* @param message Output message
* @param isError Renders output as error toggle
*/
export const end = (message:string = '', isError:boolean = false) => {
// Check spinner reference
if (!cache.spinner) return;
// Handle output
if (isError) {
cache.spinner.fail(colors.grey(message))
} else {
cache.spinner.succeed(colors.grey(message))
}
// Clear spinner reference
delete cache.spinner;
}
export const end = (message: string = '', isError: boolean = false) => {
// Check spinner reference
if (!cache.spinner) return;
// Handle output
if (isError) {
cache.spinner.fail(colors.grey(message));
} else {
cache.spinner.succeed(colors.grey(message));
}
// Clear spinner reference
delete cache.spinner;
};

/**
* Terminates the current spinner as an error with output message
* @author Mitch Pierias <github.com/MitchPierias>
* @param message Spinner message.
*/
export const fail = (message:string) => {
end(message, true);
}
export const fail = (message: string) => {
end(message, true);
};
32 changes: 17 additions & 15 deletions src/cli/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ export const startEos = async () => {
\n\
==================================================== \n'
);
spinner.end("Started EOS docker container")
spinner.end('Started EOS docker container');
} catch (error) {
spinner.fail('Failed to start the EOS container');
console.log(` --> ${error}`);
Expand Down Expand Up @@ -354,20 +354,22 @@ export const compileContract = async (contractPath: string) => {
const basename = path.basename(contractPath, '.cpp');
const fullPath = path.join(ConfigManager.outDir, path.dirname(contractPath));
// Pull docker images
await docker.command(
// Arg 1 is filename, arg 2 is contract name.
`exec lamington /opt/eosio/bin/scripts/compile_contract.sh "/${path.join(
'opt',
'eosio',
'bin',
'project',
contractPath
)}" "${fullPath}" "${basename}"`
).catch(err => {
spinner.fail("Failed to compile");
console.log(` --> ${err}`);
throw err;
});
await docker
.command(
// Arg 1 is filename, arg 2 is contract name.
`exec lamington /opt/eosio/bin/scripts/compile_contract.sh "/${path.join(
'opt',
'eosio',
'bin',
'project',
contractPath
)}" "${fullPath}" "${basename}"`
)
.catch(err => {
spinner.fail('Failed to compile');
console.log(` --> ${err}`);
throw err;
});
// Notify build task completed
spinner.end(`Compiled contract`);
};
46 changes: 28 additions & 18 deletions src/configManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,15 @@ export interface LamingtonConfig {
cdt: string;
eos: string;
keepAlive?: boolean;
outDir?: string,
exclude?: string | RegExp | Array<string|RegExp>
outDir?: string;
exclude?: string | RegExp | Array<string | RegExp>;
}

/**
* Fetches and stores the latest EOS configuration images
* @author Kevin Brown <github.com/thekevinbrown>
*/
export class ConfigManager {

/** @hidden EOSIO and EOSIO.CDT configuration settings */
private static config: LamingtonConfig;

Expand All @@ -51,7 +50,9 @@ export class ConfigManager {
*/
private static async getAssetURL(organization: string, repository: string, filter: string) {
// Get the projects latest GitHub repository release
const result = await axios.get(`https://api.github.com/repos/${organization}/${repository}/releases/latest`);
const result = await axios.get(
`https://api.github.com/repos/${organization}/${repository}/releases/latest`
);
// Handle failed GitHub request
if (!result.data || !result.data.assets || !Array.isArray(result.data.assets)) {
console.error(result);
Expand All @@ -62,9 +63,10 @@ export class ConfigManager {
asset.browser_download_url.includes(filter)
);
// Handle no assets found
if (!asset) throw new Error (
`Could not locate asset with ${filter} in the download URL in the ${organization}/${repository} repository`
);
if (!asset)
throw new Error(
`Could not locate asset with ${filter} in the download URL in the ${organization}/${repository} repository`
);
// Return captured download url
return asset.browser_download_url as string;
}
Expand All @@ -78,30 +80,38 @@ export class ConfigManager {
public static async initWithDefaults() {
// Load existing configuration
const userConfig = {
outDir:CACHE_DIRECTORY,
keepAlive:false,
exclude:[],
...await ConfigManager.readConfigFromProject()
}
outDir: CACHE_DIRECTORY,
keepAlive: false,
exclude: [],
...(await ConfigManager.readConfigFromProject()),
};
// Check if configuration exists
if (!(await ConfigManager.configExists())) {
// Create the config directory
await mkdirp(CACHE_DIRECTORY);
// Fetch the latest repository configuration
const defaultConfig: LamingtonConfig = {
cdt: await ConfigManager.getAssetURL('EOSIO', 'eosio.cdt', 'amd64.deb'),
eos: await ConfigManager.getAssetURL('EOSIO', 'eos', 'ubuntu-18.04')
eos: await ConfigManager.getAssetURL('EOSIO', 'eos', 'ubuntu-18.04'),
};
// Freeze repository image
await writeFile(CONFIG_FILE_PATH, JSON.stringify(defaultConfig, null, 4), ENCODING);
}
// Load cached config
const existingConfig = JSON.parse(await readFile(CONFIG_FILE_PATH, ENCODING));
// Save cached configuration
await writeFile(CONFIG_FILE_PATH, JSON.stringify({
...existingConfig,
...userConfig
}, null, 4), ENCODING);
await writeFile(
CONFIG_FILE_PATH,
JSON.stringify(
{
...existingConfig,
...userConfig,
},
null,
4
),
ENCODING
);
// Load existing configuration
await ConfigManager.loadConfigFromDisk();
}
Expand Down Expand Up @@ -134,7 +144,7 @@ export class ConfigManager {
private static async readConfigFromProject() {
return (await exists(CONFIGURATION_FILE_NAME))
? JSON.parse(await readFile(CONFIGURATION_FILE_NAME, ENCODING))
: {}
: {};
}

/**
Expand Down
Loading

0 comments on commit 9a6b7b3

Please sign in to comment.