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()
"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"
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)
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)
}
}
}