6 "github.com/vapor/blockchain/query"
7 chainjson "github.com/vapor/encoding/json"
8 "github.com/vapor/protocol/vm/vmutil"
11 func isValidJSON(b []byte) bool {
13 err := json.Unmarshal(b, &v)
17 //Annotated annotate the asset
18 func Annotated(a *Asset) (*query.AnnotatedAsset, error) {
19 jsonDefinition := json.RawMessage(`{}`)
21 // a.RawDefinitionByte is the asset definition as it appears on the
22 // blockchain, so it's untrusted and may not be valid json.
23 if isValidJSON(a.RawDefinitionByte) {
24 jsonDefinition = json.RawMessage(a.RawDefinitionByte)
27 annotatedAsset := &query.AnnotatedAsset{
30 VMVersion: a.VMVersion,
31 RawDefinitionByte: a.RawDefinitionByte,
32 Definition: &jsonDefinition,
33 IssuanceProgram: chainjson.HexBytes(a.IssuanceProgram),
36 annotatedAsset.LimitHeight = vmutil.GetIssuanceProgramRestrictHeight(a.IssuanceProgram)
38 annotatedAsset.AnnotatedSigner = query.AnnotatedSigner{
40 XPubs: a.Signer.XPubs,
41 Quorum: a.Signer.Quorum,
42 KeyIndex: a.Signer.KeyIndex,
43 DeriveRule: a.Signer.DeriveRule,
46 return annotatedAsset, nil