-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,125 @@ | ||
API: Voting | ||
=========== | ||
|
||
Contract overview | ||
----------------- | ||
|
||
``Bios.sol`` - is the main kernel smartcontract with all the logic about consensus, staking and voting. Its based on the ``QueueHelper`` that brings queue implementation code. | ||
|
||
Voting mechanism consists of two parts - firs is "proposal call" that initiates possibility for voting for any change for other participants (for instance - adding new Authority node or Bios contract changing etc). | ||
After that voting begins and in the in a certain period of time Authority Nodes could vote for any active initiatives. | ||
|
||
Proposal Functions | ||
------------------ | ||
|
||
- **function proposeNewAuthority(address participant) public** | ||
Propose a poll for a new authority. | ||
``Input parameter`` : "address participant" - the address of the new Autority Node. | ||
``Output parameter`` : none | ||
|
||
- **function proposeBlacklistAuthority(address participant) public** | ||
Propose a poll for blacklisting the authority to the authority black list. | ||
``Input parameter`` : "address participant" - the address of the Autority Node that should be added to the black list. | ||
``Output parameter`` : none | ||
|
||
Proposal Examples | ||
----------------- | ||
|
||
Below you can see JS example of usage ``Bios.sol`` smartcontract from the Papyrus Wallet implemetatin | ||
|
||
.. code-block:: javascript | ||
:emphasize-lines: 3, 14 | ||
async proposeNewAuthority(address, callbacks = {}) { | ||
return this.process( | ||
this.contract.methods.proposeNewAuthority(address).send({ | ||
from: this.account, | ||
gas: 100000 | ||
}), | ||
callbacks | ||
); | ||
} | ||
async proposeBlacklistAuthority(address, callbacks = {}) { | ||
return this.process( | ||
this.contract.methods.proposeBlacklistAuthority(address).send({ | ||
from: this.account, | ||
gas: 100000 | ||
}), | ||
callbacks | ||
); | ||
} | ||
Voting Functions | ||
---------------- | ||
|
||
- **function voteForNewAuthority(uint slot, address participant) public** | ||
Function that could be called by existing Authority Vote for the voting for the new Authority Node | ||
``Input parameter`` : "slot" - number of voting slot to bet. | ||
``Input parameter`` : "participant" - address of the proposed authority. | ||
``Output parameter`` : none | ||
|
||
- **function voteForBlackListAuthority(address participant) public** | ||
Function that could be called by existing Authority Vote for the voting for the adding another Authority Node to the blacklist | ||
``Input parameter`` : "slot" - number of voting slot to bet. | ||
``Input parameter`` : "participant" - address of the proposed authority. | ||
``Output parameter`` : none | ||
|
||
- **function handleClosedPolls() public** | ||
Handle all pollings where time is up. Anybody could call this function. | ||
``Input parameter`` : none | ||
``Output parameter`` : none | ||
|
||
|
||
Voting Examples | ||
--------------- | ||
|
||
.. code-block:: javascript | ||
:emphasize-lines: 3, 14 | ||
import Web3 from 'web3'; | ||
import abi from '@/abis/abi.json'; | ||
const noop = () => {}; | ||
const cbCaller = function(fn, ...args) { | ||
if (fn && typeof fn === 'function') { | ||
fn(...args); | ||
} | ||
}; | ||
export class Web3Service { | ||
web3 = null; | ||
contract = null; | ||
provider = null; | ||
account = null; | ||
constructor(provider) { | ||
this.provider = provider; | ||
this.web3 = new Web3(provider); | ||
this.contract = new this.web3.eth.Contract( | ||
abi, | ||
process.env.VUE_APP_BIOS_ADDRESS | ||
); | ||
} | ||
async voteForNewAuthority(votes, address, callbacks = {}) { | ||
return this.process( | ||
this.contract.methods.voteForNewAuthority(votes, address).send({ | ||
from: this.account, | ||
gas: 100000 | ||
}), | ||
callbacks | ||
); | ||
} | ||
async voteForBlackListAuthority(address, callbacks = {}) { | ||
return this.process( | ||
this.contract.methods.voteForBlackListAuthority(address).send({ | ||
from: this.account, | ||
gas: 100000 | ||
}), | ||
callbacks | ||
); | ||
} | ||