Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add exchange_rate_in_cents to ExchangeRate #875

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/exchange_rates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ pub struct ExchangeRate {

/// Expiration time of this exchange rate.
pub expiration_time: OffsetDateTime,

/// Exchange rate in cents
pub exchange_rate_in_cents: f64,
}

impl ExchangeRate {
Expand All @@ -90,7 +93,14 @@ impl FromProtobuf<services::ExchangeRate> for ExchangeRate {
let hbars = pb.hbar_equiv as u32;
let cents = pb.cent_equiv as u32;

Ok(Self { hbars, cents, expiration_time: pb_getf!(pb, expiration_time)?.into() })
let exchange_rate_in_cents = f64::from(cents) / f64::from(hbars);

Ok(Self {
hbars,
cents,
exchange_rate_in_cents,
expiration_time: pb_getf!(pb, expiration_time)?.into(),
})
}
}

Expand Down Expand Up @@ -126,11 +136,13 @@ mod tests {
hbars: 30000,
cents: 580150,
expiration_time: 2022-02-24 15:00:00.0 +00:00:00,
exchange_rate_in_cents: 19.338333333333335,
},
next_rate: ExchangeRate {
hbars: 30000,
cents: 587660,
expiration_time: 2022-02-24 16:00:00.0 +00:00:00,
exchange_rate_in_cents: 19.588666666666665,
},
}
"#]]
Expand Down
2 changes: 2 additions & 0 deletions src/transaction_receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,13 @@ mod tests {
hbars: 100,
cents: 100,
expiration_time: EXPIRATION_TIME,
exchange_rate_in_cents: f64::from(100) / f64::from(100),
},
next_rate: ExchangeRate {
hbars: 200,
cents: 200,
expiration_time: EXPIRATION_TIME,
exchange_rate_in_cents: f64::from(200) / f64::from(200),
},
}),
contract_id: Some(ContractId::new(3, 2, 1)),
Expand Down
Loading