Skip to content

Commit 9a39c6b

Browse files
muse254Osoro Bironga
andauthored
accounts/abi: improve documentation and names (#21540)
* accounts: abi/bid/backends; cleaned doc errors, camelCase refactors and anonymous variable assignments * acounts/abi/bind: doc errors, anonymous parameter assignments * accounts/abi: doc edits, camelCase refactors * accounts/abi/bind: review fix * reverted name changes * name revert Co-authored-by: Osoro Bironga <osoro@doctaroo.com>
1 parent f354c62 commit 9a39c6b

File tree

16 files changed

+62
-61
lines changed

16 files changed

+62
-61
lines changed

accounts/abi/abi.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func (abi ABI) Pack(name string, args ...interface{}) ([]byte, error) {
8080
return append(method.ID, arguments...), nil
8181
}
8282

83-
// Unpack output in v according to the abi specification
83+
// Unpack output in v according to the abi specification.
8484
func (abi ABI) Unpack(v interface{}, name string, data []byte) (err error) {
8585
// since there can't be naming collisions with contracts and events,
8686
// we need to decide whether we're calling a method or an event
@@ -96,7 +96,7 @@ func (abi ABI) Unpack(v interface{}, name string, data []byte) (err error) {
9696
return fmt.Errorf("abi: could not locate named method or event")
9797
}
9898

99-
// UnpackIntoMap unpacks a log into the provided map[string]interface{}
99+
// UnpackIntoMap unpacks a log into the provided map[string]interface{}.
100100
func (abi ABI) UnpackIntoMap(v map[string]interface{}, name string, data []byte) (err error) {
101101
// since there can't be naming collisions with contracts and events,
102102
// we need to decide whether we're calling a method or an event
@@ -112,7 +112,7 @@ func (abi ABI) UnpackIntoMap(v map[string]interface{}, name string, data []byte)
112112
return fmt.Errorf("abi: could not locate named method or event")
113113
}
114114

115-
// UnmarshalJSON implements json.Unmarshaler interface
115+
// UnmarshalJSON implements json.Unmarshaler interface.
116116
func (abi *ABI) UnmarshalJSON(data []byte) error {
117117
var fields []struct {
118118
Type string
@@ -201,8 +201,8 @@ func (abi *ABI) overloadedEventName(rawName string) string {
201201
return name
202202
}
203203

204-
// MethodById looks up a method by the 4-byte id
205-
// returns nil if none found
204+
// MethodById looks up a method by the 4-byte id,
205+
// returns nil if none found.
206206
func (abi *ABI) MethodById(sigdata []byte) (*Method, error) {
207207
if len(sigdata) < 4 {
208208
return nil, fmt.Errorf("data too short (%d bytes) for abi method lookup", len(sigdata))

accounts/abi/abi_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1092,7 +1092,7 @@ func TestDoubleDuplicateEventNames(t *testing.T) {
10921092
}
10931093

10941094
// TestUnnamedEventParam checks that an event with unnamed parameters is
1095-
// correctly handled
1095+
// correctly handled.
10961096
// The test runs the abi of the following contract.
10971097
// contract TestEvent {
10981098
// event send(uint256, uint256);

accounts/abi/argument.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ type ArgumentMarshaling struct {
4141
Indexed bool
4242
}
4343

44-
// UnmarshalJSON implements json.Unmarshaler interface
44+
// UnmarshalJSON implements json.Unmarshaler interface.
4545
func (argument *Argument) UnmarshalJSON(data []byte) error {
4646
var arg ArgumentMarshaling
4747
err := json.Unmarshal(data, &arg)
@@ -59,7 +59,7 @@ func (argument *Argument) UnmarshalJSON(data []byte) error {
5959
return nil
6060
}
6161

62-
// NonIndexed returns the arguments with indexed arguments filtered out
62+
// NonIndexed returns the arguments with indexed arguments filtered out.
6363
func (arguments Arguments) NonIndexed() Arguments {
6464
var ret []Argument
6565
for _, arg := range arguments {
@@ -70,12 +70,12 @@ func (arguments Arguments) NonIndexed() Arguments {
7070
return ret
7171
}
7272

73-
// isTuple returns true for non-atomic constructs, like (uint,uint) or uint[]
73+
// isTuple returns true for non-atomic constructs, like (uint,uint) or uint[].
7474
func (arguments Arguments) isTuple() bool {
7575
return len(arguments) > 1
7676
}
7777

78-
// Unpack performs the operation hexdata -> Go format
78+
// Unpack performs the operation hexdata -> Go format.
7979
func (arguments Arguments) Unpack(v interface{}, data []byte) error {
8080
if len(data) == 0 {
8181
if len(arguments) != 0 {
@@ -100,7 +100,7 @@ func (arguments Arguments) Unpack(v interface{}, data []byte) error {
100100
return arguments.unpackAtomic(v, marshalledValues[0])
101101
}
102102

103-
// UnpackIntoMap performs the operation hexdata -> mapping of argument name to argument value
103+
// UnpackIntoMap performs the operation hexdata -> mapping of argument name to argument value.
104104
func (arguments Arguments) UnpackIntoMap(v map[string]interface{}, data []byte) error {
105105
// Make sure map is not nil
106106
if v == nil {
@@ -122,7 +122,7 @@ func (arguments Arguments) UnpackIntoMap(v map[string]interface{}, data []byte)
122122
return nil
123123
}
124124

125-
// unpackAtomic unpacks ( hexdata -> go ) a single value
125+
// unpackAtomic unpacks ( hexdata -> go ) a single value.
126126
func (arguments Arguments) unpackAtomic(v interface{}, marshalledValues interface{}) error {
127127
dst := reflect.ValueOf(v).Elem()
128128
src := reflect.ValueOf(marshalledValues)
@@ -207,13 +207,13 @@ func (arguments Arguments) UnpackValues(data []byte) ([]interface{}, error) {
207207
return retval, nil
208208
}
209209

210-
// PackValues performs the operation Go format -> Hexdata
211-
// It is the semantic opposite of UnpackValues
210+
// PackValues performs the operation Go format -> Hexdata.
211+
// It is the semantic opposite of UnpackValues.
212212
func (arguments Arguments) PackValues(args []interface{}) ([]byte, error) {
213213
return arguments.Pack(args...)
214214
}
215215

216-
// Pack performs the operation Go format -> Hexdata
216+
// Pack performs the operation Go format -> Hexdata.
217217
func (arguments Arguments) Pack(args ...interface{}) ([]byte, error) {
218218
// Make sure arguments match up and pack them
219219
abiArgs := arguments

accounts/abi/bind/auth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func NewTransactor(keyin io.Reader, passphrase string) (*TransactOpts, error) {
4545
}
4646

4747
// NewKeyStoreTransactor is a utility method to easily create a transaction signer from
48-
// an decrypted key from a keystore
48+
// a decrypted key from a keystore.
4949
func NewKeyStoreTransactor(keystore *keystore.KeyStore, account accounts.Account) (*TransactOpts, error) {
5050
return &TransactOpts{
5151
From: account.Address,

accounts/abi/bind/backend.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ var (
4141
ErrNoCodeAfterDeploy = errors.New("no contract code after deployment")
4242
)
4343

44-
// ContractCaller defines the methods needed to allow operating with contract on a read
44+
// ContractCaller defines the methods needed to allow operating with a contract on a read
4545
// only basis.
4646
type ContractCaller interface {
4747
// CodeAt returns the code of the given account. This is needed to differentiate
@@ -62,8 +62,8 @@ type PendingContractCaller interface {
6262
PendingCallContract(ctx context.Context, call ethereum.CallMsg) ([]byte, error)
6363
}
6464

65-
// ContractTransactor defines the methods needed to allow operating with contract
66-
// on a write only basis. Beside the transacting method, the remainder are helpers
65+
// ContractTransactor defines the methods needed to allow operating with a contract
66+
// on a write only basis. Besides the transacting method, the remainder are helpers
6767
// used when the user does not provide some needed values, but rather leaves it up
6868
// to the transactor to decide.
6969
type ContractTransactor interface {

accounts/abi/bind/base.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ func (c *BoundContract) Transact(opts *TransactOpts, method string, params ...in
177177
}
178178

179179
// RawTransact initiates a transaction with the given raw calldata as the input.
180-
// It's usually used to initiates transaction for invoking **Fallback** function.
180+
// It's usually used to initiate transactions for invoking **Fallback** function.
181181
func (c *BoundContract) RawTransact(opts *TransactOpts, calldata []byte) (*types.Transaction, error) {
182182
// todo(rjl493456442) check the method is payable or not,
183183
// reject invalid transaction at the first place

accounts/abi/bind/bind.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func Bind(types []string, abis []string, bytecodes []string, fsigs []map[string]
5252
// contracts is the map of each individual contract requested binding
5353
contracts = make(map[string]*tmplContract)
5454

55-
// structs is the map of all reclared structs shared by passed contracts.
55+
// structs is the map of all redeclared structs shared by passed contracts.
5656
structs = make(map[string]*tmplStruct)
5757

5858
// isLib is the map used to flag each encountered library as such
@@ -80,10 +80,10 @@ func Bind(types []string, abis []string, bytecodes []string, fsigs []map[string]
8080
fallback *tmplMethod
8181
receive *tmplMethod
8282

83-
// identifiers are used to detect duplicated identifier of function
84-
// and event. For all calls, transacts and events, abigen will generate
83+
// identifiers are used to detect duplicated identifiers of functions
84+
// and events. For all calls, transacts and events, abigen will generate
8585
// corresponding bindings. However we have to ensure there is no
86-
// identifier coliision in the bindings of these categories.
86+
// identifier collisions in the bindings of these categories.
8787
callIdentifiers = make(map[string]bool)
8888
transactIdentifiers = make(map[string]bool)
8989
eventIdentifiers = make(map[string]bool)
@@ -246,7 +246,7 @@ var bindType = map[Lang]func(kind abi.Type, structs map[string]*tmplStruct) stri
246246
LangJava: bindTypeJava,
247247
}
248248

249-
// bindBasicTypeGo converts basic solidity types(except array, slice and tuple) to Go one.
249+
// bindBasicTypeGo converts basic solidity types(except array, slice and tuple) to Go ones.
250250
func bindBasicTypeGo(kind abi.Type) string {
251251
switch kind.T {
252252
case abi.AddressTy:
@@ -286,7 +286,7 @@ func bindTypeGo(kind abi.Type, structs map[string]*tmplStruct) string {
286286
}
287287
}
288288

289-
// bindBasicTypeJava converts basic solidity types(except array, slice and tuple) to Java one.
289+
// bindBasicTypeJava converts basic solidity types(except array, slice and tuple) to Java ones.
290290
func bindBasicTypeJava(kind abi.Type) string {
291291
switch kind.T {
292292
case abi.AddressTy:
@@ -330,7 +330,7 @@ func bindBasicTypeJava(kind abi.Type) string {
330330
}
331331

332332
// pluralizeJavaType explicitly converts multidimensional types to predefined
333-
// type in go side.
333+
// types in go side.
334334
func pluralizeJavaType(typ string) string {
335335
switch typ {
336336
case "boolean":
@@ -369,7 +369,7 @@ var bindTopicType = map[Lang]func(kind abi.Type, structs map[string]*tmplStruct)
369369
}
370370

371371
// bindTopicTypeGo converts a Solidity topic type to a Go one. It is almost the same
372-
// funcionality as for simple types, but dynamic types get converted to hashes.
372+
// functionality as for simple types, but dynamic types get converted to hashes.
373373
func bindTopicTypeGo(kind abi.Type, structs map[string]*tmplStruct) string {
374374
bound := bindTypeGo(kind, structs)
375375

@@ -386,15 +386,15 @@ func bindTopicTypeGo(kind abi.Type, structs map[string]*tmplStruct) string {
386386
}
387387

388388
// bindTopicTypeJava converts a Solidity topic type to a Java one. It is almost the same
389-
// funcionality as for simple types, but dynamic types get converted to hashes.
389+
// functionality as for simple types, but dynamic types get converted to hashes.
390390
func bindTopicTypeJava(kind abi.Type, structs map[string]*tmplStruct) string {
391391
bound := bindTypeJava(kind, structs)
392392

393393
// todo(rjl493456442) according solidity documentation, indexed event
394394
// parameters that are not value types i.e. arrays and structs are not
395395
// stored directly but instead a keccak256-hash of an encoding is stored.
396396
//
397-
// We only convert stringS and bytes to hash, still need to deal with
397+
// We only convert strings and bytes to hash, still need to deal with
398398
// array(both fixed-size and dynamic-size) and struct.
399399
if bound == "String" || bound == "byte[]" {
400400
bound = "Hash"
@@ -415,7 +415,7 @@ var bindStructType = map[Lang]func(kind abi.Type, structs map[string]*tmplStruct
415415
func bindStructTypeGo(kind abi.Type, structs map[string]*tmplStruct) string {
416416
switch kind.T {
417417
case abi.TupleTy:
418-
// We compose raw struct name and canonical parameter expression
418+
// We compose a raw struct name and a canonical parameter expression
419419
// together here. The reason is before solidity v0.5.11, kind.TupleRawName
420420
// is empty, so we use canonical parameter expression to distinguish
421421
// different struct definition. From the consideration of backward
@@ -454,7 +454,7 @@ func bindStructTypeGo(kind abi.Type, structs map[string]*tmplStruct) string {
454454
func bindStructTypeJava(kind abi.Type, structs map[string]*tmplStruct) string {
455455
switch kind.T {
456456
case abi.TupleTy:
457-
// We compose raw struct name and canonical parameter expression
457+
// We compose a raw struct name and a canonical parameter expression
458458
// together here. The reason is before solidity v0.5.11, kind.TupleRawName
459459
// is empty, so we use canonical parameter expression to distinguish
460460
// different struct definition. From the consideration of backward
@@ -486,7 +486,7 @@ func bindStructTypeJava(kind abi.Type, structs map[string]*tmplStruct) string {
486486
}
487487

488488
// namedType is a set of functions that transform language specific types to
489-
// named versions that my be used inside method names.
489+
// named versions that may be used inside method names.
490490
var namedType = map[Lang]func(string, abi.Type) string{
491491
LangGo: func(string, abi.Type) string { panic("this shouldn't be needed") },
492492
LangJava: namedTypeJava,
@@ -528,7 +528,7 @@ func alias(aliases map[string]string, n string) string {
528528
}
529529

530530
// methodNormalizer is a name transformer that modifies Solidity method names to
531-
// conform to target language naming concentions.
531+
// conform to target language naming conventions.
532532
var methodNormalizer = map[Lang]func(string) string{
533533
LangGo: abi.ToCamelCase,
534534
LangJava: decapitalise,

accounts/abi/bind/template.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type tmplData struct {
3030
type tmplContract struct {
3131
Type string // Type name of the main contract binding
3232
InputABI string // JSON ABI used as the input to generate the binding from
33-
InputBin string // Optional EVM bytecode used to denetare deploy code from
33+
InputBin string // Optional EVM bytecode used to generate deploy code from
3434
FuncSigs map[string]string // Optional map: string signature -> 4-byte signature
3535
Constructor abi.Method // Contract constructor for deploy parametrization
3636
Calls map[string]*tmplMethod // Contract calls that only read state data
@@ -50,7 +50,8 @@ type tmplMethod struct {
5050
Structured bool // Whether the returns should be accumulated into a struct
5151
}
5252

53-
// tmplEvent is a wrapper around an a
53+
// tmplEvent is a wrapper around an abi.Event that contains a few preprocessed
54+
// and cached data fields.
5455
type tmplEvent struct {
5556
Original abi.Event // Original event as parsed by the abi package
5657
Normalized abi.Event // Normalized version of the parsed fields
@@ -64,7 +65,7 @@ type tmplField struct {
6465
SolKind abi.Type // Raw abi type information
6566
}
6667

67-
// tmplStruct is a wrapper around an abi.tuple contains an auto-generated
68+
// tmplStruct is a wrapper around an abi.tuple and contains an auto-generated
6869
// struct name.
6970
type tmplStruct struct {
7071
Name string // Auto-generated struct name(before solidity v0.5.11) or raw name.
@@ -78,8 +79,8 @@ var tmplSource = map[Lang]string{
7879
LangJava: tmplSourceJava,
7980
}
8081

81-
// tmplSourceGo is the Go source template use to generate the contract binding
82-
// based on.
82+
// tmplSourceGo is the Go source template that the generated Go contract binding
83+
// is based on.
8384
const tmplSourceGo = `
8485
// Code generated - DO NOT EDIT.
8586
// This file is a generated binding and any manual changes will be lost.
@@ -543,8 +544,8 @@ var (
543544
{{end}}
544545
`
545546

546-
// tmplSourceJava is the Java source template use to generate the contract binding
547-
// based on.
547+
// tmplSourceJava is the Java source template that the generated Java contract binding
548+
// is based on.
548549
const tmplSourceJava = `
549550
// This file is an automatically generated Java binding. Do not modify as any
550551
// change will likely be lost upon the next re-generation!

accounts/abi/event.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type Event struct {
3232
// the raw name and a suffix will be added in the case of a event overload.
3333
//
3434
// e.g.
35-
// There are two events have same name:
35+
// These are two events that have the same name:
3636
// * foo(int,int)
3737
// * foo(uint,uint)
3838
// The event name of the first one wll be resolved as foo while the second one

accounts/abi/event_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ func TestEventUnpackIndexed(t *testing.T) {
371371
require.Equal(t, uint8(8), rst.Value2)
372372
}
373373

374-
// TestEventIndexedWithArrayUnpack verifies that decoder will not overlow when static array is indexed input.
374+
// TestEventIndexedWithArrayUnpack verifies that decoder will not overflow when static array is indexed input.
375375
func TestEventIndexedWithArrayUnpack(t *testing.T) {
376376
definition := `[{"name": "test", "type": "event", "inputs": [{"indexed": true, "name":"value1", "type":"uint8[2]"},{"indexed": false, "name":"value2", "type":"string"}]}]`
377377
type testStruct struct {

0 commit comments

Comments
 (0)