"github.com/vapor/protocol/vm/vmutil"
)
-// POST /create-account
-func (a *API) createAccount(ctx context.Context, ins struct {
+type CreateAccountReq struct {
RootXPubs []chainkd.XPub `json:"root_xpubs"`
Quorum int `json:"quorum"`
Alias string `json:"alias"`
-}) Response {
+}
+
+// POST /create-account
+func (a *API) createAccount(ctx context.Context, ins CreateAccountReq) Response {
acc, err := a.wallet.AccountMgr.Create(ins.RootXPubs, ins.Quorum, ins.Alias, signers.BIP0044)
if err != nil {
return NewErrorResponse(err)
}
// POST /delete-account
-func (a *API) deleteAccount(ctx context.Context, filter struct {
- AccountID string `json:"account_id"`
- AccountAlias string `json:"account_alias"`
-}) Response {
+func (a *API) deleteAccount(ctx context.Context, filter AccountFilter) Response {
accountID := filter.AccountID
if filter.AccountAlias != "" {
acc, err := a.wallet.AccountMgr.FindByAlias(filter.AccountAlias)
return NewSuccessResponse(resp)
}
-type addressResp struct {
+type AddressReq struct {
+ AccountID string `json:"account_id"`
+ AccountAlias string `json:"account_alias"`
+ From uint `json:"from"`
+ Count uint `json:"count"`
+}
+
+type AddressResp struct {
AccountAlias string `json:"account_alias"`
AccountID string `json:"account_id"`
Address string `json:"address"`
}
// SortByIndex implements sort.Interface for addressResp slices
-type SortByIndex []addressResp
+type SortByIndex []AddressResp
func (a SortByIndex) Len() int { return len(a) }
func (a SortByIndex) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a SortByIndex) Less(i, j int) bool { return a[i].KeyIndex < a[j].KeyIndex }
-func (a *API) listAddresses(ctx context.Context, ins struct {
- AccountID string `json:"account_id"`
- AccountAlias string `json:"account_alias"`
- From uint `json:"from"`
- Count uint `json:"count"`
-}) Response {
+func (a *API) listAddresses(ctx context.Context, ins AddressReq) Response {
accountID := ins.AccountID
var target *account.Account
if ins.AccountAlias != "" {
return NewErrorResponse(err)
}
- addresses := []addressResp{}
+ addresses := []AddressResp{}
for _, cp := range cps {
if cp.Address == "" || cp.AccountID != target.ID {
continue
}
- addresses = append(addresses, addressResp{
+ addresses = append(addresses, AddressResp{
AccountAlias: target.Alias,
AccountID: cp.AccountID,
Address: cp.Address,