-
Notifications
You must be signed in to change notification settings - Fork 1
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
Example client block cache #26
Conversation
dgca
commented
Aug 29, 2023
•
edited
Loading
edited
- Adds example client block caching
- Stubs out account processor (not hooked up yet)
- Fixes issue with Ironfish client not being cached
const amount = result.value(); | ||
|
||
const currentBalance = account.assetBalances.get(assetId) ?? BigInt(0); | ||
account.assetBalances.set(assetId, currentBalance + amount); |
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.
Instead of just storing balances here, can we store notes? This will make spending possible, since we need to fund the spends with owned notes. Otherwise we would need to rescan the blockchain for owned notes. Balance could then be calculated at runtime by summing the value of the owned notes.
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.
FYI probably simplest to store serialized note buffer
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.
@@ -0,0 +1,135 @@ | |||
import { generateKeyFromPrivateKey, Key } from "@ironfish/rust-nodejs"; | |||
import { NoteEncrypted } from "@ironfish/sdk/build/src/primitives/noteEncrypted"; |
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.
We should try and remove all references to the sdk in this client as much as possible, since integrators working here will not have access to SDK functions (unless they are in typescript, which is unlikely)
LightTransaction, | ||
} from "../../../../src/models/lightstreamer"; | ||
import { BlockCache } from "./BlockCache"; | ||
import { Note } from "@ironfish/sdk/build/src/primitives/note"; |
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, we should use the ironfish-rust-nodejs
version of the note:
https://github.com/iron-fish/ironfish/blob/b887f5198c6b7c9b9d06eddbc7f72a99d5650c98/ironfish-rust-nodejs/src/structs/note.rs#L47
@@ -123,15 +109,17 @@ export class BlockProcessor { | |||
} | |||
|
|||
private async _processBlock(block: LightBlock) { | |||
this.blockCache.cacheBlock(block); | |||
|
|||
const notes: NoteEncrypted[] = []; |
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.
Can we change the function signature of the addNotesToMerkleTree
to just take in the type of output.note[]? I just want to encapsulate all the sdk calls to the merkle tree so that it will be clear how to handle clients without the sdk.
I know you didn't make this code, so feel free to say no or push out :)
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.
LGTM, I would just say make sure you scan an account you know has SOME balance, and verify the add works, I know the spends don't work yet so balance won't match