-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
AriaCertificate.sol
85 lines (72 loc) · 2.68 KB
/
AriaCertificate.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "./node_modules/@nibbstack/erc721/src/contracts/tokens/nf-token.sol";
import "./node_modules/@nibbstack/erc721/src/contracts/ownership/ownable.sol";
import {ERC20Spendable} from "./AriaToken.sol";
/**
* @notice A non-fungible certificate that anybody can create by spending tokens
*/
contract AriaCertificate is NFToken, Ownable
{
/// @notice The price to create new certificates
uint256 _mintingPrice;
/// @notice The currency to create new certificates
ERC20Spendable _mintingCurrency;
/// @dev The serial number of the next certificate to create
uint256 nextCertificateId = 1;
mapping(uint256 => bytes32) certificateDataHashes;
/**
* @notice Query the certificate hash for a token
* @param tokenId Which certificate to query
* @return The hash for the certificate
*/
function hashForToken(uint256 tokenId) external view returns (bytes32) {
return certificateDataHashes[tokenId];
}
/**
* @notice The price to create certificates
* @return The price to create certificates
*/
function mintingPrice() external view returns (uint256) {
return _mintingPrice;
}
/**
* @notice The currency (ERC20) to create certificates
* @return The currency (ERC20) to create certificates
*/
function mintingCurrency() external view returns (ERC20Spendable) {
return _mintingCurrency;
}
/**
* @notice Set new price to create certificates
* @param newMintingPrice The new price
*/
function setMintingPrice(uint256 newMintingPrice) onlyOwner external {
_mintingPrice = newMintingPrice;
}
/**
* @notice Set new ERC20 currency to create certificates
* @param newMintingCurrency The new currency
*/
function setMintingCurrency(ERC20Spendable newMintingCurrency) onlyOwner external {
_mintingCurrency = newMintingCurrency;
}
/**
* @notice Allows anybody to create a certificate, takes payment from the
* msg.sender
* @param dataHash A representation of the certificate data using the Aria
* protocol (a 0xcert cenvention).
* @return The new certificate ID
*
*/
function create(bytes32 dataHash) external returns (uint) {
// Take payment for this service
_mintingCurrency.spend(msg.sender, _mintingPrice);
// Create the certificate
uint256 newCertificateId = nextCertificateId;
_mint(msg.sender, newCertificateId);
certificateDataHashes[newCertificateId] = dataHash;
nextCertificateId = nextCertificateId + 1;
return newCertificateId;
}
}