From 884827e0912a8df6cae618c03e93786e863e9349 Mon Sep 17 00:00:00 2001 From: stringhandler Date: Wed, 22 Nov 2023 15:08:16 +0200 Subject: [PATCH 1/2] feat: add metadata string parser (#780) Description --- Adds the ability to pass in a string that will converted to a Metadata table in the dan_wallet_client Motivation and Context --- It was previously not possible to create a Metadata object from args passed to a scaffolded CLI program. I believe this would have been a problem for JS clients as well. This makes it possible to pass a CLI arg in the form `key=value, key2=value` and it will be converted to a Metadata table. How Has This Been Tested? --- Tested using the scaffold of the stablecoin contract, passing in `provider_name=mike` What process can a PR reviewer use to test or verify this change? --- Scaffold a contract that takes in a parameter of type Metadata, then call that method using the above syntax Breaking Changes --- - [x] None - [ ] Requires data directory to be deleted - [ ] Other - Please specify --- dan_layer/engine_types/src/argument_parser.rs | 12 ++++++++++- dan_layer/template_lib/src/models/metadata.rs | 21 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/dan_layer/engine_types/src/argument_parser.rs b/dan_layer/engine_types/src/argument_parser.rs index f6762c5c3..101c6ee17 100644 --- a/dan_layer/engine_types/src/argument_parser.rs +++ b/dan_layer/engine_types/src/argument_parser.rs @@ -5,7 +5,11 @@ use std::str::FromStr; use serde::{Deserialize, Deserializer}; use serde_json as json; -use tari_template_lib::{arg, args::Arg, models::Amount}; +use tari_template_lib::{ + arg, + args::Arg, + models::{Amount, Metadata}, +}; use crate::{substate::SubstateAddress, template::parse_template_address, TemplateAddress}; @@ -76,6 +80,10 @@ fn try_parse_special_string_arg(s: &str) -> Result, ArgParseError> return Ok(StringArg::TemplateAddress(address)); } + if let Ok(metadata) = Metadata::from_str(s) { + return Ok(StringArg::Metadata(metadata)); + } + match s { "true" => return Ok(StringArg::Bool(true)), "false" => return Ok(StringArg::Bool(false)), @@ -102,6 +110,7 @@ pub enum StringArg<'a> { UnsignedInteger(u64), SignedInteger(i64), Bool(bool), + Metadata(Metadata), } impl From> for Arg { @@ -124,6 +133,7 @@ impl From> for Arg { StringArg::SignedInteger(v) => arg!(v), StringArg::Bool(v) => arg!(v), StringArg::Workspace(s) => arg!(Workspace(s)), + StringArg::Metadata(m) => arg!(m), } } } diff --git a/dan_layer/template_lib/src/models/metadata.rs b/dan_layer/template_lib/src/models/metadata.rs index 715901f09..831734f2e 100644 --- a/dan_layer/template_lib/src/models/metadata.rs +++ b/dan_layer/template_lib/src/models/metadata.rs @@ -20,6 +20,8 @@ // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE // USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +use std::str::FromStr; + use serde::{Deserialize, Serialize}; use tari_bor::BorTag; use tari_template_abi::rust::{collections::BTreeMap, fmt::Display}; @@ -52,6 +54,25 @@ impl Metadata { } } +impl FromStr for Metadata { + type Err = String; + + fn from_str(s: &str) -> Result { + let pairs = s.split(',').map(|pair| { + let mut split = pair.split('='); + let key = split.next().ok_or_else(|| "Missing key".to_string())?; + let value = split.next().ok_or_else(|| "Missing value".to_string())?; + Ok::<(String, String), String>((key.to_string(), value.to_string())) + }); + let mut map = BTreeMap::new(); + for pair in pairs { + let (key, value) = pair?; + map.insert(key, value); + } + Ok(Self(BorTag::new(map))) + } +} + impl From> for Metadata { fn from(value: BTreeMap) -> Self { Self(BorTag::new(value)) From 26f8f8233703665b4a1f4e6d07cb46cb4a53a3ed Mon Sep 17 00:00:00 2001 From: "C.Lee Taylor" <47312074+leet4tari@users.noreply.github.com> Date: Wed, 22 Nov 2023 16:10:26 +0200 Subject: [PATCH 2/2] ci(fix): docker - add openssl and ca-certificates to runtime (#782) Description Add openssl and ca-certificates packages to docker runtime image Motivation and Context Fix missing openssl requirements How Has This Been Tested? Tested in local fork. What process can a PR reviewer use to test or verify this change? --- Breaking Changes --- - [x] None - [ ] Requires data directory to be deleted - [ ] Other - Please specify --- docker_rig/tari-dan.Dockerfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docker_rig/tari-dan.Dockerfile b/docker_rig/tari-dan.Dockerfile index b398f47d1..8ec7b15c8 100644 --- a/docker_rig/tari-dan.Dockerfile +++ b/docker_rig/tari-dan.Dockerfile @@ -112,7 +112,9 @@ ARG DEBIAN_FRONTEND=noninteractive RUN apt-get update && \ apt-get --no-install-recommends install -y \ - dumb-init + dumb-init \ + ca-certificates \ + openssl RUN groupadd --gid 1000 tari && \ useradd --create-home --no-log-init --shell /bin/bash \