mattlockyer / composables-998

An implementation and documentation repo for developing the ERC-998 standard for Ethereum.
MIT License
103 stars 64 forks source link

Duplicate Contracts Added To NFT #3

Closed mudgen closed 6 years ago

mudgen commented 6 years ago

I am really liking composable NFTs!

I noticed that the childReceived function will add duplicate contracts to childContracts[_tokenId] if multiple tokens from the same contract are transferred. When this happens the childContractsOwnedBy will return duplicate contracts, and this will cause other problems in the contract.

It seems that if a contract has already been added to childContracts[_tokenId] then it should not be added again.

mattlockyer commented 6 years ago

Great catch Nick, is there any chance you might be able to send me a pull request? It should just be a simple one liner 👍

mattlockyer commented 6 years ago

I came up with this:

if (childContractIndex[_tokenId][_from] == 0 && childContracts[0] != _from) {
    childContractIndex[_tokenId][_from] = childContracts[_tokenId].length;
    childContracts[_tokenId].push(_from);
}

But how do you know when to remove the contract from the contracts list? Since you don't know if you're removing the last token from that contract that's owned by this contract?

Is there anything we can do besides iterate?

Perhaps we'll need to store an array of childTokenId for each contract?

mudgen commented 6 years ago

Good solution. I will look into it.

mudgen commented 6 years ago

The latest pull request fixes this.