github.com/bytom/bytom@v1.1.2-0.20221014091027-bbcba3df6075/api/receivers.go (about)

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