mirror of https://github.com/poanetwork/quorum.git
Added additional APIs
This commit is contained in:
parent
753d4baa47
commit
3c68a587ba
|
@ -28,7 +28,6 @@ import (
|
|||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/ethereum/go-ethereum/event"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/ethereum/go-ethereum/rlp"
|
||||
)
|
||||
|
||||
|
|
|
@ -298,7 +298,7 @@ func (p *PermissionCtrl) populatePermissionedNodes() error {
|
|||
opts := &bind.FilterOpts{}
|
||||
pastAddEvent, err := p.pm.PermissionsFilterer.FilterNodeApproved(opts)
|
||||
|
||||
if err != nil {
|
||||
if err == nil {
|
||||
recExists := true
|
||||
for recExists {
|
||||
recExists = pastAddEvent.Next()
|
||||
|
@ -310,7 +310,7 @@ func (p *PermissionCtrl) populatePermissionedNodes() error {
|
|||
|
||||
opts = &bind.FilterOpts{}
|
||||
pastDelEvent, err := p.pm.PermissionsFilterer.FilterNodeDeactivated(opts)
|
||||
if err != nil {
|
||||
if err == nil {
|
||||
recExists := true
|
||||
for recExists {
|
||||
recExists = pastDelEvent.Next()
|
||||
|
|
|
@ -29,8 +29,12 @@ type PermAction int
|
|||
const (
|
||||
ProposeNode PermAction = iota
|
||||
ApproveNode
|
||||
DeactivateNode
|
||||
ApproveDeactivateNode
|
||||
ProposeNodeDeactivation
|
||||
ApproveNodeDeactivation
|
||||
ProposeNodeActivation
|
||||
ApproveNodeActivation
|
||||
ProposeNodeBlacklisting
|
||||
ApproveNodeBlacklisting
|
||||
AddVoter
|
||||
RemoveVoter
|
||||
)
|
||||
|
@ -104,15 +108,34 @@ func (s *PermissionAPI) ApproveNode(nodeId string, txa ethapi.SendTxArgs) bool {
|
|||
}
|
||||
|
||||
// DeactivateNode requests a node to get deactivated
|
||||
func (s *PermissionAPI) DeactivateNode(nodeId string, txa ethapi.SendTxArgs) bool {
|
||||
return s.executePermAction(DeactivateNode, txArgs{nodeId: nodeId, txa: txa})
|
||||
func (s *PermissionAPI) ProposeNodeDeactivation(nodeId string, txa ethapi.SendTxArgs) bool {
|
||||
return s.executePermAction(ProposeNodeDeactivation, txArgs{nodeId: nodeId, txa: txa})
|
||||
}
|
||||
|
||||
// ApproveDeactivateNode approves a node to get deactivated
|
||||
func (s *PermissionAPI) ApproveDeactivateNode(nodeId string, txa ethapi.SendTxArgs) bool {
|
||||
return s.executePermAction(ApproveDeactivateNode, txArgs{nodeId: nodeId, txa: txa})
|
||||
func (s *PermissionAPI) ApproveNodeDeactivation(nodeId string, txa ethapi.SendTxArgs) bool {
|
||||
return s.executePermAction(ApproveNodeDeactivation, txArgs{nodeId: nodeId, txa: txa})
|
||||
}
|
||||
|
||||
// DeactivateNode requests a node to get deactivated
|
||||
func (s *PermissionAPI) ProposeNodeActivation(nodeId string, txa ethapi.SendTxArgs) bool {
|
||||
return s.executePermAction(ProposeNodeActivation, txArgs{nodeId: nodeId, txa: txa})
|
||||
}
|
||||
|
||||
// ApproveDeactivateNode approves a node to get deactivated
|
||||
func (s *PermissionAPI) ApproveNodeActivation(nodeId string, txa ethapi.SendTxArgs) bool {
|
||||
return s.executePermAction(ApproveNodeActivation, txArgs{nodeId: nodeId, txa: txa})
|
||||
}
|
||||
|
||||
// DeactivateNode requests a node to get deactivated
|
||||
func (s *PermissionAPI) ProposeNodeBlacklisting(nodeId string, txa ethapi.SendTxArgs) bool {
|
||||
return s.executePermAction(ProposeNodeBlacklisting, txArgs{nodeId: nodeId, txa: txa})
|
||||
}
|
||||
|
||||
// ApproveDeactivateNode approves a node to get deactivated
|
||||
func (s *PermissionAPI) ApproveNodeBlacklisting(nodeId string, txa ethapi.SendTxArgs) bool {
|
||||
return s.executePermAction(ApproveNodeBlacklisting, txArgs{nodeId: nodeId, txa: txa})
|
||||
}
|
||||
// RemoveOrgKey removes an org key combination from the org key map
|
||||
func (s *PermissionAPI) RemoveOrgKey(orgId string, pvtKey string, txa ethapi.SendTxArgs) bool {
|
||||
return s.executeOrgKeyAction(RemoveOrgKey, txArgs{txa: txa, orgId: orgId, keyId: pvtKey})
|
||||
|
@ -138,19 +161,24 @@ func (s *PermissionAPI) executePermAction(action PermAction, args txArgs) bool {
|
|||
case RemoveVoter:
|
||||
tx, err = ps.RemoveVoter(args.voter)
|
||||
case ProposeNode:
|
||||
node, err := discover.ParseNode(args.nodeId)
|
||||
if err != nil {
|
||||
log.Error("invalid node id: %v", err)
|
||||
if checkVoterExists(ps){
|
||||
node, err := discover.ParseNode(args.nodeId)
|
||||
if err != nil {
|
||||
log.Error("invalid node id: %v", err)
|
||||
return false
|
||||
}
|
||||
enodeID := node.ID.String()
|
||||
ipAddr := node.IP.String()
|
||||
port := fmt.Sprintf("%v", node.TCP)
|
||||
discPort := fmt.Sprintf("%v", node.UDP)
|
||||
raftPort := fmt.Sprintf("%v", node.RaftPort)
|
||||
ipAddrPort := ipAddr + ":" + port
|
||||
|
||||
tx, err = ps.ProposeNode(enodeID, ipAddrPort, discPort, raftPort)
|
||||
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
enodeID := node.ID.String()
|
||||
ipAddr := node.IP.String()
|
||||
port := fmt.Sprintf("%v", node.TCP)
|
||||
discPort := fmt.Sprintf("%v", node.UDP)
|
||||
raftPort := fmt.Sprintf("%v", node.RaftPort)
|
||||
ipAddrPort := ipAddr + ":" + port
|
||||
|
||||
tx, err = ps.ProposeNode(enodeID, ipAddrPort, discPort, raftPort)
|
||||
case ApproveNode:
|
||||
node, err := discover.ParseNode(args.nodeId)
|
||||
if err != nil {
|
||||
|
@ -159,7 +187,19 @@ func (s *PermissionAPI) executePermAction(action PermAction, args txArgs) bool {
|
|||
}
|
||||
enodeID := node.ID.String()
|
||||
tx, err = ps.ApproveNode(enodeID)
|
||||
case DeactivateNode:
|
||||
case ProposeNodeDeactivation:
|
||||
if checkVoterExists(ps){
|
||||
node, err := discover.ParseNode(args.nodeId)
|
||||
if err != nil {
|
||||
log.Error("invalid node id: %v", err)
|
||||
return false
|
||||
}
|
||||
enodeID := node.ID.String()
|
||||
tx, err = ps.ProposeDeactivation(enodeID)
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
case ApproveNodeDeactivation:
|
||||
node, err := discover.ParseNode(args.nodeId)
|
||||
if err != nil {
|
||||
log.Error("invalid node id: %v", err)
|
||||
|
@ -167,15 +207,52 @@ func (s *PermissionAPI) executePermAction(action PermAction, args txArgs) bool {
|
|||
}
|
||||
enodeID := node.ID.String()
|
||||
tx, err = ps.DeactivateNode(enodeID)
|
||||
case ApproveDeactivateNode:
|
||||
case ProposeNodeActivation:
|
||||
if checkVoterExists(ps){
|
||||
node, err := discover.ParseNode(args.nodeId)
|
||||
if err != nil {
|
||||
log.Error("invalid node id: %v", err)
|
||||
return false
|
||||
}
|
||||
enodeID := node.ID.String()
|
||||
tx, err = ps.ProposeNodeActivation(enodeID)
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
case ApproveNodeActivation:
|
||||
node, err := discover.ParseNode(args.nodeId)
|
||||
if err != nil {
|
||||
log.Error("invalid node id: %v", err)
|
||||
return false
|
||||
}
|
||||
enodeID := node.ID.String()
|
||||
//TODO change to approve deactivate node
|
||||
tx, err = ps.DeactivateNode(enodeID)
|
||||
tx, err = ps.ActivateNode(enodeID)
|
||||
case ProposeNodeBlacklisting:
|
||||
if checkVoterExists(ps){
|
||||
node, err := discover.ParseNode(args.nodeId)
|
||||
if err != nil {
|
||||
log.Error("invalid node id: %v", err)
|
||||
return false
|
||||
}
|
||||
enodeID := node.ID.String()
|
||||
ipAddr := node.IP.String()
|
||||
port := fmt.Sprintf("%v", node.TCP)
|
||||
discPort := fmt.Sprintf("%v", node.UDP)
|
||||
raftPort := fmt.Sprintf("%v", node.RaftPort)
|
||||
ipAddrPort := ipAddr + ":" + port
|
||||
|
||||
tx, err = ps.ProposeNodeBlacklisting(enodeID, ipAddrPort, discPort, raftPort)
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
case ApproveNodeBlacklisting:
|
||||
node, err := discover.ParseNode(args.nodeId)
|
||||
if err != nil {
|
||||
log.Error("invalid node id: %v", err)
|
||||
return false
|
||||
}
|
||||
enodeID := node.ID.String()
|
||||
tx, err = ps.BlacklistNode(enodeID)
|
||||
|
||||
}
|
||||
if err != nil {
|
||||
|
@ -219,6 +296,17 @@ func (s *PermissionAPI) validateAccount(from common.Address) (accounts.Wallet, e
|
|||
return w, nil
|
||||
}
|
||||
|
||||
// checkVoterExists checks if any vote accounts are there. If yes returns true, else false
|
||||
func checkVoterExists(ps *pbind.PermissionsSession) bool {
|
||||
log.Info("SMK-checkVoterExists @230")
|
||||
tx, err := ps.GetNumberOfVoters()
|
||||
if err == nil && tx.Cmp(big.NewInt(0)) > 0 {
|
||||
log.Info("SMK-checkVoterExists @233 voter found")
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// newPermSession creates a new permission contract session
|
||||
func (s *PermissionAPI) newPermSession(w accounts.Wallet, txa ethapi.SendTxArgs) *pbind.PermissionsSession {
|
||||
frmAcct, transactOpts, gasLimit, gasPrice, nonce := s.getTxParams(txa, w)
|
||||
|
|
|
@ -396,6 +396,7 @@ func (s *PrivateAccountAPI) SendTransaction(ctx context.Context, args SendTxArgs
|
|||
if len(data) > 0 {
|
||||
log.Info("sending private tx", "data", fmt.Sprintf("%x", data), "privatefrom", args.PrivateFrom, "privatefor", privateFor)
|
||||
data, err := private.P.Send(data, args.PrivateFrom, args.PrivateFor)
|
||||
log.Info("sent private tx", "data", fmt.Sprintf("%x", data), "privatefrom", args.PrivateFrom, "privatefor", privateFor)
|
||||
if err != nil {
|
||||
return common.Hash{}, err
|
||||
}
|
||||
|
@ -1280,6 +1281,7 @@ func (s *PublicTransactionPoolAPI) SendTransaction(ctx context.Context, args Sen
|
|||
if len(data) > 0 {
|
||||
log.Info("sending private tx", "data", fmt.Sprintf("%x", data), "privatefrom", args.PrivateFrom, "privatefor", privateFor)
|
||||
data, err = private.P.Send(data, args.PrivateFrom, privateFor)
|
||||
log.Info("sent private tx", "data", fmt.Sprintf("%x", data), "privatefrom", args.PrivateFrom, "privatefor", privateFor)
|
||||
if err != nil {
|
||||
return common.Hash{}, err
|
||||
}
|
||||
|
|
|
@ -708,14 +708,38 @@ web3._extend({
|
|||
inputFormatter: [null,web3._extend.formatters.inputTransactionFormatter]
|
||||
}),
|
||||
new web3._extend.Method({
|
||||
name: 'deactivateNode',
|
||||
call: 'quorum_deactivateNode',
|
||||
name: 'proposeNodeDeactivation',
|
||||
call: 'quorum_proposeNodeDeactivation',
|
||||
params: 2,
|
||||
inputFormatter: [null,web3._extend.formatters.inputTransactionFormatter]
|
||||
}),
|
||||
new web3._extend.Method({
|
||||
name: 'approveDeactivateNode',
|
||||
call: 'quorum_approveDeactivateNode',
|
||||
name: 'approveNodeDeactivation',
|
||||
call: 'quorum_approveNodeDeactivation',
|
||||
params: 2,
|
||||
inputFormatter: [null,web3._extend.formatters.inputTransactionFormatter]
|
||||
}),
|
||||
new web3._extend.Method({
|
||||
name: 'proposeNodeActivation',
|
||||
call: 'quorum_proposeNodeActivation',
|
||||
params: 2,
|
||||
inputFormatter: [null,web3._extend.formatters.inputTransactionFormatter]
|
||||
}),
|
||||
new web3._extend.Method({
|
||||
name: 'approveNodeActivation',
|
||||
call: 'quorum_approveNodeActivation',
|
||||
params: 2,
|
||||
inputFormatter: [null,web3._extend.formatters.inputTransactionFormatter]
|
||||
}),
|
||||
new web3._extend.Method({
|
||||
name: 'proposeNodeBlacklisting',
|
||||
call: 'quorum_proposeNodeBlacklisting',
|
||||
params: 2,
|
||||
inputFormatter: [null,web3._extend.formatters.inputTransactionFormatter]
|
||||
}),
|
||||
new web3._extend.Method({
|
||||
name: 'approveNodeBlacklisting',
|
||||
call: 'quorum_approveNodeBlacklisting',
|
||||
params: 2,
|
||||
inputFormatter: [null,web3._extend.formatters.inputTransactionFormatter]
|
||||
}),
|
||||
|
|
Loading…
Reference in New Issue