ERC725Alliance / erc725.js

Package to interact with ERC725 smart contracts
Apache License 2.0
38 stars 29 forks source link

[Bug] Not possible to fetch dynamic key parts individually #372

Closed fhildeb closed 8 months ago

fhildeb commented 9 months ago

I'm submitting a bug report

Issue

Dynamic key parts of ERC725Y storage can only be fetched when I provide more than keys:

let data = await erc725js.fetchData([
  'LSP4TokenName',
  {
    keyName: 'LSP4CreatorsMap:<address>',
    dynamicKeyParts: '0x9139def55c73c12bcda9c44f12326686e3948634',
  },
]);

However, fetching only one key does not work for any dynamic objects it seems.

a) It neither works with a single key

let data = await erc725js.fetchData({
  keyName: 'LSP4CreatorsMap:<address>',
  dynamicKeyParts: '0x9139def55c73c12bcda9c44f12326686e3948634',
});

b) Nor an array with a single key:

let data = await erc725js.fetchData([{
  keyName: 'LSP4CreatorsMap:<address>',
  dynamicKeyParts: '0x9139def55c73c12bcda9c44f12326686e3948634',
}]);

Why is this a problem

What I would like to know

Could someone explain

Related Links

richtera commented 9 months ago

One thing I did notice is that for a single item (not array) the return is also not an array, but that should not affect a single key array input when looking at getData. For a single key it will return the value also without array notation.

  const data = await getDataMultiple(erc725Options, [keyOrKeys]);

  return data[0];

So I believe since fetchData uses getData instead of getDataMultiple it's not getting an array in the single item case. But it doesn't explain the single array input case.

CJ42 commented 9 months ago

Tested with an other data key like AddressPermissions:Permissions:<address> works.

let lsp6Result = await erc725js.getData([{ keyName: 'AddressPermissions:Permissions:<address>', dynamicKeyParts: '0x9139def55c73c12bcda9c44f12326686e3948634' }]);

It looks like it has to do with the fact that the valueType / valueContent is a tuple, and the error occurs here:

https://github.com/ERC725Alliance/erc725.js/blob/330c604f55601b634f0eea381bc542e72021d19c/src/lib/decodeData.ts#L272C9-L276C11

image

This is the error I get:

let c = await erc725.getData([{ keyName: 'LSP4CreatorsMap:<address>', dynamicKeyParts: '0x9139def55c73c12bcda9c44f12326686e3948634' }]);

Uncaught TypeError: Cannot read properties of null (reading 'length')
    at async /Users/jeancavallera/Repositories/LUKSO/dApps-Projects/lukso-playground/<repl>.ts:1:33
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at getDataMultiple (/Users/jeancavallera/Repositories/LUKSO/dApps-Projects/lukso-playground/node_modules/@erc725/erc725.js/src/lib/getData.ts:131:20)
    at decodeData (/Users/jeancavallera/Repositories/LUKSO/dApps-Projects/lukso-playground/node_modules/@erc725/erc725.js/src/lib/decodeData.ts:345:17)
    at Array.map (<anonymous>)
    at /Users/jeancavallera/Repositories/LUKSO/dApps-Projects/lukso-playground/node_modules/@erc725/erc725.js/src/lib/decodeData.ts:345:36
    at processDataInput (/Users/jeancavallera/Repositories/LUKSO/dApps-Projects/lukso-playground/node_modules/@erc725/erc725.js/src/lib/decodeData.ts:340:14)
    at decodeKey (/Users/jeancavallera/Repositories/LUKSO/dApps-Projects/lukso-playground/node_modules/@erc725/erc725.js/src/lib/decodeData.ts:272:35)
    at decodeTupleKeyValue (/Users/jeancavallera/Repositories/LUKSO/dApps-Projects/lukso-playground/node_modules/@erc725/erc725.js/src/lib/decodeData.ts:161:13)
fhildeb commented 9 months ago

Same error on my side, verified

fhildeb commented 8 months ago

Solved and closed within #378