Created
February 18, 2022 13:47
-
-
Save dwook/82233b4a775b8df7dfc1ec4635beed03 to your computer and use it in GitHub Desktop.
NSeoulTowerMarket 스마트컨트랙트
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
contract NSeoulTowerMarket { | |
address private _LoveChainAddress; | |
address private _deployer; | |
uint256 private constant NFT_NUMBERS = 500; | |
constructor(address LoveChainAddress) public { | |
_LoveChainAddress = LoveChainAddress; | |
_deployer = msg.sender; | |
} | |
mapping (uint256 => address) public seller; | |
mapping (uint256 => uint256) public price; | |
function buyLoveChain(uint256 tokenId) public payable returns (bool) { | |
address payable receiver = address(uint256(seller[tokenId])); | |
uint256 _price = price[tokenId]; | |
receiver.transfer(_price * (10 ** 13)); // 저장된 가격 * 1KLAY (현재는 테스트로 0.00001 KLAY로 설정) | |
LoveChain(_LoveChainAddress).safeTransferFrom(address(this), msg.sender, tokenId, _uint256toBytes(_price)); // data로 거래 가격을 전송 | |
_clearSeller(tokenId); | |
_clearPrice(tokenId); | |
return true; | |
} | |
function _clearSeller(uint256 tokenId) private { // 거래 완료 시 seller 정보 삭제 | |
delete seller[tokenId]; | |
} | |
function _clearPrice(uint256 tokenId) private { // 거래 완료 시 price 정보 삭제 | |
delete price[tokenId]; | |
} | |
function _bytestoUint256(bytes memory _bytes) internal pure returns (uint256 value) { // 타입캐스팅 | |
assembly { | |
value := mload(add(_bytes, 0x20)) | |
} | |
} | |
function _uint256toBytes(uint256 _uint256) internal pure returns (bytes memory value) { // 타입캐스팅 | |
value = new bytes(32); | |
assembly { | |
mstore(add(value, 32), _uint256) | |
} | |
} | |
function setMintedToken(uint256 tokenId, uint256 _price) public { // 마켓으로 민팅할 때 price를 설정하기 위한 함수 | |
require(msg.sender == _LoveChainAddress, "you are not LoveChain"); | |
seller[tokenId] = _deployer; | |
price[tokenId] = _price; | |
} | |
function onKIP17Received(address operator, address from, uint256 tokenId, bytes memory data) public returns (bytes4) { | |
require(tokenId <= NFT_NUMBERS, "This token is not placed in NSeoulTower"); // 마켓이 받은 NFT가 남산타워의 것이 맞는지? | |
seller[tokenId] = from; // 판매자 주소 등록 | |
price[tokenId] = _bytestoUint256(data); // data로 받아온 price 저장 | |
return bytes4(keccak256("onKIP17Received(address,address,uint256,bytes)")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment