Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Erc1537 #171

Merged
merged 3 commits into from
Apr 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions contracts/ERC1537.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

/**
* Copyright (c) 2018-present, Leap DAO (leapdao.org)
*
* This source code is licensed under the Mozilla Public License, version 2,
* found in the LICENSE file in the root directory of this source tree.
*/

pragma solidity ^0.5.2;

import "openzeppelin-solidity/contracts/token/ERC721/ERC721.sol";
import "./IERC1537.sol";

contract ERC1537 is IERC1537, ERC721 {

mapping(uint256 => bytes32) data;

function mint(address _to, uint256 _tokenId) public {
super._mint(_to, _tokenId);
}

function burn(uint256 _tokenId) public {
super._burn(ownerOf(_tokenId), _tokenId);
delete(data[_tokenId]);
}

function readData(uint256 _tokenId) public view returns (bytes32) {
require(_exists(_tokenId));
return data[_tokenId];
}

function writeData(uint256 _tokenId, bytes32 _newData) public {
require(msg.sender == ownerOf(_tokenId));
emit DataUpdated(_tokenId, data[_tokenId], _newData);
data[_tokenId] = _newData;
}

}
19 changes: 19 additions & 0 deletions contracts/IERC1537.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

/**
* Copyright (c) 2018-present, Leap DAO (leapdao.org)
*
* This source code is licensed under the Mozilla Public License, version 2,
* found in the LICENSE file in the root directory of this source tree.
*/

pragma solidity ^0.5.2;

contract IERC1537 {

event DataUpdated(uint256 indexed tokenId, bytes32 oldData, bytes32 newData);

function readData(uint256 _tokenId) public view returns (bytes32);

function writeData(uint256 _tokenId, bytes32 _newData) public;

}
268 changes: 0 additions & 268 deletions contracts/SunDAI.sol

This file was deleted.

25 changes: 25 additions & 0 deletions test/erc1537.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const ERC1537 = artifacts.require('./ERC1537.sol');

require('./helpers/setup');

contract('ERC1537', (accounts) => {
const firstTokenId = 100;
const creator = accounts[0];
const empty = '0x0000000000000000000000000000000000000000000000000000000000000000';
const data = '0x0101010101010101010101010101010101010101010101010101010101010101';
let dataToken;

beforeEach(async () => {
dataToken = await ERC1537.new();
await dataToken.mint(creator, firstTokenId);
});

it('should allow read write read', async () => {
let rsp = await dataToken.readData(firstTokenId);
assert.equal(rsp, empty);
await dataToken.writeData(firstTokenId, data);
rsp = await dataToken.readData(firstTokenId);
assert.equal(rsp, data);
});

});
Loading