Skip to content

[account address] use value receiver where possible #142

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
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
20 changes: 10 additions & 10 deletions internal/types/accountAddress.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// - [bcs.Unmarshaler]
// - [json.Marshaler]
// - [json.Unmarshaler]
type AccountAddress [32]byte

Check failure on line 19 in internal/types/accountAddress.go

View workflow job for this annotation

GitHub Actions / lint

the methods of "AccountAddress" use pointer receiver and non-pointer receiver. (recvcheck)

// AccountZero is [AccountAddress] 0x0
var AccountZero = AccountAddress{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
Expand All @@ -41,7 +41,7 @@
// the addresses in the range from `0x0` to `0xf` (inclusive) are special.
// For more details see the v1 address standard defined as part of AIP-40:
// https://github.com/aptos-foundation/AIPs/blob/main/aips/aip-40.md
func (aa *AccountAddress) IsSpecial() bool {
func (aa AccountAddress) IsSpecial() bool {
for _, b := range aa[:31] {
if b != 0 {
return false
Expand All @@ -53,7 +53,7 @@
// String Returns the canonical string representation of the [AccountAddress]
//
// Please use [AccountAddress.StringLong] for all indexer queries.
func (aa *AccountAddress) String() string {
func (aa AccountAddress) String() string {
if aa.IsSpecial() {
return fmt.Sprintf("0x%x", aa[31])
}
Expand All @@ -67,7 +67,7 @@
}

// AuthKey converts [AccountAddress] to [crypto.AuthenticationKey]
func (aa *AccountAddress) AuthKey() *crypto.AuthenticationKey {
func (aa AccountAddress) AuthKey() *crypto.AuthenticationKey {
authKey := &crypto.AuthenticationKey{}
copy(authKey[:], aa[:])
return authKey
Expand All @@ -76,12 +76,12 @@
// StringLong Returns the long string representation of the AccountAddress
//
// This is most commonly used for all indexer queries.
func (aa *AccountAddress) StringLong() string {
func (aa AccountAddress) StringLong() string {
return util.BytesToHex(aa[:])
}

// MarshalBCS Converts the AccountAddress to BCS encoded bytes
func (aa *AccountAddress) MarshalBCS(ser *bcs.Serializer) {
func (aa AccountAddress) MarshalBCS(ser *bcs.Serializer) {
ser.FixedBytes(aa[:])
}

Expand All @@ -91,7 +91,7 @@
}

// MarshalJSON converts the AccountAddress to JSON
func (aa *AccountAddress) MarshalJSON() ([]byte, error) {
func (aa AccountAddress) MarshalJSON() ([]byte, error) {
return json.Marshal(aa.String())
}

Expand All @@ -110,22 +110,22 @@
}

// NamedObjectAddress derives a named object address based on the input address as the creator
func (aa *AccountAddress) NamedObjectAddress(seed []byte) (accountAddress AccountAddress) {
func (aa AccountAddress) NamedObjectAddress(seed []byte) (accountAddress AccountAddress) {
return aa.DerivedAddress(seed, crypto.NamedObjectScheme)
}

// ObjectAddressFromObject derives an object address based on the input address as the creator object
func (aa *AccountAddress) ObjectAddressFromObject(objectAddress *AccountAddress) (accountAddress AccountAddress) {
func (aa AccountAddress) ObjectAddressFromObject(objectAddress *AccountAddress) (accountAddress AccountAddress) {
return aa.DerivedAddress(objectAddress[:], crypto.DeriveObjectScheme)
}

// ResourceAccount derives an object address based on the input address as the creator
func (aa *AccountAddress) ResourceAccount(seed []byte) (accountAddress AccountAddress) {
func (aa AccountAddress) ResourceAccount(seed []byte) (accountAddress AccountAddress) {
return aa.DerivedAddress(seed, crypto.ResourceAccountScheme)
}

// DerivedAddress addresses are derived by the address, the seed, then the type byte
func (aa *AccountAddress) DerivedAddress(seed []byte, typeByte uint8) (accountAddress AccountAddress) {
func (aa AccountAddress) DerivedAddress(seed []byte, typeByte uint8) (accountAddress AccountAddress) {
authKey := aa.AuthKey()
authKey.FromBytesAndScheme(append(authKey[:], seed...), typeByte)
copy(accountAddress[:], authKey[:])
Expand Down
Loading