OSDN Git Service

elegent the code
[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 }) Response {
20         ass, err := a.wallet.AssetReg.Define(
21                 ins.RootXPubs,
22                 ins.Quorum,
23                 ins.Definition,
24                 strings.ToUpper(strings.TrimSpace(ins.Alias)),
25         )
26         if err != nil {
27                 return NewErrorResponse(err)
28         }
29
30         annotatedAsset, err := asset.Annotated(ass)
31         if err != nil {
32                 return NewErrorResponse(err)
33         }
34
35         log.WithField("asset ID", annotatedAsset.ID.String()).Info("Created asset")
36
37         return NewSuccessResponse(annotatedAsset)
38 }
39
40 // POST /update-asset-alias
41 func (a *API) updateAssetAlias(updateAlias struct {
42         ID       string `json:"id"`
43         NewAlias string `json:"alias"`
44 }) Response {
45         if err := a.wallet.AssetReg.UpdateAssetAlias(updateAlias.ID, updateAlias.NewAlias); err != nil {
46                 return NewErrorResponse(err)
47         }
48
49         return NewSuccessResponse(nil)
50 }