OSDN Git Service

28564da865629562972156f91162e772dd5d8fa9
[bytom/vapor.git] / api / receivers.go
1 package api
2
3 import (
4         "context"
5
6         "github.com/vapor/blockchain/txbuilder"
7 )
8
9 type AccountFilter struct {
10         AccountID    string `json:"account_id"`
11         AccountAlias string `json:"account_alias"`
12 }
13
14 func (a *API) createAccountReceiver(ctx context.Context, ins AccountFilter) Response {
15         accountID := ins.AccountID
16         if ins.AccountAlias != "" {
17                 account, err := a.wallet.AccountMgr.FindByAlias(ins.AccountAlias)
18                 if err != nil {
19                         return NewErrorResponse(err)
20                 }
21
22                 accountID = account.ID
23         }
24
25         program, err := a.wallet.AccountMgr.CreateAddress(accountID, false)
26         if err != nil {
27                 return NewErrorResponse(err)
28         }
29
30         return NewSuccessResponse(&txbuilder.Receiver{
31                 ControlProgram: program.ControlProgram,
32                 Address:        program.Address,
33         })
34 }