arda-org / xSuite

🛠️ Init, Build, Test, Deploy MultiversX smart contracts in seconds. The full suite for efficiently developing high-quality contracts.
https://xsuite.dev
MIT License
13 stars 3 forks source link

Helpers to create keys #190

Closed lcswillems closed 1 month ago

lcswillems commented 2 months ago

This is a code I wrote while doing some testing:

const state = await Promise.all([
  getAccount(ctx, userAddress),
  getAccount(ctx, sysAccAddress, [
    e.Tuple(e.TopStr("ELRONDesdt"), e.TopStr(lkmexId), e.TopU(4)).toTopHex(),
    e.Tuple(e.TopStr("ELRONDesdt"), e.TopStr(lkmexId), e.TopU(3389)).toTopHex(),
    e.Tuple(e.TopStr("ELRONDesdt"), e.TopStr(lkmexId), e.TopU(userLkmexNonce)).toTopHex(),
  ]),
  getAccount(ctx, lkmexFactoryAddress).then(a => ({ ...a, code: "file:/mnt/Data/Documents/Activités/LWEURL/MultiversX/Code/mx-exchange-sc/locked-asset/factory/output/factory.wasm" })),
  getAccount(ctx, energyFactoryAddress, [
    userEnergyKey,
    e.Tuple(e.TopStr("lockOptions")).toTopHex(),
    e.Tuple(e.TopStr("oldLockedAssetFactoryAddress")).toTopHex(),
    e.Tuple(e.TopStr("minMigratedTokenLockedPeriod")).toTopHex(),
    e.Tuple(e.TopStr("baseAssetTokenId")).toTopHex(),
    e.Tuple(e.TopStr("legacyLockedTokenId")).toTopHex(),
    e.Tuple(e.TopStr("tokenUnstakeScAddress")).toTopHex(),
    e.Tuple(e.TopStr("userUpdatedOldTokensEnergy"), e.Addr(userAddress)).toTopHex(),
  ]),
]);

Basically I needed to recreate the keys from scratch because there was no helper.

It would be great to have helpers to create those keys. It could be the key for a mapper and the different keys for an esdt (they are multiple: the key for the amount, but also the key for the latest nonce, etc).

Those helpers could then be used inside e.kvs and other relevant places. The places could be found by searching the usage of TopStr.

Of course, tests should be added.

And for the name, we could have e.MapperKey(...) and some similar names for the other keys?