Migrate to OMG v0.2 Samrong

This commit is contained in:
emizzle 2019-06-12 16:38:13 +10:00
parent a915359592
commit fb3693ad82
No known key found for this signature in database
GPG Key ID: 1FD4BAB3C37EE9BA
4 changed files with 30 additions and 154 deletions

View File

@ -41,11 +41,10 @@
"dependencies": {
"@babel/plugin-proposal-optional-chaining": "7.2.0",
"@babel/runtime-corejs2": "7.3.1",
"@omisego/omg-js": "1.2.2",
"@omisego/omg-js-childchain": "1.2.1",
"@omisego/omg-js-rootchain": "1.2.2",
"@omisego/omg-js-util": "1.2.1",
"async": "3.0.1",
"@omisego/omg-js": "2.0.0-v0.2",
"@omisego/omg-js-childchain": "2.0.0-v0.2",
"@omisego/omg-js-rootchain": "2.0.0-v0.2",
"@omisego/omg-js-util": "2.0.0-v0.2",
"axios": "0.19.0",
"date-fns": "2.0.0-alpha.27",
"embark-utils": "^4.1.0-beta.2",

View File

@ -1,9 +1,7 @@
import EmbarkJSOmg from "embarkjs-omg";
import EmbarkUtils from "./utils/embark";
import { dappPath } from "embark-utils";
import { formatDate } from "./utils";
import { getWatcherStatus } from "./utils/plasma";
import { waterfall } from "async";
// Service check constants
const SERVICE_CHECK_ON = 'on';
@ -22,47 +20,11 @@ class EmbarkOmg extends EmbarkJSOmg {
this.pluginConfig = embark.pluginConfig;
this.accounts = [];
// gets hydrated blockchain config from embark, use it to init
// this.events.once('config:load:blockchain', (blockchainConfig) => {
// this.embarkUtils = new EmbarkUtils({ events: this.events, logger: this.logger, blockchainConfig });
// try {
// this.init().then(() => {
this.addCodeToEmbarkJs();
// });
// }
// catch (err) {
// this.logger.error(err);
// }
// });
this.addCodeToEmbarkJs();
this.registerServiceCheck();
this.registerConsoleCommands();
}
// async init() {
// // init account used for root and child chains
// // try {
// // const accounts = await this.embarkUtils.accounts;
// // this.accounts = accounts.length > 1 ? accounts.slice(1) : accounts; // ignore the first account because it is our deployer account, we want the manually added account
// // } catch (e) {
// // return this.logger.error(`Error getting accounts: ${e}`);
// // }
// // try {
// // this.web3Path = await this.embarkUtils.web3Path;
// // }
// // catch (e) {
// // this.logger.error(`Error getting web3 from Embark: ${e}`);
// // }
// // try {
// // await super.init(this.accounts, this.web3Path);
// // this.events.emit("embark-omg:init");
// // }
// // catch (e) {
// // this.logger.error(`Error initializing EmbarkOmg: ${e}`);
// // }
// }
generateSymlink(varName, location) {
return new Promise((resolve, reject) => {
this.events.request('code-generator:symlink:generate', location, varName, (err, symlinkDest) => {
@ -85,20 +47,9 @@ class EmbarkOmg extends EmbarkJSOmg {
async addCodeToEmbarkJs() {
const nodePath = dappPath('node_modules');
const embarkjsOmgPath = require.resolve("embarkjs-omg", { paths: [nodePath] });
// let web3SymlinkPath,
let embarkJsOmgSymlinkPath;
await this.codeGeneratorReady();
// create a symlink to web3 - this is currently the job of the web3 connector, so either this will run
// first or the connector will overwrite it.
// try {
// web3SymlinkPath = await this.generateSymlink('web3', this.web3Path);
// }
// catch (err) {
// this.logger.error(__('Error creating a symlink to web3'));
// return this.logger.error(err.message || err);
// }
try {
embarkJsOmgSymlinkPath = await this.generateSymlink('embarkjs-omg', embarkjsOmgPath);
}
@ -183,22 +134,22 @@ class EmbarkOmg extends EmbarkJSOmg {
}
});
const sendRegex = /^plasma[\s]+send[\s]+(0x[0-9,a-f,A-F]{40,40})[\s]+([0-9]+)$/;
const sendRegex = /^plasma[\s]+transfer[\s]+(0x[0-9,a-f,A-F]{40,40})[\s]+([0-9]+)$/;
this.embark.registerConsoleCommand({
description: "Sends an ETH tx on the Plasma chain from the account configured in the DApp's blockchain configuration to any other account on the Plasma chain.",
matches: (cmd) => {
return sendRegex.test(cmd);
},
usage: "plasma send [to_address] [amount]",
usage: "plasma transfer [to_address] [amount]",
process: (cmd, callback) => {
if (!this.inited) {
return callback("The Plasma chain has not been initialized. Please initialize the Plamsa chain using 'plasma init' before continuting."); // passes a message back to cockpit console
}
const matches = cmd.match(sendRegex) || [];
if (matches.length <= 2) {
return callback("Invalid command format, please use the format 'plasma send [to_address] [amount]', ie 'plasma send 0x38d5beb778b6e62d82e3ba4633e08987e6d0f990 555'");
return callback("Invalid command format, please use the format 'plasma transfer [to_address] [amount]', ie 'plasma transfer 0x38d5beb778b6e62d82e3ba4633e08987e6d0f990 555'");
}
this.send(matches[1], matches[2])
this.transfer(matches[1], matches[2])
.then((message) => {
this.logger.info(message);
callback(null, message);
@ -265,29 +216,6 @@ class EmbarkOmg extends EmbarkJSOmg {
const name = "OMG Plasma Chain";
this.events.request("services:register", name, (cb) => {
// waterfall([
// (next) => {
// if (this.inited) {
// return next();
// }
// this.events.once("embark-omg:init", next);
// },
// (next) => {
// // TODO: web3_clientVersion method is currently not implemented in web3.js 1.0
// getWatcherStatus(this.pluginConfig.WATCHER_URL)
// .then((status) => {
// const serviceStatus = `Last block: ${formatDate(status.last_mined_child_block_timestamp)}`;
// next(null, { name: serviceStatus, status: status ? SERVICE_CHECK_ON : SERVICE_CHECK_OFF });
// })
// .catch(next);
// }
// ], (err, statusObj) => {
// if (err) {
// return cb(err);
// }
// cb(statusObj);
// });
getWatcherStatus(this.pluginConfig.WATCHER_URL)
.then((status) => {
const serviceStatus = `Last block: ${formatDate(status.last_mined_child_block_timestamp)}`;

View File

@ -1,46 +0,0 @@
export default class EmbarkUtils {
constructor({ events, logger, blockchainConfig }) {
this.events = events;
this.logger = logger;
this.blockchainConfig = blockchainConfig;
}
get accounts() {
return new Promise((resolve, reject) => {
this.events.request("blockchain:ready", () => {
// this.events.request("blockchain:get", (embarkWeb3) => {
// try {
// const accountsParsed = AccountParser.parseAccountsConfig(this.blockchainConfig.accounts, embarkWeb3, dappPath(), this.logger, []);
// resolve(accountsParsed);
// } catch (e) {
// reject(e);
// }
// });
this.events.request("blockchain:getAccounts", (err, accounts) => {
if (err) {
return reject(err);
}
resolve(accounts);
});
});
});
}
// get web3Path() {
// return new Promise((resolve, reject) => {
// this.events.request("version:get:web3", (web3Version) => {
// if (web3Version === "1.0.0-beta") {
// const nodePath = embarkPath('node_modules');
// const web3Path = require.resolve("web3", { paths: [nodePath] });
// return resolve(web3Path);
// }
// this.events.request("version:getPackageLocation", "web3", web3Version, (err, location) => {
// if (err) {
// return reject(err);
// }
// const locationPath = embarkPath(location).replace(/\\/g, '/');
// resolve(locationPath);
// });
// });
// });
// }
}

View File

@ -694,29 +694,29 @@
lodash "^4.17.11"
to-fast-properties "^2.0.0"
"@omisego/omg-js-childchain@1.2.1", "@omisego/omg-js-childchain@^1.2.1":
version "1.2.1"
resolved "https://registry.yarnpkg.com/@omisego/omg-js-childchain/-/omg-js-childchain-1.2.1.tgz#7fd83af2e47ae7936fd9743c5a98244c89f64222"
integrity sha512-UuYc0w8xTZPceDUnuWXV46MhPMUmu9+ecTbEh0sd5YSx9N9ie+t2FRikvvTH9g4+GBmQRoI0XCkFBU/pW3SJkA==
"@omisego/omg-js-childchain@2.0.0-v0.2", "@omisego/omg-js-childchain@^2.0.0-v0.2":
version "2.0.0-v0.2"
resolved "https://registry.yarnpkg.com/@omisego/omg-js-childchain/-/omg-js-childchain-2.0.0-v0.2.tgz#d2c2e1af48a8c00a68902db6107e1da824701b86"
integrity sha512-hz9U2xPg/xFbdBxUIqXfDjfA8JKIegMnG757d6b3h3Ot2kGvPL+0GK59JoMYwOG64J5uaco5HZ7NnnGfjQ5Aqw==
dependencies:
"@omisego/omg-js-util" "^1.2.1"
"@omisego/omg-js-util" "^2.0.0-v0.2"
debug "^4.0.1"
json-bigint "^0.3.0"
node-fetch "^2.2.0"
rlp "^2.1.0"
"@omisego/omg-js-rootchain@1.2.2", "@omisego/omg-js-rootchain@^1.2.2":
version "1.2.2"
resolved "https://registry.yarnpkg.com/@omisego/omg-js-rootchain/-/omg-js-rootchain-1.2.2.tgz#630ad267f0ad6b2e44098790be9acb8816413032"
integrity sha512-vgyVfUDnyVeoe0XUv7hM13kHXqdJyEghqHEV07GyTr69QfzbFfTe9jzMceLAb5f+4Y/E5gLgU1Vqlt7lNGctUQ==
"@omisego/omg-js-rootchain@2.0.0-v0.2", "@omisego/omg-js-rootchain@^2.0.0-v0.2":
version "2.0.0-v0.2"
resolved "https://registry.yarnpkg.com/@omisego/omg-js-rootchain/-/omg-js-rootchain-2.0.0-v0.2.tgz#05ebbe6ee4e583a25f26c041a8d52b1084857b8c"
integrity sha512-QRsipPvozaImfO8ifPOh9w/GmOHT9hr9mdBWtRtZ3AqBOru10QG9gHF9vSQTsCDjr0jsAnoqHC/s/wuuDVfvbg==
dependencies:
"@omisego/omg-js-util" "^1.2.1"
"@omisego/omg-js-util" "^2.0.0-v0.2"
debug "^4.0.1"
"@omisego/omg-js-util@1.2.1", "@omisego/omg-js-util@^1.2.1":
version "1.2.1"
resolved "https://registry.yarnpkg.com/@omisego/omg-js-util/-/omg-js-util-1.2.1.tgz#7495f6835681a3096cc54dabb8c0495bc37d22ec"
integrity sha512-14YTB/hycMSgGnZ/SLKiu0KA9qqwc7mTvyGfO6VE2DonX6uDrYRqmbWX0wDnk3A1hWoVLPiqG7CLBNbkOnhsKg==
"@omisego/omg-js-util@2.0.0-v0.2", "@omisego/omg-js-util@^2.0.0-v0.2":
version "2.0.0-v0.2"
resolved "https://registry.yarnpkg.com/@omisego/omg-js-util/-/omg-js-util-2.0.0-v0.2.tgz#30b5882cc8a45446e7206576240caade614c8590"
integrity sha512-J5J5Q2XC7ZkpfQJiXJxii/66Tn3x4rhnhky3BmL++XEBoK6I34wgWMs/7dzsejWNHmmhGv/M/OZb+QBI+HlvlA==
dependencies:
eth-sig-util "^2.1.1"
ethereumjs-util "^6.0.0"
@ -724,14 +724,14 @@
number-to-bn "^1.7.0"
rlp "^2.2.2"
"@omisego/omg-js@1.2.2":
version "1.2.2"
resolved "https://registry.yarnpkg.com/@omisego/omg-js/-/omg-js-1.2.2.tgz#3d7b8a179953307f1d34a321730572760f21b4e0"
integrity sha512-nnaL80FEtv+4yAocXV9qyJr3yNOGKdVNFiB2ehIdHuEx3YTy5yPc7+E4RqQSYcCm3iev7GdxTtSd9bSXGZ2lNQ==
"@omisego/omg-js@2.0.0-v0.2":
version "2.0.0-v0.2"
resolved "https://registry.yarnpkg.com/@omisego/omg-js/-/omg-js-2.0.0-v0.2.tgz#cd50f0e2ccc4beca75b0e01b9b1ad2a126ec3103"
integrity sha512-eMAjn50+bX2uyzghlyXbSFV/2tcAA5wqD8Q3pZTXvUT9U6QZBcfsu6fUTV56vNJT8KqAdCl2Rma3PKeB80IB9Q==
dependencies:
"@omisego/omg-js-childchain" "^1.2.1"
"@omisego/omg-js-rootchain" "^1.2.2"
"@omisego/omg-js-util" "^1.2.1"
"@omisego/omg-js-childchain" "^2.0.0-v0.2"
"@omisego/omg-js-rootchain" "^2.0.0-v0.2"
"@omisego/omg-js-util" "^2.0.0-v0.2"
"@types/node@^10.3.2":
version "10.14.7"
@ -952,11 +952,6 @@ async-limiter@~1.0.0:
resolved "https://registry.yarnpkg.com/async-limiter/-/async-limiter-1.0.0.tgz#78faed8c3d074ab81f22b4e985d79e8738f720f8"
integrity sha512-jp/uFnooOiO+L211eZOoSyzpOITMXx1rBITauYykG3BRYPu8h0UcxsPNB04RR5vo4Tyz3+ay17tR6JVf9qzYWg==
async@3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/async/-/async-3.0.1.tgz#dfeb34657d1e63c94c0eee424297bf8a2c9a8182"
integrity sha512-ZswD8vwPtmBZzbn9xyi8XBQWXH3AvOQ43Za1KWYq7JeycrZuUYzx01KvHcVbXltjqH4y0MWrQ33008uLTqXuDw==
async@~1.5.2:
version "1.5.2"
resolved "https://registry.yarnpkg.com/async/-/async-1.5.2.tgz#ec6a61ae56480c0c3cb241c95618e20892f9672a"