github.com/Bytom/bytom@v1.1.2-0.20210127130405-ae40204c0b09/api/assets.go (about)

     1  package api
     2  
     3  import (
     4  	"context"
     5  	"strings"
     6  
     7  	"github.com/bytom/bytom/asset"
     8  	"github.com/bytom/bytom/crypto/ed25519/chainkd"
     9  	chainjson "github.com/bytom/bytom/encoding/json"
    10  
    11  	log "github.com/sirupsen/logrus"
    12  )
    13  
    14  // POST /create-asset
    15  func (a *API) createAsset(ctx context.Context, ins struct {
    16  	Alias           string                 `json:"alias"`
    17  	RootXPubs       []chainkd.XPub         `json:"root_xpubs"`
    18  	Quorum          int                    `json:"quorum"`
    19  	Definition      map[string]interface{} `json:"definition"`
    20  	LimitHeight     int64                  `json:"limit_height"`
    21  	IssuanceProgram chainjson.HexBytes     `json:"issuance_program"`
    22  }) Response {
    23  	ass, err := a.wallet.AssetReg.Define(
    24  		ins.RootXPubs,
    25  		ins.Quorum,
    26  		ins.Definition,
    27  		ins.LimitHeight,
    28  		strings.ToUpper(strings.TrimSpace(ins.Alias)),
    29  		ins.IssuanceProgram,
    30  	)
    31  	if err != nil {
    32  		return NewErrorResponse(err)
    33  	}
    34  
    35  	annotatedAsset, err := asset.Annotated(ass)
    36  	if err != nil {
    37  		return NewErrorResponse(err)
    38  	}
    39  
    40  	log.WithField("asset ID", annotatedAsset.ID.String()).Info("Created asset")
    41  
    42  	return NewSuccessResponse(annotatedAsset)
    43  }
    44  
    45  // POST /update-asset-alias
    46  func (a *API) updateAssetAlias(updateAlias struct {
    47  	ID       string `json:"id"`
    48  	NewAlias string `json:"alias"`
    49  }) Response {
    50  	if err := a.wallet.AssetReg.UpdateAssetAlias(updateAlias.ID, updateAlias.NewAlias); err != nil {
    51  		return NewErrorResponse(err)
    52  	}
    53  
    54  	return NewSuccessResponse(nil)
    55  }