log "github.com/sirupsen/logrus"
"github.com/bytom/account"
+ "github.com/bytom/asset"
"github.com/bytom/blockchain/query"
"github.com/bytom/blockchain/signers"
"github.com/bytom/blockchain/txbuilder"
func (a *API) getAsset(ctx context.Context, filter struct {
ID string `json:"id"`
}) Response {
- asset, err := a.wallet.AssetReg.GetAsset(filter.ID)
+ ass, err := a.wallet.AssetReg.GetAsset(filter.ID)
if err != nil {
log.Errorf("getAsset: %v", err)
return NewErrorResponse(err)
}
- return NewSuccessResponse(asset)
+ annotatedAsset, err := asset.Annotated(ass)
+ if err != nil {
+ return NewErrorResponse(err)
+ }
+ return NewSuccessResponse(annotatedAsset)
}
// POST /list-assets
return NewErrorResponse(err)
}
- return NewSuccessResponse(assets)
+ annotatedAssets := []*query.AnnotatedAsset{}
+ for _, ass := range assets {
+ annotatedAsset, err := asset.Annotated(ass)
+ if err != nil {
+ return NewErrorResponse(err)
+ }
+ annotatedAssets = append(annotatedAssets, annotatedAsset)
+ }
+ return NewSuccessResponse(annotatedAssets)
}
// POST /list-balances
"github.com/bytom/blockchain/query"
"github.com/bytom/blockchain/signers"
chainjson "github.com/bytom/encoding/json"
+ "github.com/bytom/protocol/vm/vmutil"
)
func isValidJSON(b []byte) bool {
jsonDefinition = json.RawMessage(a.RawDefinitionByte)
}
- aa := &query.AnnotatedAsset{
- ID: a.AssetID,
- Definition: &jsonDefinition,
- IssuanceProgram: chainjson.HexBytes(a.IssuanceProgram),
- }
- if a.Alias != nil {
- aa.Alias = *a.Alias
+ annotatedAsset := &query.AnnotatedAsset{
+ ID: a.AssetID,
+ Alias: *a.Alias,
+ RawDefinitionByte: a.RawDefinitionByte,
+ Definition: &jsonDefinition,
+ IssuanceProgram: chainjson.HexBytes(a.IssuanceProgram),
}
+
+ annotatedAsset.LimitHeight, _ = vmutil.GetIssuanceProgramRestrictHeight(a.IssuanceProgram)
if a.Signer != nil {
path := signers.GetBip0032Path(a.Signer, signers.AssetKeySpace)
var jsonPath []chainjson.HexBytes
}
for _, xpub := range a.Signer.XPubs {
derived := xpub.Derive(path)
- aa.Keys = append(aa.Keys, &query.AssetKey{
+ annotatedAsset.Keys = append(annotatedAsset.Keys, &query.AssetKey{
RootXPub: xpub,
AssetPubkey: derived[:],
AssetDerivationPath: jsonPath,
})
}
- aa.Quorum = a.Signer.Quorum
+ annotatedAsset.Quorum = a.Signer.Quorum
}
- return aa, nil
+ return annotatedAsset, nil
}
//AnnotatedAsset means an annotated asset.
type AnnotatedAsset struct {
- ID bc.AssetID `json:"id"`
- Alias string `json:"alias,omitempty"`
- IssuanceProgram chainjson.HexBytes `json:"issuance_program"`
- Keys []*AssetKey `json:"keys"`
- Quorum int `json:"quorum"`
- Definition *json.RawMessage `json:"definition"`
+ ID bc.AssetID `json:"id"`
+ Alias string `json:"alias"`
+ VMVersion uint64 `json:"vm_version"`
+ IssuanceProgram chainjson.HexBytes `json:"issue_program"`
+ Keys []*AssetKey `json:"keys"`
+ Quorum int `json:"quorum"`
+ RawDefinitionByte chainjson.HexBytes `json:"raw_definition_byte"`
+ Definition *json.RawMessage `json:"definition"`
+ LimitHeight int64 `json:"limit_height"`
}
//AssetKey means an asset key.
}
return nil
}
+
+// GetIssuanceProgramRestrictHeight return issuance program restrict height
+func GetIssuanceProgramRestrictHeight(program []byte) (int64, error) {
+ insts, err := vm.ParseProgram(program)
+ if err != nil {
+ return 0, err
+ }
+
+ if insts[0].IsPushdata() && insts[1].Op == vm.OP_BLOCKHEIGHT && insts[2].Op == vm.OP_GREATERTHAN && insts[3].Op == vm.OP_VERIFY {
+ return vm.AsInt64(insts[0].Data)
+ }
+ return 0, nil
+}