Skip to content
This repository has been archived by the owner on May 24, 2022. It is now read-only.

Rewrite post$ to take a password and not use signer #93

Merged
merged 12 commits into from
Jan 22, 2019
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
"packages/*"
],
"useWorkspaces": true,
"version": "3.0.27"
"version": "4.0.0"
}
2 changes: 1 addition & 1 deletion packages/abi/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@parity/abi",
"description": "Ethereum ABI encoder and decoder",
"version": "3.0.27",
"version": "4.0.0",
"author": "Parity Team <admin@parity.io>",
"license": "MIT",
"repository": "https://github.com/paritytech/js-libs/tree/master/packages/abi",
Expand Down
4 changes: 2 additions & 2 deletions packages/api/package.json
Original file line number Diff line number Diff line change
@@ -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 <admin@parity.io>",
"license": "MIT",
"repository": "https://github.com/paritytech/js-libs/tree/master/packages/api",
Expand Down Expand Up @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions packages/api/src/rpc/personal/personal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions packages/contracts/package.json
Original file line number Diff line number Diff line change
@@ -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 <admin@parity.io>",
"license": "MIT",
"repository": "https://github.com/paritytech/js-libs/tree/master/packages/contracts",
Expand All @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion packages/electron/package.json
Original file line number Diff line number Diff line change
@@ -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 <admin@parity.io>",
"license": "MIT",
"repository": "https://github.com/paritytech/js-libs/tree/master/packages/electron",
Expand Down
6 changes: 3 additions & 3 deletions packages/light.js-react/package.json
Original file line number Diff line number Diff line change
@@ -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 <admin@parity.io>",
"license": "MIT",
"repository": "https://github.com/paritytech/js-libs/tree/master/packages/light.js-react",
Expand Down Expand Up @@ -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",
Expand All @@ -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"
}
}
6 changes: 3 additions & 3 deletions packages/light.js/package.json
Original file line number Diff line number Diff line change
@@ -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 <admin@parity.io>",
"license": "MIT",
"repository": "https://github.com/paritytech/js-libs/tree/master/packages/light.js",
Expand All @@ -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",
Expand Down
11 changes: 7 additions & 4 deletions packages/light.js/src/rpc/other/makeContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -97,7 +98,7 @@ const makeContractWithApi = memoizee(
args
),
...options
});
}, passphrase);
}
};
});
Expand All @@ -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
Expand All @@ -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);
};
32 changes: 12 additions & 20 deletions packages/light.js/src/rpc/other/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -55,22 +57,11 @@ 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);
observer.next({ signed: signedTransaction.raw });
postRaw$(signedTransaction.raw).subscribe(observer);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is a breaking change, what do you think of putting observer.next({ signed: ... }) here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good!


observer.complete();
} catch (error) {
observer.next({ failed: error });
observer.error(error);
Expand All @@ -87,17 +78,18 @@ 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<TxStatus>) => {
try {
const transactionHash = await api.eth.sendRawTransaction(tx);
observer.next({ signed: transactionHash });
const transactionHash = await api.eth.sendRawTransaction(rawTx);
observer.next({ sent: transactionHash });

const receipt = await getTransactionReceipt(transactionHash, api);
observer.next({ confirmed: receipt });
Expand Down
3 changes: 1 addition & 2 deletions packages/light.js/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ export interface TxStatus {
estimating?: boolean;
estimated?: BigNumber;
failed?: Error;
requested?: string;
schedule?: any;
signed?: string;
sent?: string;
}