OSDN Git Service

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