From 0f38f59d04f23139f8f6ef7bb60ff3c7cebf46da Mon Sep 17 00:00:00 2001 From: Rache Bartmoss Date: Wed, 21 Oct 2020 16:27:50 +0200 Subject: [PATCH] Serialize DomainName as string --- coeus-core/src/domain.rs | 13 +++++-------- coeus-core/src/operations/delete.rs | 1 + coeus-core/src/operations/register.rs | 2 ++ coeus-core/src/operations/renew.rs | 2 ++ coeus-core/src/operations/transfer.rs | 2 ++ coeus-core/src/operations/update.rs | 2 ++ hydra-proto/src/lib.rs | 2 +- hydra-proto/src/serializer.rs | 21 +++++++++++---------- 8 files changed, 26 insertions(+), 19 deletions(-) diff --git a/coeus-core/src/domain.rs b/coeus-core/src/domain.rs index e995c19..326d370 100644 --- a/coeus-core/src/domain.rs +++ b/coeus-core/src/domain.rs @@ -6,6 +6,7 @@ pub type DynamicContent = serde_json::Value; #[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct Domain { + #[serde(with = "serde_str")] name: DomainName, owner: Principal, children: HashMap, @@ -197,18 +198,14 @@ mod test { println!("{}", serde_json::to_string_pretty(&wallet).unwrap()); - // TODO: Seems like the `name` field in `Domain` is redundant in the current implementation + // TODO: Consider removing redundancy from the `name` field of `Domain`, + // e.g. ".wallet" child name ".wallet.joe" could be just "joe" or ".joe" let expected = json!( { - "name": [ - "wallet" - ], + "name": ".wallet", "owner": "system", "children": { "joe": { - "name": [ - "wallet", - "joe" - ], + "name": ".wallet.joe", "owner": "pez2CLkBUjHB8w8G87D3YkREjpRuiqPu6BrRsgHMQy2Pzt6", "children": {}, "subtreePolicies": {}, diff --git a/coeus-core/src/operations/delete.rs b/coeus-core/src/operations/delete.rs index 01d2040..d3413fb 100644 --- a/coeus-core/src/operations/delete.rs +++ b/coeus-core/src/operations/delete.rs @@ -3,6 +3,7 @@ use super::*; #[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)] #[serde(rename_all = "camelCase")] pub struct DoDelete { + #[serde(with = "serde_str")] pub(super) name: DomainName, } diff --git a/coeus-core/src/operations/register.rs b/coeus-core/src/operations/register.rs index aac23d7..1d607ac 100644 --- a/coeus-core/src/operations/register.rs +++ b/coeus-core/src/operations/register.rs @@ -3,6 +3,7 @@ use super::*; #[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)] #[serde(rename_all = "camelCase")] pub struct DoRegister { + #[serde(with = "serde_str")] pub(crate) name: DomainName, pub(crate) owner: Principal, pub(crate) subtree_policies: SubtreePolicies, @@ -65,6 +66,7 @@ impl Command for DoRegister { #[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)] #[serde(rename_all = "camelCase")] pub struct UndoRegister { + #[serde(with = "serde_str")] name: DomainName, old_domain: Option, } diff --git a/coeus-core/src/operations/renew.rs b/coeus-core/src/operations/renew.rs index 155d974..fbb6ac6 100644 --- a/coeus-core/src/operations/renew.rs +++ b/coeus-core/src/operations/renew.rs @@ -3,6 +3,7 @@ use super::*; #[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)] #[serde(rename_all = "camelCase")] pub struct DoRenew { + #[serde(with = "serde_str")] pub(super) name: DomainName, pub(super) expires_at_height: BlockHeight, } @@ -28,6 +29,7 @@ impl Command for DoRenew { #[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)] #[serde(rename_all = "camelCase")] pub struct UndoRenew { + #[serde(with = "serde_str")] name: DomainName, expires_at_height: BlockHeight, } diff --git a/coeus-core/src/operations/transfer.rs b/coeus-core/src/operations/transfer.rs index 301696c..6dc9012 100644 --- a/coeus-core/src/operations/transfer.rs +++ b/coeus-core/src/operations/transfer.rs @@ -3,6 +3,7 @@ use super::*; #[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)] #[serde(rename_all = "camelCase")] pub struct DoTransfer { + #[serde(with = "serde_str")] pub(super) name: DomainName, pub(super) to_owner: Principal, } @@ -32,6 +33,7 @@ impl Command for DoTransfer { #[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)] #[serde(rename_all = "camelCase")] pub struct UndoTransfer { + #[serde(with = "serde_str")] pub(super) name: DomainName, pub(super) owner: Principal, } diff --git a/coeus-core/src/operations/update.rs b/coeus-core/src/operations/update.rs index 8bbad9c..1c01c61 100644 --- a/coeus-core/src/operations/update.rs +++ b/coeus-core/src/operations/update.rs @@ -3,6 +3,7 @@ use super::*; #[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)] #[serde(rename_all = "camelCase")] pub struct DoUpdate { + #[serde(with = "serde_str")] pub(super) name: DomainName, pub(super) data: DynamicContent, } @@ -36,6 +37,7 @@ impl Command for DoUpdate { #[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)] #[serde(rename_all = "camelCase")] pub struct UndoUpdate { + #[serde(with = "serde_str")] name: DomainName, data: DynamicContent, } diff --git a/hydra-proto/src/lib.rs b/hydra-proto/src/lib.rs index 438e2ae..8d06a5e 100644 --- a/hydra-proto/src/lib.rs +++ b/hydra-proto/src/lib.rs @@ -23,7 +23,7 @@ use serde::{ }; use serde_repr::{Deserialize_repr, Serialize_repr}; use sha2::{Digest, Sha256}; -use varint::{VarintRead, VarintWrite}; +use varint::VarintWrite; // VarintRead // imports from own crates diff --git a/hydra-proto/src/serializer.rs b/hydra-proto/src/serializer.rs index 6582406..d6a5a6b 100644 --- a/hydra-proto/src/serializer.rs +++ b/hydra-proto/src/serializer.rs @@ -1,4 +1,5 @@ use super::*; + use crate::txtype::hyd_core::CoreTransactionType; use crate::txtype::{ hyd_core::{CoreAsset, CoreTransactionType as CoreTxType}, @@ -18,16 +19,16 @@ pub fn frame_bytes(value: &[u8]) -> Result> { Ok(res_bytes) } -fn unframe_bytes(bytes: Vec) -> Result> { - let mut cur = Cursor::new(bytes); - let str_length = cur.read_unsigned_varint_32()?; - - let mut str_bytes = Vec::new(); - str_bytes.resize(str_length as usize, 0u8); - cur.read_exact(str_bytes.as_mut_slice())?; - - Ok(str_bytes) -} +// fn unframe_bytes(bytes: Vec) -> Result> { +// let mut cur = Cursor::new(bytes); +// let str_length = cur.read_unsigned_varint_32()?; +// +// let mut str_bytes = Vec::new(); +// str_bytes.resize(str_length as usize, 0u8); +// cur.read_exact(str_bytes.as_mut_slice())?; +// +// Ok(str_bytes) +// } pub fn to_bytes( tx: &TransactionData, skip_signature: bool, skip_second_signature: bool,