working in embark and browser
This commit is contained in:
parent
c417b710c6
commit
9e09444465
18
.babelrc
18
.babelrc
|
@ -1,18 +0,0 @@
|
|||
{
|
||||
"comments": false,
|
||||
"compact": false,
|
||||
"env": {
|
||||
"node": {
|
||||
"plugins": [
|
||||
["@babel/plugin-transform-runtime", {
|
||||
"corejs": 2
|
||||
}]
|
||||
],
|
||||
"presets": [
|
||||
["@babel/env", {
|
||||
"targets": {"node": "8.11.3"}
|
||||
}]
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
/* global module require */
|
||||
|
||||
const cloneDeep = require('lodash.clonedeep');
|
||||
|
||||
module.exports = (api) => {
|
||||
const env = api.env();
|
||||
|
||||
const base = {};
|
||||
|
||||
const browser = cloneDeep(base);
|
||||
|
||||
const node = cloneDeep(base);
|
||||
|
||||
// const nodeTest = cloneDeep(base);
|
||||
|
||||
switch (env) {
|
||||
case 'browser':
|
||||
return browser;
|
||||
case 'node':
|
||||
return node;
|
||||
// case 'node:test':
|
||||
// return nodeTest;
|
||||
default:
|
||||
return base;
|
||||
}
|
||||
};
|
|
@ -0,0 +1,62 @@
|
|||
/* global module require */
|
||||
|
||||
const cloneDeep = require('lodash.clonedeep');
|
||||
|
||||
module.exports = (api) => {
|
||||
const env = api.env();
|
||||
|
||||
const base = {
|
||||
babelrcRoots: [
|
||||
'.',
|
||||
'packages/*'
|
||||
],
|
||||
plugins: [
|
||||
'babel-plugin-macros',
|
||||
['@babel/plugin-proposal-decorators', {
|
||||
legacy: true
|
||||
}],
|
||||
'@babel/plugin-syntax-dynamic-import',
|
||||
['@babel/plugin-proposal-class-properties', {
|
||||
loose: true
|
||||
}],
|
||||
'@babel/plugin-proposal-optional-chaining',
|
||||
['@babel/plugin-transform-runtime', {
|
||||
corejs: 2
|
||||
}]
|
||||
],
|
||||
presets: [
|
||||
'@babel/preset-env'
|
||||
]
|
||||
};
|
||||
|
||||
if (env === 'base' || env.startsWith('base:')) {
|
||||
return base;
|
||||
}
|
||||
|
||||
const browser = cloneDeep(base);
|
||||
browser.plugins[browser.plugins.length - 1][1].useESModules = true;
|
||||
browser.presets[0] = [browser.presets[0], {
|
||||
modules: false,
|
||||
targets: { browsers: ['last 1 version', 'not dead', '> 0.2%'] }
|
||||
}];
|
||||
|
||||
if (env === 'browser' || env.startsWith('browser:')) {
|
||||
return browser;
|
||||
}
|
||||
|
||||
const node = cloneDeep(base);
|
||||
node.plugins.splice(
|
||||
node.plugins.indexOf('@babel/plugin-syntax-dynamic-import') + 1,
|
||||
0,
|
||||
'babel-plugin-dynamic-import-node'
|
||||
);
|
||||
node.presets[0] = [node.presets[0], {
|
||||
targets: { node: '8.11.3' }
|
||||
}];
|
||||
|
||||
if (env === 'node' || env.startsWith('node:')) {
|
||||
return node;
|
||||
}
|
||||
|
||||
return {};
|
||||
};
|
49
package.json
49
package.json
|
@ -1,20 +1,35 @@
|
|||
{
|
||||
"name": "embark-omg",
|
||||
"name": "embarkjs-omg",
|
||||
"version": "1.0.0",
|
||||
"description": "OmiseGO plugin for Embark",
|
||||
"description": "EmbarkJS library for the OmiseGO plugin for Embark",
|
||||
"main": "dist/index.js",
|
||||
"browser": {
|
||||
"./dist/index.js": "./dist/browser/index.js",
|
||||
"xmlhttprequest": "window.XMLHttpRequest"
|
||||
},
|
||||
"browserslist": [
|
||||
"last 1 version",
|
||||
"not dead",
|
||||
"> 0.2%"
|
||||
],
|
||||
"files": [
|
||||
"dist",
|
||||
"src"
|
||||
"dist"
|
||||
],
|
||||
"scripts": {
|
||||
"lint": "./node_modules/.bin/eslint src/",
|
||||
"babel": "cross-env BABEL_ENV=node babel --out-dir dist src --source-maps",
|
||||
"build": "npm run babel",
|
||||
"clean": "rimraf dist embark-status-*.tgz package",
|
||||
"prepare": "npm run build",
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"watch": "npm run clean && npm run babel -- --verbose --watch"
|
||||
"build": "npm-run-all build:**",
|
||||
"build:browser": "cross-env BABEL_ENV=browser babel src --extensions \".js\" --out-dir dist/browser",
|
||||
"build:node": "cross-env BABEL_ENV=node babel src --extensions \".js\" --out-dir dist --source-maps",
|
||||
"// build:node:test": "cross-env BABEL_ENV=node:test babel test --extensions \".js\" --out-dir build-test --source-maps",
|
||||
"ci": "npm run qa",
|
||||
"clean": "npm run reset",
|
||||
"package": "npm pack",
|
||||
"qa": "npm-run-all build test package",
|
||||
"reset": "npx rimraf .nyc_output build-test coverage dist embark-omg-*.tgz package",
|
||||
"start": "npm run watch",
|
||||
"// test": "nyc --reporter=html --reporter=json mocha \"build-test/**/*.js\" --exit --no-timeouts --require source-map-support/register",
|
||||
"watch": "run-p \"build:** --verbose --watch\""
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
@ -32,25 +47,35 @@
|
|||
},
|
||||
"homepage": "https://github.com/emizzle/embark-omg#readme",
|
||||
"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",
|
||||
"embark-utils": "^4.1.0-beta.2",
|
||||
"axios": "0.19.0",
|
||||
"ethers": "4.0.28"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/cli": "7.2.3",
|
||||
"@babel/core": "7.2.2",
|
||||
"@babel/plugin-proposal-class-properties": "7.4.4",
|
||||
"@babel/plugin-proposal-decorators": "7.4.4",
|
||||
"@babel/plugin-syntax-dynamic-import": "7.2.0",
|
||||
"@babel/plugin-transform-runtime": "7.4.0",
|
||||
"@babel/preset-env": "7.4.1",
|
||||
"@babel/runtime-corejs2": "7.3.1",
|
||||
"babel-plugin-dynamic-import-node": "2.2.0",
|
||||
"babel-plugin-macros": "2.6.0",
|
||||
"cross-env": "5.2.0",
|
||||
"eslint": "4.19.1",
|
||||
"lodash.clonedeep": "4.5.0",
|
||||
"npm-run-all": "4.1.5",
|
||||
"rimraf": "2.6.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8.11.3"
|
||||
"node": ">=8.12.0 <12.0.0",
|
||||
"npm": ">=6.4.1",
|
||||
"yarn": ">=1.12.3"
|
||||
}
|
||||
}
|
||||
|
|
234
src/index.js
234
src/index.js
|
@ -1,44 +1,15 @@
|
|||
|
||||
import { BigNumber } from "ethers/utils";
|
||||
/* global Web3 */
|
||||
import BigNumber from "bn.js";
|
||||
import ChildChain from "@omisego/omg-js-childchain";
|
||||
import EmbarkUtils from "./utils/embark";
|
||||
import RootChain from "@omisego/omg-js-rootchain";
|
||||
import { selectUtxos } from "./utils/plasma";
|
||||
import { transaction } from "@omisego/omg-js-util";
|
||||
import { waterfall } from "async";
|
||||
|
||||
// const WEB3_PROVIDER_URL = "https://rinkeby.infura.io/";
|
||||
// const WATCHER_URL = "https://watcher.ari.omg.network/";
|
||||
// const CHILDCHAIN_URL = "https://ari.omg.network/";
|
||||
// const PLASMA_CONTRACT_ADDRESS = "0x44de0ec539b8c4a4b530c78620fe8320167f2f74";
|
||||
|
||||
// Service check constants
|
||||
const SERVICE_CHECK_ON = 'on';
|
||||
const SERVICE_CHECK_OFF = 'off';
|
||||
|
||||
|
||||
// var web3 = new Web3()
|
||||
let globalKeystore;
|
||||
let rootChain;
|
||||
let childChain;
|
||||
|
||||
// const ADDRESS = "0x1e8df8b7d4212084bf5329fddc730b9e5aaba238";
|
||||
// const ADDRESS_PK = "0x0f7aa58edd2758334a819516b3421953b6c453c3e8ed85b071ce1edf3aedfab8";
|
||||
const ACCOUNT_CONFIG_ERROR = "Blockchain accounts configuration is missing. To use the Embark-OMG plugin, you must configure blockchain accounts to use either a private key file, a private key, or a mnemonic.";
|
||||
const ACCOUNT_BALANCE_ERROR = "The configured account does not have enough funds. Please make sure this account has Rinkeby ETH.";
|
||||
|
||||
|
||||
/**
|
||||
* Plugin that connects an Embark dApp to the Status app, and allows the dApp
|
||||
* to be run in the Status browser.
|
||||
*/
|
||||
class EmbarkOmg {
|
||||
constructor(embark) {
|
||||
this.embark = embark;
|
||||
this.events = this.embark.events;
|
||||
this.pluginConfig = this.embark.pluginConfig;
|
||||
this.logger = this.embark.logger;
|
||||
this.fs = embark.fs;
|
||||
export default class BaseEmbarkOmg {
|
||||
constructor({ pluginConfig, logger }) {
|
||||
this.logger = logger;
|
||||
this.initing = false;
|
||||
this.inited = false;
|
||||
this.address = "";
|
||||
|
@ -47,24 +18,12 @@ class EmbarkOmg {
|
|||
|
||||
|
||||
// plugin opts
|
||||
this.plasmaContractAddress = this.pluginConfig.PLASMA_CONTRACT_ADDRESS;
|
||||
this.web3ProviderUrl = this.pluginConfig.WEB3_PROVIDER_URL;
|
||||
this.watcherUrl = this.pluginConfig.WATCHER_URL;
|
||||
this.childChainUrl = this.pluginConfig.CHILDCHAIN_URL;
|
||||
|
||||
this.registerServiceCheck();
|
||||
this.registerConsoleCommands();
|
||||
|
||||
// gets hydrated blockchain config from embark
|
||||
this.events.once('config:load:blockchain', (blockchainConfig) => {
|
||||
this.logger.info("blockchain config loaded...");
|
||||
this.embarkUtils = new EmbarkUtils({ events: this.events, logger: this.logger, blockchainConfig });
|
||||
|
||||
this.init();
|
||||
});
|
||||
this.plasmaContractAddress = pluginConfig.PLASMA_CONTRACT_ADDRESS;
|
||||
this.web3ProviderUrl = pluginConfig.WEB3_PROVIDER_URL;
|
||||
this.watcherUrl = pluginConfig.WATCHER_URL;
|
||||
this.childChainUrl = pluginConfig.CHILDCHAIN_URL;
|
||||
}
|
||||
|
||||
async init() {
|
||||
async init(accounts, web3Path) {
|
||||
try {
|
||||
if (this.initing) {
|
||||
const message = "Already intializing the Plasma chain, please wait...";
|
||||
|
@ -73,8 +32,6 @@ class EmbarkOmg {
|
|||
}
|
||||
this.initing = true;
|
||||
|
||||
// init account used for root and child chains
|
||||
const accounts = await this.embarkUtils.accounts;
|
||||
if (!(accounts && accounts.length)) {
|
||||
this.logger.error(ACCOUNT_CONFIG_ERROR);
|
||||
throw new Error(ACCOUNT_CONFIG_ERROR);
|
||||
|
@ -85,9 +42,9 @@ class EmbarkOmg {
|
|||
|
||||
|
||||
// init Web3
|
||||
const Web3 = await this.embarkUtils.web3;
|
||||
this.web3 = new Web3();
|
||||
const web3Provider = new Web3.providers.HttpProvider(this.web3ProviderUrl);
|
||||
const web3Lib = web3Path ? require(web3Path) : Web3;
|
||||
this.web3 = new web3Lib();
|
||||
const web3Provider = new web3Lib.providers.HttpProvider(this.web3ProviderUrl);
|
||||
this.web3.setProvider(web3Provider);
|
||||
|
||||
// check account balance on the main chain
|
||||
|
@ -110,10 +67,6 @@ class EmbarkOmg {
|
|||
// set lifecycle state vars
|
||||
this.initing = false;
|
||||
this.inited = true;
|
||||
this.events.emit("embark-omg:init");
|
||||
|
||||
// await this.deposit();
|
||||
// await this.txChildChain();
|
||||
}
|
||||
catch (e) {
|
||||
const message = `Error initializing Plasma chain: ${e}`;
|
||||
|
@ -149,7 +102,7 @@ class EmbarkOmg {
|
|||
try {
|
||||
const receipt = await this.rootChain.depositEth(depositTx, amount, { from: this.address, privateKey: this.addressPrivateKey });
|
||||
this.logger.trace(receipt);
|
||||
const message = `Successfully deposited ${amount} wei in to the Plasma chain.\nView the transaction: https://rinkeby.etherscan.io/tx/${receipt.transactionHash}.`;
|
||||
const message = `Successfully deposited ${amount} wei in to the Plasma chain.\nView the transaction: https://rinkeby.etherscan.io/tx/${receipt.transactionHash}`;
|
||||
this.logger.info(message);
|
||||
return message;
|
||||
}
|
||||
|
@ -164,7 +117,7 @@ class EmbarkOmg {
|
|||
//const val = "555";
|
||||
// const toAddress = "0x38d5beb778b6e62d82e3ba4633e08987e6d0f990";
|
||||
const utxos = await this.childChain.getUtxos(this.address);
|
||||
const utxosToSpend = selectUtxos(utxos, val, transaction.ETH_CURRENCY);
|
||||
const utxosToSpend = this.selectUtxos(utxos, val, transaction.ETH_CURRENCY);
|
||||
if (!utxosToSpend) {
|
||||
return this.logger.error(`No utxo big enough to cover the amount ${val}`);
|
||||
}
|
||||
|
@ -224,6 +177,7 @@ class EmbarkOmg {
|
|||
}
|
||||
// NB This only exits the first UTXO.
|
||||
// Selecting _which_ UTXO to exit is left as an exercise for the reader...
|
||||
const errors = [];
|
||||
utxos.forEach(async (utxo) => {
|
||||
const exitData = await this.childChain.getExitData(utxo);
|
||||
|
||||
|
@ -243,154 +197,20 @@ class EmbarkOmg {
|
|||
catch (e) {
|
||||
const message = `Error exiting the Plasma chain for UTXO ${JSON.stringify(utxo)}: ${e}`;
|
||||
this.logger.error(message);
|
||||
throw new Error(message);
|
||||
errors.push(message);
|
||||
}
|
||||
});
|
||||
if (errors.length) {
|
||||
throw new Error(errors.join("\n\n"));
|
||||
}
|
||||
}
|
||||
|
||||
registerConsoleCommands() {
|
||||
this.embark.registerConsoleCommand({
|
||||
description: `Initialises the Plasma chain using the account configured in the DApp's blockchain configuration. All transactions on the child chain will use this as the 'from' account.`,
|
||||
matches: ["plasma init", "plasma init --force"],
|
||||
usage: "plasma init [--force]",
|
||||
process: (cmd, callback) => {
|
||||
const force = cmd.endsWith("--force");
|
||||
if (this.inited && !force) {
|
||||
return callback("The Plasma chain is already initialized. If you'd like to reinitialize the chain, use the --force option ('plasma init --force')."); // passes a message back to cockpit console
|
||||
}
|
||||
this.init()
|
||||
.then((message) => {
|
||||
callback(null, message);
|
||||
})
|
||||
.catch(callback);
|
||||
}
|
||||
});
|
||||
|
||||
const depositRegex = /^plasma[\s]+deposit[\s]+([0-9]+)$/;
|
||||
this.embark.registerConsoleCommand({
|
||||
description: "Deposits ETH from the root chain (Rinkeby) to the Plasma chain to be used for transacting on the Plasma chain.",
|
||||
matches: (cmd) => {
|
||||
return depositRegex.test(cmd);
|
||||
},
|
||||
usage: "plasma deposit [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(depositRegex) || [];
|
||||
if (matches.length <= 1) {
|
||||
return callback("Invalid command format, please use the format 'plasma deposit [amount]', ie 'plasma deposit 100000'");
|
||||
}
|
||||
this.deposit(matches[1])
|
||||
.then((message) => {
|
||||
callback(null, message);
|
||||
})
|
||||
.catch(callback);
|
||||
}
|
||||
});
|
||||
|
||||
const sendRegex = /^plasma[\s]+send[\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]",
|
||||
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'");
|
||||
}
|
||||
this.txChildChain(matches[1], matches[2])
|
||||
.then((message) => {
|
||||
callback(null, message);
|
||||
})
|
||||
.catch(callback);
|
||||
}
|
||||
});
|
||||
|
||||
const exitRegex = /^plasma[\s]+exit[\s]+(0x[0-9,a-f,A-F]{40,40})$/;
|
||||
this.embark.registerConsoleCommand({
|
||||
description: "Exits the ETH from the Plasma chain to the Rinkeby chain.",
|
||||
matches: (cmd) => {
|
||||
return exitRegex.test(cmd);
|
||||
},
|
||||
usage: "plasma exit [plasma_chain_address]",
|
||||
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(exitRegex) || [];
|
||||
if (matches.length <= 1) {
|
||||
return callback("Invalid command format, please use the format 'plasma exit [plasma_chain_address]', ie 'plasma exit 0x38d5beb778b6e62d82e3ba4633e08987e6d0f990'");
|
||||
}
|
||||
this.exitChildChain(matches[1]).then((message) => {
|
||||
callback(null, message);
|
||||
}).catch((e) => {
|
||||
callback(e.message);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers this plugin for Embark service checks and sets up log messages for
|
||||
* connection and disconnection events. The service check pings the Status app.
|
||||
*
|
||||
* @returns {void}
|
||||
*/
|
||||
registerServiceCheck() {
|
||||
const NO_NODE = "noNode";
|
||||
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
|
||||
this.web3._requestManager.send({ method: 'web3_clientVersion', params: [] }, (err, version) => {
|
||||
if (err || !version) {
|
||||
return next(null, { name: "Plasma chain not found", status: SERVICE_CHECK_OFF });
|
||||
}
|
||||
if (version.indexOf("/") < 0) {
|
||||
return next(null, { name: version, status: SERVICE_CHECK_ON });
|
||||
}
|
||||
let nodeName = version.split("/")[0];
|
||||
let versionNumber = version.split("/")[1].split("-")[0];
|
||||
let name = nodeName + " " + versionNumber + " (Plasma)";
|
||||
|
||||
return next(null, { name: name, status: SERVICE_CHECK_ON });
|
||||
});
|
||||
}
|
||||
], (err, statusObj) => {
|
||||
if (err && err !== NO_NODE) {
|
||||
return cb(err);
|
||||
}
|
||||
cb(statusObj);
|
||||
});
|
||||
}, 5000, 'off');
|
||||
|
||||
this.embark.events.on('check:backOnline:OmiseGO', () => {
|
||||
this.logger.info("------------------");
|
||||
this.logger.info("Connected to the Plama chain!");
|
||||
this.logger.info("------------------");
|
||||
});
|
||||
|
||||
this.embark.events.on('check:wentOffline:OmiseGO', () => {
|
||||
this.logger.error("------------------");
|
||||
this.logger.error("Couldn't connect or lost connection to the Plasma chain...");
|
||||
this.logger.error("------------------");
|
||||
});
|
||||
selectUtxos(utxos, amount, currency) {
|
||||
const correctCurrency = utxos.filter(utxo => utxo.currency === currency);
|
||||
// Just find the first utxo that can fulfill the amount
|
||||
const selected = correctCurrency.find(utxo => new BigNumber(utxo.amount).gte(new BigNumber(amount)));
|
||||
if (selected) {
|
||||
return [selected];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default EmbarkOmg;
|
||||
|
|
|
@ -1,42 +0,0 @@
|
|||
import { AccountParser, dappPath, embarkPath } from "embark-utils";
|
||||
|
||||
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);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
get web3() {
|
||||
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(require(web3Path));
|
||||
}
|
||||
this.events.request("version:getPackageLocation", "web3", web3Version, (err, location) => {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
const locationPath = embarkPath(location).replace(/\\/g, '/');
|
||||
resolve(require(locationPath));
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
import { BigNumber } from "ethers/utils";
|
||||
|
||||
export function selectUtxos(utxos, amount, currency) {
|
||||
const correctCurrency = utxos.filter(utxo => utxo.currency === currency);
|
||||
// Just find the first utxo that can fulfill the amount
|
||||
const selected = correctCurrency.find(utxo => new BigNumber(utxo.amount).gte(new BigNumber(amount)));
|
||||
if (selected) {
|
||||
return [selected];
|
||||
}
|
||||
}
|
113
yarn-error.log
113
yarn-error.log
|
@ -1,5 +1,5 @@
|
|||
Arguments:
|
||||
/Users/emizzle/.nvm/versions/node/v10.5.0/bin/node /Users/emizzle/.yarn/bin/yarn.js add ethers/utils/bignumber --save
|
||||
/Users/emizzle/.nvm/versions/node/v10.5.0/bin/node /Users/emizzle/.yarn/bin/yarn.js watch
|
||||
|
||||
PATH:
|
||||
/Users/emizzle/.opam/default/bin:/Users/emizzle/.yarn/bin:/Users/emizzle/.config/yarn/global/node_modules/.bin:/usr/local/sbin:/Users/emizzle/.nvm/versions/node/v10.5.0/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/MacGPG2/bin:/usr/local/share/dotnet:/opt/X11/bin:~/.dotnet/tools:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Applications/Xamarin Workbooks.app/Contents/SharedSupport/path-bin:/Users/emizzle/.yarn/bin:/Users/emizzle/.config/yarn/global/node_modules/.bin:/usr/local/sbin:/Users/emizzle/.opam/default/bin:/Users/emizzle/go/bin:/Applications/Visual Studio Code.app/Contents/Resources/app/bin:/Users/emizzle/go/bin:/Applications/Visual Studio Code.app/Contents/Resources/app/bin
|
||||
|
@ -14,17 +14,12 @@ Platform:
|
|||
darwin x64
|
||||
|
||||
Trace:
|
||||
Error: https://registry.yarnpkg.com/ethers%2futils/bignumber: Request "https://registry.yarnpkg.com/ethers%2futils/bignumber" returned a 405
|
||||
at Request.params.callback [as _callback] (/Users/emizzle/.yarn/lib/cli.js:66100:18)
|
||||
at Request.self.callback (/Users/emizzle/.yarn/lib/cli.js:129590:22)
|
||||
at Request.emit (events.js:182:13)
|
||||
at Request.<anonymous> (/Users/emizzle/.yarn/lib/cli.js:130562:10)
|
||||
at Request.emit (events.js:182:13)
|
||||
at IncomingMessage.<anonymous> (/Users/emizzle/.yarn/lib/cli.js:130484:12)
|
||||
at Object.onceWrapper (events.js:273:13)
|
||||
at IncomingMessage.emit (events.js:187:15)
|
||||
at endReadableNT (_stream_readable.js:1081:12)
|
||||
at process._tickCallback (internal/process/next_tick.js:63:19)
|
||||
SyntaxError: /Users/emizzle/Code/__Github/emizzle/embark-omg/package.json: Unexpected token / in JSON at position 736
|
||||
at JSON.parse (<anonymous>)
|
||||
at /Users/emizzle/.yarn/lib/cli.js:1625:59
|
||||
at Generator.next (<anonymous>)
|
||||
at step (/Users/emizzle/.yarn/lib/cli.js:304:30)
|
||||
at /Users/emizzle/.yarn/lib/cli.js:315:13
|
||||
|
||||
npm manifest:
|
||||
{
|
||||
|
@ -38,12 +33,20 @@ npm manifest:
|
|||
],
|
||||
"scripts": {
|
||||
"lint": "./node_modules/.bin/eslint src/",
|
||||
"babel": "npm run babel:node",
|
||||
"babel:node": "cross-env BABEL_ENV=node babel --out-dir dist src --source-maps",
|
||||
"build": "npm run clean && npm run babel",
|
||||
"clean": "rimraf dist embark-status-*.tgz package",
|
||||
"prepare": "npm run build",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
"babel": "cross-env BABEL_ENV=node babel --out-dir dist src --source-maps",
|
||||
"build": "npm-run-all build:**",
|
||||
"build:browser": "cross-env BABEL_ENV=browser babel src --extensions \".js\" --out-dir dist/browser --root-mode upward",
|
||||
"build:node": "cross-env BABEL_ENV=node babel src --extensions \".js\" --out-dir dist --root-mode upward --source-maps",
|
||||
"build:node:async": "cross-env BABEL_ENV=node:async babel src/node --extensions \".js\" --out-dir dist --root-mode upward --source-maps",
|
||||
// "build:node:test": "cross-env BABEL_ENV=node:test babel test --extensions \".js\" --out-dir build-test --root-mode upward --source-maps",
|
||||
"ci": "npm run qa",
|
||||
"clean": "npm run reset",
|
||||
"package": "npm pack",
|
||||
"qa": "npm-run-all build test package",
|
||||
"reset": "npx rimraf .nyc_output build-test coverage dist embarkjs-*.tgz package",
|
||||
"start": "npm run watch",
|
||||
// "test": "nyc --reporter=html --reporter=json mocha \"build-test/**/*.js\" --exit --no-timeouts --require source-map-support/register",
|
||||
"watch": "run-p \"build:** -- --verbose --watch\""
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
@ -61,18 +64,20 @@ npm manifest:
|
|||
},
|
||||
"homepage": "https://github.com/emizzle/embark-omg#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime-corejs2": "7.3.1",
|
||||
"@omisego/omg-js": "1.2.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",
|
||||
"embark-utils": "^4.1.0-beta.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",
|
||||
"embark-utils": "^4.1.0-beta.2",
|
||||
"ethers": "4.0.28"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/cli": "7.2.3",
|
||||
"@babel/core": "7.2.2",
|
||||
"@babel/plugin-transform-runtime": "7.4.0",
|
||||
"@babel/preset-env": "7.4.1",
|
||||
"@babel/runtime-corejs2": "7.3.1",
|
||||
"cross-env": "5.2.0",
|
||||
"eslint": "4.19.1",
|
||||
"rimraf": "2.6.2"
|
||||
|
@ -717,18 +722,7 @@ Lockfile:
|
|||
lodash "^4.17.11"
|
||||
to-fast-properties "^2.0.0"
|
||||
|
||||
"@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" "^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-childchain@^1.2.1":
|
||||
"@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==
|
||||
|
@ -739,15 +733,7 @@ Lockfile:
|
|||
node-fetch "^2.2.0"
|
||||
rlp "^2.1.0"
|
||||
|
||||
"@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" "^2.0.0-v0.2"
|
||||
debug "^4.0.1"
|
||||
|
||||
"@omisego/omg-js-rootchain@^1.2.2":
|
||||
"@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==
|
||||
|
@ -755,18 +741,7 @@ Lockfile:
|
|||
"@omisego/omg-js-util" "^1.2.1"
|
||||
debug "^4.0.1"
|
||||
|
||||
"@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"
|
||||
js-sha3 "^0.8.0"
|
||||
number-to-bn "^1.7.0"
|
||||
rlp "^2.2.2"
|
||||
|
||||
"@omisego/omg-js-util@^1.2.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==
|
||||
|
@ -990,6 +965,11 @@ Lockfile:
|
|||
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"
|
||||
|
@ -2265,6 +2245,22 @@ Lockfile:
|
|||
uuid "2.0.1"
|
||||
xmlhttprequest "1.8.0"
|
||||
|
||||
ethers@4.0.28:
|
||||
version "4.0.28"
|
||||
resolved "https://registry.yarnpkg.com/ethers/-/ethers-4.0.28.tgz#74d9acb57f4ede3337c8d60476b38d0fe646af01"
|
||||
integrity sha512-5JTHrPoFLqf+xCAI3pKwXSOgWBSJJoAUdPtPLr1ZlKbSKiIFMkPlRNovmZS3jhIw5sHW1YoVWOaJ6ZR2gKRbwg==
|
||||
dependencies:
|
||||
"@types/node" "^10.3.2"
|
||||
aes-js "3.0.0"
|
||||
bn.js "^4.4.0"
|
||||
elliptic "6.3.3"
|
||||
hash.js "1.1.3"
|
||||
js-sha3 "0.5.7"
|
||||
scrypt-js "2.0.4"
|
||||
setimmediate "1.0.4"
|
||||
uuid "2.0.1"
|
||||
xmlhttprequest "1.8.0"
|
||||
|
||||
ethjs-unit@0.1.6:
|
||||
version "0.1.6"
|
||||
resolved "https://registry.yarnpkg.com/ethjs-unit/-/ethjs-unit-0.1.6.tgz#c665921e476e87bce2a9d588a6fe0405b2c41699"
|
||||
|
@ -4598,6 +4594,11 @@ Lockfile:
|
|||
resolved "https://registry.yarnpkg.com/scrypt-js/-/scrypt-js-2.0.3.tgz#bb0040be03043da9a012a2cea9fc9f852cfc87d4"
|
||||
integrity sha1-uwBAvgMEPamgEqLOqfyfhSz8h9Q=
|
||||
|
||||
scrypt-js@2.0.4:
|
||||
version "2.0.4"
|
||||
resolved "https://registry.yarnpkg.com/scrypt-js/-/scrypt-js-2.0.4.tgz#32f8c5149f0797672e551c07e230f834b6af5f16"
|
||||
integrity sha512-4KsaGcPnuhtCZQCxFxN3GVYIhKFPTdLd8PLC552XwbMndtD0cjRFAhDuuydXQ0h08ZfPgzqe6EKHozpuH74iDw==
|
||||
|
||||
scrypt.js@0.2.0:
|
||||
version "0.2.0"
|
||||
resolved "https://registry.yarnpkg.com/scrypt.js/-/scrypt.js-0.2.0.tgz#af8d1465b71e9990110bedfc593b9479e03a8ada"
|
||||
|
|
Loading…
Reference in New Issue