summaryrefslogtreecommitdiff
path: root/instrumentation/src/utils.rs
diff options
context:
space:
mode:
authorAntoine A <>2024-02-01 18:18:49 +0100
committerAntoine A <>2024-02-01 18:18:49 +0100
commit635e0e1d0ce6773f7bea4b4fed7c22f614ba2829 (patch)
tree008fb2d6af4efe91302528c7aa76089890e68020 /instrumentation/src/utils.rs
parentc97f15ab23c310dfb630f78c1513c38803ab0f2a (diff)
downloaddepolymerization-635e0e1d0ce6773f7bea4b4fed7c22f614ba2829.tar.gz
depolymerization-635e0e1d0ce6773f7bea4b4fed7c22f614ba2829.tar.bz2
depolymerization-635e0e1d0ce6773f7bea4b4fed7c22f614ba2829.zip
Update taler wire api to the newest specification
Diffstat (limited to 'instrumentation/src/utils.rs')
-rw-r--r--instrumentation/src/utils.rs50
1 files changed, 31 insertions, 19 deletions
diff --git a/instrumentation/src/utils.rs b/instrumentation/src/utils.rs
index 5509754..baf3686 100644
--- a/instrumentation/src/utils.rs
+++ b/instrumentation/src/utils.rs
@@ -44,16 +44,21 @@ pub fn print_now(disp: impl Display) {
#[must_use]
pub fn check_incoming(base_url: &str, txs: &[([u8; 32], Amount)]) -> bool {
- let history: IncomingHistory = ureq::get(&format!("{}history/incoming", base_url))
+ let res = ureq::get(&format!("{}history/incoming", base_url))
.query("delta", &format!("-{}", txs.len()))
.call()
- .unwrap()
- .into_json()
.unwrap();
+ if txs.is_empty() {
+ res.status() == 204
+ } else {
+ if res.status() != 200 {
+ return false;
+ }
+ let history: IncomingHistory = res.into_json().unwrap();
- history.incoming_transactions.len() == txs.len()
- && txs.iter().all(|(reserve_pub_key, taler_amount)| {
- history.incoming_transactions.iter().any(|h| {
+ history.incoming_transactions.len() == txs.len()
+ && txs.iter().all(|(reserve_pub_key, taler_amount)| {
+ history.incoming_transactions.iter().any(|h| {
matches!(
h,
IncomingBankTransaction::IncomingReserveTransaction {
@@ -63,7 +68,8 @@ pub fn check_incoming(base_url: &str, txs: &[([u8; 32], Amount)]) -> bool {
} if reserve_pub == &Base32::from(*reserve_pub_key) && amount == taler_amount
)
})
- })
+ })
+ }
}
pub fn gateway_error(path: &str, error: u16) {
@@ -96,10 +102,7 @@ pub fn check_gateway_down(base_url: &str) -> bool {
#[must_use]
pub fn check_gateway_up(base_url: &str) -> bool {
- ureq::get(&format!("{}history/incoming", base_url))
- .query("delta", "-5")
- .call()
- .is_ok()
+ ureq::get(&format!("{}config", base_url)).call().is_ok()
}
pub fn transfer(base_url: &str, wtid: &[u8; 32], url: &Url, credit_account: Url, amount: &Amount) {
@@ -116,18 +119,27 @@ pub fn transfer(base_url: &str, wtid: &[u8; 32], url: &Url, credit_account: Url,
#[must_use]
pub fn check_outgoing(base_url: &str, url: &Url, txs: &[([u8; 32], Amount)]) -> bool {
- let history: OutgoingHistory = ureq::get(&format!("{}history/outgoing", base_url))
+ let res = ureq::get(&format!("{}history/outgoing", base_url))
.query("delta", &format!("-{}", txs.len()))
.call()
- .unwrap()
- .into_json()
.unwrap();
- history.outgoing_transactions.len() == txs.len()
- && txs.iter().all(|(wtid, amount)| {
- history.outgoing_transactions.iter().any(|h| {
- h.wtid == Base32::from(*wtid) && &h.exchange_base_url == url && &h.amount == amount
+ if txs.is_empty() {
+ res.status() == 204
+ } else {
+ if res.status() != 200 {
+ return false;
+ }
+ let history: OutgoingHistory = res.into_json().unwrap();
+
+ history.outgoing_transactions.len() == txs.len()
+ && txs.iter().all(|(wtid, amount)| {
+ history.outgoing_transactions.iter().any(|h| {
+ h.wtid == Base32::from(*wtid)
+ && &h.exchange_base_url == url
+ && &h.amount == amount
+ })
})
- })
+ }
}
pub struct ChildGuard(pub Child);