forked from Vero-protocol/vero-core-contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdrips.rs
More file actions
78 lines (65 loc) · 2.24 KB
/
Copy pathdrips.rs
File metadata and controls
78 lines (65 loc) · 2.24 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
71
72
73
74
75
76
77
78
#![allow(missing_docs)]
use soroban_sdk::{Address, Env, IntoVal, Symbol, Val, Vec as SorobanVec};
use crate::storage;
use crate::types::{ContractError, DataKey, RewardStream};
use crate::validation;
/// Starts a Drips reward stream for a verified task to reward a contributor.
pub fn start_drips_stream(
env: &Env,
drips_address: Address,
contributor: Address,
task_id: u64,
) -> Result<(), ContractError> {
validation::validate_reward_stream_config(env, &drips_address, &contributor, task_id)?;
let task = storage::get_active_task(env, task_id).ok_or(ContractError::TaskNotFound)?;
if task.is_cancelled {
return Err(ContractError::TaskCancelled);
}
if !task.is_done {
return Err(ContractError::TaskNotVerified);
}
let stream_key = DataKey::RewardStream(task_id);
if env.storage().instance().has(&stream_key) {
return Err(ContractError::StreamAlreadyActive);
}
let resolution_status: u32 = 1;
let args: SorobanVec<Val> = SorobanVec::from_array(
env,
[
contributor.clone().into_val(env),
task_id.into_val(env),
resolution_status.into_val(env),
],
);
env.invoke_contract::<Val>(&drips_address, &Symbol::new(env, "start_stream"), args);
let stream = RewardStream {
task_id,
contributor: contributor.clone(),
drips_contract: drips_address,
active: true,
};
env.storage().instance().set(&stream_key, &stream);
let mut all_streams: SorobanVec<u64> = env
.storage()
.instance()
.get(&DataKey::AllRewardStreams)
.unwrap_or(SorobanVec::new(env));
all_streams.push_back(task_id);
env.storage()
.instance()
.set(&DataKey::AllRewardStreams, &all_streams);
Ok(())
}
/// Retrieves the reward stream details for a specific task.
pub fn get_reward_stream(env: &Env, task_id: u64) -> Option<RewardStream> {
env.storage()
.instance()
.get(&DataKey::RewardStream(task_id))
}
/// Retrieves a list of all active reward stream task IDs.
pub fn get_all_reward_streams(env: &Env) -> SorobanVec<u64> {
env.storage()
.instance()
.get(&DataKey::AllRewardStreams)
.unwrap_or(SorobanVec::new(env))
}