From 9b03dae49908dce96546ae70f60e3b32b92b2589 Mon Sep 17 00:00:00 2001 From: Eugene Valeyev Date: Mon, 15 Jan 2018 13:10:10 +0300 Subject: [PATCH] mobile: fixed lint warnings --- mobile/shhclient.go | 34 +++++++++++----------------------- mobile/types.go | 12 ++++++------ 2 files changed, 17 insertions(+), 29 deletions(-) diff --git a/mobile/shhclient.go b/mobile/shhclient.go index 53b1be762d..c970c7f98c 100644 --- a/mobile/shhclient.go +++ b/mobile/shhclient.go @@ -36,8 +36,7 @@ func NewWhisperClient(rawurl string) (client *WhisperClient, _ error) { // GetVersion returns the Whisper sub-protocol version. func (wc *WhisperClient) GetVersion(ctx *Context) (version string, _ error) { - rawVersion, err := wc.client.Version(ctx.context) - return string(rawVersion), err + return wc.client.Version(ctx.context) } // Info returns diagnostic information about the whisper node. @@ -72,27 +71,23 @@ func (wc *WhisperClient) MarkTrustedPeer(ctx *Context, enode string) error { // NewKeyPair generates a new public and private key pair for message decryption and encryption. // It returns an identifier that can be used to refer to the key. func (wc *WhisperClient) NewKeyPair(ctx *Context) (string, error) { - rawNewKeyPair, err := wc.client.NewKeyPair(ctx.context) - return string(rawNewKeyPair), err + return wc.client.NewKeyPair(ctx.context) } // AddPrivateKey stored the key pair, and returns its ID. func (wc *WhisperClient) AddPrivateKey(ctx *Context, key []byte) (string, error) { - rawAddPrivateKey, err := wc.client.AddPrivateKey(ctx.context, key) - return string(rawAddPrivateKey), err + return wc.client.AddPrivateKey(ctx.context, key) } // DeleteKeyPair delete the specifies key. func (wc *WhisperClient) DeleteKeyPair(ctx *Context, id string) (string, error) { - rawDeletePrivateKey, err := wc.client.DeleteKeyPair(ctx.context, id) - return string(rawDeletePrivateKey), err + return wc.client.DeleteKeyPair(ctx.context, id) } // HasKeyPair returns an indication if the node has a private key or // key pair matching the given ID. func (wc *WhisperClient) HasKeyPair(ctx *Context, id string) (bool, error) { - rawHasKeyPair, err := wc.client.HasKeyPair(ctx.context, id) - return bool(rawHasKeyPair), err + return wc.client.HasKeyPair(ctx.context, id) } // GetPublicKey return the public key for a key ID. @@ -108,26 +103,22 @@ func (wc *WhisperClient) GetPrivateKey(ctx *Context, id string) ([]byte, error) // NewSymmetricKey generates a random symmetric key and returns its identifier. // Can be used encrypting and decrypting messages where the key is known to both parties. func (wc *WhisperClient) NewSymmetricKey(ctx *Context) (string, error) { - rawNewSymmetricKey, err := wc.client.NewSymmetricKey(ctx.context) - return string(rawNewSymmetricKey), err + return wc.client.NewSymmetricKey(ctx.context) } // AddSymmetricKey stores the key, and returns its identifier. func (wc *WhisperClient) AddSymmetricKey(ctx *Context, key []byte) (string, error) { - rawAddSymmetricKey, err := wc.client.AddSymmetricKey(ctx.context, key) - return string(rawAddSymmetricKey), err + return wc.client.AddSymmetricKey(ctx.context, key) } // GenerateSymmetricKeyFromPassword generates the key from password, stores it, and returns its identifier. func (wc *WhisperClient) GenerateSymmetricKeyFromPassword(ctx *Context, passwd string) (string, error) { - rawSymKeyID, err := wc.client.GenerateSymmetricKeyFromPassword(ctx.context, passwd) - return string(rawSymKeyID), err + return wc.client.GenerateSymmetricKeyFromPassword(ctx.context, passwd) } // HasSymmetricKey returns an indication if the key associated with the given id is stored in the node. func (wc *WhisperClient) HasSymmetricKey(ctx *Context, id string) (bool, error) { - rawHasSymmetricKey, err := wc.client.HasSymmetricKey(ctx.context, id) - return bool(rawHasSymmetricKey), err + return wc.client.HasSymmetricKey(ctx.context, id) } // GetSymmetricKey returns the symmetric key associated with the given identifier. @@ -182,8 +173,7 @@ func (wc *WhisperClient) SubscribeMessages(ctx *Context, criteria *Criteria, han // for new messages (see FilterMessages) that satisfy the given criteria. A filter can // timeout when it was polled for in whisper.filterTimeout. func (wc *WhisperClient) NewMessageFilter(ctx *Context, criteria *Criteria) (string, error) { - rawNewMessageFilter, err := wc.client.NewMessageFilter(ctx.context, *criteria.criteria) - return string(rawNewMessageFilter), err + return wc.client.NewMessageFilter(ctx.context, *criteria.criteria) } // DeleteMessageFilter removes the filter associated with the given id. @@ -199,8 +189,6 @@ func (wc *WhisperClient) GetFilterMessages(ctx *Context, id string) (*Messages, return nil, err } res := make([]*whisper.Message, len(rawFilterMessages)) - for i := range rawFilterMessages { - res[i] = rawFilterMessages[i] - } + copy(res, rawFilterMessages) return &Messages{res}, nil } diff --git a/mobile/types.go b/mobile/types.go index 9a8f9ba961..4a6b3b9e63 100644 --- a/mobile/types.go +++ b/mobile/types.go @@ -385,12 +385,12 @@ func (nm *NewMessage) GetPublicKey() []byte { return nm.newMessage.Pu func (nm *NewMessage) SetPublicKey(publicKey []byte) { nm.newMessage.PublicKey = publicKey } func (nm *NewMessage) GetSig() string { return nm.newMessage.Sig } func (nm *NewMessage) SetSig(sig string) { nm.newMessage.Sig = sig } -func (nm *NewMessage) GetTTL() int32 { return int32(nm.newMessage.TTL) } -func (nm *NewMessage) SetTTL(ttl int32) { nm.newMessage.TTL = uint32(ttl) } +func (nm *NewMessage) GetTTL() int64 { return int64(nm.newMessage.TTL) } +func (nm *NewMessage) SetTTL(ttl int64) { nm.newMessage.TTL = uint32(ttl) } func (nm *NewMessage) GetPayload() []byte { return nm.newMessage.Payload } func (nm *NewMessage) SetPayload(payload []byte) { nm.newMessage.Payload = payload } -func (nm *NewMessage) GetPowTime() int32 { return int32(nm.newMessage.PowTime) } -func (nm *NewMessage) SetPowTime(powTime int32) { nm.newMessage.PowTime = uint32(powTime) } +func (nm *NewMessage) GetPowTime() int64 { return int64(nm.newMessage.PowTime) } +func (nm *NewMessage) SetPowTime(powTime int64) { nm.newMessage.PowTime = uint32(powTime) } func (nm *NewMessage) GetPowTarget() float64 { return nm.newMessage.PowTarget } func (nm *NewMessage) SetPowTarget(powTarget float64) { nm.newMessage.PowTarget = powTarget } func (nm *NewMessage) GetTargetPeer() string { return nm.newMessage.TargetPeer } @@ -404,8 +404,8 @@ type Message struct { } func (m *Message) GetSig() []byte { return m.message.Sig } -func (m *Message) GetTTL() int32 { return int32(m.message.TTL) } -func (m *Message) GetTimestamp() int32 { return int32(m.message.Timestamp) } +func (m *Message) GetTTL() int64 { return int64(m.message.TTL) } +func (m *Message) GetTimestamp() int64 { return int64(m.message.Timestamp) } func (m *Message) GetPayload() []byte { return m.message.Payload } func (m *Message) GetPoW() float64 { return m.message.PoW } func (m *Message) GetHash() []byte { return m.message.Hash }