pragma solidity ^0.5.0;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/dfbdb11605bab94df6a6b864afc1a068e94a67cc/contracts/crowdsale/Crowdsale.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/dfbdb11605bab94df6a6b864afc1a068e94a67cc/contracts/crowdsale/distribution/FinalizableCrowdsale.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/dfbdb11605bab94df6a6b864afc1a068e94a67cc/contracts/crowdsale/emission/AllowanceCrowdsale.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/dfbdb11605bab94df6a6b864afc1a068e94a67cc/contracts/crowdsale/price/IncreasingPriceCrowdsale.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/dfbdb11605bab94df6a6b864afc1a068e94a67cc/contracts/crowdsale/validation/CappedCrowdsale.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/dfbdb11605bab94df6a6b864afc1a068e94a67cc/contracts/crowdsale/validation/PausableCrowdsale.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/dfbdb11605bab94df6a6b864afc1a068e94a67cc/contracts/crowdsale/validation/TimedCrowdsale.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/dfbdb11605bab94df6a6b864afc1a068e94a67cc/contracts/token/ERC20/IERC20.sol";
/**
* @title SampleCrowdsale
* @dev This is an example of a fully fledged crowdsale.
* The way to add new features to a base crowdsale is by multiple inheritance.
* In this example we are providing following extensions:
* CappedCrowdsale - sets a max boundary for raised funds
* RefundableCrowdsale - set a min goal to be reached and returns funds if it's not met
* MintedCrowdsale - assumes the token can be minted by the crowdsale, which does so
* when receiving purchases.
*
* After adding multiple features it's good practice to run integration tests
* to ensure that subcontracts works together as intended.
*/
contract CresstCrowdsale is CappedCrowdsale,TimedCrowdsale,Pausable,IncreasingPriceCrowdsale,AllowanceCrowdsale,FinalizableCrowdsale {
uint constant TOKEN_DECIMALS = 18;
uint8 constant TOKEN_DECIMALS_UINT8 = 18;
uint constant TOKEN_DECIMAL_MULTIPLIER = 10 ** TOKEN_DECIMALS;
constructor (
uint256 openingTime, // opening time in unix epoch seconds
uint256 closingTime, // closing time in unix epoch seconds
uint256 rate, // rate, in TKNbits
address payable wallet, //the wallet address that will receive the donation
address payable tokenWallet, // the crowd sale wallet address
uint256 initialRate, //the rate it will start to increase its always greater
uint256 finalRate, //the rate it will end when crowd sale stops always smaller
uint256 cap, // total amount for the Crowdsale, in wei
IERC20 token // the token contract address
)
Crowdsale(rate,wallet,token)
CappedCrowdsale(cap)
TimedCrowdsale(openingTime, closingTime)
IncreasingPriceCrowdsale(initialRate,finalRate)
AllowanceCrowdsale(tokenWallet)
FinalizableCrowdsale()
public {
}
/**
* @dev Admin can move end time.
* @param _endTime New end time.
*/
function setEndTime(uint _endTime) public onlyOwner notFinalized {
require(_endTime > openingTime);
closingTime = uint32(_endTime);
}
function setStartTime(uint _startTime) public onlyOwner notFinalized {
require(_startTime < closingTime);
openingTime = uint32(_startTime);
}
function setHardCap(uint _hardCapTokens) public onlyOwner notFinalized {
require(_hardCapTokens * TOKEN_DECIMAL_MULTIPLIER > cap);
cap = _hardCapTokens * TOKEN_DECIMAL_MULTIPLIER;
}
function setNewRate(uint _NewRate) public onlyOwner notFinalized {
rate = _NewRate;
}
}在这里,我试图添加一些函数,这些函数可以用来修改startdate、enddate、cap和rate,但这给我带来了严重的错误。如果删除这四个函数,代码就可以了,但是我需要这四个函数(setEndTime、setStartTime、setHardCap、setNewRate)。拜托,我该怎么办?
发布于 2021-06-05 00:54:31
为了使用onlyOwner修饰符,合同应继承Ownable。
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v2.5.0/contracts/ownership/Ownable.sol";
contract CresstCrowdsale is ..., Ownable {
function setEndTime(uint _endTime) public onlyOwner notFinalized {
require(_endTime > openingTime);
closingTime = uint32(_endTime);
}
}https://ethereum.stackexchange.com/questions/100284
复制相似问题