Skip to content

Commit

Permalink
Fix Usage of both value and pointer receivers
Browse files Browse the repository at this point in the history
  • Loading branch information
qdm12 committed Jan 16, 2023
1 parent c326612 commit 79dee2b
Show file tree
Hide file tree
Showing 13 changed files with 54 additions and 54 deletions.
2 changes: 1 addition & 1 deletion dot/rpc/json2/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func (c *CodecRequest) WriteError(w http.ResponseWriter, _ int, err error) {
c.writeServerResponse(w, res)
}

func (c CodecRequest) tryToMapIfNotAnErrorAlready(err error) error {
func (c *CodecRequest) tryToMapIfNotAnErrorAlready(err error) error {
if _, ok := err.(*json2.Error); ok || c.errorMapper == nil {
return err
}
Expand Down
12 changes: 6 additions & 6 deletions dot/types/babe_digest.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ func NewBabePrimaryPreDigest(authorityIndex uint32,
}

// ToPreRuntimeDigest returns the BabePrimaryPreDigest as a PreRuntimeDigest
func (d *BabePrimaryPreDigest) ToPreRuntimeDigest() (*PreRuntimeDigest, error) {
return toPreRuntimeDigest(*d)
func (d BabePrimaryPreDigest) ToPreRuntimeDigest() (*PreRuntimeDigest, error) {
return toPreRuntimeDigest(d)
}

// Index returns VDT index
Expand All @@ -85,8 +85,8 @@ func NewBabeSecondaryPlainPreDigest(authorityIndex uint32, slotNumber uint64) *B
}

// ToPreRuntimeDigest returns the BabeSecondaryPlainPreDigest as a PreRuntimeDigest
func (d *BabeSecondaryPlainPreDigest) ToPreRuntimeDigest() (*PreRuntimeDigest, error) {
return toPreRuntimeDigest(*d)
func (d BabeSecondaryPlainPreDigest) ToPreRuntimeDigest() (*PreRuntimeDigest, error) {
return toPreRuntimeDigest(d)
}

// Index returns VDT index
Expand Down Expand Up @@ -118,8 +118,8 @@ func NewBabeSecondaryVRFPreDigest(authorityIndex uint32,
}

// ToPreRuntimeDigest returns the BabeSecondaryVRFPreDigest as a PreRuntimeDigest
func (d *BabeSecondaryVRFPreDigest) ToPreRuntimeDigest() (*PreRuntimeDigest, error) {
return toPreRuntimeDigest(*d)
func (d BabeSecondaryVRFPreDigest) ToPreRuntimeDigest() (*PreRuntimeDigest, error) {
return toPreRuntimeDigest(d)
}

// Index returns VDT index
Expand Down
12 changes: 6 additions & 6 deletions dot/types/consensus_digest.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,14 @@ type NextEpochData struct {
}

// Index returns VDT index
func (NextEpochData) Index() uint { return 1 }
func (NextEpochData) Index() uint { return 1 } //skipcq: GO-W1029

func (d NextEpochData) String() string {
func (d NextEpochData) String() string { //skipcq: GO-W1029
return fmt.Sprintf("NextEpochData Authorities=%v Randomness=%v", d.Authorities, d.Randomness)
}

// ToEpochData returns the NextEpochData as EpochData
func (d *NextEpochData) ToEpochData() (*EpochData, error) {
func (d *NextEpochData) ToEpochData() (*EpochData, error) { //skipcq: GO-W1029
auths, err := BABEAuthorityRawToAuthority(d.Authorities)
if err != nil {
return nil, err
Expand Down Expand Up @@ -135,15 +135,15 @@ type NextConfigData struct {
}

// Index returns VDT index
func (NextConfigData) Index() uint { return 3 }
func (NextConfigData) Index() uint { return 3 } //skipcq: GO-W1029

func (d NextConfigData) String() string {
func (d NextConfigData) String() string { //skipcq: GO-W1029
return fmt.Sprintf("NextConfigData{C1=%d, C2=%d, SecondarySlots=%d}",
d.C1, d.C2, d.SecondarySlots)
}

// ToConfigData returns the NextConfigData as ConfigData
func (d *NextConfigData) ToConfigData() *ConfigData {
func (d *NextConfigData) ToConfigData() *ConfigData { //skipcq: GO-W1029
return &ConfigData{
C1: d.C1,
C2: d.C2,
Expand Down
4 changes: 2 additions & 2 deletions internal/pprof/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ type Settings struct {
MutexProfileRate int
}

func (s *Settings) setDefaults() {
func (s *Settings) setDefaults() { //skipcq: GO-W1029
if s.ListeningAddress == "" {
s.ListeningAddress = "localhost:6060"
}
}

func (s Settings) String() string {
func (s Settings) String() string { //skipcq: GO-W1029
return fmt.Sprintf(
"listening on %s and setting block profile rate to %d, mutex profile rate to %d",
s.ListeningAddress, s.BlockProfileRate, s.MutexProfileRate)
Expand Down
2 changes: 1 addition & 1 deletion internal/trie/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (n *Node) String() string {
}

// StringNode returns a gotree compatible node for String methods.
func (n Node) StringNode() (stringNode *gotree.Node) {
func (n *Node) StringNode() (stringNode *gotree.Node) {
caser := cases.Title(language.BritishEnglish)
stringNode = gotree.New(caser.String(n.Kind().String()))
stringNode.Appendf("Generation: %d", n.Generation)
Expand Down
2 changes: 1 addition & 1 deletion internal/trie/node/subvalue.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import "bytes"
// StorageValueEqual returns true if the node storage value is equal to the
// storage value given as argument. In particular, it returns false
// if one storage value is nil and the other storage value is the empty slice.
func (n Node) StorageValueEqual(stoageValue []byte) (equal bool) {
func (n *Node) StorageValueEqual(stoageValue []byte) (equal bool) {
if len(stoageValue) == 0 && len(n.StorageValue) == 0 {
return (stoageValue == nil && n.StorageValue == nil) ||
(stoageValue != nil && n.StorageValue != nil)
Expand Down
14 changes: 7 additions & 7 deletions lib/common/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func NewHash(in []byte) (res Hash) {
}

// ToBytes turns a hash to a byte array
func (h Hash) ToBytes() []byte {
func (h Hash) ToBytes() []byte { //skipcq: GO-W1029
b := [32]byte(h)
return b[:]
}
Expand All @@ -49,24 +49,24 @@ func HashValidator(field reflect.Value) interface{} {
}

// IsEmpty returns true if the hash is empty, false otherwise.
func (h Hash) IsEmpty() bool {
func (h Hash) IsEmpty() bool { //skipcq: GO-W1029
return h == Hash{}
}

// String returns the hex string for the hash
func (h Hash) String() string {
func (h Hash) String() string { //skipcq: GO-W1029
return fmt.Sprintf("0x%x", h[:])
}

// Short returns the first 4 bytes and the last 4 bytes of the hex string for the hash
func (h Hash) Short() string {
func (h Hash) Short() string { //skipcq: GO-W1029
const nBytes = 4
return fmt.Sprintf("0x%x...%x", h[:nBytes], h[len(h)-nBytes:])
}

// SetBytes sets the hash to the value of b.
// If b is larger than len(h), b will be cropped from the left.
func (h *Hash) SetBytes(b []byte) {
func (h *Hash) SetBytes(b []byte) { //skipcq: GO-W1029
if len(b) > len(h) {
b = b[len(b)-HashLength:]
}
Expand Down Expand Up @@ -95,7 +95,7 @@ func BytesToHash(b []byte) Hash {
}

// UnmarshalJSON converts hex data to hash
func (h *Hash) UnmarshalJSON(data []byte) error {
func (h *Hash) UnmarshalJSON(data []byte) error { //skipcq: GO-W1029
trimmedData := strings.Trim(string(data), "\"")
if len(trimmedData) < 2 {
return errors.New("invalid hash format")
Expand All @@ -109,7 +109,7 @@ func (h *Hash) UnmarshalJSON(data []byte) error {
}

// MarshalJSON converts hash to hex data
func (h Hash) MarshalJSON() ([]byte, error) {
func (h Hash) MarshalJSON() ([]byte, error) { //skipcq: GO-W1029
return json.Marshal(h.String())
}

Expand Down
10 changes: 5 additions & 5 deletions lib/runtime/invalid_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import (
type InvalidTransaction scale.VaryingDataType

// Index returns the VDT index
func (InvalidTransaction) Index() uint {
func (InvalidTransaction) Index() uint { //skipcq: GO-W1029
return 0
}

func (i InvalidTransaction) String() string { return i.Error() }
func (i InvalidTransaction) String() string { return i.Error() } //skipcq: GO-W1029

// Set will set a VaryingDataTypeValue using the underlying VaryingDataType
func (i *InvalidTransaction) Set(val scale.VaryingDataTypeValue) (err error) {
func (i *InvalidTransaction) Set(val scale.VaryingDataTypeValue) (err error) { //skipcq: GO-W1029
vdt := scale.VaryingDataType(*i)
err = vdt.Set(val)
if err != nil {
Expand All @@ -31,13 +31,13 @@ func (i *InvalidTransaction) Set(val scale.VaryingDataTypeValue) (err error) {
}

// Value will return the value from the underying VaryingDataType
func (i *InvalidTransaction) Value() (val scale.VaryingDataTypeValue, err error) {
func (i *InvalidTransaction) Value() (val scale.VaryingDataTypeValue, err error) { //skipcq: GO-W1029
vdt := scale.VaryingDataType(*i)
return vdt.Value()
}

// Error returns the error message associated with the InvalidTransaction
func (i InvalidTransaction) Error() string {
func (i InvalidTransaction) Error() string { //skipcq: GO-W1029
value, err := i.Value()
if err != nil {
return fmt.Sprintf("getting invalid transaction value: %s", err)
Expand Down
6 changes: 3 additions & 3 deletions lib/runtime/transaction_validity.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var errInvalidTypeCast = errors.New("invalid type cast")
type TransactionValidityError scale.VaryingDataType

// Set will set a VaryingDataTypeValue using the underlying VaryingDataType
func (tve *TransactionValidityError) Set(val scale.VaryingDataTypeValue) (err error) {
func (tve *TransactionValidityError) Set(val scale.VaryingDataTypeValue) (err error) { //skipcq: GO-W1029
vdt := scale.VaryingDataType(*tve)
err = vdt.Set(val)
if err != nil {
Expand All @@ -30,13 +30,13 @@ func (tve *TransactionValidityError) Set(val scale.VaryingDataTypeValue) (err er
}

// Value will return the value from the underlying VaryingDataType
func (tve *TransactionValidityError) Value() (val scale.VaryingDataTypeValue, err error) {
func (tve *TransactionValidityError) Value() (val scale.VaryingDataTypeValue, err error) { //skipcq: GO-W1029
vdt := scale.VaryingDataType(*tve)
return vdt.Value()
}

// Error will return the error underlying TransactionValidityError
func (tve TransactionValidityError) Error() string {
func (tve TransactionValidityError) Error() string { //skipcq: GO-W1029
value, err := tve.Value()
if err != nil {
return fmt.Sprintf("getting transaction validity error value: %s", err)
Expand Down
10 changes: 5 additions & 5 deletions lib/runtime/unknown_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import (
type UnknownTransaction scale.VaryingDataType

// Index returns the VDT index
func (UnknownTransaction) Index() uint {
func (UnknownTransaction) Index() uint { //skipcq: GO-W1029
return 1
}

func (u UnknownTransaction) String() string { return u.Error() }
func (u UnknownTransaction) String() string { return u.Error() } //skipcq: GO-W1029

// Set will set a VaryingDataTypeValue using the underlying VaryingDataType
func (u *UnknownTransaction) Set(val scale.VaryingDataTypeValue) (err error) {
func (u *UnknownTransaction) Set(val scale.VaryingDataTypeValue) (err error) { //skipcq: GO-W1029
vdt := scale.VaryingDataType(*u)
err = vdt.Set(val)
if err != nil {
Expand All @@ -31,12 +31,12 @@ func (u *UnknownTransaction) Set(val scale.VaryingDataTypeValue) (err error) {
}

// Value will return value from the underying VaryingDataType
func (u *UnknownTransaction) Value() (val scale.VaryingDataTypeValue, err error) {
func (u *UnknownTransaction) Value() (val scale.VaryingDataTypeValue, err error) { //skipcq: GO-W1029
vdt := scale.VaryingDataType(*u)
return vdt.Value()
}

func (u UnknownTransaction) Error() string {
func (u UnknownTransaction) Error() string { //skipcq: GO-W1029
value, err := u.Value()
if err != nil {
return fmt.Sprintf("getting unknown transaction value: %s", err)
Expand Down
10 changes: 5 additions & 5 deletions lib/transaction/priority_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ type Item struct {
// A PriorityQueue implements heap.Interface and holds Items.
type priorityQueue []*Item

func (pq priorityQueue) Len() int { return len(pq) }
func (pq priorityQueue) Len() int { return len(pq) } //skipcq: GO-W1029

func (pq priorityQueue) Less(i, j int) bool {
func (pq priorityQueue) Less(i, j int) bool { //skipcq: GO-W1029
// For Item having same priority value we compare them based on their insertion order(FIFO).
if pq[i].priority == pq[j].priority {
return pq[i].order < pq[j].order
Expand All @@ -53,20 +53,20 @@ func (pq priorityQueue) Less(i, j int) bool {
return pq[i].priority > pq[j].priority
}

func (pq priorityQueue) Swap(i, j int) {
func (pq priorityQueue) Swap(i, j int) { //skipcq: GO-W1029
pq[i], pq[j] = pq[j], pq[i]
pq[i].index = i
pq[j].index = j
}

func (pq *priorityQueue) Push(x interface{}) {
func (pq *priorityQueue) Push(x interface{}) { //skipcq: GO-W1029
n := len(*pq)
item := x.(*Item)
item.index = n
*pq = append(*pq, item)
}

func (pq *priorityQueue) Pop() interface{} {
func (pq *priorityQueue) Pop() interface{} { //skipcq: GO-W1029
old := *pq
n := len(old)
item := old[n-1]
Expand Down
10 changes: 5 additions & 5 deletions pkg/scale/varying_data_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type VaryingDataTypeSlice struct {
}

// Add takes variadic parameter values to add VaryingDataTypeValue(s)
func (vdts *VaryingDataTypeSlice) Add(values ...VaryingDataTypeValue) (err error) {
func (vdts *VaryingDataTypeSlice) Add(values ...VaryingDataTypeValue) (err error) { //skipcq: GO-W1029
for _, val := range values {
copied := vdts.VaryingDataType
err = copied.Set(val)
Expand All @@ -34,7 +34,7 @@ func (vdts *VaryingDataTypeSlice) Add(values ...VaryingDataTypeValue) (err error
return
}

func (vdts VaryingDataTypeSlice) String() string {
func (vdts VaryingDataTypeSlice) String() string { //skipcq: GO-W1029
stringTypes := make([]string, len(vdts.Types))
for i, vdt := range vdts.Types {
stringTypes[i] = vdt.String()
Expand Down Expand Up @@ -65,7 +65,7 @@ type VaryingDataType struct {
}

// Set will set the VaryingDataType value
func (vdt *VaryingDataType) Set(value VaryingDataTypeValue) (err error) {
func (vdt *VaryingDataType) Set(value VaryingDataTypeValue) (err error) { //skipcq: GO-W1029
_, ok := vdt.cache[value.Index()]
if !ok {
err = fmt.Errorf("%w: %v (%T)", ErrUnsupportedVaryingDataTypeValue, value, value)
Expand All @@ -76,14 +76,14 @@ func (vdt *VaryingDataType) Set(value VaryingDataTypeValue) (err error) {
}

// Value returns value stored in vdt
func (vdt *VaryingDataType) Value() (VaryingDataTypeValue, error) {
func (vdt *VaryingDataType) Value() (VaryingDataTypeValue, error) { //skipcq: GO-W1029
if vdt.value == nil {
return nil, ErrVaryingDataTypeNotSet
}
return vdt.value, nil
}

func (vdt VaryingDataType) String() string {
func (vdt VaryingDataType) String() string { //skipcq: GO-W1029
if vdt.value == nil {
return "VaryingDataType(nil)"
}
Expand Down
14 changes: 7 additions & 7 deletions pkg/scale/varying_data_type_nested_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ func NewParentVDT() ParentVDT {
type ChildVDT scale.VaryingDataType

// Index fulfils the VaryingDataTypeValue interface. T
func (ChildVDT) Index() uint {
func (ChildVDT) Index() uint { //skipcq: GO-W1029
return 1
}

func (cvdt ChildVDT) String() string {
func (cvdt ChildVDT) String() string { //skipcq: GO-W1029
value, err := cvdt.Value()
if err != nil {
return "ChildVDT()"
Expand All @@ -61,7 +61,7 @@ func (cvdt ChildVDT) String() string {
}

// Set will set a VaryingDataTypeValue using the underlying VaryingDataType
func (cvdt *ChildVDT) Set(val scale.VaryingDataTypeValue) (err error) {
func (cvdt *ChildVDT) Set(val scale.VaryingDataTypeValue) (err error) { //skipcq: GO-W1029
// cast to VaryingDataType to use VaryingDataType.Set method
vdt := scale.VaryingDataType(*cvdt)
err = vdt.Set(val)
Expand All @@ -74,7 +74,7 @@ func (cvdt *ChildVDT) Set(val scale.VaryingDataTypeValue) (err error) {
}

// Value will return value from underying VaryingDataType
func (cvdt *ChildVDT) Value() (val scale.VaryingDataTypeValue, err error) {
func (cvdt *ChildVDT) Value() (val scale.VaryingDataTypeValue, err error) { //skipcq: GO-W1029
vdt := scale.VaryingDataType(*cvdt)
return vdt.Value()
}
Expand All @@ -95,11 +95,11 @@ func NewChildVDT() ChildVDT {
type OtherChildVDT scale.VaryingDataType

// Index fulfils the VaryingDataTypeValue interface.
func (OtherChildVDT) Index() uint {
func (OtherChildVDT) Index() uint { //skipcq: GO-W1029
return 2
}

func (cvdt OtherChildVDT) String() string {
func (cvdt OtherChildVDT) String() string { //skipcq: GO-W1029
vdt := scale.VaryingDataType(cvdt)
vdtPtr := &vdt
value, err := vdtPtr.Value()
Expand All @@ -110,7 +110,7 @@ func (cvdt OtherChildVDT) String() string {
}

// Set will set a VaryingDataTypeValue using the underlying VaryingDataType
func (cvdt *OtherChildVDT) Set(val scale.VaryingDataTypeValue) (err error) {
func (cvdt *OtherChildVDT) Set(val scale.VaryingDataTypeValue) (err error) { //skipcq: GO-W1029
// cast to VaryingDataType to use VaryingDataType.Set method
vdt := scale.VaryingDataType(*cvdt)
err = vdt.Set(val)
Expand Down

0 comments on commit 79dee2b

Please sign in to comment.