OSDN Git Service

20df934f90190c0e6f93935f45f8d4b15d478d74
[bytom/bytom.git] / blockchain / accounts.go
1 package blockchain
2
3 import (
4         "context"
5
6         "github.com/bytom/blockchain/account"
7         "github.com/bytom/crypto/ed25519/chainkd"
8
9         log "github.com/sirupsen/logrus"
10 )
11
12 // POST /create-account
13 func (bcr *BlockchainReactor) createAccount(ctx context.Context, ins struct {
14         RootXPubs []chainkd.XPub         `json:"root_xpubs"`
15         Quorum    int                    `json:"quorum"`
16         Alias     string                 `json:"alias"`
17         Tags      map[string]interface{} `json:"tags"`
18 }) Response {
19         acc, err := bcr.accounts.Create(ctx, ins.RootXPubs, ins.Quorum, ins.Alias, ins.Tags)
20         if err != nil {
21                 return NewErrorResponse(err)
22         }
23
24         annotatedAccount, err := account.Annotated(acc)
25         if err != nil {
26                 return NewErrorResponse(err)
27         }
28
29         log.WithField("account ID", annotatedAccount.ID).Info("Created account")
30
31         return NewSuccessResponse(annotatedAccount)
32 }
33
34 // POST /update-account-tags
35 func (bcr *BlockchainReactor) updateAccountTags(ctx context.Context, updateTag struct {
36         AccountInfo string                 `json:"account_info"`
37         Tags        map[string]interface{} `json:"tags"`
38 }) Response {
39
40         err := bcr.accounts.UpdateTags(nil, updateTag.AccountInfo, updateTag.Tags)
41         if err != nil {
42                 return NewErrorResponse(err)
43         }
44
45         return NewSuccessResponse(nil)
46 }
47
48 //
49 // POST /delete-account
50 func (bcr *BlockchainReactor) deleteAccount(ctx context.Context, in struct {
51         AccountInfo string `json:"account_info"`
52 }) Response {
53         if err := bcr.accounts.DeleteAccount(in); err != nil {
54                 return NewErrorResponse(err)
55         }
56         return NewSuccessResponse(nil)
57 }