6 "github.com/bytom/blockchain/query"
7 "github.com/bytom/blockchain/signers"
8 chainjson "github.com/bytom/encoding/json"
9 "github.com/bytom/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 annotatedAsset := &query.AnnotatedAsset{
31 RawDefinitionByte: a.RawDefinitionByte,
32 Definition: &jsonDefinition,
33 IssuanceProgram: chainjson.HexBytes(a.IssuanceProgram),
36 annotatedAsset.LimitHeight, _ = vmutil.GetIssuanceProgramRestrictHeight(a.IssuanceProgram)
38 path := signers.GetBip0032Path(a.Signer, signers.AssetKeySpace)
39 var jsonPath []chainjson.HexBytes
40 for _, p := range path {
41 jsonPath = append(jsonPath, p)
43 for _, xpub := range a.Signer.XPubs {
44 derived := xpub.Derive(path)
45 annotatedAsset.Keys = append(annotatedAsset.Keys, &query.AssetKey{
47 AssetPubkey: derived[:],
48 AssetDerivationPath: jsonPath,
51 annotatedAsset.Quorum = a.Signer.Quorum
53 return annotatedAsset, nil