Skip to content

Commit

Permalink
Fix/deprecated and simplify append to slice and paramenter call (#1178)
Browse files Browse the repository at this point in the history
* replace deprecated Pretty method with String

* simplify parameter signature

* simplify call when append to slice
  • Loading branch information
mariajdab authored Nov 6, 2023
1 parent 507cac0 commit 33998f9
Show file tree
Hide file tree
Showing 11 changed files with 16 additions and 20 deletions.
4 changes: 2 additions & 2 deletions api/censusdb/censusdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func (c *CensusDB) List() ([]*CensusList, error) {
c.Lock()
defer c.Unlock()
var list []*CensusList
if err := c.db.Iterate([]byte(censusDBreferencePrefix), func(key []byte, data []byte) bool {
if err := c.db.Iterate([]byte(censusDBreferencePrefix), func(key, data []byte) bool {
censusID := make([]byte, len(key))
copy(censusID, key)
dec := gob.NewDecoder(bytes.NewReader(data))
Expand Down Expand Up @@ -340,7 +340,7 @@ func (c *CensusDB) ExportCensusDB(buffer io.Writer) error {
c.Lock()
defer c.Unlock()
// Iterate through all census entries in the DB
err := c.db.Iterate([]byte(censusDBreferencePrefix), func(key []byte, data []byte) bool {
err := c.db.Iterate([]byte(censusDBreferencePrefix), func(key, data []byte) bool {
censusID := make([]byte, len(key))
copy(censusID, key)
dec := gob.NewDecoder(bytes.NewReader(data))
Expand Down
8 changes: 2 additions & 6 deletions api/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,12 +398,8 @@ func (a *API) walletElectionHandler(msg *apirest.APIdata, ctx *httprouter.HTTPCo
Description: question.Description,
Title: question.Title,
}
for _, choice := range question.Choices {
metaQuestion.Choices = append(metaQuestion.Choices, ChoiceMetadata{
Title: choice.Title,
Value: choice.Value,
})
}

metaQuestion.Choices = append(metaQuestion.Choices, question.Choices...)
metadata.Questions = append(metadata.Questions, metaQuestion)
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/cli/editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func GetPreferredEditorFromEnvironment() string {
return editor
}

func resolveEditorArguments(executable string, filename string) []string {
func resolveEditorArguments(executable, filename string) []string {
args := []string{filename}

if strings.Contains(executable, "Visual Studio Code.app") {
Expand Down
2 changes: 1 addition & 1 deletion data/ipfs/ipfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (i *Handler) Init(d *types.DataStore) error {
}
}()
log.Infow("IPFS initialization",
"peerID", node.Identity.Pretty(),
"peerID", node.Identity.String(),
"addresses", node.PeerHost.Addrs(),
"pubKey", node.PrivateKey.GetPublic(),
)
Expand Down
2 changes: 1 addition & 1 deletion db/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ type WriteTx interface {

// Set adds a key-value pair. If the key already exists, its value is
// updated.
Set(key []byte, value []byte) error
Set(key, value []byte) error
// Delete deletes a key and its value.
Delete(key []byte) error
// Apply applies the value-passed WriteTx into the given WriteTx,
Expand Down
2 changes: 1 addition & 1 deletion db/prefixeddb/prefixeddb.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (t *PrefixedWriteTx) Discard() {
}

// Set implements the db.WriteTx.Set interface method
func (t *PrefixedWriteTx) Set(key []byte, value []byte) error {
func (t *PrefixedWriteTx) Set(key, value []byte) error {
return t.tx.Set(prefixSlice(t.prefix, key), value)
}

Expand Down
2 changes: 1 addition & 1 deletion subpub/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (s *SubPub) discover(ctx context.Context) {
continue
}
cancel()
log.Infow("connected to cluster peer!", "address", peer.ID.Pretty())
log.Infow("connected to cluster peer!", "address", peer.ID.String())

// protect the peer from being disconnected by the connection manager
s.node.PeerHost.ConnManager().Protect(peer.ID, "discoveredPeer")
Expand Down
2 changes: 1 addition & 1 deletion subpub/gossipsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (s *SubPub) joinGossip(ctx context.Context, p2pPS *pubsub.PubSub, selfID pe
self: selfID,
Messages: make(chan *Message, GossipBufSize),
}
log.Infow("joined to gossipsub topic", "topic", sub.Topic(), "peer", selfID.Pretty())
log.Infow("joined to gossipsub topic", "topic", sub.Topic(), "peer", selfID.String())

// start reading messages from the subscription in a loop
go s.readGossipLoop() // this spawns a single background task per instance (since a single gossip topic is used)
Expand Down
2 changes: 1 addition & 1 deletion subpub/subpub.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (s *SubPub) Start(ctx context.Context, receiver chan *Message) {
log.Fatal("no group key provided")
}
ipfslog.SetLogLevel("*", "ERROR")
s.NodeID = s.node.PeerHost.ID().Pretty()
s.NodeID = s.node.PeerHost.ID().String()
s.messages = receiver
s.setupDiscovery(ctx)
s.setupGossip(ctx)
Expand Down
4 changes: 2 additions & 2 deletions test/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,8 @@ func TestAPIElectionCost(t *testing.T) {

func runAPIElectionCostWithParams(t *testing.T,
electionParams electionprice.ElectionParameters,
startBlock uint32, initialBalance uint64,
txCostNewProcess, networkCapacity uint64,
startBlock uint32, initialBalance,
txCostNewProcess, networkCapacity,
expectedPrice uint64,
) {
server := testcommon.APIserver{}
Expand Down
6 changes: 3 additions & 3 deletions types/big.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@ func (i *BigInt) MathBigInt() *big.Int {
}

// Add sum x+y
func (i *BigInt) Add(x *BigInt, y *BigInt) *BigInt {
func (i *BigInt) Add(x, y *BigInt) *BigInt {
return (*BigInt)(i.MathBigInt().Add(x.MathBigInt(), y.MathBigInt()))
}

// Sub subs x-y
func (i *BigInt) Sub(x *BigInt, y *BigInt) *BigInt {
func (i *BigInt) Sub(x, y *BigInt) *BigInt {
return (*BigInt)(i.MathBigInt().Sub(x.MathBigInt(), y.MathBigInt()))
}

// Mul multiplies x*y
func (i *BigInt) Mul(x *BigInt, y *BigInt) *BigInt {
func (i *BigInt) Mul(x, y *BigInt) *BigInt {
return (*BigInt)(i.MathBigInt().Mul(x.MathBigInt(), y.MathBigInt()))
}

Expand Down

0 comments on commit 33998f9

Please sign in to comment.