fmt.Println("found is:", found, "found xpub:", found.XPubs)
if !testutil.DeepEqual(account, found) {
t.Errorf("expected account %v to be recorded as %v", account, found)
+ //////////
+ t.Errorf("expected type of account %v to be recorded as %v", reflect.TypeOf(account.XPubs[0]), reflect.TypeOf(found.XPubs[0]))
}
}
func DeriveXPubs(xpubs []vcrypto.XPubKeyer, path [][]byte) []vcrypto.XPubKeyer {
res := make([]vcrypto.XPubKeyer, 0, len(xpubs))
for _, xpub := range xpubs {
- fmt.Println("DeriveXPubs =====", reflect.TypeOf(xpubs[0]))
- if xpb, ok := xpub.(edchainkd.XPub); ok {
- d := xpb.Derive(path)
+ fmt.Println("DeriveXPubs type xpubs:", reflect.TypeOf(xpubs), "type xpubs[0]:", reflect.TypeOf(xpubs[0]))
+ fmt.Println("xpubs[0] is:", xpubs[0])
+ newxpub, err := edchainkd.NewXPub(reflect.ValueOf(xpub).String())
+ if err != nil {
+ fmt.Println("csp DeriveXPubs err:", err)
+ } else {
+ d := newxpub.Derive(path)
res = append(res, d)
fmt.Println("DeriveXPubs d is:", d)
}
+
// switch xpb := xpub.(type) {
// case edchainkd.XPub:
// d := xpb.Derive(path)
import (
"encoding/hex"
"errors"
+ "fmt"
)
const (
return hex.EncodeToString(xprv.Bytes())
}
-// func (xpub *XPub) UnmarshalJSON(b []byte) error {
+func NewXPub(str string) (xpub *XPub, err error) {
+ if len(str) != 2*extendedPublicKeySize {
+ fmt.Println("str length is:", len(str))
+ fmt.Println("str is:", str)
+ return nil, errors.New("string length is invalid.")
+ }
+ if xpubBytes, err := hex.DecodeString(str); err != nil {
+ return nil, err
+ } else {
+ copy(xpub[:], xpubBytes[:])
+ }
-// return nil
-// }
+ return xpub, nil
+}