OSDN Git Service

modify annotated asset signer (#1686)
authoroysheng <33340252+oysheng@users.noreply.github.com>
Wed, 10 Apr 2019 09:00:23 +0000 (17:00 +0800)
committerPaladz <yzhu101@uottawa.ca>
Wed, 10 Apr 2019 09:00:23 +0000 (17:00 +0800)
* modify annotated asset signer

* optimise

asset/annotate.go
blockchain/query/annotated.go

index 167c7e8..2c84852 100644 (file)
@@ -4,7 +4,6 @@ import (
        "encoding/json"
 
        "github.com/bytom/blockchain/query"
-       "github.com/bytom/blockchain/signers"
        chainjson "github.com/bytom/encoding/json"
        "github.com/bytom/protocol/vm/vmutil"
 )
@@ -35,20 +34,13 @@ func Annotated(a *Asset) (*query.AnnotatedAsset, error) {
 
        annotatedAsset.LimitHeight, _ = vmutil.GetIssuanceProgramRestrictHeight(a.IssuanceProgram)
        if a.Signer != nil {
-               path := signers.GetBip0032Path(a.Signer, signers.AssetKeySpace)
-               var jsonPath []chainjson.HexBytes
-               for _, p := range path {
-                       jsonPath = append(jsonPath, p)
+               annotatedAsset.AnnotatedSigner = query.AnnotatedSigner{
+                       Type:       a.Signer.Type,
+                       XPubs:      a.Signer.XPubs,
+                       Quorum:     a.Signer.Quorum,
+                       KeyIndex:   a.Signer.KeyIndex,
+                       DeriveRule: a.Signer.DeriveRule,
                }
-               for _, xpub := range a.Signer.XPubs {
-                       derived := xpub.Derive(path)
-                       annotatedAsset.Keys = append(annotatedAsset.Keys, &query.AssetKey{
-                               RootXPub:            xpub,
-                               AssetPubkey:         derived[:],
-                               AssetDerivationPath: jsonPath,
-                       })
-               }
-               annotatedAsset.Quorum = a.Signer.Quorum
        }
        return annotatedAsset, nil
 }
index c20e29c..30d197f 100644 (file)
@@ -68,22 +68,23 @@ type AnnotatedAccount struct {
 
 //AnnotatedAsset means an annotated asset.
 type AnnotatedAsset struct {
+       AnnotatedSigner
        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.
-type AssetKey struct {
-       RootXPub            chainkd.XPub         `json:"root_xpub"`
-       AssetPubkey         chainjson.HexBytes   `json:"asset_pubkey"`
-       AssetDerivationPath []chainjson.HexBytes `json:"asset_derivation_path"`
+//AnnotatedSigner means an annotated signer for asset.
+type AnnotatedSigner struct {
+       Type       string         `json:"type"`
+       XPubs      []chainkd.XPub `json:"xpubs"`
+       Quorum     int            `json:"quorum"`
+       KeyIndex   uint64         `json:"key_index"`
+       DeriveRule uint8          `json:"derive_rule"`
 }
 
 //AnnotatedUTXO means an annotated utxo.