-
Notifications
You must be signed in to change notification settings - Fork 54
refactor(dapi,dpp)!: move dapi-client and Identifier off Buffer to Uint8Array #3680
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
base: v3.1-dev
Are you sure you want to change the base?
Changes from all commits
e703e90
ab00056
d397803
250a79c
a0e881b
c435910
b925e10
4ed8428
7885bb3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -15,7 +15,7 @@ function getBlockByHeightFactory(grpcTransport) { | |||||||||||
| * @typedef {getBlockByHeight} | ||||||||||||
| * @param {number} height | ||||||||||||
| * @param {DAPIClientOptions} [options] | ||||||||||||
| * @returns {Promise<null|Buffer>} | ||||||||||||
| * @returns {Promise<null|Uint8Array>} | ||||||||||||
| */ | ||||||||||||
| async function getBlockByHeight(height, options = {}) { | ||||||||||||
| const getBlockRequest = new GetBlockRequest(); | ||||||||||||
|
|
@@ -30,7 +30,7 @@ function getBlockByHeightFactory(grpcTransport) { | |||||||||||
|
|
||||||||||||
| const blockBinaryArray = response.getBlock(); | ||||||||||||
|
|
||||||||||||
| return Buffer.from(blockBinaryArray); | ||||||||||||
| return new Uint8Array(blockBinaryArray); | ||||||||||||
|
Comment on lines
31
to
+33
Collaborator
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. 🟡 Suggestion: Same root cause as
Suggested change
source: ['codex'] |
||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| return getBlockByHeight; | ||||||||||||
|
|
||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -29,18 +29,18 @@ function getBlockchainStatusFactory(grpcTransport) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const responseObject = response.toObject(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Respond with Buffers instead of base64 for binary fields | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Respond with Uint8Arrays instead of base64 for binary fields | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (response.getChain()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (response.getChain() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .getBestBlockHash()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| responseObject.chain.bestBlockHash = Buffer.from(response.getChain() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| responseObject.chain.bestBlockHash = new Uint8Array(response.getChain() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .getBestBlockHash()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (response.getChain() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .getChainWork()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| responseObject.chain.chainWork = Buffer.from(response.getChain() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| responseObject.chain.chainWork = new Uint8Array(response.getChain() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .getChainWork()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
34
to
46
Collaborator
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. 🟡 Suggestion: This factory was modified by this PR (e703e90 changed
Suggested change
source: ['claude', 'codex'] |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,7 +2,7 @@ const AbstractResponse = require('../response/AbstractResponse'); | |||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| class GetDocumentsResponse extends AbstractResponse { | ||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||
| * @param {Buffer[]} documents | ||||||||||||||||||||||||||||
| * @param {Uint8Array[]} documents | ||||||||||||||||||||||||||||
| * @param {Metadata} metadata | ||||||||||||||||||||||||||||
| * @param {Proof} [proof] | ||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||
|
|
@@ -13,7 +13,7 @@ class GetDocumentsResponse extends AbstractResponse { | |||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||
| * @returns {Buffer[]} | ||||||||||||||||||||||||||||
| * @returns {Uint8Array[]} | ||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||
| getDocuments() { | ||||||||||||||||||||||||||||
| return this.documents; | ||||||||||||||||||||||||||||
|
|
@@ -30,7 +30,7 @@ class GetDocumentsResponse extends AbstractResponse { | |||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| return new GetDocumentsResponse( | ||||||||||||||||||||||||||||
| documents !== undefined | ||||||||||||||||||||||||||||
| ? documents.getDocumentsList().map((document) => Buffer.from(document)) : [], | ||||||||||||||||||||||||||||
| ? documents.getDocumentsList().map((document) => new Uint8Array(document)) : [], | ||||||||||||||||||||||||||||
| metadata, | ||||||||||||||||||||||||||||
| proof, | ||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||
|
Comment on lines
31
to
36
Collaborator
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. 🟡 Suggestion: This response class was modified by this PR (e703e90). Each entry returned by
Suggested change
source: ['codex'] |
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
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.
🟡 Suggestion:
new Uint8Array(response.getBlock())corrupts the block payload under grpc-web — usegetBlock_asU8()This factory was modified by this PR (e703e90 changed
Buffer.from(response.getBlock())tonew Uint8Array(response.getBlock())). The google-protobuf JS binding returnsbytesfields as aUint8Arrayunder grpc-js but as a base64stringunder grpc-web.new Uint8Array(string)does NOT base64-decode — it coerces the string length to a numeric and produces a zero-length / bogus typed array, silently corrupting the block bytes returned to callers. The latest delta in this PR explicitly fixed this same pattern inGetTransactionResponse,GetIdentityResponse,GetIdentityByPublicKeyHashResponse,GetStatusResponse,Proof, andWaitForStateTransitionResultResponseusing the_asU8()accessor for exactly this reason. Apply the same fix here; the generated bindings exposegetBlock_asU8()for this purpose.source: ['codex']