From bdb233fe4f33628b96d57dfdf9d92d639eaac4ca Mon Sep 17 00:00:00 2001 From: neeboo Date: Thu, 18 Jul 2019 10:41:39 +0800 Subject: [PATCH] chore(transaction):added `Transaction.observe()` --- README.md | 40 +++++++++++++------ package.json | 14 +++---- .../harmony-transaction/src/transaction.ts | 14 +++++++ packages/harmony-utils/src/chain.ts | 1 + 4 files changed, 48 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 083b376..bb674a2 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,19 @@ yarn add tslib ``` +# Start hacking + +1. install `lerna` and `typescript` globally +```bash +yarn global add lerna && yarn global add typescript +``` +2. bootstrap repostory +```bash +yarn bootstrap + +``` + + # Packages 1. [@harmony-js/core](https://github.com/FireStack-Lab/Harmony-sdk-core/tree/master/packages/harmony-core) @@ -35,22 +48,23 @@ yarn add tslib 7. [@harmony-js/contract](https://github.com/FireStack-Lab/Harmony-sdk-core/tree/master/packages/harmony-contract) -# Manually Build -1. make sure you have latest `node.js` and `yarn` installed +# Manually Build/bundle + +There are two ways building + +1. building the `es5` version bundled javascript for each sub-packages, which can be run in Browser directly. -2. git clone - - ```bash - git clone git@github.com:FireStack-Lab/Harmony-sdk-core.git - cd Harmony-sdk-core - ``` + ```bash + yarn dist + ``` + All files are exported in `/dist` folder -3. cleanup and build - - ```bash - yarn global add lerna && yarn install && lerna bootstrap && lerna link && yarn dist - ``` +2. build `umd` and `esm` version javascript for each sub-packages, which can be accessed by `import` or `require` + ```bash + yarn bundle + ``` + All files are exported in `packages/dist` folder, use `**.esm.js` or `**.umd.js` format # Examples diff --git a/package.json b/package.json index 854014f..80d0417 100644 --- a/package.json +++ b/package.json @@ -5,18 +5,16 @@ "packages/*" ], "scripts": { - "packages:cleanBrowser": "gulp cleanBrowser", - "packages:cleanServer": "gulp cleanServer", - "packages:browser": "yarn packages:cleanBrowser && rollup --c scripts/rollup/bundleBrowser.js", - "packages:bundler": "yarn packages:cleanServer && yarn build:ts && ts-node -P scripts/tsconfig.json scripts/bundle.ts", - "dist": "yarn packages:bundler && rm -rf dist && cross-env NODE_ENV=production webpack --config webpack.config.js", - "bootstrap": "lerna bootstrap", - "build": "yarn build:proto && yarn build:ts", + "bootstrap": "lerna bootstrap && yarn build:ts", + "build:": "yarn build:ts && yarn build:test && yarn build:e2e", "build:ts": "tsc -b tsconfig.json", "build:test":"tsc -b tsconfig.test.json", "build:e2e":"tsc -b tsconfig.e2e.json", "bundle": "ts-node -P scripts/tsconfig.json scripts/bundle.ts umd,esm", - "clean": "lerna clean --yes && lerna run clean && rimraf includes", + "clean": "lerna clean --yes && lerna run clean && rimraf includes && yarn packages:clean", + "dist": "yarn packages:bundler && rm -rf dist && cross-env NODE_ENV=production webpack --config webpack.config.js", + "packages:clean": "gulp cleanServer", + "packages:bundler": "yarn packages:clean && yarn build:ts && ts-node -P scripts/tsconfig.json scripts/bundle.ts", "schema": "ts-node -P scripts/tsconfig.json scripts/typings/schema.ts core", "test": "cross-env TEST_ENV=unit jest -c scripts/jest/jest.config.js --rootDir=.", "test:src": "cross-env NODE_ENV=test jest --config ./scripts/jest/jest.src.config.js --silent --runInBand --no-cache", diff --git a/packages/harmony-transaction/src/transaction.ts b/packages/harmony-transaction/src/transaction.ts index e00e15b..b3a28f4 100644 --- a/packages/harmony-transaction/src/transaction.ts +++ b/packages/harmony-transaction/src/transaction.ts @@ -264,6 +264,20 @@ class Transaction { return this.getTxStatus() === TxStatus.CONFIRMED; } + observed() { + try { + if (this.emitter.resolve) { + this.emitter.resolve(this); + } + } catch (error) { + if (this.emitter.reject) { + this.emitter.reject(error); + } + throw error; + } + return this.emitter; + } + async sendTransaction(): Promise<[Transaction, string]> { // TODO: we use eth RPC setting for now, incase we have other params, we should add here if (this.txnHash === 'tx' || this.txnHash === undefined) { diff --git a/packages/harmony-utils/src/chain.ts b/packages/harmony-utils/src/chain.ts index 94d93eb..92337df 100644 --- a/packages/harmony-utils/src/chain.ts +++ b/packages/harmony-utils/src/chain.ts @@ -15,6 +15,7 @@ export const enum ChainID { EtcMainnet = 61, EtcTestnet = 62, Geth = 1337, + Ganache = 0, } export abstract class HarmonyCore {