Skip to content

Commit

Permalink
fixedd dependnecies
Browse files Browse the repository at this point in the history
  • Loading branch information
lassemand committed Sep 2, 2024
2 parents 1c3554a + 059f7ed commit 497bc7d
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 12 deletions.
2 changes: 1 addition & 1 deletion notification-server/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion notification-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
authors = ["Concordium AG [email protected]"]
edition = "2021"
name = "notification-server"
version = "0.1.11"
version = "0.1.13"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
18 changes: 9 additions & 9 deletions notification-server/src/google_cloud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,16 +397,16 @@ mod tests {
"amount": "200",
"type": "cis2-tx",
"token_id": "ffffff",
"contract_address": {"index": 3, "subindex": 0},
"contract_name": "init_contract",
"contract_address": "{\"index\":3,\"subindex\":0}",
"contract_name": "contract",
"reference": "6a6d250ecefb518253db4c0d7759b2f4ff2862217ed2c8343879a77e0c2c97a2",
}
}
});

let mock = server
.mock("POST", "/v1/projects/fake_project_id/messages:send")
.match_body(mockito::Matcher::Json(expected_body))
.match_body(mockito::Matcher::Json(expected_body.clone()))
.with_status(200)
.with_body(json!({"success": true}).to_string())
.expect(1)
Expand Down Expand Up @@ -462,10 +462,10 @@ mod tests {
"recipient": "3kBx2h5Y2veb4hZgAJWPrr8RyQESKm5TjzF3ti1QQ4VSYLwK1G",
"amount": "200",
"type": "cis2-tx",
"contract_address": {"index": 112, "subindex": 2},
"contract_name": "init_contract",
"contract_address": "{\"index\":112,\"subindex\":2}",
"contract_name": "contract",
"token_id": "ffffff",
"token_metadata": {"hash": None::<Hash>, "url": "https://example.com"},
"token_metadata": "{\"url\":\"https://example.com\",\"hash\":null}",
"reference": "494d7848e389d44a2c2fe81eeee6dc427ce33ab1d0c92cba23be321d495be110",
}
}
Expand Down Expand Up @@ -528,10 +528,10 @@ mod tests {
"recipient": "3kBx2h5Y2veb4hZgAJWPrr8RyQESKm5TjzF3ti1QQ4VSYLwK1G",
"amount": "200",
"type": "cis2-tx",
"contract_address": {"index": 111, "subindex": 1},
"contract_name": "init_contract",
"contract_address": "{\"index\":111,\"subindex\":1}",
"contract_name": "contract",
"token_id": "ffffff",
"token_metadata": {"hash": "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08", "url": "https://example.com"},
"token_metadata": "{\"url\":\"https://example.com\",\"hash\":\"9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08\"}",
"reference": "8a3a09bffa6ead269f79be4192fcb7773cc4e10a2e90c0dec3eb9ca5200c06bc"
}
}
Expand Down
35 changes: 34 additions & 1 deletion notification-server/src/models/notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,46 @@ pub struct CIS2EventNotificationInformation {
#[serde(rename = "type")]
pub transaction_type: Preference,
pub token_id: TokenId,
#[serde(serialize_with = "serialize_as_json_string")]
pub contract_address: ContractAddress,
#[serde(serialize_with = "serialize_contract_name")]
pub contract_name: OwnedContractName,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(
serialize_with = "serialize_option_as_json_string",
skip_serializing_if = "Option::is_none"
)]
pub token_metadata: Option<MetadataUrl>,
pub reference: TransactionHash,
}

fn serialize_contract_name<S>(name: &OwnedContractName, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer, {
let contract_name_str = name.as_contract_name();
serializer.serialize_str(contract_name_str.contract_name())
}

fn serialize_as_json_string<S, T>(value: &T, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
T: Serialize, {
let json_string = serde_json::to_string(value).map_err(serde::ser::Error::custom)?;
serializer.serialize_str(&json_string)
}

fn serialize_option_as_json_string<S, T>(
value: &Option<T>,
serializer: S,
) -> Result<S::Ok, S::Error>
where
S: Serializer,
T: Serialize, {
match value {
Some(v) => serialize_as_json_string(v, serializer),
None => serializer.serialize_none(),
}
}

impl CIS2EventNotificationInformation {
pub fn new(
address: AccountAddress,
Expand Down

0 comments on commit 497bc7d

Please sign in to comment.