首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Ownable()声明错误

Ownable()声明错误
EN

Ethereum用户
提问于 2018-11-16 00:23:24
回答 2查看 437关注 0票数 0

我发现在编写这份合同时遇到了问题。

代码语言:javascript
复制
import "https://github.com/OpenZeppelin/openzeppelin- 
solidity/contracts/token/ERC20/ERC20Pausable.sol";

pragma solidity ^0.4.17;

contract MetaToken is Pausable{

string public name = 'MetaMetaMeta! Token';
uint8 public decimals = 8;
string public symbol = 'M3T';
string public version = '0.4.0';

uint256 public blockReward = 1 * (10**uint256(decimals));
uint32 public halvingInterval = 210000;
uint256 public blockNumber = 0; // how many blocks mined
uint256 public totalSupply = 0;
uint256 public target   = 0x0000ffff00000000000000000000000000000000000000000000000000000000; // i.e. difficulty. miner needs to find nonce, so that (hash(nonce+random) < target)
uint256 public powLimit = 0x0000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff;
uint40 public lastMinedOn; // will be used to check how long did it take to mine
uint256 public randomness;

address public newContractAddress;

function MetaToken() Ownable() {
    lastMinedOn = uint40(block.timestamp);
    updateRandomness();
}

/// update randomness, will be used to find next Nonce
function updateRandomness() internal {
    randomness = uint256(sha3(sha3(uint256(block.blockhash(block.number-1)) + uint256(block.coinbase) + uint256(block.timestamp))));
}

/// returns `randomness` used in PoW calculations
function getRamdomness() view returns (uint256 currentRandomness) {
    return randomness;
}

/// pure, accepts randomness & nonce and returns hash as int (which should be compared to target)
function hash(uint256 nonce, uint256 currentRandomness) pure returns (uint256){
    return uint256(sha3(nonce+currentRandomness));
}

/// pure, accepts randomness, nonce & target and returns boolian whether work is good
function checkProofOfWork(uint256 nonce, uint256 currentRandomness, uint256 currentTarget) pure returns (bool workAccepted){
    return uint256(hash(nonce, currentRandomness)) < currentTarget;
}

// accepts Nonce and tells whether it is good to mine
function checkMine(uint256 nonce) view returns (bool success) {
    return checkProofOfWork(nonce, getRamdomness(), target);
}

/*
    accepts nonce aka "mining field", checks if it passess proof of work,
    rewards if it does
*/
function mine(uint256 nonce) whenNotPaused returns (bool success) {
    require(checkMine(nonce));

    Mine(msg.sender, blockReward, uint40(block.timestamp) - uint40(lastMinedOn)); // issuing event to those who listens for it

    balances[msg.sender] += blockReward; // giving reward
    blockNumber += 1;
    totalSupply += blockReward; // increasing total supply
    updateRandomness();

    // difficulty retarget:
    var mul = (block.timestamp - lastMinedOn);
    if (mul > (60*2.5*2)) {
        mul = 60*2.5*2;
    }
    if (mul < (60*2.5/2)) {
        mul = 60*2.5/2;
    }
    target *= mul;
    target /= (60*2.5);

    if (target > powLimit) { // difficulty not lower than that
        target = powLimit;
    }

    lastMinedOn = uint40(block.timestamp); // tracking time to check how much PoW took in the future
    if (blockNumber % halvingInterval == 0) { // time to halve reward?
        blockReward /= 2;
        RewardHalved();
    }

    return true;
}

function setNewContractAddress(address newAddress) onlyOwner {
    newContractAddress = newAddress;
}

event Mine(address indexed _miner, uint256 _reward, uint40 _seconds);
event RewardHalved();

}

错误-

代码语言:javascript
复制
browser/test.sol:31:26: DeclarationError: Undeclared identifier.
    function MetaToken() Ownable() {
                         ^-----^
EN

回答 2

Ethereum用户

发布于 2018-11-16 06:42:35

Ownable()是一个管理所有权的合同。你也需要进口那份合同。你可以找到它,这里

票数 1
EN

Ethereum用户

发布于 2018-11-16 08:45:22

如果Ownable是修饰符,试着去掉圆括号!

在可暂停合同中添加可拥有的修饰符,并移除如下所示的圆括号:

代码语言:javascript
复制
    function MetaToken() Ownable {

编辑的

尝试下面的代码:

代码语言:javascript
复制
pragma solidity ^0.4.17;
import "https://github.com/OpenZeppelin/openzeppelin-solidity/contracts/token/ERC20/ERC20Pausable.sol";

contract owned {
    address public owner;

    constructor () public {
        owner = msg.sender;
    }

    modifier onlyOwner {
        require(msg.sender == owner, "Only owner has the authority");
        _;
    }

    function transferOwnership(address newOwner) public onlyOwner {
        owner = newOwner;
    }
}



contract MetaToken is Pausable, owned{

string public name = 'MetaMetaMeta! Token';
uint8 public decimals = 8;
string public symbol = 'M3T';
string public version = '0.4.0';

uint256 public blockReward = 1 * (10**uint256(decimals));
uint32 public halvingInterval = 210000;
uint256 public blockNumber = 0; // how many blocks mined
uint256 public totalSupply = 0;
uint256 public target   = 0x0000ffff00000000000000000000000000000000000000000000000000000000; // i.e. difficulty. miner needs to find nonce, so that (hash(nonce+random) < target)
uint256 public powLimit = 0x0000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff;
uint40 public lastMinedOn; // will be used to check how long did it take to mine
uint256 public randomness;

address public newContractAddress;

mapping (address => uint256) public balances;

constructor () public {
    lastMinedOn = uint40(block.timestamp);
    updateRandomness();
}

/// update randomness, will be used to find next Nonce
function updateRandomness() internal {
    randomness = uint256(sha3(sha3(uint256(block.blockhash(block.number-1)) + uint256(block.coinbase) + uint256(block.timestamp))));
}

/// returns `randomness` used in PoW calculations
function getRamdomness() view returns (uint256 currentRandomness) {
    return randomness;
}

/// pure, accepts randomness & nonce and returns hash as int (which should be compared to target)
function hash(uint256 nonce, uint256 currentRandomness) pure returns (uint256){
    return uint256(sha3(nonce+currentRandomness));
}

/// pure, accepts randomness, nonce & target and returns boolian whether work is good
function checkProofOfWork(uint256 nonce, uint256 currentRandomness, uint256 currentTarget) pure returns (bool workAccepted){
    return uint256(hash(nonce, currentRandomness)) < currentTarget;
}

// accepts Nonce and tells whether it is good to mine
function checkMine(uint256 nonce) view returns (bool success) {
    return checkProofOfWork(nonce, getRamdomness(), target);
}

/*
    accepts nonce aka "mining field", checks if it passess proof of work,
    rewards if it does
*/
function mine(uint256 nonce) whenNotPaused returns (bool success) {
    require(checkMine(nonce));

    Mine(msg.sender, blockReward, uint40(block.timestamp) - uint40(lastMinedOn)); // issuing event to those who listens for it

    balances[msg.sender] += blockReward; // giving reward
    blockNumber += 1;
    totalSupply += blockReward; // increasing total supply
    updateRandomness();

    // difficulty retarget:
    uint256 mul = (block.timestamp - lastMinedOn);
    if (mul > (60*2.5*2)) {
        mul = 60*2.5*2;
    }
    if (mul < (60*2.5/2)) {
        mul = 60*2.5/2;
    }
    target *= mul;
    target /= (60*2.5);

    if (target > powLimit) { // difficulty not lower than that
        target = powLimit;
    }

    lastMinedOn = uint40(block.timestamp); // tracking time to check how much PoW took in the future
    if (blockNumber % halvingInterval == 0) { // time to halve reward?
        blockReward /= 2;
        RewardHalved();
    }

    return true;
}

function setNewContractAddress(address newAddress) onlyOwner {
    newContractAddress = newAddress;
}

event Mine(address indexed _miner, uint256 _reward, uint40 _seconds);
event RewardHalved();

}
票数 0
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/62443

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档