From 0f35bc5d01cc4b193793c0694cb765dd250e0ce0 Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Sun, 14 Apr 2024 03:09:24 +0200 Subject: [PATCH] cli: support kit import --- Cargo.lock | 12 ++++++------ cli/src/command.rs | 37 +++++++++++++++++++++++++++++++++++-- 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 08b0641..6cb2458 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -29,7 +29,7 @@ dependencies = [ [[package]] name = "aluvm" version = "0.11.0-beta.5" -source = "git+https://github.com/AluVM/rust-aluvm?branch=v0.11#472920854cd92b65f44d7b9e299a8a3df4afa6ce" +source = "git+https://github.com/AluVM/rust-aluvm?branch=v0.11#a08387f744f6679b6ee308e70f99099c318824db" dependencies = [ "amplify", "ascii-armor", @@ -1551,7 +1551,7 @@ dependencies = [ [[package]] name = "rgb-core" version = "0.11.0-beta.5" -source = "git+https://github.com/RGB-WG/rgb-core?branch=script-refactor#8392d42e0e21be8ec4ec2641a249b6682137b4a6" +source = "git+https://github.com/RGB-WG/rgb-core?branch=script-refactor#e0b0181b019ed5c59e4bf4dcf77402358a57fcb1" dependencies = [ "aluvm", "amplify", @@ -1573,7 +1573,7 @@ dependencies = [ [[package]] name = "rgb-invoice" version = "0.11.0-beta.5" -source = "git+https://github.com/RGB-WG/rgb-std?branch=script-refactor#7b0acfde419a27196cf26f317d816ece1071b41d" +source = "git+https://github.com/RGB-WG/rgb-std?branch=script-refactor#f95c39f5a74717e486bf6f8b82f25e5f4c088c26" dependencies = [ "amplify", "baid58", @@ -1633,7 +1633,7 @@ dependencies = [ [[package]] name = "rgb-std" version = "0.11.0-beta.5" -source = "git+https://github.com/RGB-WG/rgb-std?branch=script-refactor#7b0acfde419a27196cf26f317d816ece1071b41d" +source = "git+https://github.com/RGB-WG/rgb-std?branch=script-refactor#f95c39f5a74717e486bf6f8b82f25e5f4c088c26" dependencies = [ "aluvm", "amplify", @@ -2073,7 +2073,7 @@ checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" [[package]] name = "strict_encoding" version = "2.7.0-beta.1" -source = "git+https://github.com/strict-types/strict-encoding?branch=rstring#5e93109453243366f18defde30aa7191f7f3218e" +source = "git+https://github.com/strict-types/strict-encoding?branch=rstring#561f0070344f4f2c2f5fcb062b4e2e62d3ab12dd" dependencies = [ "amplify", "half", @@ -2084,7 +2084,7 @@ dependencies = [ [[package]] name = "strict_encoding_derive" version = "2.7.0-beta.1" -source = "git+https://github.com/strict-types/strict-encoding?branch=rstring#5e93109453243366f18defde30aa7191f7f3218e" +source = "git+https://github.com/strict-types/strict-encoding?branch=rstring#561f0070344f4f2c2f5fcb062b4e2e62d3ab12dd" dependencies = [ "amplify_syn", "heck 0.4.1", diff --git a/cli/src/command.rs b/cli/src/command.rs index be9041c..0ae1a83 100644 --- a/cli/src/command.rs +++ b/cli/src/command.rs @@ -384,7 +384,40 @@ impl Exec for RgbArgs { } else { let content = UniversalFile::load_file(file)?; match content { - UniversalFile::Kit(_) => todo!(), + UniversalFile::Kit(kit) => { + let id = kit.kit_id(); + eprintln!("Importing kit {id}"); + let mut iface_names = map![]; + let mut schema_names = map![]; + for iface in &kit.ifaces { + let iface_id = iface.iface_id(); + iface_names.insert(iface_id, &iface.name); + eprintln!("- Interface {} {}", iface.name, iface_id); + } + for schema in &kit.schemata { + let schema_id = schema.schema_id(); + schema_names.insert(schema_id, &schema.name); + eprintln!("- Schema {} {}", schema.name, schema_id); + } + for iimpl in &kit.iimpls { + let iface = iface_names + .get(&iimpl.iface_id) + .map(|name| name.to_string()) + .unwrap_or_else(|| iimpl.iface_id.to_string()); + let schema = schema_names + .get(&iimpl.schema_id) + .map(|name| name.to_string()) + .unwrap_or_else(|| iimpl.schema_id.to_string()); + eprintln!("- Implementation of {iface} for {schema}",); + } + for lib in &kit.scripts { + eprintln!("- AluVM library {}", lib.id()); + } + eprintln!("- Strict types: {} definitions", kit.types.len()); + let kit = kit.validate().map_err(|(status, _)| status.to_string())?; + runtime.import_kit(kit)?; + eprintln!("Kit is imported"); + } UniversalFile::Contract(contract) => { let mut resolver = self.resolver()?; let id = contract.consignment_id(); @@ -392,7 +425,7 @@ impl Exec for RgbArgs { .validate(&mut resolver, self.general.network.is_testnet()) .map_err(|(status, _)| status.to_string())?; runtime.import_contract(contract, &mut resolver)?; - eprintln!("Contract {id} imported to the stash"); + eprintln!("Contract {id} is imported"); } UniversalFile::Transfer(_) => { return Err(s!("use `validate` and `accept` commands to work with \