6 "github.com/vapor/blockchain/txbuilder"
7 chainjson "github.com/vapor/encoding/json"
10 func (a *API) createAccountReceiver(ctx context.Context, ins struct {
11 AccountID string `json:"account_id"`
12 AccountAlias string `json:"account_alias"`
14 accountID := ins.AccountID
15 if ins.AccountAlias != "" {
16 account, err := a.wallet.AccountMgr.FindByAlias(ins.AccountAlias)
18 return NewErrorResponse(err)
21 accountID = account.ID
24 program, err := a.wallet.AccountMgr.CreateAddress(accountID, false)
26 return NewErrorResponse(err)
29 return NewSuccessResponse(&txbuilder.Receiver{
30 ControlProgram: program.ControlProgram,
31 Address: program.Address,
35 type fundingResp struct {
36 MainchainAddress string `json:"mainchain_address"`
37 ControlProgram chainjson.HexBytes `json:"control_program,omitempty"`
38 ClaimScript chainjson.HexBytes `json:"claim_script"`
41 func (a *API) getPeginAddress(ctx context.Context, ins struct {
42 AccountID string `json:"account_id"`
43 AccountAlias string `json:"account_alias"`
46 accountID := ins.AccountID
47 if ins.AccountAlias != "" {
48 account, err := a.wallet.AccountMgr.FindByAlias(ins.AccountAlias)
50 return NewErrorResponse(err)
53 accountID = account.ID
56 mainchainAddress, claimScript, err := a.wallet.AccountMgr.CreatePeginAddress(accountID, false)
58 return NewErrorResponse(err)
61 return NewSuccessResponse(fundingResp{
62 MainchainAddress: mainchainAddress,
63 ClaimScript: claimScript,
67 func (a *API) getPeginContractAddress(ctx context.Context, ins struct {
68 AccountID string `json:"account_id"`
69 AccountAlias string `json:"account_alias"`
72 accountID := ins.AccountID
73 if ins.AccountAlias != "" {
74 account, err := a.wallet.AccountMgr.FindByAlias(ins.AccountAlias)
76 return NewErrorResponse(err)
79 accountID = account.ID
82 mainchainAddress, controlProgram, claimScript, err := a.wallet.AccountMgr.CreatePeginContractAddress(accountID, false)
84 return NewErrorResponse(err)
87 return NewSuccessResponse(fundingResp{
88 MainchainAddress: mainchainAddress,
89 ControlProgram: controlProgram,
90 ClaimScript: claimScript,