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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
pub use crate::services::auth_sig::SubjectPublicKeyInfo;
use crate::AccountNumber;
use async_graphql::{InputObject, SimpleObject};
use fracpack::{Pack, ToSchema, Unpack};
use serde::{Deserialize, Serialize};
#[derive(
Debug, Clone, Pack, Unpack, Serialize, Deserialize, SimpleObject, InputObject, ToSchema,
)]
#[fracpack(fracpack_mod = "fracpack")]
#[graphql(input_name = "InviteRecordInput")]
/// An invite object
pub struct InviteRecord {
/// The id of the invite (not sequential)
id: u32,
/// The id of the credential associated with the invite
cid: u32,
/// The creator of the invite object
inviter: AccountNumber,
/// Represents the number of accounts this invite can be used to create
numAccounts: u16,
/// A flag that represents whether to use hooks to notify the inviter when the invite is updated
useHooks: bool,
/// The encrypted secret used to redeem the invite
secret: String,
}
/// This interface should be implemented by a service that wants to handle hooks from the invite service
/// to be notified when an event occurs related to an invite.
#[crate::service(
name = "invite-hooks",
actions = "hooks_actions",
wrapper = "hooks_wrapper",
structs = "hooks_structs",
dispatch = false,
pub_constant = false,
psibase_mod = "crate"
)]
#[allow(non_snake_case, unused_variables)]
pub mod InviteHooks {
use crate::AccountNumber;
/// Called on the invite creator when the invite is accepted
#[action]
fn onInvAccept(inviteId: u32, accepter: AccountNumber) {
unimplemented!()
}
}
/// This service facilitates the creation and redemption of invites
///
/// Invites are generic and their acceptance can, but does not always, result
/// in the creation of a new account. This service can be used
/// by third party applications to streamline their user onboarding.
#[crate::service(name = "invite", dispatch = false, psibase_mod = "crate")]
#[allow(non_snake_case, unused_variables)]
mod service {
use crate::services::auth_sig::SubjectPublicKeyInfo;
use crate::services::tokens::Quantity;
use crate::AccountNumber;
#[action]
fn init() {
unimplemented!()
}
/// Returns the current minimum cost of creating an invite that can create the specified number of
/// accounts.
#[action]
fn getInvCost(numAccounts: u16) -> Quantity {
unimplemented!()
}
/// Creates and stores a new invite object that can be used to create new accounts
/// Returns the ID of the newly created invite
///
/// Parameters:
/// - `inviteId` is the id of the invite (could be randomly generated)
/// - `fingerprint` is the fingerprint of the invite public key
/// - `numAccounts` is the number of accounts this invite can be used to create
/// - `useHooks` is a flag that indicates whether to use hooks to notify the caller when
/// the invite is updated
/// - `secret` is an encrypted secret used to redeem the invite
/// - `resources` is the amount of resources stored in the invite (used when creating
/// new accounts). The caller must send this amount of system tokens to this
/// invite service before calling this action. Use the query interface to check
/// the resources required for an invite of the specified number of accounts.
///
/// If `useHooks` is true, the caller must be an account with a service deployed on it
/// that implements the InviteHooks interface.
#[action]
fn createInvite(
inviteId: u32,
fingerprint: crate::Checksum256,
numAccounts: u16,
useHooks: bool,
secret: String,
resources: Quantity,
) -> u32 {
unimplemented!()
}
/// Called by an invite credential (not a user account) to create the specified
/// account. The new account is authorized by the specified public key.
#[action]
fn createAccount(account: AccountNumber, accountKey: SubjectPublicKeyInfo) {
unimplemented!()
}
/// The sender accepts an invite.
/// Calling this action also requires that the sender authorizes the transaction with the
/// proof for the credential associated with the invite.
#[action]
fn accept(inviteId: u32) {
unimplemented!()
}
/// Delete the invite and its secret (if applicable).
/// Can only be called by the invite creator.
#[action]
fn delInvite(inviteId: u32) {
unimplemented!()
}
/// Called synchronously by other services to retrieve the specified invite record
#[action]
fn getInvite(inviteId: u32) -> Option<super::InviteRecord> {
unimplemented!()
}
#[event(history)]
pub fn updated(inviteId: u32, actor: AccountNumber, event: String) {
unimplemented!()
}
}
#[test]
fn verify_schema() {
crate::assert_schema_matches_package::<Wrapper>();
}