Skip to content

Commit

Permalink
Replacing walletOfOwner with ERC721AQueryable (#309)
Browse files Browse the repository at this point in the history
* Updating dependencies

* Replacing walletOfOwner with ERC721AQueryable
  • Loading branch information
liarco authored Jun 7, 2022
1 parent fbc929e commit e11db61
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 39 deletions.
32 changes: 2 additions & 30 deletions smart-contract/contracts/YourNftToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

pragma solidity >=0.8.9 <0.9.0;

import 'erc721a/contracts/ERC721A.sol';
import 'erc721a/contracts/extensions/ERC721AQueryable.sol';
import '@openzeppelin/contracts/access/Ownable.sol';
import '@openzeppelin/contracts/utils/cryptography/MerkleProof.sol';
import '@openzeppelin/contracts/security/ReentrancyGuard.sol';

contract YourNftToken is ERC721A, Ownable, ReentrancyGuard {
contract YourNftToken is ERC721AQueryable, Ownable, ReentrancyGuard {

using Strings for uint256;

Expand Down Expand Up @@ -72,34 +72,6 @@ contract YourNftToken is ERC721A, Ownable, ReentrancyGuard {
_safeMint(_receiver, _mintAmount);
}

function walletOfOwner(address _owner) public view returns (uint256[] memory) {
uint256 ownerTokenCount = balanceOf(_owner);
uint256[] memory ownedTokenIds = new uint256[](ownerTokenCount);
uint256 currentTokenId = _startTokenId();
uint256 ownedTokenIndex = 0;
address latestOwnerAddress;

while (ownedTokenIndex < ownerTokenCount && currentTokenId < _currentIndex) {
TokenOwnership memory ownership = _ownerships[currentTokenId];

if (!ownership.burned) {
if (ownership.addr != address(0)) {
latestOwnerAddress = ownership.addr;
}

if (latestOwnerAddress == _owner) {
ownedTokenIds[ownedTokenIndex] = currentTokenId;

ownedTokenIndex++;
}
}

currentTokenId++;
}

return ownedTokenIds;
}

function _startTokenId() internal view virtual override returns (uint256) {
return 1;
}
Expand Down
1 change: 0 additions & 1 deletion smart-contract/scripts/2_whitelist_open.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { MerkleTree } from 'merkletreejs';
import keccak256 from 'keccak256';
import CollectionConfig from './../config/CollectionConfig';
import NftContractProvider from '../lib/NftContractProvider';
import { ethers } from 'hardhat';

async function main() {
// Check configuration
Expand Down
10 changes: 5 additions & 5 deletions smart-contract/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,19 +202,19 @@ describe(CollectionConfig.contractName, function () {
});

it('Wallet of owner', async function () {
expect(await contract.walletOfOwner(await owner.getAddress())).deep.equal([
expect(await contract.tokensOfOwner(await owner.getAddress())).deep.equal([
BigNumber.from(1),
]);
expect(await contract.walletOfOwner(await whitelistedUser.getAddress())).deep.equal([
expect(await contract.tokensOfOwner(await whitelistedUser.getAddress())).deep.equal([
BigNumber.from(2),
BigNumber.from(3),
BigNumber.from(6),
]);
expect(await contract.walletOfOwner(await holder.getAddress())).deep.equal([
expect(await contract.tokensOfOwner(await holder.getAddress())).deep.equal([
BigNumber.from(4),
BigNumber.from(5),
]);
expect(await contract.walletOfOwner(await externalUser.getAddress())).deep.equal([]);
expect(await contract.tokensOfOwner(await externalUser.getAddress())).deep.equal([]);
});

it('Supply checks (long)', async function () {
Expand Down Expand Up @@ -248,7 +248,7 @@ describe(CollectionConfig.contractName, function () {
for (const i of [...Array(lastMintAmount).keys()].reverse()) {
expectedWalletOfOwner.push(BigNumber.from(CollectionConfig.maxSupply - i));
}
expect(await contract.walletOfOwner(
expect(await contract.tokensOfOwner(
await owner.getAddress(),
{
// Set gas limit to the maximum value since this function should be used off-chain only and it would fail otherwise...
Expand Down
6 changes: 3 additions & 3 deletions smart-contract/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3372,9 +3372,9 @@ env-paths@^2.2.0:
integrity sha512-+h1lkLKhZMTYjog1VEpJNG7NZJWcuc2DDk/qsqSTRRCOXiLjeQ1d1/udrUGhqMxUgAlwKNZ0cf2uqan5GLuS2A==

erc721a@^3.0.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/erc721a/-/erc721a-3.2.0.tgz#5f2ba2599465fbd51088b4d9d7c3e0ba340daa5e"
integrity sha512-bK6rT45M8csSpH/8SBAhlmyIlCh0LrejflvkSw9zVPU5pNRSe0P0YWmv/g6seYwc8OCfL9ND/fKL8LsuvuePmg==
version "3.3.0"
resolved "https://registry.yarnpkg.com/erc721a/-/erc721a-3.3.0.tgz#ff0fa7880759766ae44916fb7f53eb178e14b044"
integrity sha512-LqwmMcDPS3H9y7ZO+9B7R9sEoWApra17d4PwodXuP1072jP653jdo0TYkJbK4G5pBUFDdB5TCZwmJ6EQbmrysQ==
dependencies:
"@openzeppelin/contracts" "^4.4.2"

Expand Down

0 comments on commit e11db61

Please sign in to comment.