-
Notifications
You must be signed in to change notification settings - Fork 15
feat: parsing big int values that come from http requests #830
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
Conversation
b96c062
to
c1824f1
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #830 +/- ##
==========================================
+ Coverage 81.36% 82.51% +1.14%
==========================================
Files 83 84 +1
Lines 6720 6767 +47
Branches 1444 1445 +1
==========================================
+ Hits 5468 5584 +116
+ Misses 1239 1170 -69
Partials 13 13 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
eb54782
to
40df312
Compare
outputs: TxProposalOutputs[]; // Outputs data of the tx proposal | ||
tokens: string[]; |
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.
These are not coming from the wallet-service:
@@ -449,14 +454,16 @@ export interface TxByIdTokenData { | |||
voided: boolean; | |||
height?: number | null; | |||
weight: number; | |||
balance: Balance; |
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.
Type is wrong, it never came as a Balance object from the wallet-service:
tokenId: string; | ||
walletId: string; |
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.
Same, no walletId coming from the wallet-service lambdas
src/wallet/api/schemas/walletApi.ts
Outdated
* Schema for token information. | ||
*/ | ||
export const tokenInfoSchema = z.object({ | ||
id: z.string(), |
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.
Check for 64 length and hex characters?
I included the native token case as well.
id: z.string(), | |
id: z.string().regex(/^[a-fA-F0-9]{64}$|^00$/), |
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.
Great, thanks!
src/wallet/api/schemas/walletApi.ts
Outdated
rewardSpendMinBlocks: z.number(), | ||
maxNumberInputs: z.number(), | ||
maxNumberOutputs: z.number(), | ||
}); |
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.
Currently any new keys will be ignored, but we can pass them into the final data without validation (so that new keys from the fullnode do not break the api)
}); | |
}).passthrough(); |
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.
Done!
Also added a test to test for new attributes
cdfa371
to
8adf25b
Compare
src/wallet/types.ts
Outdated
script: { | ||
type: 'Buffer'; | ||
data: number[]; | ||
}; |
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.
Why?
Should the script not be serialized as hex or base64?
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.
Same, can you please check?
src/wallet/types.ts
Outdated
script: { | ||
type: 'Buffer'; | ||
data: number[]; | ||
}; |
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.
If the wallet-service is sending this "Buffer" type maybe we should change how the wallet-service is serializing the script
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.
Hey, we actually receive a simpler TxInput
and TxOutput
in websocket transactions, e.g.:
{
"height": 0,
"inputs": [
{
"address": "H79QdDV5i6KuW3dNJEahkUNe8a9axtHuCu",
"timelock": null,
"type": "P2PKH"
}
],
"nonce": 16746194,
"outputs": [
{
"address": "HDY5QHiE33goHcLxFyJmgxTErwgGHDrLdy",
"timelock": null,
"type": "P2PKH"
}
],
"parents": [],
"signal_bits": 0,
"timestamp": 1743779693,
"token_name": null,
"token_symbol": null,
"tx_id": "000009532ec33ba944c5d23b8dc642063539055ca31b4f6d4f534d33651ce8a3",
"version": 1,
"voided": false,
"weight": 16.818364568681208
}
Fixed the type and the schema validation
src/wallet/connection.ts
Outdated
this.websocket.on('new-tx', payload => this.emit('new-tx', payload.data as WsTransaction)); | ||
this.websocket.on('update-tx', payload => this.emit('update-tx', payload.data)); | ||
this.websocket.on('new-tx', payload => { | ||
const validatedTx = parseSchema(payload.data, wsTransactionSchema); |
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.
Maybe we should put a try..catch around this or use safeParse
directly.
Or do you think its better to have an unhandled error than a silent fail (only log an error) on new-tx?
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.
You are right, we shouldn't throw an error here
Fixed
8357e31
to
fe1b9fb
Compare
@@ -539,7 +539,7 @@ class HathorWalletServiceWallet extends EventEmitter implements IHathorWallet { | |||
let shouldGetNewAddresses = false; | |||
|
|||
for (const output of outputs) { | |||
if (this.newAddresses.find(newAddress => newAddress.address === output.decoded.address)) { |
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 was a bug, we were not generating new addresses when a new tx came from the websocket.
027cfbd
to
e6d5a2d
Compare
2e0f831
to
91fa491
Compare
91fa491
to
d09df09
Compare
Acceptance Criteria
Security Checklist