X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=api%2Faccounts.go;h=b75aa5133cc9c1f5a25e899861c339681133414c;hb=3f53de9ec5cce160d620d98bf5b5b706e0ded743;hp=a0d551adeae049ad8ed3b6a94992dd3fb6afa95c;hpb=db158dcf09436b003defd333f1a665e7e051d820;p=bytom%2Fvapor.git diff --git a/api/accounts.go b/api/accounts.go index a0d551ad..b75aa513 100644 --- a/api/accounts.go +++ b/api/accounts.go @@ -15,12 +15,14 @@ import ( "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) @@ -58,10 +60,7 @@ type AccountInfo struct { } // 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) @@ -114,7 +113,14 @@ func (a *API) validateAddress(ctx context.Context, ins struct { 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"` @@ -124,18 +130,13 @@ type addressResp struct { } // 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 != "" { @@ -157,12 +158,12 @@ func (a *API) listAddresses(ctx context.Context, ins struct { 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,