accounts: gofmt!

This commit is contained in:
Kiel barry 2018-05-21 18:01:54 -07:00
parent 415969f534
commit 83e2465105
11 changed files with 39 additions and 39 deletions

View file

@ -134,9 +134,9 @@ func (abi *ABI) UnmarshalJSON(data []byte) error {
return nil 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 // 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 { for _, method := range abi.Methods {
if bytes.Equal(method.Id(), sigdata[:4]) { if bytes.Equal(method.Id(), sigdata[:4]) {
return &method, nil return &method, nil

View file

@ -671,7 +671,7 @@ func TestUnpackEvent(t *testing.T) {
} }
} }
func TestABI_MethodById(t *testing.T) { func TestABI_MethodByID(t *testing.T) {
const abiJSON = `[ const abiJSON = `[
{"type":"function","name":"receive","constant":false,"inputs":[{"name":"memo","type":"bytes"}],"outputs":[],"payable":true,"stateMutability":"payable"}, {"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"}]}, {"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 { for name, m := range abi.Methods {
a := fmt.Sprintf("%v", m) a := fmt.Sprintf("%v", m)
m2, err := abi.MethodById(m.Id()) m2, err := abi.MethodByID(m.Id())
if err != nil { if err != nil {
t.Fatalf("Failed to look up ABI method: %v", err) t.Fatalf("Failed to look up ABI method: %v", err)
} }

View file

@ -32,12 +32,12 @@ var (
// have any code associated with it (i.e. suicided). // have any code associated with it (i.e. suicided).
ErrNoCode = errors.New("no contract code at given address") 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. // on a backend that doesn't implement PendingContractCaller.
ErrNoPendingState = errors.New("backend does not support pending state") ErrNoPendingState = errors.New("backend does not support pending state")
// This error is returned by WaitDeployed if contract creation leaves an // ErrNoCodeAfterDeploy is returned by WaitDeployed if contract creation leaves
// empty contract behind. // an empty contract behind.
ErrNoCodeAfterDeploy = errors.New("no contract code after deployment") ErrNoCodeAfterDeploy = errors.New("no contract code after deployment")
) )

View file

@ -40,7 +40,7 @@ const (
) )
type Key struct { 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 // to simplify lookups we also store the address
Address common.Address Address common.Address
// we only store privkey as pubkey/address can be derived from it // we only store privkey as pubkey/address can be derived from it
@ -60,21 +60,21 @@ type keyStore interface {
type plainKeyJSON struct { type plainKeyJSON struct {
Address string `json:"address"` Address string `json:"address"`
PrivateKey string `json:"privatekey"` PrivateKey string `json:"privatekey"`
Id string `json:"id"` ID string `json:"id"`
Version int `json:"version"` Version int `json:"version"`
} }
type encryptedKeyJSONV3 struct { type encryptedKeyJSONV3 struct {
Address string `json:"address"` Address string `json:"address"`
Crypto cryptoJSON `json:"crypto"` Crypto cryptoJSON `json:"crypto"`
Id string `json:"id"` ID string `json:"id"`
Version int `json:"version"` Version int `json:"version"`
} }
type encryptedKeyJSONV1 struct { type encryptedKeyJSONV1 struct {
Address string `json:"address"` Address string `json:"address"`
Crypto cryptoJSON `json:"crypto"` Crypto cryptoJSON `json:"crypto"`
Id string `json:"id"` ID string `json:"id"`
Version string `json:"version"` Version string `json:"version"`
} }
@ -95,7 +95,7 @@ func (k *Key) MarshalJSON() (j []byte, err error) {
jStruct := plainKeyJSON{ jStruct := plainKeyJSON{
hex.EncodeToString(k.Address[:]), hex.EncodeToString(k.Address[:]),
hex.EncodeToString(crypto.FromECDSA(k.PrivateKey)), hex.EncodeToString(crypto.FromECDSA(k.PrivateKey)),
k.Id.String(), k.ID.String(),
version, version,
} }
j, err = json.Marshal(jStruct) j, err = json.Marshal(jStruct)
@ -110,8 +110,8 @@ func (k *Key) UnmarshalJSON(j []byte) (err error) {
} }
u := new(uuid.UUID) u := new(uuid.UUID)
*u = uuid.Parse(keyJSON.Id) *u = uuid.Parse(keyJSON.ID)
k.Id = *u k.ID = *u
addr, err := hex.DecodeString(keyJSON.Address) addr, err := hex.DecodeString(keyJSON.Address)
if err != nil { if err != nil {
return err return err
@ -130,7 +130,7 @@ func (k *Key) UnmarshalJSON(j []byte) (err error) {
func newKeyFromECDSA(privateKeyECDSA *ecdsa.PrivateKey) *Key { func newKeyFromECDSA(privateKeyECDSA *ecdsa.PrivateKey) *Key {
id := uuid.NewRandom() id := uuid.NewRandom()
key := &Key{ key := &Key{
Id: id, ID: id,
Address: crypto.PubkeyToAddress(privateKeyECDSA.PublicKey), Address: crypto.PubkeyToAddress(privateKeyECDSA.PublicKey),
PrivateKey: privateKeyECDSA, PrivateKey: privateKeyECDSA,
} }

View file

@ -153,7 +153,7 @@ func EncryptKey(key *Key, auth string, scryptN, scryptP int) ([]byte, error) {
encryptedKeyJSONV3 := encryptedKeyJSONV3{ encryptedKeyJSONV3 := encryptedKeyJSONV3{
hex.EncodeToString(key.Address[:]), hex.EncodeToString(key.Address[:]),
cryptoStruct, cryptoStruct,
key.Id.String(), key.ID.String(),
version, version,
} }
return json.Marshal(encryptedKeyJSONV3) 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 // Depending on the version try to parse one way or another
var ( var (
keyBytes, keyId []byte keyBytes, keyID []byte
err error err error
) )
if version, ok := m["version"].(string); ok && version == "1" { 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 { if err := json.Unmarshal(keyjson, k); err != nil {
return nil, err return nil, err
} }
keyBytes, keyId, err = decryptKeyV1(k, auth) keyBytes, keyID, err = decryptKeyV1(k, auth)
} else { } else {
k := new(encryptedKeyJSONV3) k := new(encryptedKeyJSONV3)
if err := json.Unmarshal(keyjson, k); err != nil { if err := json.Unmarshal(keyjson, k); err != nil {
return nil, err return nil, err
} }
keyBytes, keyId, err = decryptKeyV3(k, auth) keyBytes, keyID, err = decryptKeyV3(k, auth)
} }
// Handle any decryption errors and return the key // Handle any decryption errors and return the key
if err != nil { if err != nil {
@ -191,13 +191,13 @@ func DecryptKey(keyjson []byte, auth string) (*Key, error) {
key := crypto.ToECDSAUnsafe(keyBytes) key := crypto.ToECDSAUnsafe(keyBytes)
return &Key{ return &Key{
Id: uuid.UUID(keyId), ID: uuid.UUID(keyID),
Address: crypto.PubkeyToAddress(key.PublicKey), Address: crypto.PubkeyToAddress(key.PublicKey),
PrivateKey: key, PrivateKey: key,
}, nil }, 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 { if keyProtected.Version != version {
return nil, nil, fmt.Errorf("Version not supported: %v", keyProtected.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) 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) mac, err := hex.DecodeString(keyProtected.Crypto.MAC)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
@ -236,11 +236,11 @@ func decryptKeyV3(keyProtected *encryptedKeyJSONV3, auth string) (keyBytes []byt
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
return plainText, keyId, err return plainText, keyID, err
} }
func decryptKeyV1(keyProtected *encryptedKeyJSONV1, auth string) (keyBytes []byte, keyId []byte, err error) { func decryptKeyV1(keyProtected *encryptedKeyJSONV1, auth string) (keyBytes []byte, keyID []byte, err error) {
keyId = uuid.Parse(keyProtected.Id) keyID = uuid.Parse(keyProtected.ID)
mac, err := hex.DecodeString(keyProtected.Crypto.MAC) mac, err := hex.DecodeString(keyProtected.Crypto.MAC)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
@ -270,7 +270,7 @@ func decryptKeyV1(keyProtected *encryptedKeyJSONV1, auth string) (keyBytes []byt
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
return plainText, keyId, err return plainText, keyID, err
} }
func getKDFKey(cryptoJSON cryptoJSON, auth string) ([]byte, error) { func getKDFKey(cryptoJSON cryptoJSON, auth string) ([]byte, error) {

View file

@ -124,13 +124,13 @@ func TestImportPreSaleKey(t *testing.T) {
// Test and utils for the key store tests in the Ethereum JSON tests; // Test and utils for the key store tests in the Ethereum JSON tests;
// testdataKeyStoreTests/basic_tests.json // testdataKeyStoreTests/basic_tests.json
type KeyStoreTestV3 struct { type KeyStoreTestV3 struct {
Json encryptedKeyJSONV3 JSON encryptedKeyJSONV3
Password string Password string
Priv string Priv string
} }
type KeyStoreTestV1 struct { type KeyStoreTestV1 struct {
Json encryptedKeyJSONV1 JSON encryptedKeyJSONV1
Password string Password string
Priv string Priv string
} }
@ -206,7 +206,7 @@ func TestV1_2(t *testing.T) {
} }
func testDecryptV3(test KeyStoreTestV3, 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 { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -217,7 +217,7 @@ func testDecryptV3(test KeyStoreTestV3, t *testing.T) {
} }
func testDecryptV1(test KeyStoreTestV1, 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 { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View file

@ -37,7 +37,7 @@ func importPreSaleKey(keyStore keyStore, keyJSON []byte, password string) (accou
if err != nil { if err != nil {
return accounts.Account{}, nil, err 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))}} 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) err = keyStore.StoreKey(a.URL.Path, key, password)
return a, key, err return a, key, err
@ -80,7 +80,7 @@ func decryptPreSaleKey(fileContent []byte, password string) (key *Key, err error
ecKey := crypto.ToECDSAUnsafe(ethPriv) ecKey := crypto.ToECDSAUnsafe(ethPriv)
key = &Key{ key = &Key{
Id: nil, ID: nil,
Address: crypto.PubkeyToAddress(ecKey.PublicKey), Address: crypto.PubkeyToAddress(ecKey.PublicKey),
PrivateKey: ecKey, PrivateKey: ecKey,
} }

View file

@ -76,12 +76,12 @@ func (u URL) MarshalJSON() ([]byte, error) {
// UnmarshalJSON parses url. // UnmarshalJSON parses url.
func (u *URL) UnmarshalJSON(input []byte) error { func (u *URL) UnmarshalJSON(input []byte) error {
var textUrl string var textURL string
err := json.Unmarshal(input, &textUrl) err := json.Unmarshal(input, &textURL)
if err != nil { if err != nil {
return err return err
} }
url, err := parseURL(textUrl) url, err := parseURL(textURL)
if err != nil { if err != nil {
return err return err
} }

View file

@ -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. // Create the keyfile object with a random UUID.
id := uuid.NewRandom() id := uuid.NewRandom()
key := &keystore.Key{ key := &keystore.Key{
Id: id, ID: id,
Address: crypto.PubkeyToAddress(privateKey.PublicKey), Address: crypto.PubkeyToAddress(privateKey.PublicKey),
PrivateKey: privateKey, PrivateKey: privateKey,
} }

View file

@ -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) 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 { if err != nil {
return nil, err return nil, err
} }

View file

@ -37,7 +37,7 @@ func verify(t *testing.T, jsondata, calldata string, exp []interface{}) {
} }
cd := common.Hex2Bytes(calldata) cd := common.Hex2Bytes(calldata)
sigdata, argdata := cd[:4], cd[4:] sigdata, argdata := cd[:4], cd[4:]
method, err := abispec.MethodById(sigdata) method, err := abispec.MethodByID(sigdata)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -199,7 +199,7 @@ func TestSelectorUnmarshalling(t *testing.T) {
t.Error(err) t.Error(err)
return return
} }
m, err := abistruct.MethodById(common.Hex2Bytes(id[2:])) m, err := abistruct.MethodByID(common.Hex2Bytes(id[2:]))
if err != nil { if err != nil {
t.Error(err) t.Error(err)
return return