mirror of https://github.com/poanetwork/quorum.git
populate initial accounts with full access via genesis.json - contract's storge
This commit is contained in:
parent
4543d5fde4
commit
442e364be1
File diff suppressed because one or more lines are too long
|
@ -1,7 +1,15 @@
|
||||||
pragma solidity ^0.4.23;
|
pragma solidity ^0.4.23;
|
||||||
|
|
||||||
contract Permissions {
|
contract Permissions {
|
||||||
|
//initialAcctList - is used to initialize accounts at network start up first time. it is populated by genesis file, don't populate it in the contract
|
||||||
|
// Example genesis storage population:
|
||||||
|
// "storage": {
|
||||||
|
// "0x0000000000000000000000000000000000000000000000000000000000000000" : "0x0000000000000000000000000000000000000003",
|
||||||
|
// "0x290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563" : "0xcA843569e3427144cEad5e4d5999a3D0cCF92B8e",
|
||||||
|
// "0x290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e564" : "0xed9d02e382b34818e88b88a309c7fe71e65f419d",
|
||||||
|
// "0x290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e565" : "0x0fbdc686b912d7722dc86510934589e0aaf3b55a"
|
||||||
|
// },
|
||||||
|
address[] initialAcctList;
|
||||||
// enum and struct declaration
|
// enum and struct declaration
|
||||||
enum NodeStatus {NotInList, PendingApproval, Approved, PendingDeactivation, Deactivated, PendingActivation, PendingBlacklisting, Blacklisted }
|
enum NodeStatus {NotInList, PendingApproval, Approved, PendingDeactivation, Deactivated, PendingActivation, PendingBlacklisting, Blacklisted }
|
||||||
struct NodeDetails {
|
struct NodeDetails {
|
||||||
|
@ -12,6 +20,7 @@ contract Permissions {
|
||||||
NodeStatus status;
|
NodeStatus status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
enum AccountAccess { FullAccess, ReadOnly, Transact, ContractDeploy }
|
enum AccountAccess { FullAccess, ReadOnly, Transact, ContractDeploy }
|
||||||
struct AccountAccessDetails {
|
struct AccountAccessDetails {
|
||||||
address acctId;
|
address acctId;
|
||||||
|
@ -27,6 +36,8 @@ contract Permissions {
|
||||||
uint private numberOfNodes;
|
uint private numberOfNodes;
|
||||||
|
|
||||||
AccountAccessDetails[] private acctAccessList;
|
AccountAccessDetails[] private acctAccessList;
|
||||||
|
|
||||||
|
|
||||||
mapping (address => uint) private acctToIndex;
|
mapping (address => uint) private acctToIndex;
|
||||||
uint private numberOfAccts;
|
uint private numberOfAccts;
|
||||||
// use an array to store account details
|
// use an array to store account details
|
||||||
|
@ -38,9 +49,13 @@ contract Permissions {
|
||||||
// valid vote count
|
// valid vote count
|
||||||
mapping (uint => uint) private voteCount;
|
mapping (uint => uint) private voteCount;
|
||||||
|
|
||||||
// checks if firts time network boot up has happened or not
|
// checks if first time network boot up has happened or not
|
||||||
bool private networkBoot = false;
|
bool private networkBoot = false;
|
||||||
|
|
||||||
|
// checks if first time network boot up for accounts has happened or not
|
||||||
|
bool private networkBootAccount = false;
|
||||||
|
|
||||||
|
|
||||||
// node permission events for new node propose
|
// node permission events for new node propose
|
||||||
event NodeProposed(string _enodeId);
|
event NodeProposed(string _enodeId);
|
||||||
event NodeApproved(string _enodeId, string _ipAddrPort, string _discPort, string _raftPort);
|
event NodeApproved(string _enodeId, string _ipAddrPort, string _discPort, string _raftPort);
|
||||||
|
@ -106,6 +121,8 @@ contract Permissions {
|
||||||
return voterAcctList.length;
|
return voterAcctList.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Get voter
|
// Get voter
|
||||||
function getVoter(uint i) public view returns (address _addr)
|
function getVoter(uint i) public view returns (address _addr)
|
||||||
{
|
{
|
||||||
|
@ -386,6 +403,20 @@ contract Permissions {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function InitAccounts() external
|
||||||
|
{
|
||||||
|
require(networkBootAccount == false, "network accounts already boot up");
|
||||||
|
for (uint i=0; i<initialAcctList.length; i++){
|
||||||
|
numberOfAccts ++;
|
||||||
|
acctToIndex[initialAcctList[i]] = numberOfAccts;
|
||||||
|
acctAccessList.push(AccountAccessDetails(initialAcctList[i], AccountAccess.FullAccess));
|
||||||
|
emit AccountAccessModified(initialAcctList[i], AccountAccess.FullAccess);
|
||||||
|
}
|
||||||
|
networkBootAccount = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Checks if the Node is already added. If yes then returns true
|
// Checks if the Node is already added. If yes then returns true
|
||||||
function updateAccountAccess(address _address, AccountAccess _accountAccess) external
|
function updateAccountAccess(address _address, AccountAccess _accountAccess) external
|
||||||
{
|
{
|
||||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -12,9 +12,9 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
||||||
|
"github.com/ethereum/go-ethereum/cmd/utils"
|
||||||
"github.com/ethereum/go-ethereum/controls"
|
"github.com/ethereum/go-ethereum/controls"
|
||||||
pbind "github.com/ethereum/go-ethereum/controls/bind"
|
pbind "github.com/ethereum/go-ethereum/controls/bind"
|
||||||
"github.com/ethereum/go-ethereum/cmd/utils"
|
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/eth"
|
"github.com/ethereum/go-ethereum/eth"
|
||||||
"github.com/ethereum/go-ethereum/ethclient"
|
"github.com/ethereum/go-ethereum/ethclient"
|
||||||
|
@ -443,7 +443,7 @@ func (p *PermissionCtrl) populateInitPermission() error {
|
||||||
// populate the initial node list from static-nodes.json
|
// populate the initial node list from static-nodes.json
|
||||||
err := p.populateStaticNodesToContract(permissionsSession)
|
err := p.populateStaticNodesToContract(permissionsSession)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// update network status to boot completed
|
// update network status to boot completed
|
||||||
|
@ -485,17 +485,10 @@ func (p *PermissionCtrl) populateStaticNodesToContract(permissionsSession *pbind
|
||||||
|
|
||||||
// Reads the acount from geth keystore and grants full access to these accounts
|
// Reads the acount from geth keystore and grants full access to these accounts
|
||||||
func (p *PermissionCtrl) populateInitAccountAccess(permissionsSession *pbind.PermissionsSession) error {
|
func (p *PermissionCtrl) populateInitAccountAccess(permissionsSession *pbind.PermissionsSession) error {
|
||||||
acctman := p.node.AccountManager()
|
_, err := permissionsSession.InitAccounts()
|
||||||
for _, wallet := range acctman.Wallets() {
|
if err != nil {
|
||||||
for _, account := range wallet.Accounts() {
|
log.Error("calling init accounts failed", "err", err)
|
||||||
nonce := p.eth.TxPool().Nonce(permissionsSession.TransactOpts.From)
|
return err
|
||||||
permissionsSession.TransactOpts.Nonce = new(big.Int).SetUint64(nonce)
|
|
||||||
|
|
||||||
_, err := permissionsSession.UpdateAccountAccess(account.Address, uint8(types.FullAccess))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue