OSDN Git Service

make some fields of BlockchainReactor public to facilitate separate API (#477)
[bytom/bytom-spv.git] / blockchain / assets.go
1 package blockchain
2
3 import (
4         "context"
5
6         "github.com/bytom/asset"
7         "github.com/bytom/crypto/ed25519/chainkd"
8
9         log "github.com/sirupsen/logrus"
10 )
11
12 // POST /create-asset
13 func (a *API) createAsset(ctx context.Context, ins struct {
14         Alias      string                 `json:"alias"`
15         RootXPubs  []chainkd.XPub         `json:"root_xpubs"`
16         Quorum     int                    `json:"quorum"`
17         Definition map[string]interface{} `json:"definition"`
18         Tags       map[string]interface{} `json:"tags"`
19 }) Response {
20         ass, err := a.wallet.AssetReg.Define(
21                 ins.RootXPubs,
22                 ins.Quorum,
23                 ins.Definition,
24                 ins.Alias,
25                 ins.Tags,
26         )
27         if err != nil {
28                 return NewErrorResponse(err)
29         }
30
31         annotatedAsset, err := asset.Annotated(ass)
32         if err != nil {
33                 return NewErrorResponse(err)
34         }
35
36         log.WithField("asset ID", annotatedAsset.ID.String()).Info("Created asset")
37
38         return NewSuccessResponse(annotatedAsset)
39 }
40
41 // POST /update-asset-tags
42 func (a *API) updateAssetTags(ctx context.Context, updateTag struct {
43         AssetInfo string                 `json:"asset_info"`
44         Tags      map[string]interface{} `json:"tags"`
45 }) Response {
46         err := a.wallet.AssetReg.UpdateTags(nil, updateTag.AssetInfo, updateTag.Tags)
47         if err != nil {
48                 return NewErrorResponse(err)
49         }
50
51         return NewSuccessResponse(nil)
52 }
53
54 // POST /update-asset-alias
55 func (a *API) updateAssetAlias(updateAlias struct {
56         OldAlias string `json:"old_alias"`
57         NewAlias string `json:"new_alias"`
58 }) Response {
59         if err := a.wallet.AssetReg.UpdateAssetAlias(updateAlias.OldAlias, updateAlias.NewAlias); err != nil {
60                 return NewErrorResponse(err)
61         }
62
63         return NewSuccessResponse(nil)
64 }