OSDN Git Service

Merge pull request #201 from Bytom/v0.1
[bytom/vapor.git] / asset / annotate.go
1 package asset
2
3 import (
4         "encoding/json"
5
6         "github.com/vapor/blockchain/query"
7         chainjson "github.com/vapor/encoding/json"
8 )
9
10 //Annotated annotate the asset
11 func Annotated(a *Asset) (*query.AnnotatedAsset, error) {
12         jsonDefinition := json.RawMessage(`{}`)
13
14         // a.RawDefinitionByte is the asset definition as it appears on the
15         // blockchain, so it's untrusted and may not be valid json.
16         if chainjson.IsValidJSON(a.RawDefinitionByte) {
17                 jsonDefinition = json.RawMessage(a.RawDefinitionByte)
18         }
19
20         annotatedAsset := &query.AnnotatedAsset{
21                 ID:                a.AssetID,
22                 Alias:             *a.Alias,
23                 VMVersion:         a.VMVersion,
24                 RawDefinitionByte: a.RawDefinitionByte,
25                 Definition:        &jsonDefinition,
26         }
27
28         return annotatedAsset, nil
29 }