Skip to content
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

bug:L2Block.fromFields() is not reconstructing the object (aztec.js) #8340

Closed
FilipHarald opened this issue Sep 3, 2024 · 2 comments · Fixed by #8882
Closed

bug:L2Block.fromFields() is not reconstructing the object (aztec.js) #8340

FilipHarald opened this issue Sep 3, 2024 · 2 comments · Fixed by #8882
Assignees

Comments

@FilipHarald
Copy link
Contributor

I'm trying to store the block in a DB and then serve it over an API. But when I retrieve the stored (JSON)data from the DB and send over an API I can't reconstruct the L2Block-object from the data. I know there are to/fromString and to/fromBuffer, but I want to make the data stored in DB queryable.

When trying to use fromFields with the JSON-data it works, but the object is not fully reconstructed. Also, the necessary types are not exported so that I can reconstruct the object.

I've reproduced it here. But the gist of it is this....

import { L2Block } from "@aztec/aztec.js";
// ... receiving `block`
  const jsonString = JSON.stringify(block, null, 2);
  const recreatedObj = L2Block.fromFields(JSON.parse(jsonString) as L2Block);
  logger.info(`Fields: ${JSON.stringify(recreatedObj, null, 2)}`);
  // below line produces an error
  logger.info(`Fields: ${recreatedObj.hash()}`);
// ...

...produces this...

TypeError: this.header.hash is not a function
    at L2Block.hash (/usr/main/node_modules/@aztec/circuit-types/src/l2_block.ts:139:24)
    at Object.store (/usr/main/services/explorer-api/src/database/models/block.ts:36:30)
    at onBlock (/usr/main/services/explorer-api/src/event-handler/on-block.ts:6:17)
    ...
@github-project-automation github-project-automation bot moved this to Todo in A3 Sep 3, 2024
@FilipHarald
Copy link
Contributor Author

When trying to reconstruct the obj required for fromFields I get stuck at not being able to import AppendOnlyTreeSnapshot for re-creation. It seems to be plenty of more classes that's not able to import.

@benesjan benesjan self-assigned this Sep 30, 2024
@github-project-automation github-project-automation bot moved this from Todo to Done in A3 Sep 30, 2024
@benesjan
Copy link
Contributor

Hello @FilipHarald, we've decided to just remove the function as it's non-essential. Please use toBuffer and fromBuffer methods when you need block serialization. Thank you for reporting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants