From 9110c74292c1a55730e3e18859315be853f03f68 Mon Sep 17 00:00:00 2001 From: Axel Chalon Date: Tue, 15 Jan 2019 00:25:36 +0100 Subject: [PATCH 1/8] Rewrite post$ to take a password and not use signer --- packages/api/src/rpc/personal/personal.js | 5 ++++ packages/light.js/src/rpc/other/post.ts | 29 ++++++++--------------- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/packages/api/src/rpc/personal/personal.js b/packages/api/src/rpc/personal/personal.js index 788a364d..692c3b7a 100644 --- a/packages/api/src/rpc/personal/personal.js +++ b/packages/api/src/rpc/personal/personal.js @@ -34,6 +34,11 @@ class Personal { .then(outAddress); } + signTransaction(options, password) { + return this._provider + .send('personal_signTransaction', inOptions(options), password); + } + sendTransaction (options, password) { return this._provider .send('personal_sendTransaction', inOptions(options), password); diff --git a/packages/light.js/src/rpc/other/post.ts b/packages/light.js/src/rpc/other/post.ts index 229153b9..461d8473 100644 --- a/packages/light.js/src/rpc/other/post.ts +++ b/packages/light.js/src/rpc/other/post.ts @@ -37,14 +37,16 @@ function getTransactionReceipt (transactionHash: string, api: any) { /** * Post a transaction to the network. * - * Calls, in this order, `eth_estimateGas`, `parity_postTransaction`, - * `parity_checkRequest` and `eth_getTransactionReceipt` to get the status of + * Calls, in this order, `eth_estimateGas`, `personal_signTransaction`, + * `eth_sendRawTransaction` and `eth_getTransactionReceipt` to get the status of * the transaction. * + * @param tx - Transaction object + * @param passphrase - Passphrase of the account * @param options? - Options to pass to the {@link RpcObservable}. * @return - The status of the transaction. */ -export function post$ (tx: Tx, options: PostOptions = {}) { +export function post$ (tx: Tx, passphrase: string, options: PostOptions = {}) { const { estimate, provider } = options; const api = provider ? createApiFromProvider(provider) : getApi(); @@ -55,22 +57,10 @@ export function post$ (tx: Tx, options: PostOptions = {}) { const gas = await api.eth.estimateGas(tx); observer.next({ estimated: gas }); } - const signerRequestId = await api.parity.postTransaction(tx); - observer.next({ requested: signerRequestId }); - const transactionHash = await api.pollMethod( - 'parity_checkRequest', - signerRequestId - ); - if (tx.condition) { - observer.next({ signed: transactionHash, schedule: tx.condition }); - } else { - observer.next({ signed: transactionHash }); - const receipt = await getTransactionReceipt(transactionHash, api); - observer.next({ confirmed: receipt }); - } + const signedTransaction = await api.personal.signTransaction(tx, passphrase); + postRaw$(signedTransaction.raw).subscribe(observer); - observer.complete(); } catch (error) { observer.next({ failed: error }); observer.error(error); @@ -87,16 +77,17 @@ export function post$ (tx: Tx, options: PostOptions = {}) { * Calls, in this order, `eth_sendRawTransaction` and * `eth_getTransactionReceipt` to get the status of the transaction. * + * @param rawTx - Raw transaction * @param options? - Options to pass to the {@link RpcObservable}. * @return - The status of the transaction. */ -export function postRaw$ (tx: string, options: PostOptions = {}) { +export function postRaw$ (rawTx: string, options: PostOptions = {}) { const { provider } = options; const api = provider ? createApiFromProvider(provider) : getApi(); const source$ = Observable.create(async (observer: Observer) => { try { - const transactionHash = await api.eth.sendRawTransaction(tx); + const transactionHash = await api.eth.sendRawTransaction(rawTx); observer.next({ signed: transactionHash }); const receipt = await getTransactionReceipt(transactionHash, api); From b38994eec07de5e909987d0096b9adea778f5580 Mon Sep 17 00:00:00 2001 From: Axel Chalon Date: Tue, 15 Jan 2019 00:39:27 +0100 Subject: [PATCH 2/8] Use new post$ in makeContract --- packages/light.js/src/rpc/other/makeContract.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/light.js/src/rpc/other/makeContract.ts b/packages/light.js/src/rpc/other/makeContract.ts index a518b1d4..fdb972de 100644 --- a/packages/light.js/src/rpc/other/makeContract.ts +++ b/packages/light.js/src/rpc/other/makeContract.ts @@ -39,19 +39,20 @@ const getContract = memoizee( ); /** - * Create a contract, givan an api object. + * Create a contract, given an api object. * Pure function version of {@link makeContract}. * * @ignore * @param address - The contract address. * @param abiJson - The contract abi. + * @param passphrase - Passphrase of the account creating the contract * @param api - The api Object. * @return - An object whose keys are all the functions of the * contract, and each function returns an Observable which will fire when the * function resolves. */ const makeContractWithApi = memoizee( - (address: Address, abiJson: any[], api: any) => { + (address: Address, abiJson: any[], passphrase: string, api: any) => { const abi = new Abi(abiJson); // use types from @parity/abi // Variable result will hold the final object to return @@ -97,7 +98,7 @@ const makeContractWithApi = memoizee( args ), ...options - }); + }, passphrase); } }; }); @@ -111,6 +112,7 @@ const makeContractWithApi = memoizee( * * @param address - The contract address. * @param abiJson - The contract abi. + * @param passphrase - Passphrase of the account creating the contract * @param options - The options to pass in when creating the contract. * @return - An object whose keys are all the functions of the * contract, and each function return an Observable which will fire when the @@ -119,10 +121,11 @@ const makeContractWithApi = memoizee( export const makeContract = ( address: Address, abiJson: any[], + passphrase: string, options: { provider?: any } = {} ) => { const { provider } = options; const api = provider ? createApiFromProvider(provider) : getApi(); - return makeContractWithApi(address, abiJson, api); + return makeContractWithApi(address, abiJson, passphrase, api); }; From f150fcdd7c51a6382ae637a305f4a1d5457d10af Mon Sep 17 00:00:00 2001 From: Axel Chalon Date: Fri, 18 Jan 2019 14:26:25 +0100 Subject: [PATCH 3/8] Grumbles & bump packages to 4.0.0 --- packages/abi/package.json | 2 +- packages/api/package.json | 4 ++-- packages/contracts/package.json | 6 +++--- packages/electron/package.json | 2 +- packages/light.js-react/package.json | 6 +++--- packages/light.js/package.json | 6 +++--- packages/light.js/src/rpc/other/post.ts | 3 ++- packages/light.js/src/types.ts | 3 +-- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/packages/abi/package.json b/packages/abi/package.json index c9c2b3e5..bd6651ab 100644 --- a/packages/abi/package.json +++ b/packages/abi/package.json @@ -1,7 +1,7 @@ { "name": "@parity/abi", "description": "Ethereum ABI encoder and decoder", - "version": "3.0.27", + "version": "4.0.0", "author": "Parity Team ", "license": "MIT", "repository": "https://github.com/paritytech/js-libs/tree/master/packages/abi", diff --git a/packages/api/package.json b/packages/api/package.json index 5e942fc1..19bff51d 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -1,7 +1,7 @@ { "name": "@parity/api", "description": "The Parity Promise-based API library for interfacing with Ethereum over RPC", - "version": "3.0.27", + "version": "4.0.0", "author": "Parity Team ", "license": "MIT", "repository": "https://github.com/paritytech/js-libs/tree/master/packages/api", @@ -39,7 +39,7 @@ "typescript": "^3.1.6" }, "dependencies": { - "@parity/abi": "^3.0.27", + "@parity/abi": "^4.0.0", "bignumber.js": "^8.0.1", "blockies": "0.0.2", "es6-error": "4.0.2", diff --git a/packages/contracts/package.json b/packages/contracts/package.json index 6cad4e3a..aba7c2cc 100644 --- a/packages/contracts/package.json +++ b/packages/contracts/package.json @@ -1,7 +1,7 @@ { "name": "@parity/contracts", "description": "Parity's contracts as ES6 classes.", - "version": "3.0.27", + "version": "4.0.0", "author": "Parity Team ", "license": "MIT", "repository": "https://github.com/paritytech/js-libs/tree/master/packages/contracts", @@ -22,8 +22,8 @@ "test": "jest" }, "dependencies": { - "@parity/abi": "^3.0.27", - "@parity/api": "^3.0.27", + "@parity/abi": "^4.0.0", + "@parity/api": "^4.0.0", "bignumber.js": "^8.0.1" }, "devDependencies": { diff --git a/packages/electron/package.json b/packages/electron/package.json index 2c58f1f2..30df5fe8 100644 --- a/packages/electron/package.json +++ b/packages/electron/package.json @@ -1,7 +1,7 @@ { "name": "@parity/electron", "description": "Control the Parity Ethereum node from Electron.", - "version": "3.0.27", + "version": "4.0.0", "author": "Parity Team ", "license": "MIT", "repository": "https://github.com/paritytech/js-libs/tree/master/packages/electron", diff --git a/packages/light.js-react/package.json b/packages/light.js-react/package.json index 9e65014f..9cef67fe 100644 --- a/packages/light.js-react/package.json +++ b/packages/light.js-react/package.json @@ -1,7 +1,7 @@ { "name": "@parity/light.js-react", "description": "A HOC to easily use @parity/light.js with React.", - "version": "3.0.27", + "version": "4.0.0", "author": "Parity Team ", "license": "MIT", "repository": "https://github.com/paritytech/js-libs/tree/master/packages/light.js-react", @@ -30,7 +30,7 @@ "symbol-observable": "^1.2.0" }, "devDependencies": { - "@parity/light.js": "^3.0.27", + "@parity/light.js": "^4.0.0", "@types/enzyme": "^3.1.13", "@types/enzyme-adapter-react-16": "^1.0.3", "@types/recompose": "^0.26.4", @@ -42,7 +42,7 @@ "typescript": "^3.1.6" }, "peerDependencies": { - "@parity/light.js": "^3.0.0", + "@parity/light.js": "^4.0.0", "rxjs": "~6.2.2" } } diff --git a/packages/light.js/package.json b/packages/light.js/package.json index 6f456669..99eb2544 100644 --- a/packages/light.js/package.json +++ b/packages/light.js/package.json @@ -1,7 +1,7 @@ { "name": "@parity/light.js", "description": "A high-level reactive JS library optimized for light clients", - "version": "3.0.27", + "version": "4.0.0", "author": "Parity Team ", "license": "MIT", "repository": "https://github.com/paritytech/js-libs/tree/master/packages/light.js", @@ -26,8 +26,8 @@ "test": "jest" }, "dependencies": { - "@parity/abi": "^3.0.27", - "@parity/api": "^3.0.27", + "@parity/abi": "^4.0.0", + "@parity/api": "^4.0.0", "async-retry": "^1.2.3", "bignumber.js": "^8.0.1", "debug": "^4.1.0", diff --git a/packages/light.js/src/rpc/other/post.ts b/packages/light.js/src/rpc/other/post.ts index 0ef338ca..78711874 100644 --- a/packages/light.js/src/rpc/other/post.ts +++ b/packages/light.js/src/rpc/other/post.ts @@ -59,6 +59,7 @@ export function post$ (tx: Tx, passphrase: string, options: PostOptions = {}) { } const signedTransaction = await api.personal.signTransaction(tx, passphrase); + observer.next({ signed: signedTransaction.raw }); postRaw$(signedTransaction.raw).subscribe(observer); } catch (error) { @@ -88,7 +89,7 @@ export function postRaw$ (rawTx: string, options: PostOptions = {}) { const source$ = Observable.create(async (observer: Observer) => { try { const transactionHash = await api.eth.sendRawTransaction(rawTx); - observer.next({ signed: transactionHash }); + observer.next({ sent: transactionHash }); const receipt = await getTransactionReceipt(transactionHash, api); observer.next({ confirmed: receipt }); diff --git a/packages/light.js/src/types.ts b/packages/light.js/src/types.ts index 00fe08ee..7870408a 100644 --- a/packages/light.js/src/types.ts +++ b/packages/light.js/src/types.ts @@ -89,7 +89,6 @@ export interface TxStatus { estimating?: boolean; estimated?: BigNumber; failed?: Error; - requested?: string; - schedule?: any; signed?: string; + sent?: string; } From 487979c7697b7106a7b12d5a56e3cf9cb7af274d Mon Sep 17 00:00:00 2001 From: Axel Chalon Date: Fri, 18 Jan 2019 14:33:09 +0100 Subject: [PATCH 4/8] Bump workspace root version to 4.0.0 --- lerna.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lerna.json b/lerna.json index c5cf9195..f4f6ade1 100644 --- a/lerna.json +++ b/lerna.json @@ -5,5 +5,5 @@ "packages/*" ], "useWorkspaces": true, - "version": "3.0.27" + "version": "4.0.0" } From d80eb903aea029e4385d83d4d261b92c66199cc6 Mon Sep 17 00:00:00 2001 From: Axel Chalon Date: Mon, 21 Jan 2019 22:43:03 +0100 Subject: [PATCH 5/8] lerna: use `--conventional-commits` to bump patch/minor/major & generate changelog --- scripts/lerna-publish.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/lerna-publish.sh b/scripts/lerna-publish.sh index f199de48..2a048513 100755 --- a/scripts/lerna-publish.sh +++ b/scripts/lerna-publish.sh @@ -6,5 +6,5 @@ set -e # Quits if there's an error git remote set-url origin https://${GH_TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git > /dev/null 2>&1 -lerna version patch --yes -m "[ci skip] Publish %s" +lerna version --conventional-commits --yes -m "[ci skip] Publish %s" lerna publish from-git --yes From 0738d314aa8f8f1fff5a45dc8852c12ecf777e78 Mon Sep 17 00:00:00 2001 From: Axel Chalon Date: Mon, 21 Jan 2019 22:57:30 +0100 Subject: [PATCH 6/8] Revert "Bump workspace root version to 4.0.0" This reverts commit 487979c7697b7106a7b12d5a56e3cf9cb7af274d. --- lerna.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lerna.json b/lerna.json index f4f6ade1..c5cf9195 100644 --- a/lerna.json +++ b/lerna.json @@ -5,5 +5,5 @@ "packages/*" ], "useWorkspaces": true, - "version": "4.0.0" + "version": "3.0.27" } From d431cc87c0df8095181db00f7a038e52d5187fa7 Mon Sep 17 00:00:00 2001 From: Axel Chalon Date: Mon, 21 Jan 2019 23:02:46 +0100 Subject: [PATCH 7/8] Revert "bump packages to 4.0.0" --- packages/abi/package.json | 2 +- packages/api/package.json | 4 ++-- packages/contracts/package.json | 6 +++--- packages/electron/package.json | 2 +- packages/light.js-react/package.json | 6 +++--- packages/light.js/package.json | 6 +++--- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/abi/package.json b/packages/abi/package.json index bd6651ab..c9c2b3e5 100644 --- a/packages/abi/package.json +++ b/packages/abi/package.json @@ -1,7 +1,7 @@ { "name": "@parity/abi", "description": "Ethereum ABI encoder and decoder", - "version": "4.0.0", + "version": "3.0.27", "author": "Parity Team ", "license": "MIT", "repository": "https://github.com/paritytech/js-libs/tree/master/packages/abi", diff --git a/packages/api/package.json b/packages/api/package.json index 19bff51d..5e942fc1 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -1,7 +1,7 @@ { "name": "@parity/api", "description": "The Parity Promise-based API library for interfacing with Ethereum over RPC", - "version": "4.0.0", + "version": "3.0.27", "author": "Parity Team ", "license": "MIT", "repository": "https://github.com/paritytech/js-libs/tree/master/packages/api", @@ -39,7 +39,7 @@ "typescript": "^3.1.6" }, "dependencies": { - "@parity/abi": "^4.0.0", + "@parity/abi": "^3.0.27", "bignumber.js": "^8.0.1", "blockies": "0.0.2", "es6-error": "4.0.2", diff --git a/packages/contracts/package.json b/packages/contracts/package.json index aba7c2cc..6cad4e3a 100644 --- a/packages/contracts/package.json +++ b/packages/contracts/package.json @@ -1,7 +1,7 @@ { "name": "@parity/contracts", "description": "Parity's contracts as ES6 classes.", - "version": "4.0.0", + "version": "3.0.27", "author": "Parity Team ", "license": "MIT", "repository": "https://github.com/paritytech/js-libs/tree/master/packages/contracts", @@ -22,8 +22,8 @@ "test": "jest" }, "dependencies": { - "@parity/abi": "^4.0.0", - "@parity/api": "^4.0.0", + "@parity/abi": "^3.0.27", + "@parity/api": "^3.0.27", "bignumber.js": "^8.0.1" }, "devDependencies": { diff --git a/packages/electron/package.json b/packages/electron/package.json index 30df5fe8..2c58f1f2 100644 --- a/packages/electron/package.json +++ b/packages/electron/package.json @@ -1,7 +1,7 @@ { "name": "@parity/electron", "description": "Control the Parity Ethereum node from Electron.", - "version": "4.0.0", + "version": "3.0.27", "author": "Parity Team ", "license": "MIT", "repository": "https://github.com/paritytech/js-libs/tree/master/packages/electron", diff --git a/packages/light.js-react/package.json b/packages/light.js-react/package.json index 9cef67fe..9e65014f 100644 --- a/packages/light.js-react/package.json +++ b/packages/light.js-react/package.json @@ -1,7 +1,7 @@ { "name": "@parity/light.js-react", "description": "A HOC to easily use @parity/light.js with React.", - "version": "4.0.0", + "version": "3.0.27", "author": "Parity Team ", "license": "MIT", "repository": "https://github.com/paritytech/js-libs/tree/master/packages/light.js-react", @@ -30,7 +30,7 @@ "symbol-observable": "^1.2.0" }, "devDependencies": { - "@parity/light.js": "^4.0.0", + "@parity/light.js": "^3.0.27", "@types/enzyme": "^3.1.13", "@types/enzyme-adapter-react-16": "^1.0.3", "@types/recompose": "^0.26.4", @@ -42,7 +42,7 @@ "typescript": "^3.1.6" }, "peerDependencies": { - "@parity/light.js": "^4.0.0", + "@parity/light.js": "^3.0.0", "rxjs": "~6.2.2" } } diff --git a/packages/light.js/package.json b/packages/light.js/package.json index 99eb2544..6f456669 100644 --- a/packages/light.js/package.json +++ b/packages/light.js/package.json @@ -1,7 +1,7 @@ { "name": "@parity/light.js", "description": "A high-level reactive JS library optimized for light clients", - "version": "4.0.0", + "version": "3.0.27", "author": "Parity Team ", "license": "MIT", "repository": "https://github.com/paritytech/js-libs/tree/master/packages/light.js", @@ -26,8 +26,8 @@ "test": "jest" }, "dependencies": { - "@parity/abi": "^4.0.0", - "@parity/api": "^4.0.0", + "@parity/abi": "^3.0.27", + "@parity/api": "^3.0.27", "async-retry": "^1.2.3", "bignumber.js": "^8.0.1", "debug": "^4.1.0", From 624aed24215d6e4a06c9ec919ab22f34c23b511e Mon Sep 17 00:00:00 2001 From: Axel Chalon Date: Mon, 21 Jan 2019 23:25:24 +0100 Subject: [PATCH 8/8] post$: pass passphrase in the options; fix makeContract$ --- .../light.js/src/rpc/other/makeContract.ts | 13 ++++++------- packages/light.js/src/rpc/other/post.ts | 19 ++++++++++++------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/packages/light.js/src/rpc/other/makeContract.ts b/packages/light.js/src/rpc/other/makeContract.ts index 8c718285..55bf8bdd 100644 --- a/packages/light.js/src/rpc/other/makeContract.ts +++ b/packages/light.js/src/rpc/other/makeContract.ts @@ -45,14 +45,13 @@ const getContract = memoizee( * @ignore * @param address - The contract address. * @param abiJson - The contract abi. - * @param passphrase - Passphrase of the account creating the contract * @param api - The api Object. * @return - An object whose keys are all the functions of the * contract, and each function returns an Observable which will fire when the * function resolves. */ const makeContractWithApi = memoizee( - (address: Address, abiJson: any[], passphrase: string, api: any) => { + (address: Address, abiJson: any[], api: any) => { const abi = new Abi(abiJson); // use types from @parity/abi // Variable result will hold the final object to return @@ -90,6 +89,8 @@ const makeContractWithApi = memoizee( ] })({ provider: api.provider })(...args); } else { + const { estimate, passphrase, ...txFields } = options; + return post$({ to: address, data: abiEncode( @@ -97,8 +98,8 @@ const makeContractWithApi = memoizee( method.inputs.map(({ kind: { type } }: any) => type), // TODO Use @parity/api types args ), - ...options - }, passphrase); + ...txFields + }, { estimate, passphrase }); } }; }); @@ -112,7 +113,6 @@ const makeContractWithApi = memoizee( * * @param address - The contract address. * @param abiJson - The contract abi. - * @param passphrase - Passphrase of the account creating the contract * @param options - The options to pass in when creating the contract. * @return - An object whose keys are all the functions of the * contract, and each function return an Observable which will fire when the @@ -121,11 +121,10 @@ const makeContractWithApi = memoizee( export const makeContract = ( address: Address, abiJson: any[], - passphrase: string, options: { provider?: any } = {} ) => { const { provider } = options; const api = provider ? createApiFromProvider(provider) : getApi(); - return makeContractWithApi(address, abiJson, passphrase, api); + return makeContractWithApi(address, abiJson, api); }; diff --git a/packages/light.js/src/rpc/other/post.ts b/packages/light.js/src/rpc/other/post.ts index 78711874..dbd51855 100644 --- a/packages/light.js/src/rpc/other/post.ts +++ b/packages/light.js/src/rpc/other/post.ts @@ -13,6 +13,7 @@ import { RpcObservableOptions, Tx, TxStatus } from '../../types'; interface PostOptions extends RpcObservableOptions { estimate?: boolean; + passphrase: String; } function getTransactionReceipt (transactionHash: string, api: any) { @@ -42,12 +43,16 @@ function getTransactionReceipt (transactionHash: string, api: any) { * the transaction. * * @param tx - Transaction object - * @param passphrase - Passphrase of the account - * @param options? - Options to pass to the {@link RpcObservable}. - * @return - The status of the transaction. + * @param options - Options to pass to the {@link RpcObservable}. + * @param options.passphrase - Passphrase of the account + * @return - The status of the transaction: (estimated), signed, sent, confirmed */ -export function post$ (tx: Tx, passphrase: string, options: PostOptions = {}) { - const { estimate, provider } = options; +export function post$ (tx: Tx, options: PostOptions) { + const { estimate, passphrase, provider } = options; + if (!passphrase) { + throw new Error('The passphrase is missing from the options'); + } + const api = provider ? createApiFromProvider(provider) : getApi(); const source$ = Observable.create(async (observer: Observer) => { @@ -80,9 +85,9 @@ export function post$ (tx: Tx, passphrase: string, options: PostOptions = {}) { * * @param rawTx - Raw transaction * @param options? - Options to pass to the {@link RpcObservable}. - * @return - The status of the transaction. + * @return - The status of the transaction: sent, confirmed */ -export function postRaw$ (rawTx: string, options: PostOptions = {}) { +export function postRaw$ (rawTx: string, options: RpcObservableOptions = {}) { const { provider } = options; const api = provider ? createApiFromProvider(provider) : getApi();