This commit is contained in:
timurgordon
2025-05-27 11:34:44 +03:00
parent 0da512484f
commit 2a2d69dafb
5 changed files with 68 additions and 38 deletions

View File

@@ -155,7 +155,7 @@ pub fn register_rhai_engine_functions(
engine.register_fn("set_address", |mut asset: Asset, address: ImmutableString| -> Result<Asset, Box<EvalAltResult>> {
asset.address = address.to_string(); Ok(asset)
});
engine.register_fn("set_asset_type_str", |mut asset: Asset, asset_type_str: ImmutableString| -> Result<Asset, Box<EvalAltResult>> {
engine.register_fn("set_asset_type", |mut asset: Asset, asset_type_str: ImmutableString| -> Result<Asset, Box<EvalAltResult>> {
asset.asset_type = self::string_to_asset_type(asset_type_str.as_str())?;
Ok(asset)
});
@@ -179,9 +179,10 @@ pub fn register_rhai_engine_functions(
engine.register_get("seller_id", |l: &mut Listing| -> ImmutableString { l.seller_id.clone().into() });
engine.register_get("price", |l: &mut Listing| l.price);
engine.register_get("currency", |l: &mut Listing| -> ImmutableString { l.currency.clone().into() });
engine.register_get("listing_type_str", |l: &mut Listing| -> ImmutableString { self::listing_type_to_string(&l.listing_type) });
engine.register_get("status_str", |l: &mut Listing| -> ImmutableString { self::listing_status_to_string(&l.status) });
engine.register_get("listing_type", |l: &mut Listing| l.listing_type.clone());
engine.register_get("status", |l: &mut Listing| l.status.clone());
engine.register_get("expires_at_ts", |l: &mut Listing| l.expires_at);
engine.register_get("expires_at_ts_opt", |l: &mut Listing| l.expires_at.map(|dt| dt.timestamp()));
engine.register_get("tags", |l: &mut Listing| -> Result<Array, Box<EvalAltResult>> {
Ok(l.tags.iter().map(|s| Dynamic::from(s.clone())).collect())
});
@@ -199,7 +200,7 @@ pub fn register_rhai_engine_functions(
engine.register_fn("set_asset_id", |mut l: Listing, asset_id: ImmutableString| -> Result<Listing, Box<EvalAltResult>> {
l.asset_id = asset_id.to_string(); Ok(l)
});
engine.register_fn("set_asset_type_str", |mut l: Listing, asset_type_str: ImmutableString| -> Result<Listing, Box<EvalAltResult>> {
engine.register_fn("set_asset_type", |mut l: Listing, asset_type_str: ImmutableString| -> Result<Listing, Box<EvalAltResult>> {
l.asset_type = self::string_to_asset_type(asset_type_str.as_str())?;
Ok(l)
});
@@ -212,8 +213,8 @@ pub fn register_rhai_engine_functions(
engine.register_fn("set_currency", |mut l: Listing, currency: ImmutableString| -> Result<Listing, Box<EvalAltResult>> {
l.currency = currency.to_string(); Ok(l)
});
engine.register_fn("set_listing_type_str", |mut l: Listing, listing_type_str: ImmutableString| -> Result<Listing, Box<EvalAltResult>> {
l.listing_type = self::string_to_listing_type(listing_type_str.as_str())?;
engine.register_fn("set_listing_type", |mut l: Listing, listing_type: ImmutableString| -> Result<Listing, Box<EvalAltResult>> {
l.listing_type = self::string_to_listing_type(listing_type.as_str())?;
Ok(l)
});
engine.register_fn("set_status_str", |mut l: Listing, status_str: ImmutableString| -> Result<Listing, Box<EvalAltResult>> {