-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: overdraft prevention * test: overdraft prevention * fix: entry type names in initiate withdrawal * fix: create idempotent deposit velocity control * chore: idempotent limit creation
- Loading branch information
1 parent
474dcc5
commit 917aa66
Showing
10 changed files
with
137 additions
and
18 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
mod overdraft_prevention; | ||
|
||
pub use overdraft_prevention::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use tracing::instrument; | ||
|
||
use cala_ledger::{velocity::*, *}; | ||
|
||
use crate::ledger::error::*; | ||
|
||
pub struct OverdraftPrevention; | ||
|
||
const OVERDRAFT_PREVENTION_ID: uuid::Uuid = uuid::uuid!("00000000-0000-0000-0000-000000000001"); | ||
|
||
impl OverdraftPrevention { | ||
#[instrument(name = "ledger.overdraft_prevention.init", skip_all)] | ||
pub async fn init(ledger: &CalaLedger) -> Result<VelocityLimitId, DepositLedgerError> { | ||
let limit = NewVelocityLimit::builder() | ||
.id(OVERDRAFT_PREVENTION_ID) | ||
.name("Overdraft Prevention") | ||
.description("Prevent overdraft on withdrawals") | ||
.window(vec![]) | ||
.limit( | ||
NewLimit::builder() | ||
.balance(vec![NewBalanceLimit::builder() | ||
.layer("SETTLED") | ||
.amount("decimal('0.0')") | ||
.enforcement_direction("DEBIT") | ||
.build() | ||
.expect("balance limit")]) | ||
.build() | ||
.expect("limit"), | ||
) | ||
.build() | ||
.expect("velocity limit"); | ||
|
||
match ledger.velocities().create_limit(limit).await { | ||
Err(cala_ledger::velocity::error::VelocityError::LimitIdAlreadyExists) => { | ||
Ok(OVERDRAFT_PREVENTION_ID.into()) | ||
} | ||
Err(e) => Err(e.into()), | ||
Ok(limit) => Ok(limit.id()), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters