-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: process tx after push #813
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
❌ Your patch check has failed because the patch coverage (66.66%) is below the target coverage (70.00%). You can increase the patch coverage or adjust the target coverage.
Additional details and impacted files@@ Coverage Diff @@
## master #813 +/- ##
===========================================
- Coverage 81.02% 65.80% -15.23%
===========================================
Files 91 91
Lines 7190 7259 +69
Branches 1517 1537 +20
===========================================
- Hits 5826 4777 -1049
- Misses 1351 2399 +1048
- Partials 13 83 +70 ☔ View full report in Codecov by Sentry. |
…nd-to-storage * origin/master: tests: check tx processing on metadata updates (#812)
export async function createTokenHelper(hWallet, name, symbol, amount, options) { | ||
export async function createTokenHelper(hWallet, name, symbol, amount, options = {}) { |
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.
unrelated to line
All changes in this file are related to typing, some jsdoc types that were not converted into ts types.
This removes some typing alerts from the tests.
Obs: We don't have alerts on the CI because we exclude tests from tsc
src/api/txApi.ts
Outdated
getTransaction(id, resolve): Promise<void | AxiosResponse<TransactionSchema>> { | ||
getTransaction(id, resolve): Promise<void> { |
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.
The getTransaction
method does not return a TransactionSchema
, it passes the TransactionSchema
instance to the resolve
argument.
We could type resolve: (a: TransactionSchema) => void
which is correct, but some other parts of the lib break due to being reliant on the implicit typing.
@@ -422,6 +424,23 @@ export default class SendTransaction extends EventEmitter { | |||
throw new WalletError(ErrorMessages.TRANSACTION_IS_NULL); | |||
} | |||
this.transaction.updateHash(); | |||
if (this.storage) { |
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.
This is the core of the PR.
When we push a transaction we need to convert it from a Transaction
instance to a IHistoryTx
(which is what is received via websocket) and add it to the storage with normal processing.
If we are creating a token we should also add it to the tokens here because the fullnode may not know that this token exists when we ask for the name and symbol for this UID. It also saves us from making an extraneous API call.
…nd-to-storage * origin/master: fix: utxo selection for getUtxosForAmount (#818)
await this.addToken(this.getNativeTokenData()); | ||
} | ||
|
||
async addToken(data: ITokenData): Promise<void> { |
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.
Missing docstring
const storeToken = await store.getToken(uid); | ||
if (storeToken === null) { | ||
// saveToken will ignore the meta and save only the token config | ||
await store.saveToken(tokenData); | ||
} |
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.
Isn't this the same as the new storage.addToken
method created?
tx.hash = 'no-outputs-case'; | ||
tx.inputs = [new Input('no-outputs', 0)]; | ||
await expect(transaction.convertTransactionToHistoryTx(tx, storage)).rejects.toThrow( | ||
'Index outsite of tx output array bounds' |
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.
fix: minor typo
'Index outsite of tx output array bounds' | |
'Index outside of tx output array bounds' |
Motivation
The process to send a transaction from the wallet-lib includes the steps:
Transaction
instance and calculate the metadata for mining.parents
andnonce
.Once the push-tx call successfully returns we can safely assume that it was accepted and propagated to the network, but the wallet is only made aware of this after the fullnode sends the tx via websocket. This wait period can vary depending on the network, fullnode and connection RTT, and can take up to a few seconds.
The main goal of this PR is to make the wallet process the transaction without the wait period since we already know its contents and that it is accepted when step 4 ends.
This will save the wallet a few seconds between each tx which will increase the maximum tx throughput of the wallets while not affecting the normal usage.
Acceptance Criteria
Transaction
instance to websocket tx format (IHistoryTx
interface)SendTransaction
facade.Security Checklist