Skip to content

Commit

Permalink
1.5.2 (#743)
Browse files Browse the repository at this point in the history
* fix main net fee split bug

* update bug fix

* add address check when authorize
  • Loading branch information
siovanus authored and tanZiWen committed Feb 5, 2019
1 parent f5993db commit 5de0ee5
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions smartcontract/service/native/governance/method.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,11 @@ func authorizeForPeer(native *native.NativeService, flag string) error {
return fmt.Errorf("getPeerAttributes error: %v", err)
}

//check if address is pee owner address
if params.Address == peerPoolItem.Address {
return fmt.Errorf("authorizeForPeer error, address can not be node owner")
}

authorizeInfo, err := getAuthorizeInfo(native, contract, peerPubkey, params.Address)
if err != nil {
return fmt.Errorf("getAuthorizeInfo, get authorizeInfo error: %v", err)
Expand Down Expand Up @@ -920,15 +925,15 @@ func executeSplit2(native *native.NativeService, contract common.Address, view u
return splitSum, nil
}

func executeAddressSplit(native *native.NativeService, contract common.Address, authorizeInfo *AuthorizeInfo, ifConsensus bool, totalPos uint64, totalAmount uint64) (uint64, error) {
func executeAddressSplit(native *native.NativeService, contract common.Address, authorizeInfo *AuthorizeInfo, ifConsensus bool, totalPos uint64, totalAmount uint64, peerAddress common.Address) (uint64, error) {
var validatePos uint64
if ifConsensus {
validatePos = authorizeInfo.ConsensusPos + authorizeInfo.WithdrawConsensusPos
} else {
validatePos = authorizeInfo.CandidatePos + authorizeInfo.WithdrawCandidatePos
}

if validatePos == 0 {
if validatePos == 0 || authorizeInfo.Address == peerAddress {
return 0, nil
}
amount := validatePos * totalAmount / totalPos
Expand Down Expand Up @@ -1290,7 +1295,7 @@ func splitNodeFee(native *native.NativeService, contract common.Address, peerPub
}

//fee split
splitAmount, err := executeAddressSplit(native, contract, &authorizeInfo, ifConsensus, totalPos, amount)
splitAmount, err := executeAddressSplit(native, contract, &authorizeInfo, ifConsensus, totalPos, amount, peerAddress)
if err != nil {
return fmt.Errorf("excuteAddressSplit, excuteAddressSplit error: %v", err)
}
Expand Down

0 comments on commit 5de0ee5

Please sign in to comment.