OSDN Git Service

feat: add build crosschain input (#91)
[bytom/vapor.git] / wallet / indexer.go
index ddf7248..f3b7d57 100644 (file)
@@ -9,6 +9,7 @@ import (
        log "github.com/sirupsen/logrus"
 
        "github.com/vapor/account"
        log "github.com/sirupsen/logrus"
 
        "github.com/vapor/account"
+       "github.com/vapor/asset"
        "github.com/vapor/blockchain/query"
        "github.com/vapor/crypto/sha3pool"
        dbm "github.com/vapor/database/leveldb"
        "github.com/vapor/blockchain/query"
        "github.com/vapor/crypto/sha3pool"
        dbm "github.com/vapor/database/leveldb"
@@ -86,8 +87,13 @@ func saveExternalAssetDefinition(b *types.Block, walletDB dbm.DB) {
        defer storeBatch.Write()
 
        for _, tx := range b.Transactions {
        defer storeBatch.Write()
 
        for _, tx := range b.Transactions {
-               for _, _ = range tx.Inputs {
-                       // handle cross chain input here
+               for _, orig := range tx.Inputs {
+                       if cci, ok := orig.TypedInput.(*types.CrossChainInput); ok {
+                               assetID := cci.AssetId
+                               if assetExist := walletDB.Get(asset.ExtAssetKey(assetID)); assetExist == nil {
+                                       storeBatch.Set(asset.ExtAssetKey(assetID), cci.AssetDefinition)
+                               }
+                       }
                }
        }
 }
                }
        }
 }