我正在使用openzeppelin作为CappedCrowdsale和TimedCrowdsale创建一个ICO,如下面的链接中提到的示例所示。
参考资料:https://github.com/buddies2705/Solidity-Tutorial/blob/master/contracts/ExampleTokenCrowdsale.sol
FinalizableCrowdsale中的Fin终()方法是合同中可访问的方法,如MEW所示。到目前为止,该方法仅通过检查合同的结束时间来检查合同是否已结束。我想改变这个方法,以完成它,即使达到上限(或)时间已经结束。
请协助

contract SampleCrowdsale is CappedCrowdsale, RefundableCrowdsale, MintedCrowdsale {
constructor(
uint256 openingTime,
uint256 closingTime,
uint256 rate,
address wallet,
uint256 cap,
ERC20Mintable token,
uint256 goal
)
public
Crowdsale(rate, wallet, token)
CappedCrowdsale(cap)
TimedCrowdsale(openingTime, closingTime)
RefundableCrowdsale(goal)
{
//As goal needs to be met for a successful crowdsale
//the value needs to less or equal than a cap which is limit for accepted funds
require(goal <= cap,"Goal <= Cap is an requirement");
}
}下面的合同来自开放的齐柏林飞艇图书馆,我不想修改。
contract RefundableCrowdsale is FinalizableCrowdsale {
using SafeMath for uint256;
// minimum amount of funds to be raised in weis
uint256 private _goal;
// refund escrow used to hold funds while crowdsale is running
RefundEscrow private _escrow;
/**
* @dev Constructor, creates RefundEscrow.
* @param goal Funding goal
*/
constructor(uint256 goal) internal {
require(goal > 0);
_escrow = new RefundEscrow(wallet());
_goal = goal;
}
/**
* @return minimum amount of funds to be raised in wei.
*/
function goal() public view returns(uint256) {
return _goal;
}
/**
* @dev Investors can claim refunds here if crowdsale is unsuccessful
* @param beneficiary Whose refund will be claimed.
*/
function claimRefund(address beneficiary) public {
require(finalized());
require(!goalReached());
_escrow.withdraw(beneficiary);
}
/**
* @dev Checks whether funding goal was reached.
* @return Whether funding goal was reached
*/
function goalReached() public view returns (bool) {
return weiRaised() >= _goal;
}
/**
* @dev escrow finalization task, called when finalize() is called
*/
function _finalization() internal {
if (goalReached()) {
_escrow.close();
_escrow.beneficiaryWithdraw();
} else {
_escrow.enableRefunds();
}
super._finalization();
}
/**
* @dev Overrides Crowdsale fund forwarding, sending funds to escrow.
*/
function _forwardFunds() internal {
_escrow.deposit.value(msg.value)(msg.sender);
}
}contract FinalizableCrowdsale is TimedCrowdsale {
using SafeMath for uint256;
bool private _finalized;
event CrowdsaleFinalized();
constructor() internal {
_finalized = false;
}
/**
* @return true if the crowdsale is finalized, false otherwise.
*/
function finalized() public view returns (bool) {
return _finalized;
}
/**
* @dev Must be called after crowdsale ends, to do some extra finalization
* work. Calls the contract's finalization function.
*/
function finalize() public {
require(!_finalized);
require(hasClosed());
_finalized = true;
_finalization();
emit CrowdsaleFinalized();
}
/**
* @dev Can be overridden to add finalization logic. The overriding function
* should call super._finalization() to ensure the chain of finalization is
* executed entirely.
*/
function _finalization() internal {
}
}发布于 2018-10-27 14:39:11
为了覆盖父方法,需要在具有相同签名的子契约中定义方法。
函数可以被具有相同名称和相同数目/类型的输入的另一个函数重写。如果重写函数具有不同类型的输出参数,则会导致错误。本地函数调用和基于消息的函数调用都会考虑这些重写。
https://solidity.readthedocs.io/en/v0.4.21/contracts.html#inheritance
在您的例子中,finalize()看起来很好。
_finalized是私有的,编写它是不可能的,但是可以像这样覆盖finalize():
function finalize() public {
require(capReached());
super.finalize(); // call parent's finalize function
}https://ethereum.stackexchange.com/questions/61272
复制相似问题