Skip to content

Commit

Permalink
Fix bug on createTwinInternal (#469)
Browse files Browse the repository at this point in the history
* Fix bug on createTwinInternal

* Review change
  • Loading branch information
anajuliabit authored Nov 18, 2022
1 parent 5489ea6 commit c518abf
Show file tree
Hide file tree
Showing 5 changed files with 390 additions and 773 deletions.
9 changes: 5 additions & 4 deletions contracts/protocol/bases/TwinBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ contract TwinBase is ProtocolBase, IBosonTwinEvents {
// Twin supply must exist and can't be zero
require(_twin.supplyAvailable > 0, INVALID_SUPPLY_AVAILABLE);

// Get the next twinId and increment the counter
uint256 twinId = protocolCounters().nextTwinId++;
_twin.id = twinId;

if (_twin.tokenType == TokenType.NonFungibleToken) {
// Check if the token supports IERC721 interface
require(contractSupportsInterface(_twin.tokenAddress, type(IERC721).interfaceId), INVALID_TOKEN_ADDRESS);
Expand Down Expand Up @@ -122,14 +126,11 @@ contract TwinBase is ProtocolBase, IBosonTwinEvents {
require(_twin.amount > 0 && _twin.amount <= _twin.supplyAvailable, INVALID_AMOUNT);
}

// Get the next twinId and increment the counter
uint256 twinId = protocolCounters().nextTwinId++;

// Get storage location for twin
(, Twin storage twin) = fetchTwin(twinId);

// Set twin props individually since memory structs can't be copied to storage
twin.id = _twin.id = twinId;
twin.id = twinId;
twin.sellerId = _twin.sellerId = sellerId;
twin.supplyAvailable = _twin.supplyAvailable;
twin.amount = _twin.amount;
Expand Down
Loading

0 comments on commit c518abf

Please sign in to comment.