OSDN Git Service

fix https://github.com/Bytom/vapor/pull/77/files#r286744635 & https://github.com...
authorHAOYUatHZ <haoyu@protonmail.com>
Thu, 23 May 2019 02:29:32 +0000 (10:29 +0800)
committerHAOYUatHZ <haoyu@protonmail.com>
Thu, 23 May 2019 02:29:32 +0000 (10:29 +0800)
asset/asset.go
asset/builder.go
wallet/indexer.go

index 6cfebe9..12ae60b 100644 (file)
@@ -102,33 +102,6 @@ type Asset struct {
        DefinitionMap     map[string]interface{} `json:"definition"`
 }
 
-// SaveExtAsset store external asset
-func (reg *Registry) SaveExtAsset(a *Asset) error {
-       reg.assetMu.Lock()
-       defer reg.assetMu.Unlock()
-
-       aliasKey := aliasKey(a.AssetID.String())
-       if existed := reg.db.Get(aliasKey); existed != nil {
-               return ErrDuplicateAlias
-       }
-
-       assetKey := ExtAssetKey(&a.AssetID)
-       if existAsset := reg.db.Get(assetKey); existAsset != nil {
-               return ErrDuplicateAsset
-       }
-
-       rawAsset, err := json.Marshal(a)
-       if err != nil {
-               return ErrMarshalAsset
-       }
-
-       storeBatch := reg.db.NewBatch()
-       storeBatch.Set(aliasKey, []byte(a.AssetID.String()))
-       storeBatch.Set(assetKey, rawAsset)
-       storeBatch.Write()
-       return nil
-}
-
 // SaveAsset store asset
 func (reg *Registry) SaveAsset(a *Asset, alias string) error {
        reg.assetMu.Lock()
index ca36b0d..5b7d333 100644 (file)
@@ -9,7 +9,6 @@ import (
 
        "github.com/vapor/blockchain/txbuilder"
        "github.com/vapor/consensus/federation"
-       chainjson "github.com/vapor/encoding/json"
        "github.com/vapor/errors"
        "github.com/vapor/protocol/bc"
        "github.com/vapor/protocol/bc/types"
@@ -52,31 +51,14 @@ func (a *crossInAction) Build(ctx context.Context, builder *txbuilder.TemplateBu
                return errors.New("mainchain output double spent")
        }
 
-       var err error
-       asset := &Asset{}
-       if preAsset, _ := a.reg.GetAsset(a.AssetId.String()); preAsset != nil {
-               asset = preAsset
-       } else {
-               asset.RawDefinitionByte, err = serializeAssetDef(a.AssetDefinition)
-               if err != nil {
-                       return ErrSerializing
-               }
-
-               if !chainjson.IsValidJSON(asset.RawDefinitionByte) {
-                       return errors.New("asset definition is not in valid json format")
-               }
-
-               asset.DefinitionMap = a.AssetDefinition
-               asset.VMVersion = 1
-               asset.AssetID = *a.AssetId
-               extAlias := a.AssetId.String()
-               asset.Alias = &(extAlias)
-               a.reg.SaveExtAsset(asset)
+       rawDefinitionByte, err := serializeAssetDef(a.AssetDefinition)
+       if err != nil {
+               return ErrSerializing
        }
 
        fed := federation.GetFederation()
        // arguments will be set when materializeWitnesses
-       txin := types.NewCrossChainInput(nil, a.SourceID, *a.AssetId, a.Amount, a.SourcePos, fed.ControlProgram, asset.RawDefinitionByte)
+       txin := types.NewCrossChainInput(nil, a.SourceID, *a.AssetId, a.Amount, a.SourcePos, fed.ControlProgram, rawDefinitionByte)
        log.Info("cross-chain input action built")
        tplIn := &txbuilder.SigningInstruction{}
        tplIn.AddRawWitnessKeys(fed.XPubs, fed.Path, fed.Quorum)
index 96ecd9d..f3b7d57 100644 (file)
@@ -89,11 +89,9 @@ func saveExternalAssetDefinition(b *types.Block, walletDB dbm.DB) {
        for _, tx := range b.Transactions {
                for _, orig := range tx.Inputs {
                        if cci, ok := orig.TypedInput.(*types.CrossChainInput); ok {
-                               if chainjson.IsValidJSON(cci.AssetDefinition) {
-                                       assetID := cci.AssetId
-                                       if assetExist := walletDB.Get(asset.ExtAssetKey(assetID)); assetExist == nil {
-                                               storeBatch.Set(asset.ExtAssetKey(assetID), cci.AssetDefinition)
-                                       }
+                               assetID := cci.AssetId
+                               if assetExist := walletDB.Get(asset.ExtAssetKey(assetID)); assetExist == nil {
+                                       storeBatch.Set(asset.ExtAssetKey(assetID), cci.AssetDefinition)
                                }
                        }
                }