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
}
// 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

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 = `[
{"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)
}

View file

@ -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")
)

View file

@ -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,
}

View file

@ -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) {

View file

@ -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)
}

View file

@ -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,
}

View file

@ -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
}

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.
id := uuid.NewRandom()
key := &keystore.Key{
Id: id,
ID: id,
Address: crypto.PubkeyToAddress(privateKey.PublicKey),
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)
}
method, err := abispec.MethodById(sigdata)
method, err := abispec.MethodByID(sigdata)
if err != nil {
return nil, err
}

View file

@ -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