以太坊DAO的概念是什么

资讯 2024-07-11 阅读:48 评论:0
发布时间:2022-01-15 14:36:51 来源:亿速云...
美化布局示例

欧易(OKX)最新版本

【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   全球官网 大陆官网

币安(Binance)最新版本

币安交易所app【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   官网地址

火币HTX最新版本

火币老牌交易所【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   官网地址
发布时间:2022-01-15 14:36:51 来源:亿速云 阅读:239 作者:iii 栏目:互联网科技

这篇文章主要讲解了“以太坊DAO的概念是什么”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“以太坊DAO的概念是什么”吧!

Decentralized Autonomous Organization,简称DAO,以太坊中重要的概念。一般翻译为去中心化的自治组织。

The general translation is a decentralised self-governing organization.

“在区块链上,没有人知道你是一台冰箱”——理查德布朗

"On the block chain, no one knows you're a refrigerator." Richard Brown.

到目前为止,我们列出的所有合约都是由人类持有的其他账户拥有和执行的。但是在以太坊生态系统中不存在对机器人或人类的歧视,合约可以像任何其他帐户一样创造任意行为。合约可以拥有代币,参与众筹,甚至是其他合约的投票成员。

So far, all the contracts we have listed are owned and executed by other accounts held by humans. But there is no discrimination against robots or humans in the Etherno ecosystem, and contracts can create arbitrary behaviors like any other account. Contracts can have tokens, participation in public fund-raising, and even voting members of other contracts.

在本节中,我们将建立一个去中心化的民主组织机构,仅存在于区块链上,但这可以做任何简单账户所能做到的事情。该组织有一个中央经理,负责决定谁是成员和投票规则,但正如我们所看到的,这也可以改变。

In this section, we will establish a decentralised democratic organization that exists only on the block chain, but that can do anything that a simple account can do. The organization has a central manager who decides who is a member and who to vote for, but as we can see, it can also change.

这种特殊民主的运作方式是它拥有一个像管理员,首席执行官或总统一样工作的所有者Owner。所有者可以向组织添加(或删除)投票成员。任何成员都可以提出一个提议,该提议以以太坊交易的形式发送以太或执行某些合约,其他成员可以投票支持或反对该提案。一旦预定的时间量和一定数量的成员投票,就可以执行提案:合约计票,如果有足够的票数,它将执行给定的交易。

This particular democracy operates in such a way that it has a manager, CEO, or president-like owner Owner. The owner may add (or delete) members to the organization to vote. Any member may make a proposal that is sent in the form of a Tai Jin deal to execute certain contracts, and other members may vote in favour of or against the proposal. Once a predetermined number of time and a certain number of members vote, the proposal can be implemented: the contract is counted and, if there are enough votes, it will execute the given deal.

区块链大会

文末附全部代码。

Attachs all the codes at the end of the text.

pragma solidity >=0.4.22 <0.6.0;

contract owned {
    address public owner;

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

    modifier onlyOwner {
        require(msg.sender == owner);
        _;
    }

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

contract tokenRecipient {
    event receivedEther(address sender, uint amount);
    event receivedTokens(address _from, uint256 _value, address _token, bytes _extraData);

    function receiveApproval(address _from, uint256 _value, address _token, bytes memory _extraData) public {
        Token t = Token(_token);
        require(t.transferFrom(_from, address(this), _value));
        emit receivedTokens(_from, _value, _token, _extraData);
    }

    function () payable external {
        emit receivedEther(msg.sender, msg.value);
    }
}

interface Token {
    function transferFrom(address _from, address _to, uint256 _value) external returns (bool success);
}

contract Congress is owned, tokenRecipient {
    // Contract Variables and events
    uint public minimumQuorum;
    uint public debatingPeriodInMinutes;
    int public majorityMargin;
    Proposal[] public proposals;
    uint public numProposals;
    mapping (address => uint) public memberId;
    Member[] public members;

    event ProposalAdded(uint proposalID, address recipient, uint amount, string description);
    event Voted(uint proposalID, bool position, address voter, string justification);
    event ProposalTallied(uint proposalID, int result, uint quorum, bool active);
    event MembershipChanged(address member, bool isMember);
    event ChangeOfRules(uint newMinimumQuorum, uint newDebatingPeriodInMinutes, int newMajorityMargin);

    struct Proposal {
        address recipient;
        uint amount;
        string description;
        uint minExecutionDate;
        bool executed;
        bool proposalPassed;
        uint numberOfVotes;
        int currentResult;
        bytes32 proposalHash;
        Vote[] votes;
        mapping (address => bool) voted;
    }
.....
如何部署

打开钱包(如果你只是测试,请转到菜单开发>网络>testnet),转到合约选项卡,然后点击部署合约 ,在上粘贴上面的代码。在合约选择器上,选择 ,你将看到设置变量。

Open the wallet (if you are just testing, go to the menu development > network > testnet), go to the contract tab and click on the deployment contract to paste the code above. On the contract selection, select, you will see the settings variable.

  • 提案的最低法定人数是提案在执行之前需要的最低票数。

    The minimum quorum for proposals is the minimum number of votes required before the proposals are implemented.

  • 争论的时间是在执行之前需要经过的最短时间(以分钟为单位)。

    The argument is the shortest time (in minutes) required before implementation.

  • 多数票的保证金如果超过50%的票数加上保证金,则提案通过。在简单多数时保留为0,将其设为成员数-1要求绝对共识。

    The proposal is adopted if the bond of the majority exceeds 50% of the votes plus the bond.

以太坊DAO的概念是什么

 what's the concept of the Etherpant DAO

你可以稍后更改这些参数。首先,你可以选择5分钟进行辩论,并将剩余参数保留为0。在页面上稍微低一点,你将看到在以太网中部署合约的成本估算值。如果要保存,可以尝试降低价格,但这可能意味着必须等待更长时间才能创建合约。 单击部署 ,键入密码并等待。

You can change these parameters later. First, you can choose five minutes to debate and keep the remaining parameters to zero. A little lower on the page, you will see the cost estimate of deploying the contract in the Ethernet. If you want to save it, you can try to lower the price, but this may mean that it will take longer to create the contract. Click on deployment, type the password and wait.

几秒钟后,你将被带到仪表板dashboard,向下滚动,你将能够看到正在创建的交易。在不到一分钟的时间内,你将看到交易成功,并且将创建一个新的唯一图标。单击合约的名称以查看它(你可以随时在合约选项卡上找到它)。

In a few seconds, you will be taken to the dashboard dashboard, rolling down, and you will be able to see the transaction being created. In less than a minute, you will see the transaction succeed, and a new unique icon will be created. Click the name of the contract to see it (you can always find it on the contract tab).

以太坊DAO的概念是什么

 what's the concept of the Etherpant DAO

与他人分享

如果你想与他人共享你的DAO,那么他们需要合约地址和接口文件,这是一个小文本字符串,作为合约的使用说明书。单击复制地址以获取前者并 显示界面以显示后者。

If you want to share your DAO with others, they need a contractual address and interface file, which is a small text string that is used as a description of the contract. Click the copy address to get the former and show the interface to show the latter.

在另一台计算机上,进入合约选项卡,然后单击监视合约 。添加正确的地址和界面,然后单击。

On another computer, enter the contract tab and then click the watch contract. Add the correct address and interface, and then click.

以太坊DAO的概念是什么

 what's the concept of the Etherpant DAO

与合约互动

在从合约中读取中,你可以看到合约中可以免费执行的所有功能,因为它们只是从区块链中读取信息。例如,你可以在此处查看合约的当前所有者(应该是上载合约的帐户)。

In reading from a contract, you can see all the functions that can be performed free of charge in the contract, because they are simply reading information from the block chain. For example, you can see here the current owner of the contract (which should be the account on which the contract is uploaded).

在写入合约中,你有一个列表,其中列出了将尝试进行某些计算以将数据保存到区块链的所有函数,因此将花费以太。选择,它将显示该功能的所有选项。

In writing a contract, you have a list of all the functions that will try to make certain calculations to save the data to the block chain, so it will cost you too. Select, it will show all options for the function.

在与合约交互之前,你需要添加新成员才能投票。 在选择器上,选择。添加你要成为会员的人的地址(要删除会员,请选择功能)。 在时,请确保你拥有与所有者相同的帐户,因为这只是主要管理员可以执行的操作。点击执行并等待几秒钟,以便下一个块进行更改。

Before you interact with the contract, you need to add new members to vote. On the selector, choose. Add the address of the person you want to be a member (to delete the member, select the function). In this case, make sure that you have the same account as the owner, because this is only an exercise that the main administrator can perform. Click and wait for a few seconds to change the next block.

没有成员列表,但你可以通过将其地址放在列的功能上来检查是否有人是成员。

There is no list of members, but you can check whether a member is a member by putting his address on the list.

此外,如果你想让合约有自己的钱,你需要存入一些以太(或其他代币),否则你将拥有一个非常无聊的组织。按右上角的。

In addition, if you want the contract to have its own money, you need to put it in a few toos (or other tokens), otherwise you'll have a very boring organization. Press the upper right corner.

添加一个简单的提案:发送以太

现在让我们将第一个提案添加到合约中。在函数选择器上,选择。

Now let's add the first proposal to the contract. On the function selector, choose.

对于“受益人”,添加你要发送以太的人的地址,并在标有“Wei Amount”的框中输入你要发送的数量。Wei是以太的最小单位,等于10^-18以太,并且必须始终作为整数给出。例如,如果要发送1以太,请输入1000000000000000000(即18个零)。最后,添加一些描述你要执行此操作的原因的文本。暂时将“Transaction bytecode”留空。单击执行并键入密码。几秒钟后,numProposals将增加到1,第一个提案编号0将出现在左列上。当你添加更多提案时,只需将提案编号放在字段中即可看到其中的任何提案,你可以阅读所有提案。

For the “beneficiary”, add the address of the person you want to send to the Queen, and enter the number you want to send in the box marked “Wei Amount”. Wei is the smallest unit of the Queen, equal to 10-18 plus, and must always be given as an integer. For example, if +1 is sent, please enter 1,000,000,000,000 (i.e. 18 zeroes). Finally, add some text describing the reasons why you want to do this. Leave the word “Transation bytecode” blank for the time being. Click on the execution and type the password. After a few seconds, NumProposals will increase to 1 and the first proposal number 0 will appear in the left column. When you add more proposals, just place the number of the proposal in the field and you can read all the proposals.

投票提案也很简单。在函数选择器上选择。在第一个框中键入提议编号,如果你同意,请选中框(或将其留空以对其进行投票)。点击发送你的投票。

The voting proposal is also simple. Select on the function selector. Type the proposal number in the first box, and if you agree, tick the box (or leave it empty to vote on it). Click to send your vote.

以太坊DAO的概念是什么

 what's the concept of the Etherpant DAO

投票时间过后,你可以选择。如果提案只是发送以太,那么你也可以将字段留空。在点击之后但在输入密码之前,请注意出现的屏幕。

After voting time, you can choose. If the proposal is sent only to the T-shirt, you can leave the field empty. After clicking, but before entering the password, please note that the screen appears.

如果即估计费用消耗字段上有警告,则表示由于某种原因,被调用的函数将不会执行并将突然终止。这可能意味着许多事情,但在本合约的上下文中,只要你在截止日期过后尝试执行合约,或者用户尝试发送的字节码数据与原始提案不同,就会显示此警告。出于安全原因,如果发生任何这些事情,合约执行将突然终止,并且尝试非法交易的用户将失去他发送的用于支付交易费用的所有以太费用。

If there is a warning in the estimated cost-consumption field, it means that, for some reason, the requested function will not be executed and will be abruptly terminated. This may mean many things, but in the context of this contract, this warning will be shown as long as you try to execute the contract after the deadline or if the user tries to send the byte-code data different from the original proposal. For security reasons, if anything happens, the contract execution will be abruptly terminated, and the user who tries to deal illegally will lose all the costs he sends to cover the transaction costs.

如果交易被执行,那么几秒钟之后你应该能够看到结果:执行将变为真,并且应该从该合约的余额和收件人地址中减去正确的以太量。

If the transaction is executed, then a few seconds later you should be able to see the result: the execution will become true and the correct amount should be deducted from the balance of the contract and the addressee's address.

添加复杂提案:拥有另一个代币

你可以使用此民主方式来执行以太坊上的任何交易,只要你能够找出该交易生成的字节码即可。幸运的是,你可以使用钱包做到这一点!

You can use this democratic way to carry out any transaction in the Tai Chamber, as long as you can find the byte code generated by the transaction. Fortunately, you can do it with a wallet!

在这个例子中,我们将使用一个代币来表明这个合约可以容纳多于以太,并且可以在任何其他基于以太坊的资产中进行交易。首先,创建一个属于你的普通帐户的代币 。在合约页面上,单击转移以太网和代币以将其中一些转移到新的合约中(为简单起见,不要将超过一半的硬币发送到你的DAO)。之后,我们将模拟你要执行的操作。因此,如果你想建议DAO向个人发送500毫克黄金代币作为付款,请按照你从你拥有的帐户执行该交易的步骤,然后点击但是当确认屏幕时弹出,不要输入密码 。

In this case, we will use a token to show that the contract can accommodate more than the Ether and can be traded in any other asset based on Ether. First, create a token belonging to your ordinary account. On the contract page, click the transfer to the Tainet and the token to transfer some of them to the new contract (for the sake of simplicity, do not send more than half of the coin to your DAO). After that, we will simulate the operation you are about to perform. So, if you want to suggest that DAO send 500 milligrams of gold in exchange to a person for payment, please follow the steps you take to execute the transaction from an account you own, and then click, but when the screen is confirmed, do not enter the password.

以太坊DAO的概念是什么

 what's the concept of the Etherpant DAO

而是单击显示原始数据链接并复制字段上显示的代码并将其保存到文本文件或记事本中。取消交易。你还需要你将要为该操作调用的合约的地址,在这种情况下是代币合约。你可以在选项卡上找到它:将其保存在某处。

Instead, you click to show the original data link and copy the code displayed in the field and save it in the text file or book. Cancel the transaction. You also need the address of the contract that you will call for the operation, in which case it is a token contract. You can find it on the tab: save it somewhere.

现在回到合约并使用以下参数创建新提案:

Now go back to the contract and use the following parameters to create new proposals:

  • 作为受益人,请填写你的代币地址(如果它是相同的图标请注意)。

    As beneficiaries, please fill out your currency address (if it is the same icon).

  • 将以太币量留空。

    The amount will be left empty in the talisman.

  • 在工作描述上,只需写下你想要完成内容的描述。

    In the job description, just write the description of what you want to complete.

  • 在上 ,粘贴你在上一步中从数据字段中保存的字节码。

    Up, paste the byte number you saved from the data field in the previous step.

以太坊DAO的概念是什么

 what's the concept of the Etherpant DAO

几秒钟后,你应该能够看到提案的详细信息。你会注意到交易字节码不会在那里显示,而是只有一个交易哈希。与其他字段不同,字节码可能非常冗长,因此存储在区块链上非常昂贵,因此稍后执行调用的人将提供字节码,而不是对其进行存档。

In a few seconds, you should be able to see the details of the proposal. You'll notice that the byte code will not be displayed there, but that there is only one deal, Hashi. Unlike other fields, the byte number may be very long, so it is very expensive to store on the block chain, so the person who performs the call later will provide the byte number instead of archiving it.

但是,这当然会造成一个安全漏洞:如果没有实际代码,投票如何投票?什么阻止用户在提案投票后执行不同的代码?这就是交易哈希的用武之地。在从合约中读取功能列表中滚动一下,你会看到一个提议检查功能,任何人都可以放置所有的功能参数并检查它们是否与被投票的匹配。这也保证了除非字节码的hash与提供的代码上的hash完全匹配,否则不会执行提议。

But, of course, this creates a security gap: if there is no actual code, how to vote? What prevents users from implementing different codes after a vote on a proposal? This is the place to trade in Hashi. Scrolling through a list of functions in a contract, you see a proposed check that anyone can place all the functional parameters and check if they match the cast.

以太坊DAO的概念是什么

 what's the concept of the Etherpant DAO

任何人都可以通过遵循相同的步骤来获取正确的字节码,然后将提议编号和其他参数添加到从合约中读取底部的名为 检查提案代码的功能,从而可以非常轻松地检查提案。

Anyone can access the correct byte code by following the same step and then add the proposal number and other parameters to the function of checking the proposal code by reading it from the bottom of the contract so that the proposal can be examined very easily.

其余的投票过程保持不变:所有成员都可以投票,在截止日期之后,有人可以执行该投标。唯一的区别是,这次你必须提供之前提交的相同字节码。注意确认窗口上的任何警告:如果它说它不会执行你的代码,请检查截止日期是否已经过去,是否有足够的投票以及你的交易字节码是否已检出。

The remaining voting process remains the same: all members can vote, and after the deadline someone can execute the bid. The only difference is that this time you must provide the same byte numbers that were submitted earlier. Note any warning on the confirmation window: if it says it will not execute your code, check whether the deadline is over, whether there are enough votes and if your transaction bytes have been detected.

让它更好

以下是当前DAO的一些缺点,我们将其作为练习留给读者:

The following are some of the shortcomings of the current DAO, which we leave to the reader as an exercise:

  • 你可以将会员列表公开并编入索引吗?

    Can you make the membership list public and index it?

  • 你能否允许成员改变他们的选票(在投票后但在投票结果出来之前)?

    Could you allow members to change their votes (after the ballot but before the result of the ballot)?

  • 目前投票信息仅在日志上可见,你是否可以创建一个显示所有投票的功能?

    Currently, voting information is only available on the log. Can you create a function to show all votes?

======================================================================

分享一些以太坊、EOS、比特币等区块链相关的交互式在线编程实战教程:

To share some of the interactive online programming lessons associated with the Etheria, EOS, Bitcoin and other block chains:

  • java以太坊开发教程,主要是针对java和android程序员进行区块链以太坊开发的web3j详解。

    The Java E-Team development curriculum, which is aimed primarily at the Java and Android programmers, provides a detailed explanation of the web3j development of the block chain by Ee-Team.

  • python以太坊,主要是针对python工程师使用web3.py进行区块链以太坊开发的详解。

    Python Etheria, mainly for engineers in python, used web3.py to elaborate on the development of block chains.

  • php以太坊,主要是介绍使用php进行智能合约开发交互,进行账号创建、交易、转账、代币开发以及过滤器和交易等内容。

    php uses php as an interactive introduction to smart contract development using php for account creation, transactions, transfers, currency development, filters and transactions.

  • 以太坊入门教程,主要介绍智能合约与dapp应用开发,适合入门。

    The Etheraya introductory course, which focuses on the development of intellectual contracts and dapp applications, is suitable for entry.

  • 以太坊开发进阶教程,主要是介绍使用node.js、mongodb、区块链、ipfs实现去中心化电商DApp实战,适合进阶。

    Etheria has developed an advanced curriculum, which mainly introduces the use of node.js, mongodb, block chains, and ipfs to decentralize the power provider Dapp, which is suitable for progress.

  • C#以太坊,主要讲解如何使用C#开发基于.Net的以太坊应用,包括账户管理、状态与交易、智能合约开发与交互、过滤器和交易等。

    C#Etheria, which focuses on the use of C# to develop.Net-based Ether applications, includes account management, status and transactions, smart contract development and interaction, filters and transactions.

  • EOS教程,本课程帮助你快速入门EOS区块链去中心化应用的开发,内容涵盖EOS工具链、账户与钱包、发行代币、智能合约开发与部署、使用代码与智能合约交互等核心知识点,最后综合运用各知识点完成一个便签DApp的开发。

    The EOS course, which supports the development of the fast-track EOS block chain decentralised applications, covers core knowledge points such as the EOS tool chain, accounts and wallets, currency issuance, smart contract development and deployment, and the use of codes to interact with smart contracts, and finally completes the development of a signed DApp using a combination of knowledge points.

  • java比特币开发教程,本课程面向初学者,内容即涵盖比特币的核心概念,例如区块链存储、去中心化共识机制、密钥与脚本、交易与UTXO等,同时也详细讲解如何在Java代码中集成比特币支持功能,例如创建地址、管理钱包、构造裸交易等,是Java工程师不可多得的比特币开发学习课程。

    The Javabitcoin development curriculum, which is intended for starters, covers the core concepts of Bitcoin, such as block chain storage, decentralised consensus mechanisms, keys and scripts, trades and UTXO, and details how to integrate bitcoin support functions in Java codes, such as the creation of addresses, the management of wallets, the construction of nudity trading, etc., is a bitcoin development learning course not available to Java engineers.

  • php比特币开发教程,本课程面向初学者,内容即涵盖比特币的核心概念,例如区块链存储、去中心化共识机制、密钥与脚本、交易与UTXO等,同时也详细讲解如何在Php代码中集成比特币支持功能,例如创建地址、管理钱包、构造裸交易等,是Php工程师不可多得的比特币开发学习课程。

    The phpbitcoin development curriculum, which is intended for starters, covers the core concepts of Bitcoin, such as block chain storage, decentralised consensus mechanisms, keys and scripts, trades and UTXO, and details how to integrate bitcoin support functions in the Php code, such as the creation of addresses, the management of wallets, the construction of nud trading, etc., is a learning course in bitcoin development that Php engineer cannot gain more.

  • tendermint区块链开发详解,本课程适合希望使用tendermint进行区块链开发的工程师,课程内容即包括tendermint应用开发模型中的核心概念,例如ABCI接口、默克尔树、多版本状态库等,也包括代币发行等丰富的实操代码,是go语言工程师快速入门区块链开发的最佳选择。

    This course, suitable for engineers who wish to use it for block chain development, includes core concepts in the application development model, such as ABCI interfaces, Merkel trees, multi-version status libraries, etc., as well as a rich practical code, such as the issuance of tokens, and is the best option for quick entry block chain development for Go Language Engineers.

汇智网原创翻译,转载请标明出处。这里是原文以太坊DAO之区块链大会

The original translator for Hints Network. Please identify where you want it from. This is the original section of the Taifu DAO.

附代码:

Attached code:

pragma solidity >=0.4.22 <0.6.0;

contract owned {
    address public owner;

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

    modifier onlyOwner {
        require(msg.sender == owner);
        _;
    }

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

contract tokenRecipient {
    event receivedEther(address sender, uint amount);
    event receivedTokens(address _from, uint256 _value, address _token, bytes _extraData);

    function receiveApproval(address _from, uint256 _value, address _token, bytes memory _extraData) public {
        Token t = Token(_token);
        require(t.transferFrom(_from, address(this), _value));
        emit receivedTokens(_from, _value, _token, _extraData);
    }

    function () payable external {
        emit receivedEther(msg.sender, msg.value);
    }
}

interface Token {
    function transferFrom(address _from, address _to, uint256 _value) external returns (bool success);
}

contract Congress is owned, tokenRecipient {
    // Contract Variables and events
    uint public minimumQuorum;
    uint public debatingPeriodInMinutes;
    int public majorityMargin;
    Proposal[] public proposals;
    uint public numProposals;
    mapping (address => uint) public memberId;
    Member[] public members;

    event ProposalAdded(uint proposalID, address recipient, uint amount, string description);
    event Voted(uint proposalID, bool position, address voter, string justification);
    event ProposalTallied(uint proposalID, int result, uint quorum, bool active);
    event MembershipChanged(address member, bool isMember);
    event ChangeOfRules(uint newMinimumQuorum, uint newDebatingPeriodInMinutes, int newMajorityMargin);

    struct Proposal {
        address recipient;
        uint amount;
        string description;
        uint minExecutionDate;
        bool executed;
        bool proposalPassed;
        uint numberOfVotes;
        int currentResult;
        bytes32 proposalHash;
        Vote[] votes;
        mapping (address => bool) voted;
    }

    struct Member {
        address member;
        string name;
        uint memberSince;
    }

    struct Vote {
        bool inSupport;
        address voter;
        string justification;
    }

    // Modifier that allows only shareholders to vote and create new proposals
    modifier onlyMembers {
        require(memberId[msg.sender] != 0);
        _;
    }

    
    constructor (
        uint minimumQuorumForProposals,
        uint minutesForDebate,
        int marginOfVotesForMajority
    )  payable public {
        changeVotingRules(minimumQuorumForProposals, minutesForDebate, marginOfVotesForMajority);
        // It’s necessary to add an empty first member
        addMember(address(0), "");
        // and let's add the founder, to save a step later
        addMember(owner, 'founder');
    }

    
    function addMember(address targetMember, string memory memberName) onlyOwner public {
        uint id = memberId[targetMember];
        if (id == 0) {
            memberId[targetMember] = members.length;
            id = members.length++;
        }

        members[id] = Member({member: targetMember, memberSince: now, name: memberName});
        emit MembershipChanged(targetMember, true);
    }

    
    function removeMember(address targetMember) onlyOwner public {
        require(memberId[targetMember] != 0);

        for (uint i = memberId[targetMember]; i<members.length-1; i++){
            members[i] = members[i+1];
            memberId[members[i].member] = i;
        }
        memberId[targetMember] = 0;
        delete members[members.length-1];
        members.length--;
    }

    
    function changeVotingRules(
        uint minimumQuorumForProposals,
        uint minutesForDebate,
        int marginOfVotesForMajority
    ) onlyOwner public {
        minimumQuorum = minimumQuorumForProposals;
        debatingPeriodInMinutes = minutesForDebate;
        majorityMargin = marginOfVotesForMajority;

        emit ChangeOfRules(minimumQuorum, debatingPeriodInMinutes, majorityMargin);
    }

    
    function newProposal(
        address beneficiary,
        uint weiAmount,
        string memory jobDescription,
        bytes memory transactionBytecode
    )
        onlyMembers public
        returns (uint proposalID)
    {
        proposalID = proposals.length++;
        Proposal storage p = proposals[proposalID];
        p.recipient = beneficiary;
        p.amount = weiAmount;
        p.description = jobDescription;
        p.proposalHash = keccak256(abi.encodePacked(beneficiary, weiAmount, transactionBytecode));
        p.minExecutionDate = now + debatingPeriodInMinutes * 1 minutes;
        p.executed = false;
        p.proposalPassed = false;
        p.numberOfVotes = 0;
        emit ProposalAdded(proposalID, beneficiary, weiAmount, jobDescription);
        numProposals = proposalID+1;

        return proposalID;
    }

    
    function newProposalInEther(
        address beneficiary,
        uint etherAmount,
        string memory jobDescription,
        bytes memory transactionBytecode
    )
        onlyMembers public
        returns (uint proposalID)
    {
        return newProposal(beneficiary, etherAmount * 1 ether, jobDescription, transactionBytecode);
    }

    
    function checkProposalCode(
        uint proposalNumber,
        address beneficiary,
        uint weiAmount,
        bytes memory transactionBytecode
    )
        view public
        returns (bool codeChecksOut)
    {
        Proposal storage p = proposals[proposalNumber];
        return p.proposalHash == keccak256(abi.encodePacked(beneficiary, weiAmount, transactionBytecode));
    }

    
    function vote(
        uint proposalNumber,
        bool supportsProposal,
        string memory justificationText
    )
        onlyMembers public
        returns (uint voteID)
    {
        Proposal storage p = proposals[proposalNumber]; // Get the proposal
        require(!p.voted[msg.sender]);                  // If has already voted, cancel
        p.voted[msg.sender] = true;                     // Set this voter as having voted
        p.numberOfVotes++;                              // Increase the number of votes
        if (supportsProposal) {                         // If they support the proposal
            p.currentResult++;                          // Increase score
        } else {                                        // If they don't
            p.currentResult--;                          // Decrease the score
        }

        // Create a log of this event
        emit Voted(proposalNumber,  supportsProposal, msg.sender, justificationText);
        return p.numberOfVotes;
    }

    
    function executeProposal(uint proposalNumber, bytes memory transactionBytecode) public {
        Proposal storage p = proposals[proposalNumber];

        require(now > p.minExecutionDate                                            // If it is past the voting deadline
            && !p.executed                                                         // and it has not already been executed
            && p.proposalHash == keccak256(abi.encodePacked(p.recipient, p.amount, transactionBytecode))  // and the supplied code matches the proposal
            && p.numberOfVotes >= minimumQuorum);                                  // and a minimum quorum has been reached...

        // ...then execute result

        if (p.currentResult > majorityMargin) {
            // Proposal passed; execute the transaction

            p.executed = true; // Avoid recursive calling
            
            (bool success, ) = p.recipient.call.value(p.amount)(transactionBytecode);
            require(success);

            p.proposalPassed = true;
        } else {
            // Proposal failed
            p.proposalPassed = false;
        }

        // Fire Events
        emit ProposalTallied(proposalNumber, p.currentResult, p.numberOfVotes, p.proposalPassed);
    }
}

感谢各位的阅读,以上就是“以太坊DAO的概念是什么”的内容了,经过本文的学习后,相信大家对以太坊DAO的概念是什么这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!

美化布局示例

欧易(OKX)最新版本

【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   全球官网 大陆官网

币安(Binance)最新版本

币安交易所app【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   官网地址

火币HTX最新版本

火币老牌交易所【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   官网地址
文字格式和图片示例

注册有任何问题请添加 微信:MVIP619 拉你进入群

弹窗与图片大小一致 文章转载注明

分享:

扫一扫在手机阅读、分享本文

发表评论
平台列表
美化布局示例

欧易(OKX)

  全球官网 大陆官网

币安(Binance)

  官网

火币(HTX)

  官网

Gate.io

  官网

Bitget

  官网

deepcoin

  官网
热门文章
  • 区块链社区有哪些?区块链社区是什么?

    区块链社区有哪些?区块链社区是什么?
    展开全文...
  • 0.00006694个比特币等于多少人民币/美金

    0.00006694个比特币等于多少人民币/美金
    0.00006694比特币等于多少人民币?根据比特币对人民币的最新汇率,0.00006694比特币等于4.53424784美元/32.5436 16人民币。比特币(BTC)美元(USDT)人民币(CNY)0.000066944.53424784【比特币密码】32.82795436 16比特币对人民币的最新汇率为:490408.64 CNY(1比特币=490408.64人民币)(1美元=7.24人民币)(0.00006694USDT=0.0004846456 CNY)汇率更新时...
  • 0.00015693个比特币等于多少人民币/美金

    0.00015693个比特币等于多少人民币/美金
    0.000 15693比特币等于多少人民币?根据比特币对人民币的最新汇率,0.000 15693比特币等于10.6 1678529美元/76.86554996人民币。比特币(BTC)【比特币价格翻倍】美元(USDT)人民币(CNY)0.000/克洛克-0/5693【数字货币矿机】10.6 167852976.8655254996比特币对人民币的最新汇率为:489,807.72 CNY(1比特币= 489,807.72人民币)(1美元=7.24人民币)(0.00015693 U...
  • 0.00003374个比特币等于多少人民币/美金

    0.00003374个比特币等于多少人民币/美金
    0.00003374比特币等于多少人民币?根据比特币对人民币的最新汇率,0.00003374比特币等于2.2826 1222美元/16.5261124728人民币。比特币(BTC)美元(USDT)人民币(CNY)0.00003374克洛克-0/22216.5261124728比特币对人民币的最新汇率为:489807.72 CNY(1比特币=489807.72人民币)(1美元=7.24人民币)(0.00003374USDT=0.0002442776 CNY)。汇率更新于2024...
  • 2018-5-31币圈简报

    2018-5-31币圈简报
    一、要闻资讯类I. KEY INFORMATION CATEGORY1、央视:数字货币在京揭牌成立!中国或为此突变!1. View: Digital currency is established in Kyoto! China or mutated for it!中国数字货币来了˂a href="https://mp.weixin.qq.com/s/69fxKCf8GKSCscS4lT8WCA" Target="_blank"rel="noformlow"" Chinese...
标签列表