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

Commit

Permalink
Merge 624aed2 into 7641688
Browse files Browse the repository at this point in the history
  • Loading branch information
axelchalon committed Jan 21, 2019
2 parents 7641688 + 624aed2 commit 8cc98a0
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 30 deletions.
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
8 changes: 5 additions & 3 deletions packages/light.js/src/rpc/other/makeContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const getContract = memoizee(
);

/**
* Create a contract, givan an api object.
* Create a contract, given an api object.
* Pure function version of {@link makeContract}.
*
* @ignore
Expand Down Expand Up @@ -89,15 +89,17 @@ const makeContractWithApi = memoizee(
]
})({ provider: api.provider })(...args);
} else {
const { estimate, passphrase, ...txFields } = options;

return post$({
to: address,
data: abiEncode(
method.name,
method.inputs.map(({ kind: { type } }: any) => type), // TODO Use @parity/api types
args
),
...options
});
...txFields
}, { estimate, passphrase });
}
};
});
Expand Down
45 changes: 21 additions & 24 deletions packages/light.js/src/rpc/other/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { RpcObservableOptions, Tx, TxStatus } from '../../types';

interface PostOptions extends RpcObservableOptions {
estimate?: boolean;
passphrase: String;
}

function getTransactionReceipt (transactionHash: string, api: any) {
Expand All @@ -37,15 +38,21 @@ 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 options? - Options to pass to the {@link RpcObservable}.
* @return - The status of the transaction.
* @param tx - Transaction object
* @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, 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<TxStatus>) => {
Expand All @@ -55,22 +62,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);

observer.complete();
} catch (error) {
observer.next({ failed: error });
observer.error(error);
Expand All @@ -87,17 +83,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.
* @return - The status of the transaction: sent, confirmed
*/
export function postRaw$ (tx: string, options: PostOptions = {}) {
export function postRaw$ (rawTx: string, options: RpcObservableOptions = {}) {
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;
}
2 changes: 1 addition & 1 deletion scripts/lerna-publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 8cc98a0

Please sign in to comment.