Skip to content

Commit

Permalink
Account creation works.
Browse files Browse the repository at this point in the history
  • Loading branch information
thekevinbrown committed Apr 9, 2019
1 parent f45d19b commit c2cdee0
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 115 deletions.
5 changes: 5 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 @@ -54,6 +54,7 @@
"mkdirp": "0.5.1",
"mocha": "6.0.2",
"node-fetch": "2.3.0",
"qrcode-terminal": "0.12.0",
"rimraf": "2.6.3",
"ts-mocha": "6.0.0"
},
Expand Down
18 changes: 18 additions & 0 deletions src/@types/qrcode-terminal.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
declare module 'qrcode-terminal' {
export interface GenerationCallback {
(result: string): void;
}

export interface QRCodeGenerationOptions {
small?: boolean;
}

export function generate(value: string, callback?: GenerationCallback): void;
export function generate(
value: string,
options?: QRCodeGenerationOptions,
callback?: GenerationCallback
): void;

export function setErrorLevel(errorLevel: string): void;
}
18 changes: 18 additions & 0 deletions src/accounts/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,22 @@ export class Account {
},
};
}

public get active() {
return [
{
actor: this.name,
permission: 'active',
},
];
}

public get owner() {
return [
{
actor: this.name,
permission: 'owner',
},
];
}
}
153 changes: 57 additions & 96 deletions src/accounts/accountManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,112 +42,73 @@ export class AccountManager {
EOSManager.signatureProvider.keys.set(account.publicKey, account.privateKey);
}

return await eos.transact(
const systemContract = await eos.getContract('eosio');

const actions: any = [
{
actions: [
{
account: 'eosio',
name: 'newaccount',
authorization: [
{
actor: creator.name,
permission: 'active',
},
],
data: {
creator: creator.name,
name: account.name,
owner: {
threshold: 1,
keys: [
{
key: account.publicKey,
weight: 1,
},
],
accounts: [],
waits: [],
},
active: {
threshold: 1,
keys: [
{
key: account.publicKey,
weight: 1,
},
],
accounts: [],
waits: [],
},
},
},
{
account: 'eosio',
name: 'buyrambytes',
authorization: [
account: 'eosio',
name: 'newaccount',
authorization: creator.active,
data: {
creator: creator.name,
name: account.name,
owner: {
threshold: 1,
keys: [
{
actor: creator.name,
permission: 'active',
key: account.publicKey,
weight: 1,
},
],
data: {
payer: creator.name,
receiver: account.name,
bytes: 8192,
},
accounts: [],
waits: [],
},
{
account: 'eosio',
name: 'delegatebw',
authorization: [
active: {
threshold: 1,
keys: [
{
actor: creator.name,
permission: 'active',
key: account.publicKey,
weight: 1,
},
],
data: {
from: creator.name,
receiver: account.name,
stake_net_quantity: '10.0000 SYS',
stake_cpu_quantity: '10.0000 SYS',
transfer: false,
},
accounts: [],
waits: [],
},
],
},
},
// {
// actions: [
// {
// newaccount: {
// creator: creator.name,
// name: account.name,
// owner: account.publicKey,
// active: account.publicKey,
// },
// },
// {
// buyrambytes: {
// payer: creator.name,
// receiver: account.name,
// bytes: 8192,
// },
// },
// {
// delegatebw: {
// from: creator.name,
// receiver: account.name,
// stake_net_quantity: '10.0000 SYS',
// stake_cpu_quantity: '10.0000 SYS',
// transfer: 0,
// },
// },
// ],
// },
{
blocksBehind: 3,
expireSeconds: 30,
}
);
];

// Do we need to buyrambytes? If there's a system contract with that action we do.
if (systemContract.actions.has('buyrambytes')) {
actions.push({
account: 'eosio',
name: 'buyrambytes',
authorization: creator.active,
data: {
payer: creator.name,
receiver: account,
bytes: 8192,
},
});
}

// Same deal for delegatebw. Only if it's actually a thing.
if (systemContract.actions.has('delegatebw')) {
actions.push({
account: 'eosio',
name: 'delegatebw',
authorization: creator.active,
data: {
from: creator.name,
receiver: account.name,
stake_net_quantity: '10.0000 SYS',
stake_cpu_quantity: '10.0000 SYS',
transfer: false,
},
});
}

return await EOSManager.transact({ actions }, eos);
};

private static flattenOptions(options?: AccountCreationOptions) {
Expand Down
48 changes: 30 additions & 18 deletions src/cli/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import axios from 'axios';
import * as Mocha from 'mocha';
import * as mkdirpCallback from 'mkdirp';
import * as rimrafCallback from 'rimraf';
import * as qrcode from 'qrcode-terminal';
import { writeFile as writeFileCallback, exists as existsCallback } from 'fs';
import * as globCallback from 'glob';
import * as path from 'path';
Expand All @@ -23,6 +24,8 @@ import { untilBlockNumber } from '../accounts';

const EOS_VERSION = '1.7.0';
const CDT_VERSION = '1.6.1';
// const CONTRACTS_VERSION = '1.6.0';
// const DOCKER_IMAGE_NAME = `lamington:eos${EOS_VERSION}-cdt${CDT_VERSION}-contracts${CONTRACTS_VERSION}`;
const DOCKER_IMAGE_NAME = `lamington:eos${EOS_VERSION}-cdt${CDT_VERSION}`;
const TEMP_DOCKER_DIRECTORY = path.join(__dirname, '.temp-docker');

Expand All @@ -43,24 +46,24 @@ export const buildImage = async () => {
`
FROM ubuntu:18.04
RUN apt-get update
RUN apt-get install -y wget sudo curl
RUN wget https://github.com/EOSIO/eosio.cdt/releases/download/v${CDT_VERSION}/eosio.cdt_${CDT_VERSION}-1_amd64.deb
RUN sudo apt install -y ./eosio.cdt_${CDT_VERSION}-1_amd64.deb
RUN wget https://github.com/EOSIO/eos/releases/download/v${EOS_VERSION}/eosio_${EOS_VERSION}-1-ubuntu-18.04_amd64.deb
RUN sudo apt install -y ./eosio_${EOS_VERSION}-1-ubuntu-18.04_amd64.deb`
RUN apt-get update && apt-get install -y --no-install-recommends wget curl build-essential cmake ca-certificates
RUN wget https://github.com/EOSIO/eosio.cdt/releases/download/v${CDT_VERSION}/eosio.cdt_${CDT_VERSION}-1_amd64.deb && apt install -y ./eosio.cdt_${CDT_VERSION}-1_amd64.deb && rm -f *.deb
RUN wget https://github.com/EOSIO/eos/releases/download/v${EOS_VERSION}/eosio_${EOS_VERSION}-1-ubuntu-18.04_amd64.deb && apt install -y ./eosio_${EOS_VERSION}-1-ubuntu-18.04_amd64.deb && rm -f *.deb
RUN apt-get clean && rm -rf /tmp/* /var/tmp/* && rm -rf /var/lib/apt/lists/*
`
);

console.log(await docker.command(`build -t ${DOCKER_IMAGE_NAME} "${TEMP_DOCKER_DIRECTORY}"`));
await docker.command(`build -t ${DOCKER_IMAGE_NAME} "${TEMP_DOCKER_DIRECTORY}"`);

// Clean up after ourselves.
await rimraf(TEMP_DOCKER_DIRECTORY);
};

export const startContainer = () =>
docker.command(
export const startContainer = async () => {
await docker.command(
`run --rm --name lamington -d -p 8888:8888 -p 9876:9876 --mount type=bind,src="${workingDirectory}",dst=/opt/eosio/bin/project --mount type=bind,src="${__dirname}/../scripts",dst=/opt/eosio/bin/scripts -w "/opt/eosio/bin/" ${DOCKER_IMAGE_NAME} /bin/bash -c "./scripts/init_blockchain.sh"`
);
};

export const stopContainer = () => docker.command('stop lamington');

Expand Down Expand Up @@ -95,10 +98,16 @@ export const startEos = async () => {
await mkdirp(path.join(workingDirectory, '.lamington', 'data'));

if (!(await imageExists())) {
console.log('Container does not yet exist. Building...');
console.log('--------------------------------------------------------------');
console.log('Docker image does not yet exist. Building...');
console.log(
'Note: This will take a few minutes but only happens once for each version of the EOS tools you use.'
);
console.log();
console.log(`We've prepared some hold music for you: https://youtu.be/6g4dkBF5anU`);
console.log();
qrcode.generate('https://youtu.be/6g4dkBF5anU');

await buildImage();
}

Expand All @@ -107,14 +116,17 @@ export const startEos = async () => {

await untilEosIsReady();

console.log();
console.log('==========================================');
console.log(' EOS running, admin account created.');
console.log();
console.log(' RPC: http://localhost:8888');
console.log(' Docker Container: lamington');
console.log('==========================================');
console.log();
console.log(
' \n\
==================================================== \n\
\n\
EOS running, admin account created. \n\
\n\
RPC: http://localhost:8888 \n\
Docker Container: lamington \n\
\n\
===================================================='
);
} catch (error) {
console.error('Could not start EOS blockchain. Error: ', error);
process.exit(1);
Expand Down
9 changes: 8 additions & 1 deletion src/eosManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,19 @@ export class EOSManager {
// when this is actually following the getting started docs on EOSJS.
EOSManager.rpc = new JsonRpc('http://127.0.0.1:8888', { fetch: fetch as any });
EOSManager.api = new Api({
chainId: 'cf057bbfb72640471fd910bcb67639c22df9f92470936cddc1ade0e2f2e7dc4f',
rpc: EOSManager.rpc,
signatureProvider: EOSManager.signatureProvider,
// Same deal here, type mismatch when there really shouldn't be.
textDecoder: new TextDecoder() as any,
textEncoder: new TextEncoder(),
});
};

static transact = (
transaction: any,
eos = EOSManager.api,
options = { blocksBehind: 0, expireSeconds: 30 }
) => {
return eos.transact(transaction, options);
};
}
3 changes: 3 additions & 0 deletions src/scripts/init_blockchain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ PATH="$PATH:/opt/eosio/bin:/opt/eosio/bin/scripts"

set -m

# Clear the data directory
rm -rf /mnt/dev/data

# start nodeos ( local node of blockchain )
# run it in a background job such that docker run could continue
nodeos -e -p eosio -d /mnt/dev/data \
Expand Down

0 comments on commit c2cdee0

Please sign in to comment.