forked from StellarSplit/StellarSplit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.rs
More file actions
70 lines (65 loc) · 2.29 KB
/
Copy pathtypes.rs
File metadata and controls
70 lines (65 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//! # Custom Types for Split Template Contract
//!
//! Core data structures for managing reusable split templates.
use soroban_sdk::{contracterror, contracttype, Address, String, Vec};
/// Defines how a split is divided among participants.
#[contracttype]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum SplitType {
/// Split equally among all participants
Equal = 0,
/// Split by percentage (shares sum to 100)
Percentage = 1,
/// Split by fixed amounts
Fixed = 2,
}
/// A participant in a split template with their share/allocation.
#[contracttype]
#[derive(Clone, Debug)]
pub struct Participant {
/// The participant's Stellar address
pub address: Address,
/// Share value: for Equal type, meaningless; for Percentage, 0-100; for Fixed, amount
pub share: i128,
}
/// A reusable split template that can be applied to multiple splits.
#[contracttype]
#[derive(Clone, Debug)]
pub struct Template {
/// Unique deterministic ID based on creator + name + timestamp
pub id: String,
/// Address of the template creator
pub creator: Address,
/// Human-readable template name
pub name: String,
/// How this template divides funds
pub split_type: SplitType,
/// List of participants and their shares
pub participants: Vec<Participant>,
/// Template schema version
pub version: u32,
/// Number of times this template has been successfully applied
pub use_count: u32,
/// Optional maximum number of times this template may be applied.
/// `None` means unlimited. When `Some(n)`, applying the template after
/// `use_count` has reached `n` returns `Error::TemplateLimitReached`.
pub max_uses: Option<u32>,
}
/// Contract errors
#[contracterror]
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
#[repr(u32)]
pub enum Error {
/// Template with the given ID was not found
TemplateNotFound = 1,
/// Participants list is empty
InvalidParticipants = 2,
/// Shares are invalid for the given split type
InvalidShares = 3,
/// Template version is incompatible with the current contract
IncompatibleVersion = 4,
/// A template with the same name already exists for this creator
DuplicateName = 5,
/// The template has reached its maximum number of allowed applications
TemplateLimitReached = 6,
}