return cp, nil
}
-// listAddressesById
-func (m *Manager) ListCtrlProgramsByXpubs(ctx context.Context, xpubs []chainkd.XPub) ([]*CtrlProgram, error) {
+// ListCtrlProgramsByAccountId
+func (m *Manager) ListCtrlProgramsByAccountId(ctx context.Context, accountId string) ([]*CtrlProgram, error) {
cps, err := m.ListControlProgram()
if err != nil {
return nil, err
var result []*CtrlProgram
for _, cp := range cps {
- if cp.Address == "" || chainkd.IsXpubsEqual(cp.XPubs, xpubs) {
+ if cp.Address == "" || cp.AccountID != accountId {
continue
}
result = append(result, cp)
return &CtrlProgram{
AccountID: account.ID,
- XPubs: account.Signer.XPubs,
Address: address.EncodeAddress(),
KeyIndex: idx,
ControlProgram: control,
return &CtrlProgram{
AccountID: account.ID,
- XPubs: account.Signer.XPubs,
Address: address.EncodeAddress(),
KeyIndex: idx,
ControlProgram: control,
//CtrlProgram is structure of account control program
type CtrlProgram struct {
AccountID string
- XPubs []chainkd.XPub
Address string
KeyIndex uint64
ControlProgram []byte
target = acc
}
- cps, err := a.wallet.AccountMgr.ListCtrlProgramsByXpubs(ctx, target.XPubs)
+ cps, err := a.wallet.AccountMgr.ListCtrlProgramsByAccountId(ctx, target.ID)
if err != nil {
return NewErrorResponse(err)
}
package chainkd
import (
- "bytes"
"crypto/hmac"
"crypto/rand"
"crypto/sha512"
XPub [64]byte
)
-// IsXpubsEqual
-func IsXpubsEqual(a, b []XPub) bool {
- for i, xpub := range a {
- result := bytes.Compare(xpub[:], b[i][:])
- if result != 0 {
- return false
- }
- }
- return true
-}
-
// NewXPrv takes a source of random bytes and produces a new XPrv.
// If r is nil, crypto/rand.Reader is used.
func NewXPrv(r io.Reader) (xprv XPrv, err error) {
keyInfo.Percent = 100
keyInfo.Complete = true
- if cps, err := w.AccountMgr.ListCtrlProgramsByXpubs(nil, keyInfo.account.XPubs); err == nil {
+ if cps, err := w.AccountMgr.ListCtrlProgramsByAccountId(nil, keyInfo.account.ID); err == nil {
for _, cp := range cps {
if !w.status.OnChainAddresses.Contains(cp.Address) {
w.AccountMgr.DeleteAccountControlProgram(cp.ControlProgram)