Skip to content

Commit e95b38d

Browse files
authored
Merge pull request #123 from filecoin-project/feat/add-node-to-allocator-db
changed DB, added node_address and node_token
2 parents 7f31950 + 50e42f5 commit e95b38d

File tree

5 files changed

+44
-4
lines changed

5 files changed

+44
-4
lines changed

fplus-database/src/database/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ pub async fn get_allocators() ->Result<Vec<AllocatorModel>, sea_orm::DbErr> {
2222
* @param installation_id: Option<i64> - The installation ID
2323
* @param multisig_address: Option<String> - The multisig address
2424
* @param verifiers_gh_handles: Option<String> - The GitHub handles of the verifiers
25+
* @param node_address: Option<String> - The node address
26+
* @param node_token: Option<String> - The node token
2527
*
2628
* # Returns
2729
* @return Result<AllocatorModel, sea_orm::DbErr> - The result of the operation
@@ -32,6 +34,8 @@ pub async fn update_allocator(
3234
installation_id: Option<i64>,
3335
multisig_address: Option<String>,
3436
verifiers_gh_handles: Option<String>,
37+
node_address: Option<String>,
38+
node_token: Option<String>,
3539
) -> Result<AllocatorModel, sea_orm::DbErr> {
3640
let conn = get_database_connection().await?;
3741

@@ -42,6 +46,8 @@ pub async fn update_allocator(
4246
allocator_active_model.installation_id = Set(installation_id);
4347
allocator_active_model.multisig_address = Set(multisig_address);
4448
allocator_active_model.verifiers_gh_handles = Set(verifiers_gh_handles);
49+
allocator_active_model.node_address = Set(node_address);
50+
allocator_active_model.node_token = Set(node_token);
4551

4652
let updated_model = allocator_active_model.update(&conn).await?;
4753

@@ -82,6 +88,8 @@ pub async fn get_allocator(
8288
* @param installation_id: Option<i64> - The installation ID
8389
* @param multisig_address: Option<String> - The multisig address
8490
* @param verifiers_gh_handles: Option<String> - The GitHub handles of the verifiers
91+
* @param node_address: Option<String> - The node address
92+
* @param node_token: Option<String> - The node token
8593
*
8694
* # Returns
8795
* @return Result<AllocatorModel, sea_orm::DbErr> - The result of the operation
@@ -92,6 +100,8 @@ pub async fn create_or_update_allocator(
92100
installation_id: Option<i64>,
93101
multisig_address: Option<String>,
94102
verifiers_gh_handles: Option<String>,
103+
node_address: Option<String>,
104+
node_token: Option<String>,
95105
) -> Result<AllocatorModel, sea_orm::DbErr> {
96106

97107
let existing_allocator = get_allocator(&owner, &repo).await?;
@@ -102,6 +112,8 @@ pub async fn create_or_update_allocator(
102112
allocator_active_model.installation_id = Set(installation_id);
103113
allocator_active_model.multisig_address = Set(multisig_address);
104114
allocator_active_model.verifiers_gh_handles = Set(verifiers_gh_handles);
115+
allocator_active_model.node_address = Set(node_address);
116+
allocator_active_model.node_token = Set(node_token);
105117

106118
let updated_model = allocator_active_model.update(&conn).await?;
107119

@@ -113,6 +125,8 @@ pub async fn create_or_update_allocator(
113125
installation_id: Set(installation_id),
114126
multisig_address: Set(multisig_address),
115127
verifiers_gh_handles: Set(verifiers_gh_handles),
128+
node_address: Set(node_address),
129+
node_token: Set(node_token),
116130
..Default::default()
117131
};
118132

fplus-database/src/lib.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,17 @@ mod tests {
102102
let installation_id = Some(1234);
103103
let multisig_address = Some("0x1234567890".to_string());
104104
let verifiers_gh_handles = Some("test_verifier_1, test_verifier_2".to_string());
105+
let node_address = Some("wss://lotus-node-1.ngrok-free.app/rpc/v0".to_string());
106+
let node_token = Some("222".to_string());
105107

106108
let result = database::create_or_update_allocator(
107109
owner,
108110
repo,
109111
installation_id,
110112
multisig_address,
111-
verifiers_gh_handles
113+
verifiers_gh_handles,
114+
node_address,
115+
node_token
112116
).await;
113117
assert!(result.is_ok());
114118
}
@@ -149,13 +153,17 @@ mod tests {
149153
let multisig_address = Some
150154
("0x1234567890".to_string());
151155
let verifiers_gh_handles = Some("test_verifier_1, test_verifier_2".to_string());
156+
let node_address = Some("wss://lotus-node.app/rpc/v0".to_string());
157+
let node_token = Some("111".to_string());
152158

153159
let result = database::create_or_update_allocator(
154160
owner.clone(),
155161
repo.clone(),
156162
installation_id,
157163
multisig_address,
158-
verifiers_gh_handles
164+
verifiers_gh_handles,
165+
node_address,
166+
node_token
159167
).await;
160168
assert!(result.is_ok());
161169
}
@@ -165,13 +173,17 @@ mod tests {
165173
let installation_id = Some(1234);
166174
let multisig_address = Some("0x0987654321".to_string());
167175
let verifiers_gh_handles = Some("test_verifier_3, test_verifier_4".to_string());
176+
let node_address = Some("wss://lotus-node.app/rpc/v0".to_string());
177+
let node_token = Some("111".to_string());
168178

169179
let result = database::update_allocator(
170180
&owner,
171181
&repo,
172182
installation_id,
173183
multisig_address,
174-
verifiers_gh_handles
184+
verifiers_gh_handles,
185+
node_address,
186+
node_token
175187
).await;
176188
assert!(result.is_ok());
177189
}
@@ -216,13 +228,17 @@ mod tests {
216228
let installation_id = Some(1234);
217229
let multisig_address = Some("0x1234567890".to_string());
218230
let verifiers_gh_handles = Some("test_verifier_1, test_verifier_2".to_string());
231+
let node_address = Some("wss://lotus-node-2.ngrok-free.app/rpc/v0".to_string());
232+
let node_token = Some("333".to_string());
219233

220234
let result = database::create_or_update_allocator(
221235
owner.clone(),
222236
repo.clone(),
223237
installation_id,
224238
multisig_address,
225-
verifiers_gh_handles
239+
verifiers_gh_handles,
240+
node_address,
241+
node_token
226242
).await;
227243

228244
assert!(result.is_ok());

fplus-database/src/models/allocators.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ pub struct Model {
1414
pub multisig_address: Option<String>,
1515
#[sea_orm(column_type = "Text", nullable)]
1616
pub verifiers_gh_handles: Option<String>,
17+
pub node_address: Option<String>,
18+
pub node_token: Option<String>,
1719
}
1820

1921
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]

fplus-http-server/src/router/allocator.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ pub async fn create_or_update(info: web::Json<Allocator>) -> impl Responder {
3737
info.installation_id,
3838
info.multisig_address.clone(),
3939
info.verifiers_gh_handles.clone(),
40+
info.node_address.clone(),
41+
info.node_token.clone(),
4042
).await {
4143
Ok(allocator_model) => HttpResponse::Ok().json(allocator_model),
4244
Err(e) => {
@@ -70,6 +72,8 @@ pub async fn update(
7072
info.installation_id,
7173
info.multisig_address.clone(),
7274
info.verifiers_gh_handles.clone(),
75+
info.node_address.clone(),
76+
info.node_token.clone(),
7377
).await {
7478
Ok(allocator_model) => HttpResponse::Ok().json(allocator_model),
7579
Err(e) => {

fplus-lib/src/core/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,17 @@ pub struct Allocator {
9898
pub installation_id: Option<i64>,
9999
pub multisig_address: Option<String>,
100100
pub verifiers_gh_handles: Option<String>,
101+
pub node_address: Option<String>,
102+
pub node_token: Option<String>,
101103
}
102104

103105
#[derive(Deserialize)]
104106
pub struct AllocatorUpdateInfo {
105107
pub installation_id: Option<i64>,
106108
pub multisig_address: Option<String>,
107109
pub verifiers_gh_handles: Option<String>,
110+
pub node_address: Option<String>,
111+
pub node_token: Option<String>,
108112
}
109113

110114
#[derive(Deserialize)]

0 commit comments

Comments
 (0)