populate initial accounts with full access via genesis.json - contract's storge

This commit is contained in:
amalraj.manigmail.com 2018-11-16 18:08:49 +08:00
parent 4543d5fde4
commit 442e364be1
5 changed files with 63 additions and 18 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,7 +1,15 @@
pragma solidity ^0.4.23;
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 NodeStatus {NotInList, PendingApproval, Approved, PendingDeactivation, Deactivated, PendingActivation, PendingBlacklisting, Blacklisted }
struct NodeDetails {
@ -12,6 +20,7 @@ contract Permissions {
NodeStatus status;
}
enum AccountAccess { FullAccess, ReadOnly, Transact, ContractDeploy }
struct AccountAccessDetails {
address acctId;
@ -27,6 +36,8 @@ contract Permissions {
uint private numberOfNodes;
AccountAccessDetails[] private acctAccessList;
mapping (address => uint) private acctToIndex;
uint private numberOfAccts;
// use an array to store account details
@ -38,9 +49,13 @@ contract Permissions {
// valid vote count
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;
// checks if first time network boot up for accounts has happened or not
bool private networkBootAccount = false;
// node permission events for new node propose
event NodeProposed(string _enodeId);
event NodeApproved(string _enodeId, string _ipAddrPort, string _discPort, string _raftPort);
@ -106,6 +121,8 @@ contract Permissions {
return voterAcctList.length;
}
// Get voter
function getVoter(uint i) public view returns (address _addr)
{
@ -386,6 +403,20 @@ contract Permissions {
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
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

View File

@ -12,9 +12,9 @@ import (
"sync"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/controls"
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/eth"
"github.com/ethereum/go-ethereum/ethclient"
@ -443,7 +443,7 @@ func (p *PermissionCtrl) populateInitPermission() error {
// populate the initial node list from static-nodes.json
err := p.populateStaticNodesToContract(permissionsSession)
if err != nil {
return err
return err
}
// 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
func (p *PermissionCtrl) populateInitAccountAccess(permissionsSession *pbind.PermissionsSession) error {
acctman := p.node.AccountManager()
for _, wallet := range acctman.Wallets() {
for _, account := range wallet.Accounts() {
nonce := p.eth.TxPool().Nonce(permissionsSession.TransactOpts.From)
permissionsSession.TransactOpts.Nonce = new(big.Int).SetUint64(nonce)
_, err := permissionsSession.UpdateAccountAccess(account.Address, uint8(types.FullAccess))
if err != nil {
return err
}
}
_, err := permissionsSession.InitAccounts()
if err != nil {
log.Error("calling init accounts failed", "err", err)
return err
}
return nil
}