return nextIndex
}
+// GetContractIndex return the current index
+func (m *Manager) GetContractIndex(accountID string) uint64 {
+ m.accIndexMu.Lock()
+ defer m.accIndexMu.Unlock()
+
+ index := uint64(1)
+ if rawIndexBytes := m.db.Get(contractIndexKey(accountID)); rawIndexBytes != nil {
+ index = common.BytesToUnit64(rawIndexBytes)
+ }
+ return index
+}
+
// Create creates a new Account.
func (m *Manager) Create(ctx context.Context, xpubs []chainkd.XPub, quorum int, alias string) (*Account, error) {
m.accountMu.Lock()
m.Handle("/create-account-receiver", jsonHandler(a.createAccountReceiver))
m.Handle("/list-addresses", jsonHandler(a.listAddresses))
m.Handle("/validate-address", jsonHandler(a.validateAddress))
+ m.Handle("/list-pubkeys", jsonHandler(a.listPubKeys))
m.Handle("/create-asset", jsonHandler(a.createAsset))
m.Handle("/update-asset-alias", jsonHandler(a.updateAssetAlias))
import (
"context"
+ "encoding/hex"
"fmt"
log "github.com/sirupsen/logrus"
"github.com/bytom/account"
"github.com/bytom/blockchain/query"
+ "github.com/bytom/blockchain/signers"
"github.com/bytom/consensus"
+ "github.com/bytom/crypto/ed25519/chainkd"
chainjson "github.com/bytom/encoding/json"
"github.com/bytom/protocol/bc"
"github.com/bytom/protocol/bc/types"
gasrate := map[string]int64{"gas_rate": consensus.VMGasRate}
return NewSuccessResponse(gasrate)
}
+
+// PubKeyInfo is structure of pubkey info
+type PubKeyInfo struct {
+ Pubkey string `json:"pubkey"`
+ Path []chainjson.HexBytes `json:"derivation_path"`
+}
+
+// AccountPubkey is detail of account pubkey info
+type AccountPubkey struct {
+ RootXPub chainkd.XPub `json:"root_xpub"`
+ PubKeyInfos []PubKeyInfo `json:"pubkey_infos"`
+}
+
+// POST /list-pubkeys
+func (a *API) listPubKeys(ctx context.Context, ins struct {
+ AccountID string `json:"account_id"`
+}) Response {
+ account, err := a.wallet.AccountMgr.FindByID(ctx, ins.AccountID)
+ if err != nil {
+ return NewErrorResponse(err)
+ }
+
+ pubKeyInfos := []PubKeyInfo{}
+ idx := a.wallet.AccountMgr.GetContractIndex(ins.AccountID)
+ for i := uint64(1); i <= idx; i++ {
+ rawPath := signers.Path(account.Signer, signers.AccountKeySpace, i)
+ derivedXPub := account.XPubs[0].Derive(rawPath)
+ pubkey := derivedXPub.PublicKey()
+
+ var path []chainjson.HexBytes
+ for _, p := range rawPath {
+ path = append(path, chainjson.HexBytes(p))
+ }
+
+ pubKeyInfos = append([]PubKeyInfo{{
+ Pubkey: hex.EncodeToString(pubkey),
+ Path: path,
+ }}, pubKeyInfos...)
+ }
+
+ return NewSuccessResponse(&AccountPubkey{
+ RootXPub: account.XPubs[0],
+ PubKeyInfos: pubKeyInfos,
+ })
+}
},
}
+var listPubKeysCmd = &cobra.Command{
+ Use: "list-pubkeys <accountID>",
+ Short: "list the account pubkeys",
+ Args: cobra.ExactArgs(1),
+ Run: func(cmd *cobra.Command, args []string) {
+ var ins = struct {
+ AccountID string `json:"account_id"`
+ }{AccountID: args[0]}
+
+ data, exitCode := util.ClientCall("/list-pubkeys", &ins)
+ if exitCode != util.Success {
+ os.Exit(exitCode)
+ }
+
+ printJSON(data)
+ },
+}
+
var listBalancesCmd = &cobra.Command{
Use: "list-balances",
Short: "List the accounts balances",
BytomcliCmd.AddCommand(createAccountReceiverCmd)
BytomcliCmd.AddCommand(listAddressesCmd)
BytomcliCmd.AddCommand(validateAddressCmd)
+ BytomcliCmd.AddCommand(listPubKeysCmd)
BytomcliCmd.AddCommand(createAssetCmd)
BytomcliCmd.AddCommand(getAssetCmd)
createAccountReceiverCmd.Name(),
listAddressesCmd.Name(),
validateAddressCmd.Name(),
+ listPubKeysCmd.Name(),
createAssetCmd.Name(),
getAssetCmd.Name(),