OSDN Git Service

take place CompareTwoXpubs with chainkd.IsXpubsEqual
authorYongfeng LI <wliyongfeng@gmail.com>
Tue, 17 Apr 2018 06:31:36 +0000 (14:31 +0800)
committerYongfeng LI <wliyongfeng@gmail.com>
Tue, 17 Apr 2018 06:31:36 +0000 (14:31 +0800)
account/accounts.go
crypto/ed25519/chainkd/chainkd.go

index b85cfd0..0a3a197 100644 (file)
@@ -277,7 +277,7 @@ func (m *Manager) ListCtrlProgramsByXpubs(ctx context.Context, xpubs []chainkd.X
 
        var result []*CtrlProgram
        for _, cp := range cps {
-               if cp.Address == "" || chainkd.CompareTwoXPubs(cp.XPubs, xpubs) != 0 {
+               if cp.Address == "" || chainkd.IsXpubsEqual(cp.XPubs, xpubs) {
                        continue
                }
                result = append(result, cp)
index 23f6fc2..eebeef4 100644 (file)
@@ -1,6 +1,7 @@
 package chainkd
 
 import (
+       "bytes"
        "crypto/hmac"
        "crypto/rand"
        "crypto/sha512"
@@ -8,7 +9,6 @@ import (
 
        "github.com/bytom/crypto/ed25519"
        "github.com/bytom/crypto/ed25519/ecmath"
-       "bytes"
 )
 
 type (
@@ -18,15 +18,15 @@ type (
        XPub [64]byte
 )
 
-// CompareTwoXPubs
-func CompareTwoXPubs(a, b []XPub) int {
+// IsXpubsEqual
+func IsXpubsEqual(a, b []XPub) bool {
        for i, xpub := range a {
                result := bytes.Compare(xpub[:], b[i][:])
                if result != 0 {
-                       return result
+                       return false
                }
        }
-       return 0
+       return true
 }
 
 // NewXPrv takes a source of random bytes and produces a new XPrv.