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/core/types"
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/event"
|
"github.com/ethereum/go-ethereum/event"
|
||||||
"github.com/ethereum/go-ethereum/log"
|
|
||||||
"github.com/ethereum/go-ethereum/rlp"
|
"github.com/ethereum/go-ethereum/rlp"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -298,7 +298,7 @@ func (p *PermissionCtrl) populatePermissionedNodes() error {
|
||||||
opts := &bind.FilterOpts{}
|
opts := &bind.FilterOpts{}
|
||||||
pastAddEvent, err := p.pm.PermissionsFilterer.FilterNodeApproved(opts)
|
pastAddEvent, err := p.pm.PermissionsFilterer.FilterNodeApproved(opts)
|
||||||
|
|
||||||
if err != nil {
|
if err == nil {
|
||||||
recExists := true
|
recExists := true
|
||||||
for recExists {
|
for recExists {
|
||||||
recExists = pastAddEvent.Next()
|
recExists = pastAddEvent.Next()
|
||||||
|
@ -310,7 +310,7 @@ func (p *PermissionCtrl) populatePermissionedNodes() error {
|
||||||
|
|
||||||
opts = &bind.FilterOpts{}
|
opts = &bind.FilterOpts{}
|
||||||
pastDelEvent, err := p.pm.PermissionsFilterer.FilterNodeDeactivated(opts)
|
pastDelEvent, err := p.pm.PermissionsFilterer.FilterNodeDeactivated(opts)
|
||||||
if err != nil {
|
if err == nil {
|
||||||
recExists := true
|
recExists := true
|
||||||
for recExists {
|
for recExists {
|
||||||
recExists = pastDelEvent.Next()
|
recExists = pastDelEvent.Next()
|
||||||
|
|
|
@ -29,8 +29,12 @@ type PermAction int
|
||||||
const (
|
const (
|
||||||
ProposeNode PermAction = iota
|
ProposeNode PermAction = iota
|
||||||
ApproveNode
|
ApproveNode
|
||||||
DeactivateNode
|
ProposeNodeDeactivation
|
||||||
ApproveDeactivateNode
|
ApproveNodeDeactivation
|
||||||
|
ProposeNodeActivation
|
||||||
|
ApproveNodeActivation
|
||||||
|
ProposeNodeBlacklisting
|
||||||
|
ApproveNodeBlacklisting
|
||||||
AddVoter
|
AddVoter
|
||||||
RemoveVoter
|
RemoveVoter
|
||||||
)
|
)
|
||||||
|
@ -104,15 +108,34 @@ func (s *PermissionAPI) ApproveNode(nodeId string, txa ethapi.SendTxArgs) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeactivateNode requests a node to get deactivated
|
// DeactivateNode requests a node to get deactivated
|
||||||
func (s *PermissionAPI) DeactivateNode(nodeId string, txa ethapi.SendTxArgs) bool {
|
func (s *PermissionAPI) ProposeNodeDeactivation(nodeId string, txa ethapi.SendTxArgs) bool {
|
||||||
return s.executePermAction(DeactivateNode, txArgs{nodeId: nodeId, txa: txa})
|
return s.executePermAction(ProposeNodeDeactivation, txArgs{nodeId: nodeId, txa: txa})
|
||||||
}
|
}
|
||||||
|
|
||||||
// ApproveDeactivateNode approves a node to get deactivated
|
// ApproveDeactivateNode approves a node to get deactivated
|
||||||
func (s *PermissionAPI) ApproveDeactivateNode(nodeId string, txa ethapi.SendTxArgs) bool {
|
func (s *PermissionAPI) ApproveNodeDeactivation(nodeId string, txa ethapi.SendTxArgs) bool {
|
||||||
return s.executePermAction(ApproveDeactivateNode, txArgs{nodeId: nodeId, txa: txa})
|
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
|
// RemoveOrgKey removes an org key combination from the org key map
|
||||||
func (s *PermissionAPI) RemoveOrgKey(orgId string, pvtKey string, txa ethapi.SendTxArgs) bool {
|
func (s *PermissionAPI) RemoveOrgKey(orgId string, pvtKey string, txa ethapi.SendTxArgs) bool {
|
||||||
return s.executeOrgKeyAction(RemoveOrgKey, txArgs{txa: txa, orgId: orgId, keyId: pvtKey})
|
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:
|
case RemoveVoter:
|
||||||
tx, err = ps.RemoveVoter(args.voter)
|
tx, err = ps.RemoveVoter(args.voter)
|
||||||
case ProposeNode:
|
case ProposeNode:
|
||||||
node, err := discover.ParseNode(args.nodeId)
|
if checkVoterExists(ps){
|
||||||
if err != nil {
|
node, err := discover.ParseNode(args.nodeId)
|
||||||
log.Error("invalid node id: %v", err)
|
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
|
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:
|
case ApproveNode:
|
||||||
node, err := discover.ParseNode(args.nodeId)
|
node, err := discover.ParseNode(args.nodeId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -159,7 +187,19 @@ func (s *PermissionAPI) executePermAction(action PermAction, args txArgs) bool {
|
||||||
}
|
}
|
||||||
enodeID := node.ID.String()
|
enodeID := node.ID.String()
|
||||||
tx, err = ps.ApproveNode(enodeID)
|
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)
|
node, err := discover.ParseNode(args.nodeId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("invalid node id: %v", err)
|
log.Error("invalid node id: %v", err)
|
||||||
|
@ -167,15 +207,52 @@ func (s *PermissionAPI) executePermAction(action PermAction, args txArgs) bool {
|
||||||
}
|
}
|
||||||
enodeID := node.ID.String()
|
enodeID := node.ID.String()
|
||||||
tx, err = ps.DeactivateNode(enodeID)
|
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)
|
node, err := discover.ParseNode(args.nodeId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("invalid node id: %v", err)
|
log.Error("invalid node id: %v", err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
enodeID := node.ID.String()
|
enodeID := node.ID.String()
|
||||||
//TODO change to approve deactivate node
|
tx, err = ps.ActivateNode(enodeID)
|
||||||
tx, err = ps.DeactivateNode(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 {
|
if err != nil {
|
||||||
|
@ -219,6 +296,17 @@ func (s *PermissionAPI) validateAccount(from common.Address) (accounts.Wallet, e
|
||||||
return w, nil
|
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
|
// newPermSession creates a new permission contract session
|
||||||
func (s *PermissionAPI) newPermSession(w accounts.Wallet, txa ethapi.SendTxArgs) *pbind.PermissionsSession {
|
func (s *PermissionAPI) newPermSession(w accounts.Wallet, txa ethapi.SendTxArgs) *pbind.PermissionsSession {
|
||||||
frmAcct, transactOpts, gasLimit, gasPrice, nonce := s.getTxParams(txa, w)
|
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 {
|
if len(data) > 0 {
|
||||||
log.Info("sending private tx", "data", fmt.Sprintf("%x", data), "privatefrom", args.PrivateFrom, "privatefor", privateFor)
|
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)
|
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 {
|
if err != nil {
|
||||||
return common.Hash{}, err
|
return common.Hash{}, err
|
||||||
}
|
}
|
||||||
|
@ -1280,6 +1281,7 @@ func (s *PublicTransactionPoolAPI) SendTransaction(ctx context.Context, args Sen
|
||||||
if len(data) > 0 {
|
if len(data) > 0 {
|
||||||
log.Info("sending private tx", "data", fmt.Sprintf("%x", data), "privatefrom", args.PrivateFrom, "privatefor", privateFor)
|
log.Info("sending private tx", "data", fmt.Sprintf("%x", data), "privatefrom", args.PrivateFrom, "privatefor", privateFor)
|
||||||
data, err = private.P.Send(data, args.PrivateFrom, 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 {
|
if err != nil {
|
||||||
return common.Hash{}, err
|
return common.Hash{}, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -708,14 +708,38 @@ web3._extend({
|
||||||
inputFormatter: [null,web3._extend.formatters.inputTransactionFormatter]
|
inputFormatter: [null,web3._extend.formatters.inputTransactionFormatter]
|
||||||
}),
|
}),
|
||||||
new web3._extend.Method({
|
new web3._extend.Method({
|
||||||
name: 'deactivateNode',
|
name: 'proposeNodeDeactivation',
|
||||||
call: 'quorum_deactivateNode',
|
call: 'quorum_proposeNodeDeactivation',
|
||||||
params: 2,
|
params: 2,
|
||||||
inputFormatter: [null,web3._extend.formatters.inputTransactionFormatter]
|
inputFormatter: [null,web3._extend.formatters.inputTransactionFormatter]
|
||||||
}),
|
}),
|
||||||
new web3._extend.Method({
|
new web3._extend.Method({
|
||||||
name: 'approveDeactivateNode',
|
name: 'approveNodeDeactivation',
|
||||||
call: 'quorum_approveDeactivateNode',
|
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,
|
params: 2,
|
||||||
inputFormatter: [null,web3._extend.formatters.inputTransactionFormatter]
|
inputFormatter: [null,web3._extend.formatters.inputTransactionFormatter]
|
||||||
}),
|
}),
|
||||||
|
|
Loading…
Reference in New Issue