-
Notifications
You must be signed in to change notification settings - Fork 0
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: [Hardhat] implement nft support for the json rpc api library and js mock … #173
base: main
Are you sure you want to change the base?
Changes from 3 commits
d6c17f3
45996f4
40eece1
9f4940e
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 | ||||
---|---|---|---|---|---|---|
|
@@ -274,4 +274,60 @@ function slotMapOf(token) { | |||||
return map; | ||||||
} | ||||||
|
||||||
module.exports = { slotMapOf, packValues }; | ||||||
/** | ||||||
* Represents the value in the `PersistentStorage`. | ||||||
* Each token has its own SlotMap. Any value can be assigned to this storage | ||||||
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.
Suggested change
|
||||||
* ad-hoc. It can be used for dynamically determined keys needed to be persistent. | ||||||
* | ||||||
* @typedef {Object} PersistentStorage | ||||||
* @property {SlotMap} slotMap - The SlotMap instance. | ||||||
* @property {string} target - The target string. | ||||||
*/ | ||||||
|
||||||
/** | ||||||
* Represents the value in the `Storage`. | ||||||
* Each token has its own SlotMap. Any value can be assigned to this storage | ||||||
* ad-hoc. It can be used for dynamically determined keys needed to be persistent. | ||||||
* | ||||||
* @typedef {Object} PersistentSlotMap | ||||||
* @property {function(bigint): Array<{ | ||||||
* offset: number; | ||||||
* value:Value; | ||||||
* path:string; | ||||||
* type:string; | ||||||
* }>|undefined} load - Loads the value associated with a slot. | ||||||
* @property {function(bigint, string): void} store - Stores a value in the slot map. | ||||||
*/ | ||||||
|
||||||
/** | ||||||
* @type {Array<PersistentStorage>} | ||||||
*/ | ||||||
const persistentStorage = []; | ||||||
acuarica marked this conversation as resolved.
Show resolved
Hide resolved
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. This is actually a Map, whose keys are addresses (and 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. I would move this global state to |
||||||
|
||||||
/** | ||||||
* Slot map of token, but persistent, will not be removed between multiple separate requests. | ||||||
* | ||||||
* @param {string} target | ||||||
* @returns {PersistentSlotMap} An object with `load` and `store` methods. | ||||||
*/ | ||||||
function persistentSlotMapOf(target) { | ||||||
const found = persistentStorage.filter(occupiedSlot => occupiedSlot.target === target); | ||||||
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. what about |
||||||
const initialized = { | ||||||
target, | ||||||
slotMap: found.length > 0 && found[0] ? found[0].slotMap : new SlotMap(), | ||||||
}; | ||||||
persistentStorage.push(initialized); | ||||||
return { | ||||||
load: slot => initialized.slotMap.load(slot), | ||||||
store: (slot, value) => | ||||||
visit( | ||||||
{ label: 'value', slot: slot.toString(), type: 't_string_storage', offset: 0 }, | ||||||
0n, | ||||||
{ value }, | ||||||
'', | ||||||
initialized.slotMap | ||||||
), | ||||||
}; | ||||||
} | ||||||
|
||||||
module.exports = { packValues, persistentSlotMapOf, slotMapOf }; |
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.
moreover, not sure this works as intended, since it's going to always write when asked for token uri.
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.
When querying the first slot holding the tokenUri, it will store the values for all slots containing this single string.