"github.com/bytom/consensus"
"github.com/bytom/crypto/ed25519/chainkd"
chainjson "github.com/bytom/encoding/json"
+ "github.com/bytom/errors"
"github.com/bytom/protocol/bc"
"github.com/bytom/protocol/bc/types"
)
// POST /list-pubkeys
func (a *API) listPubKeys(ctx context.Context, ins struct {
- AccountID string `json:"account_id"`
+ AccountID string `json:"account_id"`
+ AccountAlias string `json:"account_alias"`
+ PublicKey string `json:"public_key"`
}) Response {
- account, err := a.wallet.AccountMgr.FindByID(ins.AccountID)
+ var err error
+ account := &account.Account{}
+ if ins.AccountAlias != "" {
+ account, err = a.wallet.AccountMgr.FindByAlias(ins.AccountAlias)
+ } else {
+ account, err = a.wallet.AccountMgr.FindByID(ins.AccountID)
+ }
+
if err != nil {
return NewErrorResponse(err)
}
pubKeyInfos := []PubKeyInfo{}
- idx := a.wallet.AccountMgr.GetContractIndex(ins.AccountID)
+ idx := a.wallet.AccountMgr.GetContractIndex(account.ID)
for i := uint64(1); i <= idx; i++ {
rawPath := signers.Path(account.Signer, signers.AccountKeySpace, i)
derivedXPub := account.XPubs[0].Derive(rawPath)
pubkey := derivedXPub.PublicKey()
+ if ins.PublicKey != "" && ins.PublicKey != hex.EncodeToString(pubkey) {
+ continue
+ }
+
var path []chainjson.HexBytes
for _, p := range rawPath {
path = append(path, chainjson.HexBytes(p))
}}, pubKeyInfos...)
}
+ if len(pubKeyInfos) == 0 {
+ return NewErrorResponse(errors.New("Not found publickey for the account"))
+ }
+
return NewSuccessResponse(&AccountPubkey{
RootXPub: account.XPubs[0],
PubKeyInfos: pubKeyInfos,
import (
"os"
+ "strings"
"github.com/spf13/cobra"
jww "github.com/spf13/jwalterweatherman"
createAccountCmd.PersistentFlags().IntVarP(&accountQuorum, "quorom", "q", 1, "quorum must be greater than 0 and less than or equal to the number of signers")
createAccountCmd.PersistentFlags().StringVarP(&accountToken, "access", "a", "", "access token")
- listAccountsCmd.PersistentFlags().StringVar(&accountID, "id", "", "ID of account")
+ listAccountsCmd.PersistentFlags().StringVar(&accountID, "id", "", "account ID")
listAddressesCmd.PersistentFlags().StringVar(&accountID, "id", "", "account ID")
listAddressesCmd.PersistentFlags().StringVar(&accountAlias, "alias", "", "account alias")
}
var listPubKeysCmd = &cobra.Command{
- Use: "list-pubkeys <accountID>",
+ Use: "list-pubkeys <accountInfo> [publicKey]",
Short: "list the account pubkeys",
- Args: cobra.ExactArgs(1),
+ Args: cobra.RangeArgs(1, 2),
Run: func(cmd *cobra.Command, args []string) {
var ins = struct {
- AccountID string `json:"account_id"`
- }{AccountID: args[0]}
+ AccountID string `json:"account_id"`
+ AccountAlias string `json:"account_alias"`
+ PublicKey string `json:"public_key"`
+ }{}
+
+ if len(args[0]) == 13 && strings.HasPrefix(args[0], "0") {
+ ins.AccountID = args[0]
+ } else {
+ ins.AccountAlias = args[0]
+ }
+
+ if len(args) == 2 {
+ ins.PublicKey = args[1]
+ }
data, exitCode := util.ClientCall("/list-pubkeys", &ins)
if exitCode != util.Success {