This repository has been archived by the owner on May 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 39
Rewrite post$ to take a password and not use signer #93
Merged
Merged
Changes from 2 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
9110c74
Rewrite post$ to take a password and not use signer
axelchalon b38994e
Use new post$ in makeContract
axelchalon 4d9e6c6
Merge branch 'master' into ac-post
axelchalon f150fcd
Grumbles & bump packages to 4.0.0
axelchalon 487979c
Bump workspace root version to 4.0.0
axelchalon d80eb90
lerna: use `--conventional-commits` to bump patch/minor/major & gene…
axelchalon 0738d31
Revert "Bump workspace root version to 4.0.0"
axelchalon d431cc8
Revert "bump packages to 4.0.0"
axelchalon aba163e
Merge branch 'master' into ac-post
axelchalon 624aed2
post$: pass passphrase in the options; fix makeContract$
axelchalon ceb6169
Update tutorial
axelchalon 7a40419
Fix tests
axelchalon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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<TxStatus>) => { | ||
try { | ||
const transactionHash = await api.eth.sendRawTransaction(tx); | ||
const transactionHash = await api.eth.sendRawTransaction(rawTx); | ||
observer.next({ signed: transactionHash }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ... and changing here to |
||
|
||
const receipt = await getTransactionReceipt(transactionHash, api); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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: ... })
hereThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds good!