Skip to content

TowerBuilders/NVM-Advanced-Storage-Objects

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 

Repository files navigation

NVM Advanced Storage Objects

These are example implementations of the PackedList and DynamicList structures in Python.

Background

NVM prevents arrays from holding more than 1024 items.

The PackedList is used to store more than 1024 items in a structure in NVM smart contracts.

The PackedList is limited that it can only hold 7 layers. That caps its storage at:

(1024 * 7 - 6)

or

7,162

total items.

A further implementation is the DynamicList storage object, that dynamically creates new PackedList's as needed. It can store 1024 PackedList objects for a total storage of:

1024 * (1024 * 7 - 6)

or

7,333,888

total items.

PackedList Implementation

The PackedList has the follow structure:

packed = {
  "array": [],
  "items": 0
}

Each time an item is added or removed from the array, the items count is changed. When the array becomes full, it is wrapped in a new array.

For example, if the maximum array length was 2:

[]            // Starting
[1]           // Add 1
[1, 2]        // Add 2
[[1, 2], 3]   // Add 3

To remove an item, just swap it with the last item and remove the last item

[1, 3]        // Remove 2

DynamicList Implementation

The DynamicList has the follow structure:

dynamic = {
  "packed": [],
  "items": 0
}

Each time an item is added or removed from the array, the items count is changed. When all of the PackedList objects in the packed array become full, a new PackedList is allocated and added.

Releases

No releases published

Packages

No packages published

Languages