OSDN Git Service

Merge pull request #41 from Bytom/dev
[bytom/vapor.git] / api / receivers.go
1 package api
2
3 import (
4         "context"
5
6         "github.com/vapor/blockchain/txbuilder"
7         "github.com/vapor/claim/rpc"
8         chainjson "github.com/vapor/encoding/json"
9 )
10
11 func (a *API) createAccountReceiver(ctx context.Context, ins struct {
12         AccountID    string `json:"account_id"`
13         AccountAlias string `json:"account_alias"`
14 }) 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 }
35
36 type fundingResp struct {
37         MainchainAddress string             `json:"mainchain_address"`
38         ControlProgram   chainjson.HexBytes `json:"control_program,omitempty"`
39         ClaimScript      chainjson.HexBytes `json:"claim_script"`
40 }
41
42 func (a *API) getPeginAddress(ctx context.Context, ins rpc.ClaimArgs) Response {
43
44         pegin := &rpc.BytomPeginRpc{
45                 ClaimArgs: ins,
46                 Wallet:    a.wallet,
47         }
48
49         resp, err := pegin.GetPeginAddress()
50         if err != nil {
51                 return NewErrorResponse(err)
52         }
53
54         return NewSuccessResponse(resp)
55 }
56
57 func (a *API) getPeginContractAddress(ctx context.Context, ins struct {
58         AccountID    string `json:"account_id"`
59         AccountAlias string `json:"account_alias"`
60 }) Response {
61         pegin := &rpc.BytomPeginRpc{
62                 ClaimArgs: ins,
63                 Wallet:    a.wallet,
64         }
65         resp, err := pegin.GetPeginContractAddress()
66         if err != nil {
67                 return NewErrorResponse(err)
68         }
69
70         return NewSuccessResponse(resp)
71 }