6 "github.com/vapor/blockchain/query"
7 "github.com/vapor/blockchain/signers"
8 chainjson "github.com/vapor/encoding/json"
9 "github.com/vapor/protocol/vm/vmutil"
12 func isValidJSON(b []byte) bool {
14 err := json.Unmarshal(b, &v)
18 //Annotated annotate the asset
19 func Annotated(a *Asset) (*query.AnnotatedAsset, error) {
20 jsonDefinition := json.RawMessage(`{}`)
22 // a.RawDefinitionByte is the asset definition as it appears on the
23 // blockchain, so it's untrusted and may not be valid json.
24 if isValidJSON(a.RawDefinitionByte) {
25 jsonDefinition = json.RawMessage(a.RawDefinitionByte)
28 aa := &query.AnnotatedAsset{
30 Definition: &jsonDefinition,
31 IssuanceProgram: chainjson.HexBytes(a.IssuanceProgram),
37 path := signers.GetBip0032Path(a.Signer, signers.AssetKeySpace)
38 var jsonPath []chainjson.HexBytes
39 for _, p := range path {
40 jsonPath = append(jsonPath, p)
42 for _, xpub := range a.Signer.XPubs {
43 derived := xpub.Derive(path)
44 aa.Keys = append(aa.Keys, &query.AssetKey{
46 AssetPubkey: derived[:],
47 AssetDerivationPath: jsonPath,
50 aa.Quorum = a.Signer.Quorum
52 pubkeys, quorum, err := vmutil.ParseP2SPMultiSigProgram(a.IssuanceProgram)
54 for _, pubkey := range pubkeys {
56 aa.Keys = append(aa.Keys, &query.AssetKey{
57 AssetPubkey: chainjson.HexBytes(pubkey[:]),