2

So I recently started learning some solidity and was looking at code to make nft series like the punks.

I noticed that in their code there are always three conditions that appear to do the same thing.

!allPunksAssigned
punksRemainingToAssign == 0
punkIndex >= 10000

Why are the three of them needed? I see that one of them has to be manually activated but still, don't see the reason for the three conditions in almost every function. Shouldn't punkIndex >= 10000 suffice? I feel like I'm missing something.

function getPunk(uint punkIndex) {
        if (!allPunksAssigned) throw;
        if (punksRemainingToAssign == 0) throw;
        if (punkIndexToAddress[punkIndex] != 0x0) throw;
        if (punkIndex >= 10000) throw;
        punkIndexToAddress[punkIndex] = msg.sender;
        balanceOf[msg.sender]++;
        punksRemainingToAssign--;
        Assign(msg.sender, punkIndex);
    }

https://github.com/larvalabs/cryptopunks/blob/master/contracts/CryptoPunksMarket.sol

1 Answer 1

2

They serve different purposes

  • allPunksAssigned A better name would be allInitialPunksAssigned. All operations are disabled until a set of initial punks were assigned by the contract owner.
  • punkIndex All values between 0 and 9999 were available. A user was able to choose their favorite number in that range.
  • punksRemainingToAssign Counter of assigned punks.

It is possible to combine the last two if punkIndex is assigned sequentially, but they decided to allow some freedom.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.