OSDN Git Service

init saveExternalAssetDefinition
authorHAOYUatHZ <haoyu@protonmail.com>
Wed, 22 May 2019 08:10:55 +0000 (16:10 +0800)
committerHAOYUatHZ <haoyu@protonmail.com>
Wed, 22 May 2019 08:10:55 +0000 (16:10 +0800)
asset/builder.go
wallet/indexer.go

index 65fcaf6..d323edc 100644 (file)
@@ -32,7 +32,7 @@ type crossInAction struct {
 }
 
 // TODO: also need to hard-code mapTx
-// TODO: iter cross-in and save asset
+// TODO: iter cross-in and save asset, saveExternalAssetDefinition
 // TODO: federation can sign? check arguments length?
 func (a *crossInAction) Build(ctx context.Context, builder *txbuilder.TemplateBuilder) error {
        var missing []string
@@ -82,11 +82,11 @@ func (a *crossInAction) Build(ctx context.Context, builder *txbuilder.TemplateBu
 
        var sourceID bc.Hash
        if err := sourceID.UnmarshalText([]byte(a.SourceID)); err != nil {
-               return errors.New("invalid source ID format")
+               return errors.New("invalid sourceID format")
        }
 
        txin := types.NewCrossChainInput(arguments, sourceID, *a.AssetId, a.Amount, a.SourcePos, a.Program, asset.RawDefinitionByte)
-       log.Info("cross-chain input action build")
+       log.Info("cross-chain input action built")
        builder.RestrictMinTime(time.Now())
        return builder.AddInput(txin, &txbuilder.SigningInstruction{})
 }
index ddf7248..86b1268 100644 (file)
@@ -87,7 +87,14 @@ func saveExternalAssetDefinition(b *types.Block, walletDB dbm.DB) {
 
        for _, tx := range b.Transactions {
                for _, _ = range tx.Inputs {
-                       // handle cross chain input here
+                       if cci, ok := orig.TypedInput.(*types.CrossChainInput); ok {
+                               if isValidJSON(cci.AssetDefinition) {
+                                       assetID := cci.AssetID()
+                                       if assetExist := walletDB.Get(asset.ExtAssetKey(&assetID)); assetExist == nil {
+                                               storeBatch.Set(asset.ExtAssetKey(&assetID), cci.AssetDefinition)
+                                       }
+                               }
+                       }
                }
        }
 }