Skip to content

Commit

Permalink
Serialize DomainName as string
Browse files Browse the repository at this point in the history
  • Loading branch information
izolyomi committed Oct 21, 2020
1 parent 75f4346 commit 0f38f59
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 19 deletions.
13 changes: 5 additions & 8 deletions coeus-core/src/domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Edge, Domain>,
Expand Down Expand Up @@ -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": {},
Expand Down
1 change: 1 addition & 0 deletions coeus-core/src/operations/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down
2 changes: 2 additions & 0 deletions coeus-core/src/operations/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<Domain>,
}
Expand Down
2 changes: 2 additions & 0 deletions coeus-core/src/operations/renew.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand All @@ -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,
}
Expand Down
2 changes: 2 additions & 0 deletions coeus-core/src/operations/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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,
}
Expand Down
2 changes: 2 additions & 0 deletions coeus-core/src/operations/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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,
}
Expand Down
2 changes: 1 addition & 1 deletion hydra-proto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
21 changes: 11 additions & 10 deletions hydra-proto/src/serializer.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::*;

use crate::txtype::hyd_core::CoreTransactionType;
use crate::txtype::{
hyd_core::{CoreAsset, CoreTransactionType as CoreTxType},
Expand All @@ -18,16 +19,16 @@ pub fn frame_bytes(value: &[u8]) -> Result<Vec<u8>> {
Ok(res_bytes)
}

fn unframe_bytes(bytes: Vec<u8>) -> Result<Vec<u8>> {
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<u8>) -> Result<Vec<u8>> {
// 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,
Expand Down

0 comments on commit 0f38f59

Please sign in to comment.