Skip to content

Commit

Permalink
Update StakeManager
Browse files Browse the repository at this point in the history
  • Loading branch information
ironbeer committed Nov 28, 2024
1 parent 0549050 commit 4415e66
Show file tree
Hide file tree
Showing 8 changed files with 1,936 additions and 193 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ jobs:
- name: Checkout Code
uses: actions/checkout@v2

- name: Setup Go 1.17
- name: Setup Go 1.22
if: matrix.arch == 'amd64'
uses: actions/setup-go@v1
with:
go-version: 1.17
go-version: 1.22

- name: Build Binary - ${{ matrix.os }} ${{ matrix.arch }}
if: matrix.arch == 'amd64'
Expand All @@ -46,13 +46,13 @@ jobs:
-w ${{ github.workspace }} \
-e GOOS=${{ matrix.os }} \
-e GOARCH=${{ matrix.arch }} \
arm64v8/golang:1.17.8-buster go build -o oaspos
arm64v8/golang:1.22.9-bullseye go build -o oaspos
- name: Compress Binary
run: zip oaspos-${{ matrix.os }}-${{ matrix.arch }}.zip ./oaspos

- name: Upload Artifact
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: ${{ github.ref_name }}
path: oaspos-${{ matrix.os }}-${{ matrix.arch }}.zip
Expand All @@ -66,7 +66,7 @@ jobs:
uses: actions/checkout@v2

- name: Download Artifact
uses: actions/download-artifact@v2
uses: actions/download-artifact@v4
with:
name: ${{ github.ref_name }}
path: artifacts
Expand Down
2 changes: 1 addition & 1 deletion cmd/staker/showRewards.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func doRewards(ec *ethclient.Client, staker common.Address) {
utils.Fatal(err)
}

validators, _, _, _, err := cmdutils.GetValidators(ctx, stakemanager, common.Big0)
validators, _, _, _, _, err := cmdutils.GetValidators(ctx, stakemanager, common.Big0)
if err != nil {
utils.Fatal(err)
}
Expand Down
4 changes: 3 additions & 1 deletion cmd/utils/stakemanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func GetValidators(
) (
owners []common.Address,
operators []common.Address,
blsPublicKeys [][]byte,
stakes []*big.Int,
candidates []bool,
err error,
Expand All @@ -28,7 +29,7 @@ func GetValidators(
for {
result, err := stakemanager.GetValidators(callOpts, epoch, cursor, howMany)
if err != nil {
return nil, nil, nil, nil, err
return nil, nil, nil, nil, nil, err
}
if len(result.Owners) == 0 {
break
Expand All @@ -37,6 +38,7 @@ func GetValidators(
cursor = result.NewCursor
owners = append(owners, result.Owners...)
operators = append(operators, result.Operators...)
blsPublicKeys = append(blsPublicKeys, result.BlsPublicKeys...)
stakes = append(stakes, result.Stakes...)
candidates = append(candidates, result.Candidates...)
}
Expand Down
3 changes: 3 additions & 0 deletions cmd/validator/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/spf13/cobra"

Expand Down Expand Up @@ -97,8 +98,10 @@ func doInfo(ec *ethclient.Client, validator common.Address) {

fmt.Printf("%s : %s\n", rightPad("Joined"), b2s(joined))
fmt.Printf("%s : %s\n", rightPad("Status"), status)
fmt.Printf("%s : %s\n", rightPad("Candidate"), b2s(currentInfo.Candidate))
fmt.Printf("%s : %s\n", rightPad("Jailed"), b2s(currentInfo.Jailed))
fmt.Printf("%s : %s\n", rightPad("Operator Address"), currentInfo.Operator.String())
fmt.Printf("%s : %s\n", rightPad("BLS Public Key"), hexutil.Encode(currentInfo.BlsPublicKey))
fmt.Printf("%s : %s\n", rightPad("Commissions"), utils.FormatWei(commissions))
fmt.Printf("%s : %s\n", rightPad("Current Epoch Staking"), utils.FormatWei(currentInfo.Stakes))
fmt.Printf("%s : %s\n", rightPad("Next Epoch Staking"), utils.FormatWei(nextInfo.Stakes))
Expand Down
47 changes: 17 additions & 30 deletions cmd/validator/infoAll.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package validator

import (
"context"
"math/big"
"os"
"time"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/olekukonko/tablewriter"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -60,60 +60,47 @@ func doInfoAll(ec *ethclient.Client, showNextEpoch bool) {
epoch.Add(epoch, common.Big1)
}

validators, _, _, _, err := cmdutils.GetValidators(ctx, stakemanager, epoch)
owners, operators, blsPublicKeys, stakes, candidates, err := cmdutils.GetValidators(ctx, stakemanager, epoch)
if err != nil {
utils.Fatal(err)
}

type info struct {
operator common.Address
active bool
jailed bool
stakes *big.Int
}

infos := map[common.Address]*info{}
for _, validator := range validators {
result1, err := stakemanager.GetValidatorInfo(callOpts, validator, epoch)
if err != nil {
utils.Fatal(err)
}
infos[validator] = &info{
active: result1.Active,
jailed: result1.Jailed,
stakes: result1.Stakes,
}

result2, err := stakemanager.Validators(callOpts, validator)
actives := make([]bool, len(owners))
jails := make([]bool, len(owners))
for i, owner := range owners {
info, err := stakemanager.GetValidatorInfo(callOpts, owner, epoch)
if err != nil {
utils.Fatal(err)
}
infos[validator].operator = result2.Operator
actives[i] = info.Active
jails[i] = info.Jailed
}

table := tablewriter.NewWriter(os.Stdout)
table.SetAutoFormatHeaders(false)
table.SetHeader([]string{
"Owner",
"Operator",
"BLS Public Key",
"Total Stake",
"Status",
"Candidate",
"Jailed",
})
for _, owner := range validators {
info := infos[owner]

for i, owner := range owners {
status := "active"
if !info.active {
if !actives[i] {
status = "inactive"
}

table.Append([]string{
owner.String(),
info.operator.String(),
utils.FormatWei(info.stakes),
operators[i].String(),
hexutil.Encode(blsPublicKeys[i]),
utils.FormatWei(stakes[i]),
status,
b2s(info.jailed),
b2s(candidates[i]),
b2s(jails[i]),
})
}
table.Render()
Expand Down
2,024 changes: 1,870 additions & 154 deletions contracts/stakemanager/stakemanager.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/oasysgames/oasys-pos-cli

go 1.17
go 1.22

require (
github.com/ethereum/go-ethereum v1.10.17
Expand All @@ -27,4 +27,4 @@ require (
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 // indirect
golang.org/x/sys v0.0.0-20210816183151-1e6c022a8912 // indirect
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
)
)
Loading

0 comments on commit 4415e66

Please sign in to comment.