DefinitionMap map[string]interface{} `json:"definition"`
}
+// SaveExtAsset store external asset
+func (reg *Registry) SaveExtAsset(a *Asset, alias string) error {
+ reg.assetMu.Lock()
+ defer reg.assetMu.Unlock()
+
+ aliasKey := aliasKey(alias)
+ 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()
type crossInAction struct {
reg *Registry
bc.AssetAmount
- SourceID string `json:"source_id"` // AnnotatedUTXO
+ SourceID string `json:"source_id"`
SourcePos uint64 `json:"source_pos"`
Program chainjson.HexBytes `json:"control_program"`
AssetDefinition map[string]interface{} `json:"asset_definition"`
}
// TODO: also need to hard-code mapTx
-// TODO: iter cross-in and save asset, saveExternalAssetDefinition
-// TODO: federation can sign? check arguments length?
+// TODO: federation can sign? check arguments length? will path be diff?
func (a *crossInAction) Build(ctx context.Context, builder *txbuilder.TemplateBuilder) error {
var missing []string
if len(a.Program) == 0 {
asset.AssetID = *a.AssetId
extAlias := a.AssetId.String()
asset.Alias = &(extAlias)
- a.reg.SaveAsset(asset, extAlias)
+ a.reg.SaveExtAsset(asset, extAlias)
}
arguments := [][]byte{}