Skip to content
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
47 changes: 0 additions & 47 deletions contracts/splitter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ contractmeta!(
pub const TOTAL_SHARES: u32 = 10_000;
pub const MAX_RECIPIENTS: u32 = 32;
pub const MAX_CASCADE_DEPTH: u32 = 5;
pub const MAX_DISTRIBUTE_TOKENS: u32 = 10;

const DAY_LEDGERS: u32 = 17_280;
const TTL_THRESHOLD: u32 = 30 * DAY_LEDGERS;
Expand Down Expand Up @@ -78,10 +77,6 @@ pub enum Error {
SplitHasBalance = 12,
/// Code 13. The cascade depth exceeds the maximum allowed limit.
MaxDepthExceeded = 13,
/// Code 14. The number of tokens to distribute exceeds the allowed limit.
TooManyTokens = 14,
/// Code 15. No pending control transfer exists for this split.
NoPendingTransfer = 15,
}

#[contracttype]
Expand Down Expand Up @@ -524,48 +519,6 @@ impl Splitter {
distribute_recursive(&env, id, &token, 0, max_depth)
}

/// Pays out all escrowed tokens for a split, up to `MAX_DISTRIBUTE_TOKENS` (10).
/// Returns the list of tokens and their distributed amounts.
/// If no tokens are specified, retrieves all tokens that currently have balances.
/// Zero-balance tokens are skipped and do not cause errors.
pub fn distribute_all_tokens(
env: Env,
id: u64,
tokens: Option<Vec<Address>>,
) -> Result<Vec<TokenDistribution>, Error> {
let _split = load(&env, id)?;
let tokens_to_process = match tokens {
Some(t) => t,
None => Self::held_tokens(env.clone(), id),
};
if tokens_to_process.len() > MAX_DISTRIBUTE_TOKENS {
return Err(Error::TooManyTokens);
}
let mut distributions = Vec::new(&env);
for token in tokens_to_process.iter() {
let bal = Self::balance(env.clone(), id, token.clone());
if bal <= 0 {
continue;
}
let (node_split, amount) = distribute_node(&env, id, &token)?;
payout(
&env,
&node_split,
&env.current_contract_address(),
&token,
amount,
);
Distributed {
id,
token: token.clone(),
amount,
}
.publish(&env);
distributions.push_back(TokenDistribution { token, amount });
}
Ok(distributions)
}

/// Returns the exact per-recipient amounts a payment of `amount` would
/// produce, without moving any funds.
pub fn preview_payout(env: Env, id: u64, amount: i128) -> Result<Vec<i128>, Error> {
Expand Down
Loading
Loading