Skip to content

Commit

Permalink
fix: get storage at should always return 32 bytes
Browse files Browse the repository at this point in the history
Signed-off-by: Mariusz Jasuwienas <[email protected]>
  • Loading branch information
arianejasuwienas committed Jan 3, 2025
1 parent be3e361 commit bc32a9c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
const { strict: assert } = require('assert');
const debug = require('util').debuglog('hts-forking');

const { ZERO_HEX_20_BYTE, ZERO_HEX_32_BYTE, toIntHex256 } = require('./utils');
const { ZERO_HEX_32_BYTE, toIntHex256 } = require('./utils');
const { slotMapOf, packValues, persistentSlotMapOf } = require('./slotmap');
const { deployedBytecode } = require('../out/HtsSystemContract.sol/HtsSystemContract.json');

Expand Down Expand Up @@ -149,13 +149,13 @@ async function getHtsStorageAt(address, requestedSlot, blockNumber, mirrorNodeCl
(await mirrorNodeClient.getNftByTokenIdAndNumber(tokenId, serialId, blockNumber)) ?? {};
if (typeof spender !== 'string')
return ret(
ZERO_HEX_20_BYTE,
ZERO_HEX_32_BYTE,
`NFT ${tokenId}#${serialId} is not approved to any address`
);
const account = await mirrorNodeClient.getAccount(spender, blockNumber);
if (account === null)
return ret(
ZERO_HEX_20_BYTE,
ZERO_HEX_32_BYTE,
`NFT ${tokenId}#${serialId} is approved to address \`${spender}\`, failed to get its EVM Alias`
);

Expand All @@ -181,13 +181,13 @@ async function getHtsStorageAt(address, requestedSlot, blockNumber, mirrorNodeCl
};
if (typeof nft['account_id'] !== 'string')
return ret(
ZERO_HEX_20_BYTE,
ZERO_HEX_32_BYTE,
`Failed to determine an owner of the NFT ${tokenId}#${serialId}`
);
const account = await mirrorNodeClient.getAccount(`${nft['account_id']}`, blockNumber);
if (account === null)
return ret(
ZERO_HEX_20_BYTE,
ZERO_HEX_32_BYTE,
`NFT ${tokenId}#${serialId} belongs to \`${nft['account_id']}\`, failed to get its EVM Alias`
);

Expand All @@ -213,7 +213,7 @@ async function getHtsStorageAt(address, requestedSlot, blockNumber, mirrorNodeCl
};
if (typeof metadata !== 'string')
return ret(
ZERO_HEX_20_BYTE,
ZERO_HEX_32_BYTE,
`Failed to get the metadata of the NFT ${tokenId}#${serialId}`
);
persistentSlotMapOf(tokenId).store(nrequestedSlot, atob(metadata));
Expand Down
1 change: 0 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ module.exports = {
/**
* When a slot is empty, zero must be returned.
*/
ZERO_HEX_20_BYTE: '0x0000000000000000000000000000000000000000',
ZERO_HEX_32_BYTE: '0x0000000000000000000000000000000000000000000000000000000000000000',

/**
Expand Down

0 comments on commit bc32a9c

Please sign in to comment.