-
Notifications
You must be signed in to change notification settings - Fork 320
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
feat: barebones addressbook for tagging #9572
Merged
sklppy88
merged 1 commit into
master
from
ek/feat/new-note-taggging-scheme-implementation/barebones-address-book
Oct 31, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,8 +36,9 @@ import { type PxeDatabase } from './pxe_database.js'; | |
*/ | ||
export class KVPxeDatabase implements PxeDatabase { | ||
#synchronizedBlock: AztecSingleton<Buffer>; | ||
#addresses: AztecArray<Buffer>; | ||
#addressIndex: AztecMap<string, number>; | ||
#completeAddresses: AztecArray<Buffer>; | ||
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. Have renamed it to be more accurate to what it was |
||
#completeAddressIndex: AztecMap<string, number>; | ||
#addressBook: AztecSet<string>; | ||
#authWitnesses: AztecMap<string, Buffer[]>; | ||
#capsules: AztecArray<Buffer[]>; | ||
#notes: AztecMap<string, Buffer>; | ||
|
@@ -72,8 +73,10 @@ export class KVPxeDatabase implements PxeDatabase { | |
constructor(private db: AztecKVStore) { | ||
this.#db = db; | ||
|
||
this.#addresses = db.openArray('addresses'); | ||
this.#addressIndex = db.openMap('address_index'); | ||
this.#completeAddresses = db.openArray('complete_addresses'); | ||
this.#completeAddressIndex = db.openMap('complete_address_index'); | ||
|
||
this.#addressBook = db.openSet('address_book'); | ||
|
||
this.#authWitnesses = db.openMap('auth_witnesses'); | ||
this.#capsules = db.openArray('capsules'); | ||
|
@@ -509,15 +512,15 @@ export class KVPxeDatabase implements PxeDatabase { | |
return this.#db.transaction(() => { | ||
const addressString = completeAddress.address.toString(); | ||
const buffer = completeAddress.toBuffer(); | ||
const existing = this.#addressIndex.get(addressString); | ||
const existing = this.#completeAddressIndex.get(addressString); | ||
if (typeof existing === 'undefined') { | ||
const index = this.#addresses.length; | ||
void this.#addresses.push(buffer); | ||
void this.#addressIndex.set(addressString, index); | ||
const index = this.#completeAddresses.length; | ||
void this.#completeAddresses.push(buffer); | ||
void this.#completeAddressIndex.set(addressString, index); | ||
|
||
return true; | ||
} else { | ||
const existingBuffer = this.#addresses.at(existing); | ||
const existingBuffer = this.#completeAddresses.at(existing); | ||
|
||
if (existingBuffer?.equals(buffer)) { | ||
return false; | ||
|
@@ -531,12 +534,12 @@ export class KVPxeDatabase implements PxeDatabase { | |
} | ||
|
||
#getCompleteAddress(address: AztecAddress): CompleteAddress | undefined { | ||
const index = this.#addressIndex.get(address.toString()); | ||
const index = this.#completeAddressIndex.get(address.toString()); | ||
if (typeof index === 'undefined') { | ||
return undefined; | ||
} | ||
|
||
const value = this.#addresses.at(index); | ||
const value = this.#completeAddresses.at(index); | ||
return value ? CompleteAddress.fromBuffer(value) : undefined; | ||
} | ||
|
||
|
@@ -545,7 +548,31 @@ export class KVPxeDatabase implements PxeDatabase { | |
} | ||
|
||
getCompleteAddresses(): Promise<CompleteAddress[]> { | ||
return Promise.resolve(Array.from(this.#addresses).map(v => CompleteAddress.fromBuffer(v))); | ||
return Promise.resolve(Array.from(this.#completeAddresses).map(v => CompleteAddress.fromBuffer(v))); | ||
} | ||
|
||
async addContactAddress(address: AztecAddress): Promise<boolean> { | ||
if (this.#addressBook.has(address.toString())) { | ||
return false; | ||
} | ||
|
||
await this.#addressBook.add(address.toString()); | ||
|
||
return true; | ||
} | ||
|
||
getContactAddresses(): AztecAddress[] { | ||
return [...this.#addressBook.entries()].map(AztecAddress.fromString); | ||
} | ||
|
||
async removeContactAddress(address: AztecAddress): Promise<boolean> { | ||
if (!this.#addressBook.has(address.toString())) { | ||
return false; | ||
} | ||
|
||
await this.#addressBook.delete(address.toString()); | ||
|
||
return true; | ||
} | ||
|
||
getSynchedBlockNumberForAccount(account: AztecAddress): number | undefined { | ||
|
@@ -570,7 +597,7 @@ export class KVPxeDatabase implements PxeDatabase { | |
(sum, value) => sum + value.length * Fr.SIZE_IN_BYTES, | ||
0, | ||
); | ||
const addressesSize = this.#addresses.length * CompleteAddress.SIZE_IN_BYTES; | ||
const addressesSize = this.#completeAddresses.length * CompleteAddress.SIZE_IN_BYTES; | ||
const treeRootsSize = Object.keys(MerkleTreeId).length * Fr.SIZE_IN_BYTES; | ||
|
||
return incomingNotesSize + outgoingNotesSize + treeRootsSize + authWitsSize + addressesSize; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Quick typo fix