Skip to content
Closed
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod v0;
mod v1;

use crate::drive::Drive;
use crate::error::drive::DriveError;
Expand Down Expand Up @@ -43,9 +44,15 @@ impl Drive {
transaction,
platform_version,
),
1 => self.deduct_from_prefunded_specialized_balance_v1(
specialized_balance_id,
amount,
transaction,
platform_version,
),
version => Err(Error::Drive(DriveError::UnknownVersionMismatch {
method: "deduct_from_prefunded_specialized_balance".to_string(),
known_versions: vec![0],
known_versions: vec![0, 1],
received: version,
})),
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
use crate::drive::Drive;
use crate::error::Error;
use crate::fees::op::LowLevelDriveOperation;

use dpp::identifier::Identifier;
use dpp::version::PlatformVersion;
use grovedb::TransactionArg;

impl Drive {
/// Deducts from a prefunded specialized balance (v1).
///
/// Functionally identical to `deduct_from_prefunded_specialized_balance_v0`:
/// version selection for the actual deduction logic happens inside the
/// `deduct_from_prefunded_specialized_balance_operations` dispatcher, which
/// routes to `_operations_v0` / `_operations_v1` based on the platform
/// version. This top-level wrapper just collects those operations and
/// applies the resulting grovedb batch.
///
/// # Arguments
///
/// * `amount` - The amount of credits to be removed from the prefunded balance.
/// * `transaction` - A `TransactionArg` object representing the transaction to be used.
/// * `platform_version` - A `PlatformVersion` object specifying the version of Platform.
///
/// # Returns
///
/// * `Result<(), Error>` - If successful, returns `Ok(())`. Otherwise, returns an `Error`.
#[inline(always)]
pub(super) fn deduct_from_prefunded_specialized_balance_v1(
&self,
specialized_balance_id: Identifier,
amount: u64,
transaction: TransactionArg,
platform_version: &PlatformVersion,
) -> Result<(), Error> {
let mut drive_operations = vec![];
let batch_operations = self.deduct_from_prefunded_specialized_balance_operations(
specialized_balance_id,
amount,
&mut None,
transaction,
platform_version,
)?;
let grove_db_operations =
LowLevelDriveOperation::grovedb_operations_batch(&batch_operations);
self.grove_apply_batch_with_add_costs(
grove_db_operations,
false,
transaction,
&mut drive_operations,
&platform_version.drive,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl Drive {
),
version => Err(Error::Drive(DriveError::UnknownVersionMismatch {
method: "deduct_from_prefunded_specialized_balance_operations".to_string(),
known_versions: vec![0],
known_versions: vec![0, 1],
received: version,
})),
}
Expand Down
Loading