From 83e2465105831ef7ab1ec25d8611025b9e4ce7e1 Mon Sep 17 00:00:00 2001 From: Kiel barry Date: Mon, 21 May 2018 18:01:54 -0700 Subject: [PATCH] accounts: gofmt! --- accounts/abi/abi.go | 4 ++-- accounts/abi/abi_test.go | 4 ++-- accounts/abi/bind/backend.go | 6 +++--- accounts/keystore/key.go | 16 ++++++++-------- accounts/keystore/keystore_passphrase.go | 22 +++++++++++----------- accounts/keystore/keystore_plain_test.go | 8 ++++---- accounts/keystore/presale.go | 4 ++-- accounts/url.go | 6 +++--- cmd/ethkey/generate.go | 2 +- signer/core/abihelper.go | 2 +- signer/core/abihelper_test.go | 4 ++-- 11 files changed, 39 insertions(+), 39 deletions(-) diff --git a/accounts/abi/abi.go b/accounts/abi/abi.go index 254b1f7fb4..fa46d6728a 100644 --- a/accounts/abi/abi.go +++ b/accounts/abi/abi.go @@ -134,9 +134,9 @@ func (abi *ABI) UnmarshalJSON(data []byte) error { return nil } -// MethodById looks up a method by the 4-byte id +// MethodByID looks up a method by the 4-byte id // returns nil if none found -func (abi *ABI) MethodById(sigdata []byte) (*Method, error) { +func (abi *ABI) MethodByID(sigdata []byte) (*Method, error) { for _, method := range abi.Methods { if bytes.Equal(method.Id(), sigdata[:4]) { return &method, nil diff --git a/accounts/abi/abi_test.go b/accounts/abi/abi_test.go index 8018df7756..3360ef7d31 100644 --- a/accounts/abi/abi_test.go +++ b/accounts/abi/abi_test.go @@ -671,7 +671,7 @@ func TestUnpackEvent(t *testing.T) { } } -func TestABI_MethodById(t *testing.T) { +func TestABI_MethodByID(t *testing.T) { const abiJSON = `[ {"type":"function","name":"receive","constant":false,"inputs":[{"name":"memo","type":"bytes"}],"outputs":[],"payable":true,"stateMutability":"payable"}, {"type":"event","name":"received","anonymous":false,"inputs":[{"indexed":false,"name":"sender","type":"address"},{"indexed":false,"name":"amount","type":"uint256"},{"indexed":false,"name":"memo","type":"bytes"}]}, @@ -702,7 +702,7 @@ func TestABI_MethodById(t *testing.T) { } for name, m := range abi.Methods { a := fmt.Sprintf("%v", m) - m2, err := abi.MethodById(m.Id()) + m2, err := abi.MethodByID(m.Id()) if err != nil { t.Fatalf("Failed to look up ABI method: %v", err) } diff --git a/accounts/abi/bind/backend.go b/accounts/abi/bind/backend.go index ca60cc1b43..4c13cbc16c 100644 --- a/accounts/abi/bind/backend.go +++ b/accounts/abi/bind/backend.go @@ -32,12 +32,12 @@ var ( // have any code associated with it (i.e. suicided). ErrNoCode = errors.New("no contract code at given address") - // This error is raised when attempting to perform a pending state action + // ErrNoPendingState is raised when attempting to perform a pending state action // on a backend that doesn't implement PendingContractCaller. ErrNoPendingState = errors.New("backend does not support pending state") - // This error is returned by WaitDeployed if contract creation leaves an - // empty contract behind. + // ErrNoCodeAfterDeploy is returned by WaitDeployed if contract creation leaves + // an empty contract behind. ErrNoCodeAfterDeploy = errors.New("no contract code after deployment") ) diff --git a/accounts/keystore/key.go b/accounts/keystore/key.go index 211fa863d7..efe18b6f07 100644 --- a/accounts/keystore/key.go +++ b/accounts/keystore/key.go @@ -40,7 +40,7 @@ const ( ) type Key struct { - Id uuid.UUID // Version 4 "random" for unique id not derived from key data + ID uuid.UUID // Version 4 "random" for unique id not derived from key data // to simplify lookups we also store the address Address common.Address // we only store privkey as pubkey/address can be derived from it @@ -60,21 +60,21 @@ type keyStore interface { type plainKeyJSON struct { Address string `json:"address"` PrivateKey string `json:"privatekey"` - Id string `json:"id"` + ID string `json:"id"` Version int `json:"version"` } type encryptedKeyJSONV3 struct { Address string `json:"address"` Crypto cryptoJSON `json:"crypto"` - Id string `json:"id"` + ID string `json:"id"` Version int `json:"version"` } type encryptedKeyJSONV1 struct { Address string `json:"address"` Crypto cryptoJSON `json:"crypto"` - Id string `json:"id"` + ID string `json:"id"` Version string `json:"version"` } @@ -95,7 +95,7 @@ func (k *Key) MarshalJSON() (j []byte, err error) { jStruct := plainKeyJSON{ hex.EncodeToString(k.Address[:]), hex.EncodeToString(crypto.FromECDSA(k.PrivateKey)), - k.Id.String(), + k.ID.String(), version, } j, err = json.Marshal(jStruct) @@ -110,8 +110,8 @@ func (k *Key) UnmarshalJSON(j []byte) (err error) { } u := new(uuid.UUID) - *u = uuid.Parse(keyJSON.Id) - k.Id = *u + *u = uuid.Parse(keyJSON.ID) + k.ID = *u addr, err := hex.DecodeString(keyJSON.Address) if err != nil { return err @@ -130,7 +130,7 @@ func (k *Key) UnmarshalJSON(j []byte) (err error) { func newKeyFromECDSA(privateKeyECDSA *ecdsa.PrivateKey) *Key { id := uuid.NewRandom() key := &Key{ - Id: id, + ID: id, Address: crypto.PubkeyToAddress(privateKeyECDSA.PublicKey), PrivateKey: privateKeyECDSA, } diff --git a/accounts/keystore/keystore_passphrase.go b/accounts/keystore/keystore_passphrase.go index da632fe345..b2dfd5fbac 100644 --- a/accounts/keystore/keystore_passphrase.go +++ b/accounts/keystore/keystore_passphrase.go @@ -153,7 +153,7 @@ func EncryptKey(key *Key, auth string, scryptN, scryptP int) ([]byte, error) { encryptedKeyJSONV3 := encryptedKeyJSONV3{ hex.EncodeToString(key.Address[:]), cryptoStruct, - key.Id.String(), + key.ID.String(), version, } return json.Marshal(encryptedKeyJSONV3) @@ -168,7 +168,7 @@ func DecryptKey(keyjson []byte, auth string) (*Key, error) { } // Depending on the version try to parse one way or another var ( - keyBytes, keyId []byte + keyBytes, keyID []byte err error ) if version, ok := m["version"].(string); ok && version == "1" { @@ -176,13 +176,13 @@ func DecryptKey(keyjson []byte, auth string) (*Key, error) { if err := json.Unmarshal(keyjson, k); err != nil { return nil, err } - keyBytes, keyId, err = decryptKeyV1(k, auth) + keyBytes, keyID, err = decryptKeyV1(k, auth) } else { k := new(encryptedKeyJSONV3) if err := json.Unmarshal(keyjson, k); err != nil { return nil, err } - keyBytes, keyId, err = decryptKeyV3(k, auth) + keyBytes, keyID, err = decryptKeyV3(k, auth) } // Handle any decryption errors and return the key if err != nil { @@ -191,13 +191,13 @@ func DecryptKey(keyjson []byte, auth string) (*Key, error) { key := crypto.ToECDSAUnsafe(keyBytes) return &Key{ - Id: uuid.UUID(keyId), + ID: uuid.UUID(keyID), Address: crypto.PubkeyToAddress(key.PublicKey), PrivateKey: key, }, nil } -func decryptKeyV3(keyProtected *encryptedKeyJSONV3, auth string) (keyBytes []byte, keyId []byte, err error) { +func decryptKeyV3(keyProtected *encryptedKeyJSONV3, auth string) (keyBytes []byte, keyID []byte, err error) { if keyProtected.Version != version { return nil, nil, fmt.Errorf("Version not supported: %v", keyProtected.Version) } @@ -206,7 +206,7 @@ func decryptKeyV3(keyProtected *encryptedKeyJSONV3, auth string) (keyBytes []byt return nil, nil, fmt.Errorf("Cipher not supported: %v", keyProtected.Crypto.Cipher) } - keyId = uuid.Parse(keyProtected.Id) + keyID = uuid.Parse(keyProtected.ID) mac, err := hex.DecodeString(keyProtected.Crypto.MAC) if err != nil { return nil, nil, err @@ -236,11 +236,11 @@ func decryptKeyV3(keyProtected *encryptedKeyJSONV3, auth string) (keyBytes []byt if err != nil { return nil, nil, err } - return plainText, keyId, err + return plainText, keyID, err } -func decryptKeyV1(keyProtected *encryptedKeyJSONV1, auth string) (keyBytes []byte, keyId []byte, err error) { - keyId = uuid.Parse(keyProtected.Id) +func decryptKeyV1(keyProtected *encryptedKeyJSONV1, auth string) (keyBytes []byte, keyID []byte, err error) { + keyID = uuid.Parse(keyProtected.ID) mac, err := hex.DecodeString(keyProtected.Crypto.MAC) if err != nil { return nil, nil, err @@ -270,7 +270,7 @@ func decryptKeyV1(keyProtected *encryptedKeyJSONV1, auth string) (keyBytes []byt if err != nil { return nil, nil, err } - return plainText, keyId, err + return plainText, keyID, err } func getKDFKey(cryptoJSON cryptoJSON, auth string) ([]byte, error) { diff --git a/accounts/keystore/keystore_plain_test.go b/accounts/keystore/keystore_plain_test.go index a1c3bc4b6c..93cceda020 100644 --- a/accounts/keystore/keystore_plain_test.go +++ b/accounts/keystore/keystore_plain_test.go @@ -124,13 +124,13 @@ func TestImportPreSaleKey(t *testing.T) { // Test and utils for the key store tests in the Ethereum JSON tests; // testdataKeyStoreTests/basic_tests.json type KeyStoreTestV3 struct { - Json encryptedKeyJSONV3 + JSON encryptedKeyJSONV3 Password string Priv string } type KeyStoreTestV1 struct { - Json encryptedKeyJSONV1 + JSON encryptedKeyJSONV1 Password string Priv string } @@ -206,7 +206,7 @@ func TestV1_2(t *testing.T) { } func testDecryptV3(test KeyStoreTestV3, t *testing.T) { - privBytes, _, err := decryptKeyV3(&test.Json, test.Password) + privBytes, _, err := decryptKeyV3(&test.JSON, test.Password) if err != nil { t.Fatal(err) } @@ -217,7 +217,7 @@ func testDecryptV3(test KeyStoreTestV3, t *testing.T) { } func testDecryptV1(test KeyStoreTestV1, t *testing.T) { - privBytes, _, err := decryptKeyV1(&test.Json, test.Password) + privBytes, _, err := decryptKeyV1(&test.JSON, test.Password) if err != nil { t.Fatal(err) } diff --git a/accounts/keystore/presale.go b/accounts/keystore/presale.go index 1554294e14..a806ec3993 100644 --- a/accounts/keystore/presale.go +++ b/accounts/keystore/presale.go @@ -37,7 +37,7 @@ func importPreSaleKey(keyStore keyStore, keyJSON []byte, password string) (accou if err != nil { return accounts.Account{}, nil, err } - key.Id = uuid.NewRandom() + key.ID = uuid.NewRandom() a := accounts.Account{Address: key.Address, URL: accounts.URL{Scheme: KeyStoreScheme, Path: keyStore.JoinPath(keyFileName(key.Address))}} err = keyStore.StoreKey(a.URL.Path, key, password) return a, key, err @@ -80,7 +80,7 @@ func decryptPreSaleKey(fileContent []byte, password string) (key *Key, err error ecKey := crypto.ToECDSAUnsafe(ethPriv) key = &Key{ - Id: nil, + ID: nil, Address: crypto.PubkeyToAddress(ecKey.PublicKey), PrivateKey: ecKey, } diff --git a/accounts/url.go b/accounts/url.go index 21df668efd..a5add10216 100644 --- a/accounts/url.go +++ b/accounts/url.go @@ -76,12 +76,12 @@ func (u URL) MarshalJSON() ([]byte, error) { // UnmarshalJSON parses url. func (u *URL) UnmarshalJSON(input []byte) error { - var textUrl string - err := json.Unmarshal(input, &textUrl) + var textURL string + err := json.Unmarshal(input, &textURL) if err != nil { return err } - url, err := parseURL(textUrl) + url, err := parseURL(textURL) if err != nil { return err } diff --git a/cmd/ethkey/generate.go b/cmd/ethkey/generate.go index 6d57d17fb4..9f1ab5c7b2 100644 --- a/cmd/ethkey/generate.go +++ b/cmd/ethkey/generate.go @@ -84,7 +84,7 @@ If you want to encrypt an existing private key, it can be specified by setting // Create the keyfile object with a random UUID. id := uuid.NewRandom() key := &keystore.Key{ - Id: id, + ID: id, Address: crypto.PubkeyToAddress(privateKey.PublicKey), PrivateKey: privateKey, } diff --git a/signer/core/abihelper.go b/signer/core/abihelper.go index 1d4fbc7dc2..e0ca17c58f 100644 --- a/signer/core/abihelper.go +++ b/signer/core/abihelper.go @@ -79,7 +79,7 @@ func parseCallData(calldata []byte, abidata string) (*decodedCallData, error) { return nil, fmt.Errorf("Failed parsing JSON ABI: %v, abidata: %v", err, abidata) } - method, err := abispec.MethodById(sigdata) + method, err := abispec.MethodByID(sigdata) if err != nil { return nil, err } diff --git a/signer/core/abihelper_test.go b/signer/core/abihelper_test.go index 8bb5776691..45fe41ec97 100644 --- a/signer/core/abihelper_test.go +++ b/signer/core/abihelper_test.go @@ -37,7 +37,7 @@ func verify(t *testing.T, jsondata, calldata string, exp []interface{}) { } cd := common.Hex2Bytes(calldata) sigdata, argdata := cd[:4], cd[4:] - method, err := abispec.MethodById(sigdata) + method, err := abispec.MethodByID(sigdata) if err != nil { t.Fatal(err) @@ -199,7 +199,7 @@ func TestSelectorUnmarshalling(t *testing.T) { t.Error(err) return } - m, err := abistruct.MethodById(common.Hex2Bytes(id[2:])) + m, err := abistruct.MethodByID(common.Hex2Bytes(id[2:])) if err != nil { t.Error(err) return