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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
use crate::{
services::{
nft::NID,
tokens::{Quantity, TID},
},
TimePointSec,
};
use fracpack::{Pack, ToSchema, Unpack};
use serde::{Deserialize, Serialize};
#[derive(Debug, Copy, Clone, Pack, Unpack, ToSchema, Serialize, Deserialize)]
#[fracpack(fracpack_mod = "fracpack")]
pub struct Stream {
pub nft_id: NID,
pub token_id: TID,
pub half_life_seconds: u32,
pub total_deposited: Quantity,
pub total_claimed: Quantity,
pub last_deposit_timestamp: TimePointSec,
pub claimable_at_last_deposit: Quantity,
}
#[crate::service(name = "token-stream", dispatch = false, psibase_mod = "crate")]
#[allow(non_snake_case, unused_variables)]
pub mod Service {
use crate::{
services::{token_stream::Stream, tokens::Quantity},
AccountNumber,
};
/// Lookup stream information
///
/// # Arguments
/// * `nft_id` - ID of the stream AKA Redeemer NFT ID.
///
/// # Returns
/// Option of stream information, will be None if no longer exists.
#[action]
fn get_stream(nft_id: u32) -> Option<Stream> {
unimplemented!()
}
/// Creates a token stream.
///
/// # Arguments
/// * `half_life_seconds` - Time (in seconds) until half of the total unvested balance is withdrawable
/// * `token_id` - Token ID to be deposited into the stream.
///
/// # Returns
/// The ID of the redeemer NFT which is also the unique ID of the stream.
#[action]
fn create(half_life_seconds: u32, token_id: u32) -> u32 {
unimplemented!()
}
/// Deposit into a token stream.
///
/// * Requires pre-existing shared balance of the token assigned to the strema, whole balance will be billed.
///
/// # Arguments
/// * `nft_id` - ID of the stream AKA Redeemer NFT ID.
/// * `amount` - Amount to deposit.
#[action]
fn deposit(nft_id: u32, amount: Quantity) {
unimplemented!()
}
/// Claim from a token stream.
///
/// * Requires holding the redeemer NFT of the stream.
///
/// # Arguments
/// * `nft_id` - ID of the stream AKA Redeemer NFT ID.
///
/// Returns quantity of amount claimed
#[action]
fn claim(nft_id: u32) -> Quantity {
unimplemented!()
}
/// Delete a stream.
///
/// * Requires stream to be empty.
///
/// # Arguments
/// * `nft_id` - ID of the stream AKA Redeemer NFT ID.
#[action]
fn delete(nft_id: u32) {
unimplemented!()
}
#[event(history)]
pub fn created(nft_id: u32, half_life_seconds: u32, token_id: u32, creator: AccountNumber) {}
#[event(history)]
pub fn updated(nft_id: u32, actor: AccountNumber, tx_type: String, amount: String) {}
}
#[test]
fn verify_schema() {
crate::assert_schema_matches_package::<Wrapper>();
}