Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implementing pip-8 #711

Merged
merged 3 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,16 @@ linters-settings:
nonamedreturns:
# Report named error if it is assigned inside defer.
# Default: false
report-error-in-defer: false
report-error-in-defer: false

issues:
exclude-rules:
# disable funlen for all _test.go files
- path: _test.go
linters:
- funlen
- maintidx

- linters:
- govet
text: "shadow: declaration of \"err\" shadows"

20 changes: 10 additions & 10 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ func CreateNode(numValidators int, chain genesis.ChainType, workingDir string,

validatorAddrs := []string{}
for i := 0; i < numValidators; i++ {
addr, err := walletInstance.DeriveNewAddress(fmt.Sprintf("Validator address %v", i+1))
addr, err := walletInstance.NewValidatorAddress(fmt.Sprintf("Validator address %v", i+1))
if err != nil {
return nil, nil, err
}
Expand All @@ -276,7 +276,7 @@ func CreateNode(numValidators int, chain genesis.ChainType, workingDir string,

rewardAddrs := []string{}
for i := 0; i < numValidators; i++ {
addr, err := walletInstance.DeriveNewAddress(fmt.Sprintf("Reward address %v", i+1))
addr, err := walletInstance.NewBLSAccountAddress(fmt.Sprintf("Reward address %v", i+1))
if err != nil {
return nil, nil, err
}
Expand Down Expand Up @@ -394,7 +394,7 @@ func StartNode(workingDir string, passwordFetcher func(*wallet.Wallet) (string,
if err != nil {
return nil, nil, err
}
addrLabels := walletInstance.AddressLabels()
addrLabels := walletInstance.AddressInfos()

// Create signers
if len(addrLabels) < conf.Node.NumValidators {
Expand All @@ -404,7 +404,7 @@ func StartNode(workingDir string, passwordFetcher func(*wallet.Wallet) (string,
for i := 0; i < conf.Node.NumValidators; i++ {
validatorAddrs[i] = addrLabels[i].Address
}
signers := make([]crypto.Signer, conf.Node.NumValidators)
valKeys := make([]*bls.ValidatorKey, conf.Node.NumValidators)
password, ok := passwordFetcher(walletInstance)
if !ok {
return nil, nil, fmt.Errorf("aborted")
Expand All @@ -413,8 +413,8 @@ func StartNode(workingDir string, passwordFetcher func(*wallet.Wallet) (string,
if err != nil {
return nil, nil, err
}
for i, key := range prvKeys {
signers[i] = crypto.NewSigner(key)
for i, prv := range prvKeys {
valKeys[i] = bls.NewValidatorKey(prv.(*bls.PrivateKey))
}

// Create reward addresses
Expand All @@ -432,7 +432,7 @@ func StartNode(workingDir string, passwordFetcher func(*wallet.Wallet) (string,
}
}

nodeInstance, err := node.NewNode(gen, conf, signers, rewardAddrs)
nodeInstance, err := node.NewNode(gen, conf, valKeys, rewardAddrs)
if err != nil {
return nil, nil, err
}
Expand All @@ -456,9 +456,9 @@ func makeLocalGenesis(w wallet.Wallet) *genesis.Genesis {

vals := make([]*validator.Validator, 4)
for i := 0; i < 4; i++ {
ai := w.AddressInfo(w.AddressLabels()[i].Address)
vals[i] = validator.NewValidator(
ai.Pub.(*bls.PublicKey), int32(i))
info := w.AddressInfo(w.AddressInfos()[i].Address)
pub, _ := bls.PublicKeyFromString(info.PublicKey)
vals[i] = validator.NewValidator(pub, int32(i))
}

// create genesis
Expand Down
4 changes: 2 additions & 2 deletions cmd/gtk/dialog_addresss_details.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ func showAddressDetails(wallet *wallet.Wallet, addr string) {
pathEntry := getEntryObj(builder, "id_entry_path")

addressEntry.SetText(info.Address)
pubKeyEntry.SetText(info.Pub.String())
pathEntry.SetText(info.Path.String())
pubKeyEntry.SetText(info.PublicKey)
pathEntry.SetText(info.Path)

getButtonObj(builder, "id_button_close").SetImage(CloseIcon())

Expand Down
2 changes: 1 addition & 1 deletion cmd/gtk/dialog_transaction_bond.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func broadcastTransactionBond(wallet *wallet.Wallet, valAddrs []crypto.Address)
getButtonObj(builder, "id_button_cancel").SetImage(CancelIcon())
getButtonObj(builder, "id_button_send").SetImage(SendIcon())

for _, i := range wallet.AddressLabels() {
for _, i := range wallet.AddressInfos() {
senderEntry.Append(i.Address, i.Address)
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/gtk/dialog_transaction_transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func broadcastTransactionSend(wallet *wallet.Wallet) {
getButtonObj(builder, "id_button_cancel").SetImage(CancelIcon())
getButtonObj(builder, "id_button_send").SetImage(SendIcon())

for _, i := range wallet.AddressLabels() {
for _, i := range wallet.AddressInfos() {
senderEntry.Append(i.Address, i.Address)
}
senderEntry.SetActive(0)
Expand Down
2 changes: 1 addition & 1 deletion cmd/gtk/main_window.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (mw *mainWindow) OnTransactionBond() {
valAddrs := []crypto.Address{}
consMgr := mw.widgetNode.model.node.ConsManager()
for _, inst := range consMgr.Instances() {
valAddrs = append(valAddrs, inst.SignerKey().Address())
valAddrs = append(valAddrs, inst.ConsensusKey().ValidatorAddress())
}
broadcastTransactionBond(mw.widgetWallet.model.wallet, valAddrs)
}
6 changes: 3 additions & 3 deletions cmd/gtk/model_wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ func (model *walletModel) ToTreeModel() *gtk.TreeModel {
func (model *walletModel) rebuildModel() {
go func() {
data := [][]string{}
for no, info := range model.wallet.AddressLabels() {
for no, info := range model.wallet.AddressInfos() {
label := info.Label
if info.Imported {
if info.Path == "" {
label += "(Imported)"
}

Expand Down Expand Up @@ -86,7 +86,7 @@ func (model *walletModel) rebuildModel() {
}

func (model *walletModel) createAddress() error {
address, err := model.wallet.DeriveNewAddress("")
address, err := model.wallet.NewBLSAccountAddress("")
if err != nil {
return err
}
Expand Down
15 changes: 7 additions & 8 deletions cmd/wallet/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func buildAllAddressesCmd(parentCmd *cobra.Command) {
cmd.FatalErrorCheck(err)

cmd.PrintLine()
for i, info := range wallet.AddressLabels() {
for i, info := range wallet.AddressInfos() {
line := fmt.Sprintf("%v- %s\t", i+1, info.Address)

if *balanceOpt {
Expand All @@ -59,7 +59,7 @@ func buildAllAddressesCmd(parentCmd *cobra.Command) {
}

line += info.Label
if info.Imported {
if info.Path == "" {
line += " (Imported)"
}

Expand All @@ -81,7 +81,7 @@ func buildNewAddressCmd(parentCmd *cobra.Command) {
wallet, err := openWallet()
cmd.FatalErrorCheck(err)

addr, err := wallet.DeriveNewAddress(label)
addr, err := wallet.NewBLSAccountAddress(label)
cmd.FatalErrorCheck(err)

err = wallet.Save()
Expand Down Expand Up @@ -167,9 +167,9 @@ func buildPublicKeyCmd(parentCmd *cobra.Command) {
}

cmd.PrintLine()
cmd.PrintInfoMsgf("Public Key: %v", info.Pub.String())
if !info.Imported {
cmd.PrintInfoMsgf("Path: %v", info.Path.String())
cmd.PrintInfoMsgf("Public Key: %v", info.PublicKey)
if info.Path != "" {
cmd.PrintInfoMsgf("Path: %v", info.Path)
}
}
}
Expand Down Expand Up @@ -201,8 +201,7 @@ func buildImportPrivateKeyCmd(parentCmd *cobra.Command) {
cmd.FatalErrorCheck(err)

cmd.PrintLine()
cmd.PrintSuccessMsgf("Private Key imported. Address: %v",
prv.PublicKey().Address())
cmd.PrintSuccessMsgf("Private Key imported.") // TODO: display imported addresses
}
}

Expand Down
6 changes: 3 additions & 3 deletions committee/committee.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func NewCommittee(validators []*validator.Validator, committeeSize int,

for _, val := range validators {
el := validatorList.InsertAtTail(cloneValidator(val))
if val.Address().EqualsTo(proposerAddress) {
if val.Address() == proposerAddress {
proposerPos = el
}
}
Expand Down Expand Up @@ -133,7 +133,7 @@ func (c *committee) Contains(addr crypto.Address) bool {
func (c *committee) find(addr crypto.Address) *validator.Validator {
var found *validator.Validator
c.iterate(func(v *validator.Validator) bool {
if v.Address().EqualsTo(addr) {
if v.Address() == addr {
found = v
return true
}
Expand All @@ -145,7 +145,7 @@ func (c *committee) find(addr crypto.Address) *validator.Validator {
// IsProposer checks if the given address is the proposer for the specified round.
func (c *committee) IsProposer(addr crypto.Address, round int16) bool {
p := c.proposer(round)
return p.Address().EqualsTo(addr)
return p.Address() == addr
}

// Proposer returns an instance of the proposer validator for the specified round.
Expand Down
8 changes: 4 additions & 4 deletions committee/committee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import (
func TestContains(t *testing.T) {
ts := testsuite.NewTestSuite(t)

committee, signers := ts.GenerateTestCommittee(21)
nonExist := ts.RandAddress()
committee, valKeys := ts.GenerateTestCommittee(21)
nonExist := ts.RandAccAddress()

assert.True(t, committee.Contains(signers[0].Address()))
assert.True(t, committee.Contains(valKeys[0].Address()))
assert.False(t, committee.Contains(nonExist))
}

Expand Down Expand Up @@ -331,7 +331,7 @@ func TestIsProposer(t *testing.T) {
assert.Equal(t, committee.Proposer(1).Number(), int32(1))
assert.True(t, committee.IsProposer(val3.Address(), 2))
assert.False(t, committee.IsProposer(val4.Address(), 2))
assert.False(t, committee.IsProposer(ts.RandAddress(), 2))
assert.False(t, committee.IsProposer(ts.RandAccAddress(), 2))
assert.Equal(t, committee.Validators(), []*validator.Validator{val1, val2, val3, val4})
}

Expand Down
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type Config struct {
}

type NodeConfig struct {
NumValidators int `toml:"num_validators"`
NumValidators int `toml:"num_validators"` // TODO: we can remove this now
RewardAddresses []string `toml:"reward_addresses"`
}

Expand Down
8 changes: 4 additions & 4 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func TestNodeConfigBasicCheck(t *testing.T) {
t.Run("invalid number of reward addresses", func(t *testing.T) {
conf := DefaultNodeConfig()
conf.RewardAddresses = []string{
ts.RandAddress().String(),
ts.RandAccAddress().String(),
}

assert.Error(t, conf.BasicCheck())
Expand All @@ -104,7 +104,7 @@ func TestNodeConfigBasicCheck(t *testing.T) {
conf := DefaultNodeConfig()
conf.NumValidators = 2
conf.RewardAddresses = []string{
ts.RandAddress().String(),
ts.RandAccAddress().String(),
"abcd",
}

Expand All @@ -115,8 +115,8 @@ func TestNodeConfigBasicCheck(t *testing.T) {
conf := DefaultNodeConfig()
conf.NumValidators = 2
conf.RewardAddresses = []string{
ts.RandAddress().String(),
ts.RandAddress().String(),
ts.RandAccAddress().String(),
ts.RandAccAddress().String(),
}

assert.NoError(t, conf.BasicCheck())
Expand Down
Loading