From 78b7d601c2b660584fdc10ba8c31b909ede1d41f Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Sat, 30 Jun 2018 23:09:57 -0400 Subject: [PATCH] Simplifying transfer when buying token --- contracts/SpaceshipToken.sol | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/contracts/SpaceshipToken.sol b/contracts/SpaceshipToken.sol index d226ac9..60aeaec 100644 --- a/contracts/SpaceshipToken.sol +++ b/contracts/SpaceshipToken.sol @@ -28,13 +28,6 @@ contract SpaceshipToken is ERC721Token("CryptoSpaceships", "CST"), Ownable { uint[] public shipsForSale; mapping(uint => uint) indexes; // shipId => shipForSale - function transferSelfOwnedToken(address _to, uint _tokenId) private { - clearApproval(address(this), _tokenId); - removeTokenFrom(address(this), _tokenId); - addTokenTo(_to, _tokenId); - emit Transfer(msg.sender, _to, _tokenId); - } - function mint(bytes _metadataHash, uint8 _energy, uint8 _lasers, @@ -73,8 +66,10 @@ contract SpaceshipToken is ERC721Token("CryptoSpaceships", "CST"), Ownable { // Se debe enviar al menos el precio de la nave require(msg.value != 0); - // Transferimos la nave - transferSelfOwnedToken(msg.sender, _spaceshipId); + // Transferimos la + // Approbamos directamente para evitar tener que crear una transaccion extra + tokenApprovals[_spaceshipId] = msg.sender; + safeTransferFrom(address(this), msg.sender, _spaceshipId); // La eliminamos de la lista para venta uint256 replacer = shipsForSale[shipsForSale.length - 1];