Skip to content

Commit

Permalink
Merge branch 'development' into indexer-optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
mrnaveira authored Nov 22, 2023
2 parents 2a9c8e0 + 26f8f82 commit ccf20fa
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
12 changes: 11 additions & 1 deletion dan_layer/engine_types/src/argument_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -76,6 +80,10 @@ fn try_parse_special_string_arg(s: &str) -> Result<StringArg<'_>, 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)),
Expand All @@ -102,6 +110,7 @@ pub enum StringArg<'a> {
UnsignedInteger(u64),
SignedInteger(i64),
Bool(bool),
Metadata(Metadata),
}

impl From<StringArg<'_>> for Arg {
Expand All @@ -124,6 +133,7 @@ impl From<StringArg<'_>> for Arg {
StringArg::SignedInteger(v) => arg!(v),
StringArg::Bool(v) => arg!(v),
StringArg::Workspace(s) => arg!(Workspace(s)),
StringArg::Metadata(m) => arg!(m),
}
}
}
Expand Down
21 changes: 21 additions & 0 deletions dan_layer/template_lib/src/models/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -52,6 +54,25 @@ impl Metadata {
}
}

impl FromStr for Metadata {
type Err = String;

fn from_str(s: &str) -> Result<Self, Self::Err> {
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<BTreeMap<String, String>> for Metadata {
fn from(value: BTreeMap<String, String>) -> Self {
Self(BorTag::new(value))
Expand Down
4 changes: 3 additions & 1 deletion docker_rig/tari-dan.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down

0 comments on commit ccf20fa

Please sign in to comment.