OSDN Git Service

init for remove issue (#63)
[bytom/vapor.git] / asset / annotate.go
1 package asset
2
3 import (
4         "encoding/json"
5
6         "github.com/vapor/blockchain/query"
7 )
8
9 func isValidJSON(b []byte) bool {
10         var v interface{}
11         err := json.Unmarshal(b, &v)
12         return err == nil
13 }
14
15 //Annotated annotate the asset
16 func Annotated(a *Asset) (*query.AnnotatedAsset, error) {
17         jsonDefinition := json.RawMessage(`{}`)
18
19         // a.RawDefinitionByte is the asset definition as it appears on the
20         // blockchain, so it's untrusted and may not be valid json.
21         if isValidJSON(a.RawDefinitionByte) {
22                 jsonDefinition = json.RawMessage(a.RawDefinitionByte)
23         }
24
25         annotatedAsset := &query.AnnotatedAsset{
26                 ID:                a.AssetID,
27                 Alias:             *a.Alias,
28                 VMVersion:         a.VMVersion,
29                 RawDefinitionByte: a.RawDefinitionByte,
30                 Definition:        &jsonDefinition,
31         }
32
33         return annotatedAsset, nil
34 }