Skip to content

Remove Blockchain.getStorage / Blockchain.putStorage #399

@fulldecent

Description

@fulldecent

The function signature for Blockchain.getStorage / Blockchain.putStorage encourages boilerplate code and this results in unsafe implementations.

  1. Assumption: every contract using Blockchain.putStorage are implementing hashmaps/arrays
  2. Assumption: every contract using Blockchain.putStorage has 2 or more hashmaps/arrays
  3. Now therefore, the following will be best practice for every contract:
private enum StorageSlots {
    NamesArray,
    BalancesHashMap
}

Blockchain.putStorage(
    Blockchain.blake2b(
        AionBuffer.allocate(SOMETHING_GOES_HERE)
                .putInt(StorageSlots.NamesArray.toString())
                // .put* PUT OTHER STUFF HERE
                .getArray();
    ),
    SOME_VALUE
);

Therefore, in every case, the boilerplate can be factored out at least to:

Blockchain.putStorage(
    STORGE_SLOT,
    SUB_SLOT,
    SOME_VALUE
);

where SUB_SLOT can be null or any value. And then this new function will apply Blockchain.blake2b to SUB_SLOT.

In every case it seems that this API would be safer, semantic and reduce verbosity, therefore I recommend that this replace the existing API.

References

  • --NO LINK YET-- Will's upcoming AIP

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions