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

Example client block cache #26

Merged
merged 12 commits into from
Aug 30, 2023
Merged

Example client block cache #26

merged 12 commits into from
Aug 30, 2023

Conversation

dgca
Copy link
Contributor

@dgca dgca commented Aug 29, 2023

  • 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);
Copy link
Contributor

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.

Copy link
Contributor

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

Copy link
Contributor Author

@dgca dgca Aug 29, 2023

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";
Copy link
Contributor

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";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -123,15 +109,17 @@ export class BlockProcessor {
}

private async _processBlock(block: LightBlock) {
this.blockCache.cacheBlock(block);

const notes: NoteEncrypted[] = [];
Copy link
Contributor

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 :)

Copy link
Contributor

@jowparks jowparks left a 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

@dgca dgca merged commit 56e48e2 into main Aug 30, 2023
@dgca dgca deleted the client-block-cache branch September 11, 2023 21:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants