DVote Solidity – D注固性区块链毕设代写

区块链毕设代写本文提供国外最新区块链项目源码下载,包括solidity,eth,fabric等blockchain区块链,DVote Solidity – D注固性区块链毕设代写 是一篇很好的国外资料

DVote Solidity

This repo provides toolkit to interact with the EntityResolver, the Process and the Namespace smart contracts.

  • Smart Contracts source code in Solidity
  • JSON files with the contract ABI and the Bytecode of each
  • JS/Typescript support to import the JSON ABI and Bytecode

Contracts

Entity Resolver

The entity resolver is a flexible way to reference entities by their ethereum address or by the Entity ID (the hash of the address). It features the standard ENS implementation plus a specialized version of Text records that allows arrays.

It is currently used for its Text records, which store a link to the Entity Metadata on IPFS.

Namespace

Allows to define different voting namespaces (production, development, organization X, Y, Z, …). A namespace contains a chainId, genesis information, validators[] and oracles[].

Every process instance (see below) has to point to one namespace contract.

Process

In vocdoni, everything is a process, the main building block of any decentralized governance activity.

  • Allows to set the details that define the vote
  • Allows to control how the Vochain should handle the process
  • Allows to control what status clients should display
  • Acts as the persistent source of truth
  • Stores the results

Storage Proof

In order to run EVM census based elections, voters submit census Merkle Proofs that are checked against a certain block hash on the Ethereum blockchain. This contract is in charge of storing the ERC tokens available and validating the balance mapping position.

Base contracts

Chainable

It is quite likely that contracts like process will need to be upgraded, while we also expect older data to remain available.

Chainable is a base contract that allows defining predecessor instances and activate future instances succeeding the current one. Legacy data can be navigated to, pretty much as you would do on a MiniMe token contract.

Contracts inheriting from Chainable can either:

  • Have no predecessor and become active as soon as they are deployed
  • Have a predecessor and start inactive by default

When a predecessor activates a successor

  • The predecessor becomes inactive
  • The successor becomes active

Get started

For JavaScript, install NodeJS and NPM on your system.

npm install dvote-solidity 

See the example on /lib/example.js

Usage

To import the ABI and the bytecode:

const { EnsPublicResolver, Process, TokenStorageProof, Namespace } = require("dvote-solidity")  console.log(EnsPublicResolver.abi) console.log(EnsPublicResolver.bytecode)  console.log(Process.abi) console.log(Process.bytecode)  console.log(TokenStorageProof.abi) console.log(TokenStorageProof.bytecode)  console.log(Namespace.abi) console.log(Namespace.bytecode)

If you use Typescript, you may need to add "resolveJsonModule": true in your tsconfig.json file.

Then use a client library to attach to an instance or deploy your own:

JavaScript (ethers.js)

const { EnsPublicResolver, Process, TokenStorageProof, Namespace } = require("dvote-solidity") const ethers = require("ethers") const config = { ... }  const { abi: entityResolverAbi, bytecode: entityResolverByteCode } = EnsPublicResolver const { abi: processAbi, bytecode: processByteCode } = Process const { abi: tokenStorageProofAbi, bytecode: tokenStorageProofByteCode } = TokenStorageProof const { abi: namespaceAbi, bytecode: namespaceByteCode } = Namespace  const provider = new ethers.providers.JsonRpcProvider(config.GATEWAY_URL)  const privateKey = ethers.Wallet.fromMnemonic(config.MNEMONIC).privateKey const address = await ethers.Wallet.fromMnemonic(config.MNEMONIC).getAddress()  const wallet = new ethers.Wallet(privateKey, provider);  // deploying const resolverFactory = new ethers.ContractFactory(entityResolverAbi, entityResolverByteCode, wallet) const processFactory = new ethers.ContractFactory(processAbi, processByteCode, wallet) const tokenStorageProofFactory = new ethers.ContractFactory(tokenStorageProofAbi, tokenStorageProofByteCode, wallet) const namespaceFactory = new ethers.ContractFactory(namespaceAbi, namespaceByteCode, wallet)  const resolverInstance = await resolverFactory.deploy() console.log("Resolver deployed at", resolverInstance.address)  const tokenStorageProofInstance = await tokenStorageProofFactory.deploy() console.log("Token Storage Proof deployed at", tokenStorageProofInstance.address)  const namespaceInstance = await namespaceFactory.deploy() console.log("Namespace deployed at", namespaceInstance.address)  // The process contract needs the address of an already deployed namespace instance const predecessorInstanceAddress = "0x0000000000000000000000000000000000000000" // No predecessor const processInstance = await processFactory.deploy(predecessorInstanceAddress, namespaceInstance.address, tokenStorageProofInstance.address) console.log("Process deployed at", processInstance.address)  // or attaching const resolver = new ethers.Contract(resolverAddress, entityResolverAbi, wallet) const process = new ethers.Contract(processAddress, processAbi, wallet) const tokenStorageProof = new ethers.Contract(tokenStorageProofAddress, tokenStorageProofAbi, wallet) const namespace = new ethers.Contract(namespaceAddress, namespaceAbi, wallet)  const tx1 = await resolver.setText(...) await tx1.wait() const tx2 = await process.newProcess(...) await tx2.wait() const tx3 = await process.addOracle(...) await tx3.wait()

Types and values

A Voting Process is defined by the following fields within the contract:

struct Process {     uint8 mode; // The selected process mode. See: https://vocdoni.io/docs/#/architecture/smart-contracts/process?id=flags     uint8 envelopeType; // One of valid envelope types, see: https://vocdoni.io/docs/#/architecture/smart-contracts/process?id=flags     address entityAddress; // The Ethereum address of the Entity     uint64 startBlock; // Tendermint block number on which the voting process starts     uint32 blockCount; // Amount of Tendermint blocks during which the voting process should be active     string metadata; // Content Hashed URI of the JSON meta data (See Data Origins)     string censusMerkleRoot; // Hex string with the Merkle Root hash of the census     string censusMerkleTree; // Content Hashed URI of the exported Merkle Tree (not including the public keys)     Status status; // One of 0 [ready], 1 [ended], 2 [canceled], 3 [paused], 4 [results]          uint8 questionIndex; // The index of the currently active question (only assembly processes)     // How many questions are available to vote     // questionCount >= 1     uint8 questionCount;          // How many choices can be made for each question.     // 1 <= maxCount <= 100     uint8 maxCount;          // Determines the acceptable value range.     // N => valid votes will range from 0 to N (inclusive)     uint8 maxValue;          uint8 maxVoteOverwrites; // How many times a vote can be replaced (only the last one counts)     // Choices for a question cannot appear twice or more          bool uniqueValues;     // Limits up to how much cost, the values of a vote can add up to (if applicable).     // 0 => No limit / Not applicable          uint16 maxTotalCost;     // Defines the exponent that will be used to compute the "cost" of the options voted and compare it against `maxTotalCost`.     // totalCost = Σ (value[i] ** costExponent) <= maxTotalCost     //     // Exponent range:     // - 0 => 0.0000     // - 10000 => 1.0000     // - 65535 => 6.5535     uint16 costExponent;          // Self-assign to a certain namespace.     // This will determine the oracles that listen and react to it.     // Indirectly, it will also determine the Vochain that hosts this process.          uint16 namespace;          bytes32 paramsSignature; // entity.sign({...}) // fields that the oracle uses to authentify process creation          string results; // string containing the results }

Behaviour is defined by the flags on these variables:

  • mode
    • The process mode (how it behaves)
  • envelopeType
    • How votes look like
  • status
    • Whether the process is open, ended, canceled, paused, results

Process Mode

The process mode affects both the Vochain, the contract itself and even the metadata.

0b00001111       ||||       |||`- autoStart       ||`-- interruptible       |`--- dynamicCensus       `---- encryptedMetadata 

autoStart

  • false ⇒ Needs to be set to READY by the creator. Starts PAUSED by default.
  • true ⇒ Will start by itself at block startBlock.

newProcess() enforces startBlock > 0 accordingly

interruptible

  • false ⇒ Only the Vochain can END the process at block startBlock + blockCount
  • true ⇒ In addition to the above, the admin can END, PAUSE and CANCEL
    • Pausing a process prevents votes from being received, blockCount stays unchanged by now

dynamicCensus

  • false ⇒ Census is immutable
  • true ⇒ Census can be edited during the life-cycle of the process. Allowing to add, subtract new keys, or change the census entirely, to a process that has already started.
    • Intended for long-term polls
    • Warning: The admin has the opportunity to obscurely cheat by enabling keys and then removing them

encryptedMetadata

  • false ⇒ The processMetadata is in plain text
  • true ⇒ The questions and options of a process will be encrypted, so an observer of the network won’t be able to see what the process is about unless it has the key.

It requires a prior process to share the encryption key with the users that will have the rights to read the data. This will be likely be handled by the User Registry

JavaScript wrapper

A JavaScript wrapper is available for convenience

import { ProcessMode } from "dvote-solidity" // Flags ProcessMode.AUTO_START // => 1 ProcessMode.INTERRUPTIBLE // => 2 ProcessMode.DYNAMIC_CENSUS // => 4 ProcessMode.ENCRYPTED_METADATA // => 8  // Also mode = ProcessMode.make({}) // => 0 mode = ProcessMode.make({ autoStart: false, interruptible: false, dynamicCensus: false, encryptedMetadata: false }) // => 0 mode = ProcessMode.make({ autoStart: true, interruptible: true, dynamicCensus: true, encryptedMetadata: true }) // => 15  // And also const pMode = new ProcessMode(15) pMode.isAutoStart // true pMode.isInterruptible // true pMode.hasDynamicCensus // true pMode.hasEncryptedMetadata // true

Envelope Type

The envelope type tells how the vote envelope is formatted and handled. Its value is generated by combining the flags below.

0b00001111       ||||       |||`- serial       ||`-- anonymous       |`--- encryptedVote       `---- uniqueValues 

serial

  • false A single envelope is expected with all votes in it
  • true An envelope needs to be sent for each question, as questionIndex increases

anonymous

  • false The voter identity (public key) can be known and therefore, the vote is pseudonymous. If an observer can correlate the voter public key with personal data, the voter could be identified.
  • true The voter public key can’t be known. Instead, the voter will submit a ZK-snark proof, ensuring that:
    • He/she belongs to the census of the process
    • He/she has not already voted on the process

encryptedVote

  • false Votes are sent in plain text. Results can be seen in real time.
  • true The vote payload will be encrypted. The results will become available once the encryption key is published at the end of the process by the miners.

uniqueValues

  • false The same choice can be made twice or more, as long as maxTotalCost is held.
  • true Choices for a question cannot appear twice or more.

JavaScript wrapper

A JavaScript wrapper is available for convenience

import { ProcessEnvelopeType } from "dvote-solidity" // Flags ProcessEnvelopeType.SERIAL // => 1 ProcessEnvelopeType.ANONYMOUS // => 2 ProcessEnvelopeType.ENCRYPTED_VOTES // => 4 ProcessEnvelopeType.UNIQUE_VALUES // => 8  // Also type = ProcessEnvelopeType.make({}) // => 0 type = ProcessEnvelopeType.make({ serial: false, anonymousVoters: false, encryptedVotes: false, uniqueValues: false }) // => 0 type = ProcessEnvelopeType.make({ serial: true, anonymousVoters: true, encryptedVotes: true, uniqueValues: true }) // => 15  // And also const pEnvType = new ProcessEnvelopeType(15) pEnvType.hasSerialVoting // true pEnvType.hasAnonymousVoters // true pEnvType.hasEncryptedVotes // true pEnvType.hasUniqueValues // true

Process Status

The status of a process is a simple enum, defined as follows:

  • READY (0)
    • The process is marked as ready. It is intended as a passive authorization to open the process
    • Vochain nodes will accept incoming votes if AUTO_START is disabled
    • Otherwise, they will accept votes when the Vochain block number reaches startBlock
  • ENDED (1)
    • Tells the Vochain to stop accepting votes and start computing the results (if not already available)
    • Only when INTERRUPTIBLE is set
  • CANCELED (2)
    • Tells the Vochain to stop accepting votes and drop the existing data. No results will be published.
    • Only when INTERRUPTIBLE is set
  • PAUSED (3)
    • Tells the Vochain to stop processing votes temporarily. The process might be resumed in the future.
    • Only when INTERRUPTIBLE is set, or right after creation if AUTO_START is not set
  • RESULTS (4)
    • Set by the Oracle as soon as the results of a process have become available

Development

Compile and export the contracts ABI and Bytecode: make all

Run the test suite locally make test

Current testing

Feel free to contribute any additional test cases that you consider necessary.

  Chainable Process contract     ✓ should fail deploying if the predecessor address is not a contract (1183ms)     Instance forking       ✓ should allow to deploy a contract with no predecessorAddress (1083ms)       ✓ should not allow to deploy with itself as a predecessor (416ms)       ✓ should retrieve the predecessorAddress if set (1176ms)       ✓ should retrieve the successorAddress if set (1280ms)       ✓ should have no successor by default (1198ms)       ✓ should allow to read processes on the old instance from the new one (2002ms)       ✓ should get the instance address where a process was originally created (2462ms)       ✓ reading from non-existing processes should fail the same from a forked instance (1452ms)       ✓ getEntityProcessCount should count both new and old processes (3493ms)       ✓ namespace data should stay the same after a fork (1051ms)     Instance activation       ✓ should retrieve the activationBlock if set (1202ms)       ✓ should not allow to create new processes before it has been activated (1273ms)       ✓ should allow to create new processes after the predecessor activates it (1499ms)       ✓ should not allow to create new processes after a successor has been activated (1419ms)       ✓ should not allow to update the census after a successor has been activated (1452ms)       ✓ should allow to update the status, questionIndex and results after a successor has been activated (1794ms)       ✓ only the predecessor should be able to activate a new contract (2531ms)       ✓ only the contract owner should be able to call activateSuccessor contract (1459ms)       ✓ should not allow to activate itself as a successor (756ms)       ✓ should not allow to activate if not active itself (2001ms)       ✓ should fail activating with no predecessor defined (1471ms)       ✓ can only be deactivated once (1566ms)       ✓ can only be activated once (804ms)    Entity Resolver     ✓ Should deploy the contract (119ms)     ✓ Should compute the ID of an entity by its address     Text Records       ✓ Should set a Text record and keep the right value (132ms)       ✓ Should override an existing Text record (98ms)       ✓ Should reject updates from extraneous accounts (293ms)       ✓ Should override the entity name (290ms)       ✓ Should emit an event (4026ms)    Namespace contract     ✓ should deploy the contract (168ms)     Namespace management       ✓ should set a whole namespace at once (1529ms)       ✓ should allow only the contract creator to update a namespace (63ms)       ✓ should emit an event (1113ms)     ChainID updates       ✓ only contract creator (50ms)       ✓ should persist (128ms)       ✓ should fail if duplicated (137ms)       ✓ should emit an event (2635ms)     Genesis updates       ✓ only contract creator       ✓ should persist (299ms)       ✓ should fail if duplicated (137ms)       ✓ should emit an event (2568ms)     Validator inclusion       ✓ only when the contract owner requests it (425ms)       ✓ should add the validator public key to the validator list (448ms)       ✓ should fail if it is already present (389ms)       ✓ should add the validator to the right namespace (474ms)       ✓ should emit an event (998ms)     Validator removal       ✓ only when the contract owner account requests it (501ms)       ✓ should fail if the idx does not match validatorPublicKey (498ms)       ✓ should remove from the right namespace (550ms)       ✓ should emit an event (1400ms)     Oracle inclusion       ✓ only when the contract owner requests it (936ms)       ✓ should add the oracle address to the oracle list (882ms)       ✓ should fail if it is already present (888ms)       ✓ should add the validator to the right namespace (889ms)       ✓ should emit an event (3142ms)     Oracle removal       ✓ only when the contract owner requests it (974ms)       ✓ should fail if the idx is not valid (886ms)       ✓ should fail if the idx does not match oracleAddress (888ms)       ✓ should remove from the right namespace (1003ms)       ✓ should emit an event (2924ms)    Process contract     ✓ should deploy the contract (1712ms)     ✓ should fail deploying if the namespace address is not a contract (953ms)     ✓ should compute a processId from the entity address, index and namespace (151ms)     ✓ should compute the next processId (251ms)     Process Creation       ✓ should allow anyone to create a process (539ms)       ✓ retrieved metadata should match the one submitted (3088ms)       ✓ getting a non-existent process should fail (101ms)       ✓ unwrapped metadata should match the unwrapped response (655ms)       ✓ paramsSignature should match the given one (704ms)       ✓ should increment the processCount of the entity on success (217ms)       ✓ should fail with auto start set and startBlock being zero       ✓ should fail if not interruptible and blockCount is zero       ✓ should fail if the metadata or census references are empty       ✓ should fail if questionCount is zero (58ms)       ✓ should fail if maxCount is zero or above 100 (55ms)       ✓ should fail if maxValue is zero       ✓ should not increment the processCount of the entity on error (59ms)       ✓ should emit an event (3001ms)     Process Status       ✓ setting the status of a non-existent process should fail (116ms)       ✓ should create paused processes by default (671ms)       ✓ should create processes in ready status when autoStart is set (679ms)       ✓ should reject invalid status codes (887ms)       ✓ should emit an event (14622ms)       Not interruptible         ✓ should allow paused => ready (the first time) if autoStart is not set (1077ms)         ✓ should reject any other status update (1340ms)       Interruptible         from ready           ✓ should fail if setting to ready (887ms)           ✓ should allow to set to paused (1190ms)           ✓ should allow to set to ended (1138ms)           ✓ should allow to set to canceled (1019ms)           ✓ should fail if setting to results (769ms)           ✓ should fail if someone else tries to update the status (2483ms)         from paused           ✓ should allow to set to ready (1328ms)           ✓ should fail if setting to paused (953ms)           ✓ should allow to set to ended (1221ms)           ✓ should allow to set to canceled (1164ms)           ✓ should fail if setting to results (1019ms)           ✓ should fail if someone else tries to update the status (3145ms)         from ended           ✓ should never allow the status to be updated [creator] (1035ms)           ✓ should never allow the status to be updated [other account] (2299ms)         from canceled           ✓ should never allow the status to be updated [creator] (913ms)           ✓ should never allow the status to be updated [other account] (2296ms)         from results           ✓ should never allow the status to be updated [creator] (1316ms)           ✓ should never allow the status to be updated [other account] (2900ms)         only the oracle           ✓ can set the results (2566ms)     Serial envelope       ✓ incrementing the question index of a non-existent process should fail (259ms)       ✓ The question index should be read-only by default (1044ms)       ✓ The question index can be incremented in serial envelope mode (943ms)       ✓ Should only allow the process creator to increment (811ms)       ✓ Should fail if the process is paused (869ms)       ✓ Should fail if the process is terminated (2703ms)       ✓ Should end a process after the last question has been incremented (1347ms)       ✓ Should emit an event when the current question is incremented (3078ms)       ✓ Should emit an event when question increment ends the process (2792ms)     Dynamic Census       ✓ setting the census of a non-existent process should fail (220ms)       ✓ Should keep the census read-only by default (2163ms)       ✓ Should allow to update the census in dynamic census mode (1651ms)       ✓ Should only allow the creator to update the census (975ms)       ✓ Should fail updating the census on terminated processes (2818ms)       ✓ should emit an event (3283ms)     Process Results       ✓ getting the results of a non-existent process should fail (111ms)       ✓ setting results on a non-existent process should fail (921ms)       ✓ should be accepted when the sender is a registered oracle (529ms)       ✓ should be accepted when the processId exists (790ms)       ✓ should not be accepted when the process is canceled (912ms)       ✓ should retrieve the submited results (1132ms)       ✓ should allow oracles to set the results (2100ms)       ✓ should prevent publishing twice (1243ms)       ✓ should emit an event (1897ms)     Namespace management       ✓ should allow to retrieve the current namespace contract address (773ms)       ✓ should allow the contract creator to update the namespace contract address (426ms)       ✓ should fail if someone else attempts to update the namespace contract address (781ms)       ✓ should stop allowing setResults from an oracle that no longer belongs to the new instance (1663ms)       ✓ should emit an event (773ms)    StorageProofTest contract     ✓ should deploy the contract (257ms)     ✓ should verify inclusion (358ms)     ✓ should verify exclusion (175ms)    Envelope Type wrapper     ✓ Should build correct bitmasks     ✓ Should identity the appropriate flags     ✓ Should fail for invalid types    Process Census Origin wrapper     ✓ should handle valid census origins     ✓ should fail on invalid process status    Process contract parameter wrapper     ✓ should wrap the 'create' input parameters     ✓ should unwrap the 'get' response values    Process Mode wrapper     ✓ Should build correct bitmasks     ✓ Should identify the appropriate flags     ✓ Should fail for invalid types    Process Status wrapper     ✓ should handle valid process status     ✓ should fail on invalid process status     150 passing (5m) 

Deployments

xDAI

This network currently features an old version. Expect it to be soon updated.

Sokol

  • ENS Registry:
    • Address: 0xDb6C74071116D17a47D9c191cbE6d640111Ee5C2
  • ENS Resolver:
    • Address: 0xf3c50b2f86C0FC53e06CeaB88236BB404c3F2F9d
    • Domain: entities.vocdoni.eth
  • Process:
    • Address: 0xd92D591322A2375C1F010DF36FFC23257c71a418
    • Domain: processes.vocdoni.eth
    • Predecessor: 0x0000000000000000000000000000000000000000
  • Token Storage Proofs:
    • ERC20
      • Address: 0xeA2bafa402AbDF2888eB23224df998FaF8AA79a8
      • Domain: erc20.proofs.vocdoni.eth
  • Namespace:
    • Address: 0xC9d39F57a14FadA742c69FF7EDaB2C965e933921
    • Domain: namespaces.vocdoni.eth

Goerli

  • ENS Registry:
    • Address: 0xDA49dD1B5c62018C4F33ff2e39B30A21644E4EE8
  • ENS Resolver:
    • Address: 0x5aE2bD1998f4dEFD6Be5629780c8CFfB52CE612D
    • Domain: entities.vocdoni.eth
  • Process:
    • Address: 0x671884dB8DFB20d1D26173947a45622956009a0e
    • Domain: processes.vocdoni.eth
    • Predecessor: 0x0000000000000000000000000000000000000000
  • Token Storage Proofs:
    • ERC20
      • Address: 0x9564C87eAcbfD357c11536e7Cec921a48FE25EAA
      • Domain: erc20.proofs.vocdoni.eth
  • Namespace:
    • Address: 0x2266b67B76c1fE6789f8aF3A1FC5ce26B15fD007
    • Domain: namespaces.vocdoni.eth

Development

Run make install to get the dependencies

On Linux, you may need to remove package-lock.json and try again.

Adding a missing TS type


而smart命名空间提供了与这个进程进行交互的tyresolver。

  • 智能契约源代码稳定
  • JSON文件,其中包含契约ABI和每个的字节码
  • JS/Typescript支持导入JSON ABI和字节码

Contracts

实体解析器

实体解析器是一种通过以太坊eth地址或实体ID(地址的哈希)引用实体的灵活方法。它的特点是标准ENS实现加上允许数组的文本记录的专门版本。

它当前用于文本记录,文本记录存储到IPFS上实体元数据的链接。

命名空间

允许定义不同的投票名称空间(生产、开发、组织X、Y、Z等)。命名空间包含chainId、genesis信息、验证器[]和oracles[]。

每个流程实例(见下文)都必须指向一个命名空间协定。

过程

在vocdoni中,一切都是一个过程,是任何分散式治理活动的主要组成部分。

  • 允许设置定义投票的详细信息
  • 允许控制Vochain应如何处理该过程
  • 允许控制客户端应显示的状态
  • 充当持久的真相来源
  • 存储结果

存储证明

为了运行基于EVM人口普查的选举,选民提交人口普查Merkle证明,并对照以太坊eth区块链blockchain上的某个块散列进行检查。此合同负责存储可用的ERC令牌并验证余额映射位置。

基本契约

可链接

类似合同的流程很可能需要升级,同时我们也希望旧数据仍然可用。

Chainable是一种基本约定,允许定义前置实例并激活当前实例之后的未来实例。遗留数据可以被导航到,就像您在MiniMe令牌契约上所做的那样。

从Chainable继承的契约可以是:

  • 没有前置任务,部署后立即变为活动的
  • 有前置任务并开始不活动默认情况下,

当前任为JavaScript激活继任者时,在系统上安装NodeJS和NPM。

  • 前置进程变为非活动状态
  • 后继进程变为活动状态

入门

参见/lib上的示例/示例.js

npm install dvote-solidity 

要导入ABI和字节码:

用法

如果使用Typescript,可能需要在tsconfig.json文件文件。

const { EnsPublicResolver, Process, TokenStorageProof, Namespace } = require("dvote-solidity")  console.log(EnsPublicResolver.abi) console.log(EnsPublicResolver.bytecode)  console.log(Process.abi) console.log(Process.bytecode)  console.log(TokenStorageProof.abi) console.log(TokenStorageProof.bytecode)  console.log(Namespace.abi) console.log(Namespace.bytecode)

然后使用客户端库附加到实例或部署自己的实例:

投票过程由协定中的以下字段定义:

JavaScript(以太.js)

const { EnsPublicResolver, Process, TokenStorageProof, Namespace } = require("dvote-solidity") const ethers = require("ethers") const config = { ... }  const { abi: entityResolverAbi, bytecode: entityResolverByteCode } = EnsPublicResolver const { abi: processAbi, bytecode: processByteCode } = Process const { abi: tokenStorageProofAbi, bytecode: tokenStorageProofByteCode } = TokenStorageProof const { abi: namespaceAbi, bytecode: namespaceByteCode } = Namespace  const provider = new ethers.providers.JsonRpcProvider(config.GATEWAY_URL)  const privateKey = ethers.Wallet.fromMnemonic(config.MNEMONIC).privateKey const address = await ethers.Wallet.fromMnemonic(config.MNEMONIC).getAddress()  const wallet = new ethers.Wallet(privateKey, provider);  // deploying const resolverFactory = new ethers.ContractFactory(entityResolverAbi, entityResolverByteCode, wallet) const processFactory = new ethers.ContractFactory(processAbi, processByteCode, wallet) const tokenStorageProofFactory = new ethers.ContractFactory(tokenStorageProofAbi, tokenStorageProofByteCode, wallet) const namespaceFactory = new ethers.ContractFactory(namespaceAbi, namespaceByteCode, wallet)  const resolverInstance = await resolverFactory.deploy() console.log("Resolver deployed at", resolverInstance.address)  const tokenStorageProofInstance = await tokenStorageProofFactory.deploy() console.log("Token Storage Proof deployed at", tokenStorageProofInstance.address)  const namespaceInstance = await namespaceFactory.deploy() console.log("Namespace deployed at", namespaceInstance.address)  // The process contract needs the address of an already deployed namespace instance const predecessorInstanceAddress = "0x0000000000000000000000000000000000000000" // No predecessor const processInstance = await processFactory.deploy(predecessorInstanceAddress, namespaceInstance.address, tokenStorageProofInstance.address) console.log("Process deployed at", processInstance.address)  // or attaching const resolver = new ethers.Contract(resolverAddress, entityResolverAbi, wallet) const process = new ethers.Contract(processAddress, processAbi, wallet) const tokenStorageProof = new ethers.Contract(tokenStorageProofAddress, tokenStorageProofAbi, wallet) const namespace = new ethers.Contract(namespaceAddress, namespaceAbi, wallet)  const tx1 = await resolver.setText(...) await tx1.wait() const tx2 = await process.newProcess(...) await tx2.wait() const tx3 = await process.addOracle(...) await tx3.wait()

类型和值

行为由这些变量上的标志定义:

struct Process {     uint8 mode; // The selected process mode. See: https://vocdoni.io/docs/#/architecture/smart-contracts/process?id=flags     uint8 envelopeType; // One of valid envelope types, see: https://vocdoni.io/docs/#/architecture/smart-contracts/process?id=flags     address entityAddress; // The Ethereum address of the Entity     uint64 startBlock; // Tendermint block number on which the voting process starts     uint32 blockCount; // Amount of Tendermint blocks during which the voting process should be active     string metadata; // Content Hashed URI of the JSON meta data (See Data Origins)     string censusMerkleRoot; // Hex string with the Merkle Root hash of the census     string censusMerkleTree; // Content Hashed URI of the exported Merkle Tree (not including the public keys)     Status status; // One of 0 [ready], 1 [ended], 2 [canceled], 3 [paused], 4 [results]          uint8 questionIndex; // The index of the currently active question (only assembly processes)     // How many questions are available to vote     // questionCount >= 1     uint8 questionCount;          // How many choices can be made for each question.     // 1 <= maxCount <= 100     uint8 maxCount;          // Determines the acceptable value range.     // N => valid votes will range from 0 to N (inclusive)     uint8 maxValue;          uint8 maxVoteOverwrites; // How many times a vote can be replaced (only the last one counts)     // Choices for a question cannot appear twice or more          bool uniqueValues;     // Limits up to how much cost, the values of a vote can add up to (if applicable).     // 0 => No limit / Not applicable          uint16 maxTotalCost;     // Defines the exponent that will be used to compute the "cost" of the options voted and compare it against `maxTotalCost`.     // totalCost = Σ (value[i] ** costExponent) <= maxTotalCost     //     // Exponent range:     // - 0 => 0.0000     // - 10000 => 1.0000     // - 65535 => 6.5535     uint16 costExponent;          // Self-assign to a certain namespace.     // This will determine the oracles that listen and react to it.     // Indirectly, it will also determine the Vochain that hosts this process.          uint16 namespace;          bytes32 paramsSignature; // entity.sign({...}) // fields that the oracle uses to authentify process creation          string results; // string containing the results }

过程模式影响Vochain、协定本身甚至元数据。

  • 进程模式(其行为方式)
  • 信封类型投票看起来如何
  • 状态进程是否打开、结束、取消,暂停,结果

过程模式

newProcess()相应地强制startBlock&gt;0

0b00001111       ||||       |||`- autoStart       ||`-- interruptible       |`--- dynamicCensus       `---- encryptedMetadata 

自动启动

  • 错误⇒需要由创建者设置为就绪。默认情况下暂停启动。
  • 正确⇒将在块开始块处自动启动。

它需要一个预先的进程来与有权读取数据的用户共享加密密钥。这可能由用户注册表来处理

可中断的

  • 假⇒只有Vochain可以在block startBlock+blockCount处结束流程
  • 真⇒除此之外,管理员还可以结束、暂停和取消暂停流程阻止收到投票,blockCount现在保持不变

动态加密

  • 假⇒普查是不可变的
  • 真⇒普查可以在流程的生命周期中编辑。允许在已经开始的过程中添加、减去新的键,或者完全更改普查。用于长期轮询警告:管理员有机会通过启用密钥然后删除它们来进行模糊欺骗

加密元数据

  • true⇒进程的问题和选项将被加密,因此网络的观察者将无法看到进程的内容,除非它具有密钥。
  • false一个信封中应包含所有投票

为了方便起见,可以使用JavaScript包装器

JavaScript包装

信封类型告诉如何格式化和处理投票信封。它的值是通过组合下面的标志生成的。

import { ProcessMode } from "dvote-solidity" // Flags ProcessMode.AUTO_START // => 1 ProcessMode.INTERRUPTIBLE // => 2 ProcessMode.DYNAMIC_CENSUS // => 4 ProcessMode.ENCRYPTED_METADATA // => 8  // Also mode = ProcessMode.make({}) // => 0 mode = ProcessMode.make({ autoStart: false, interruptible: false, dynamicCensus: false, encryptedMetadata: false }) // => 0 mode = ProcessMode.make({ autoStart: true, interruptible: true, dynamicCensus: true, encryptedMetadata: true }) // => 15  // And also const pMode = new ProcessMode(15) pMode.isAutoStart // true pMode.isInterruptible // true pMode.hasDynamicCensus // true pMode.hasEncryptedMetadata // true

信封类型

为了方便起见,可以使用JavaScript包装器

0b00001111       ||||       |||`- serial       ||`-- anonymous       |`--- encryptedVote       `---- uniqueValues 

串行

  • true每个问题都需要发送一个信封,随着问题索引的增加
  • false可以知道投票人身份(公钥),因此投票是假名的。如果观察者能够将投票者公钥与个人数据相关联,则可以识别投票者。

匿名

  • true无法知道投票者公钥。相反,投票人将提交一份ZK snark证明,确保:他/她属于普查过程他/她尚未对该过程投票他/她属于普查过程他/她尚未对该过程投票他/她以明文形式发送虚假投票。结果可以实时查看。
  • true投票有效负载将被加密。一旦加密密钥在进程结束时由矿工发布,结果将变为可用。

加密投票

  • 就绪(0)进程被标记为就绪。它是一种打开进程的被动授权,如果禁用自动启动,Vochain节点将接受传入的投票,否则,当Vochain块号达到startBlock时,它们将接受投票进程标记为就绪。它是一种被动授权,用于打开进程
  • 如果禁用了自动启动,Vochain节点将接受传入的投票

唯一值

  • 否则,当Vochain块号达到startBlock时,它们将接受投票
  • 结束(1)通知Vochain停止接受投票并开始计算结果(如果还没有)可用)仅当设置可中断时

JavaScript包装

进程的状态是一个简单的枚举,定义如下:

import { ProcessEnvelopeType } from "dvote-solidity" // Flags ProcessEnvelopeType.SERIAL // => 1 ProcessEnvelopeType.ANONYMOUS // => 2 ProcessEnvelopeType.ENCRYPTED_VOTES // => 4 ProcessEnvelopeType.UNIQUE_VALUES // => 8  // Also type = ProcessEnvelopeType.make({}) // => 0 type = ProcessEnvelopeType.make({ serial: false, anonymousVoters: false, encryptedVotes: false, uniqueValues: false }) // => 0 type = ProcessEnvelopeType.make({ serial: true, anonymousVoters: true, encryptedVotes: true, uniqueValues: true }) // => 15  // And also const pEnvType = new ProcessEnvelopeType(15) pEnvType.hasSerialVoting // true pEnvType.hasAnonymousVoters // true pEnvType.hasEncryptedVotes // true pEnvType.hasUniqueValues // true

开发

编译并导出契约ABI和字节码:make all

  • 通知Vochain停止接受投票并开始计算结果(如果尚未可用)
  • 仅当设置了中断时
  • 在进程结果可用时由Oracle设置地址:0xdb6c74071116d17a47d9c191cbe640111ee5c2
  • 进程:地址:0xd92D591322A2375C1F010DF36FFC23257c71a418域:工艺.vocdoni.eth前身:0x000000000000000000000000000000000000000000000000000000地址:0xd92D591322A2375C1F010DF36FFC23257c71a418域:工艺.vocdoni.eth
  • ERC20地址:0xeA2bafa402AbDF2888eB23224df998FaF8AA79a8域:ERC20。证明.vocdoni.eth地址:0xeA2bafa402AbDF2888eB23224df998FaF8AA79a8域:erc20。多尼思·普罗夫斯

当前测试

在本地运行测试套件make test

可以随意提供您认为必要的任何其他测试用例。

部署

此网络当前采用旧版本。预计很快就会更新。

  Chainable Process contract     ✓ should fail deploying if the predecessor address is not a contract (1183ms)     Instance forking       ✓ should allow to deploy a contract with no predecessorAddress (1083ms)       ✓ should not allow to deploy with itself as a predecessor (416ms)       ✓ should retrieve the predecessorAddress if set (1176ms)       ✓ should retrieve the successorAddress if set (1280ms)       ✓ should have no successor by default (1198ms)       ✓ should allow to read processes on the old instance from the new one (2002ms)       ✓ should get the instance address where a process was originally created (2462ms)       ✓ reading from non-existing processes should fail the same from a forked instance (1452ms)       ✓ getEntityProcessCount should count both new and old processes (3493ms)       ✓ namespace data should stay the same after a fork (1051ms)     Instance activation       ✓ should retrieve the activationBlock if set (1202ms)       ✓ should not allow to create new processes before it has been activated (1273ms)       ✓ should allow to create new processes after the predecessor activates it (1499ms)       ✓ should not allow to create new processes after a successor has been activated (1419ms)       ✓ should not allow to update the census after a successor has been activated (1452ms)       ✓ should allow to update the status, questionIndex and results after a successor has been activated (1794ms)       ✓ only the predecessor should be able to activate a new contract (2531ms)       ✓ only the contract owner should be able to call activateSuccessor contract (1459ms)       ✓ should not allow to activate itself as a successor (756ms)       ✓ should not allow to activate if not active itself (2001ms)       ✓ should fail activating with no predecessor defined (1471ms)       ✓ can only be deactivated once (1566ms)       ✓ can only be activated once (804ms)    Entity Resolver     ✓ Should deploy the contract (119ms)     ✓ Should compute the ID of an entity by its address     Text Records       ✓ Should set a Text record and keep the right value (132ms)       ✓ Should override an existing Text record (98ms)       ✓ Should reject updates from extraneous accounts (293ms)       ✓ Should override the entity name (290ms)       ✓ Should emit an event (4026ms)    Namespace contract     ✓ should deploy the contract (168ms)     Namespace management       ✓ should set a whole namespace at once (1529ms)       ✓ should allow only the contract creator to update a namespace (63ms)       ✓ should emit an event (1113ms)     ChainID updates       ✓ only contract creator (50ms)       ✓ should persist (128ms)       ✓ should fail if duplicated (137ms)       ✓ should emit an event (2635ms)     Genesis updates       ✓ only contract creator       ✓ should persist (299ms)       ✓ should fail if duplicated (137ms)       ✓ should emit an event (2568ms)     Validator inclusion       ✓ only when the contract owner requests it (425ms)       ✓ should add the validator public key to the validator list (448ms)       ✓ should fail if it is already present (389ms)       ✓ should add the validator to the right namespace (474ms)       ✓ should emit an event (998ms)     Validator removal       ✓ only when the contract owner account requests it (501ms)       ✓ should fail if the idx does not match validatorPublicKey (498ms)       ✓ should remove from the right namespace (550ms)       ✓ should emit an event (1400ms)     Oracle inclusion       ✓ only when the contract owner requests it (936ms)       ✓ should add the oracle address to the oracle list (882ms)       ✓ should fail if it is already present (888ms)       ✓ should add the validator to the right namespace (889ms)       ✓ should emit an event (3142ms)     Oracle removal       ✓ only when the contract owner requests it (974ms)       ✓ should fail if the idx is not valid (886ms)       ✓ should fail if the idx does not match oracleAddress (888ms)       ✓ should remove from the right namespace (1003ms)       ✓ should emit an event (2924ms)    Process contract     ✓ should deploy the contract (1712ms)     ✓ should fail deploying if the namespace address is not a contract (953ms)     ✓ should compute a processId from the entity address, index and namespace (151ms)     ✓ should compute the next processId (251ms)     Process Creation       ✓ should allow anyone to create a process (539ms)       ✓ retrieved metadata should match the one submitted (3088ms)       ✓ getting a non-existent process should fail (101ms)       ✓ unwrapped metadata should match the unwrapped response (655ms)       ✓ paramsSignature should match the given one (704ms)       ✓ should increment the processCount of the entity on success (217ms)       ✓ should fail with auto start set and startBlock being zero       ✓ should fail if not interruptible and blockCount is zero       ✓ should fail if the metadata or census references are empty       ✓ should fail if questionCount is zero (58ms)       ✓ should fail if maxCount is zero or above 100 (55ms)       ✓ should fail if maxValue is zero       ✓ should not increment the processCount of the entity on error (59ms)       ✓ should emit an event (3001ms)     Process Status       ✓ setting the status of a non-existent process should fail (116ms)       ✓ should create paused processes by default (671ms)       ✓ should create processes in ready status when autoStart is set (679ms)       ✓ should reject invalid status codes (887ms)       ✓ should emit an event (14622ms)       Not interruptible         ✓ should allow paused => ready (the first time) if autoStart is not set (1077ms)         ✓ should reject any other status update (1340ms)       Interruptible         from ready           ✓ should fail if setting to ready (887ms)           ✓ should allow to set to paused (1190ms)           ✓ should allow to set to ended (1138ms)           ✓ should allow to set to canceled (1019ms)           ✓ should fail if setting to results (769ms)           ✓ should fail if someone else tries to update the status (2483ms)         from paused           ✓ should allow to set to ready (1328ms)           ✓ should fail if setting to paused (953ms)           ✓ should allow to set to ended (1221ms)           ✓ should allow to set to canceled (1164ms)           ✓ should fail if setting to results (1019ms)           ✓ should fail if someone else tries to update the status (3145ms)         from ended           ✓ should never allow the status to be updated [creator] (1035ms)           ✓ should never allow the status to be updated [other account] (2299ms)         from canceled           ✓ should never allow the status to be updated [creator] (913ms)           ✓ should never allow the status to be updated [other account] (2296ms)         from results           ✓ should never allow the status to be updated [creator] (1316ms)           ✓ should never allow the status to be updated [other account] (2900ms)         only the oracle           ✓ can set the results (2566ms)     Serial envelope       ✓ incrementing the question index of a non-existent process should fail (259ms)       ✓ The question index should be read-only by default (1044ms)       ✓ The question index can be incremented in serial envelope mode (943ms)       ✓ Should only allow the process creator to increment (811ms)       ✓ Should fail if the process is paused (869ms)       ✓ Should fail if the process is terminated (2703ms)       ✓ Should end a process after the last question has been incremented (1347ms)       ✓ Should emit an event when the current question is incremented (3078ms)       ✓ Should emit an event when question increment ends the process (2792ms)     Dynamic Census       ✓ setting the census of a non-existent process should fail (220ms)       ✓ Should keep the census read-only by default (2163ms)       ✓ Should allow to update the census in dynamic census mode (1651ms)       ✓ Should only allow the creator to update the census (975ms)       ✓ Should fail updating the census on terminated processes (2818ms)       ✓ should emit an event (3283ms)     Process Results       ✓ getting the results of a non-existent process should fail (111ms)       ✓ setting results on a non-existent process should fail (921ms)       ✓ should be accepted when the sender is a registered oracle (529ms)       ✓ should be accepted when the processId exists (790ms)       ✓ should not be accepted when the process is canceled (912ms)       ✓ should retrieve the submited results (1132ms)       ✓ should allow oracles to set the results (2100ms)       ✓ should prevent publishing twice (1243ms)       ✓ should emit an event (1897ms)     Namespace management       ✓ should allow to retrieve the current namespace contract address (773ms)       ✓ should allow the contract creator to update the namespace contract address (426ms)       ✓ should fail if someone else attempts to update the namespace contract address (781ms)       ✓ should stop allowing setResults from an oracle that no longer belongs to the new instance (1663ms)       ✓ should emit an event (773ms)    StorageProofTest contract     ✓ should deploy the contract (257ms)     ✓ should verify inclusion (358ms)     ✓ should verify exclusion (175ms)    Envelope Type wrapper     ✓ Should build correct bitmasks     ✓ Should identity the appropriate flags     ✓ Should fail for invalid types    Process Census Origin wrapper     ✓ should handle valid census origins     ✓ should fail on invalid process status    Process contract parameter wrapper     ✓ should wrap the 'create' input parameters     ✓ should unwrap the 'get' response values    Process Mode wrapper     ✓ Should build correct bitmasks     ✓ Should identify the appropriate flags     ✓ Should fail for invalid types    Process Status wrapper     ✓ should handle valid process status     ✓ should fail on invalid process status     150 passing (5m) 

xDAI

Sokol

在Linux上运行make install以获取依赖项,您可能需要删除包-json.lock再试一次。

Goerli

  • ENS Registry:
    • Address: 0xDb6C74071116D17a47D9c191cbE6d640111Ee5C2
  • ENS Resolver:
    • Address: 0xf3c50b2f86C0FC53e06CeaB88236BB404c3F2F9d
    • Domain: entities.vocdoni.eth
  • Process:
    • Address: 0xd92D591322A2375C1F010DF36FFC23257c71a418
    • Domain: processes.vocdoni.eth
    • Predecessor: 0x0000000000000000000000000000000000000000
  • Token Storage Proofs:
    • ERC20
      • Address: 0xeA2bafa402AbDF2888eB23224df998FaF8AA79a8
      • Domain: erc20.proofs.vocdoni.eth
  • Namespace:
    • Address: 0xC9d39F57a14FadA742c69FF7EDaB2C965e933921
    • Domain: namespaces.vocdoni.eth

开发

  • ENS Registry:
    • Address: 0xDA49dD1B5c62018C4F33ff2e39B30A21644E4EE8
  • ENS Resolver:
    • Address: 0x5aE2bD1998f4dEFD6Be5629780c8CFfB52CE612D
    • Domain: entities.vocdoni.eth
  • Process:
    • Address: 0x671884dB8DFB20d1D26173947a45622956009a0e
    • Domain: processes.vocdoni.eth
    • Predecessor: 0x0000000000000000000000000000000000000000
  • Token Storage Proofs:
    • ERC20
      • Address: 0x9564C87eAcbfD357c11536e7Cec921a48FE25EAA
      • Domain: erc20.proofs.vocdoni.eth
  • Namespace:
    • Address: 0x2266b67B76c1fE6789f8aF3A1FC5ce26B15fD007
    • Domain: namespaces.vocdoni.eth

Development

Run make install to get the dependencies

On Linux, you may need to remove package-lock.json and try again.

Adding a missing TS type

部分转自网络,侵权联系删除区块链源码网

www.interchains.cc

https://www.interchains.cc/19602.html

区块链毕设网(www.interchains.cc)全网最靠谱的原创区块链毕设代做网站 部分资料来自网络,侵权联系删除! 最全最大的区块链源码站 ! QQ3039046426
区块链知识分享网, 以太坊dapp资源网, 区块链教程, fabric教程下载, 区块链书籍下载, 区块链资料下载, 区块链视频教程下载, 区块链基础教程, 区块链入门教程, 区块链资源 » DVote Solidity – D注固性区块链毕设代写

提供最优质的资源集合

立即查看 了解详情