-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWheels.sol
51 lines (51 loc) · 1.89 KB
/
Wheels.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
pragma solidity ^0.5.5;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v2.5.0/contracts/token/ERC721/ERC721Full.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v2.5.0/contracts/drafts/Counters.sol";
/**
ERC721 Token URI JSON Schema
{
"title": "Download Metadata",
"type": "object",
"properties": {
"Text": {
"type": "string",
"description": ""
},
"Song": {
"type": "string",
"description": ""
},
"Video": {
"type": "uint",
"description": ""
}
}
}
**/
contract Wheels is ERC721Full {
constructor() ERC721Full("Wheels", "WHLS") public { }
using Counters for Counters.Counter;
Counters.Counter token_ids;
struct File {
string file_id;
uint alterations;
}
// Stores token_id => File
// Only permanent data that you would need to use within the smart contract later should be stored on-chain
mapping(uint => File) public files;
event Alteration(uint token_id, string report_uri);
function registerDownload(address owner, string memory file_id, string memory token_uri) public returns(uint) {
token_ids.increment();
uint token_id = token_ids.current();
_mint(owner, token_id);
_setTokenURI(token_id, token_uri);
files[token_id] = File(file_id, 0);
return token_id;
}
function reportAlteration(uint token_id, string memory report_uri) public returns(uint) {
files[token_id].alterations += 1;
// Permanently associates the report_uri with the token_id on-chain via Events for a lower gas-cost than storing directly in the contract's storage.
emit Alteration(token_id, report_uri);
return files[token_id].alterations;
}
}