Skip to content

Commit b6fd67e

Browse files
committed
node: ApiClient vfs methods take references
1 parent 1e9e1eb commit b6fd67e

File tree

4 files changed

+34
-32
lines changed

4 files changed

+34
-32
lines changed

node/src/api/client.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,19 +119,19 @@ impl ApiClient for LexeApiClient {
119119
.await
120120
}
121121

122-
async fn get_file(&self, data: FileId) -> Result<Option<File>, ApiError> {
122+
async fn get_file(&self, data: &FileId) -> Result<Option<File>, ApiError> {
123123
let endpoint = "/file";
124124
self.request(&Method::GET, Backend, V1, endpoint, &data)
125125
.await
126126
}
127127

128-
async fn create_file(&self, data: File) -> Result<File, ApiError> {
128+
async fn create_file(&self, data: &File) -> Result<File, ApiError> {
129129
let endpoint = "/file";
130130
self.request(&Method::POST, Backend, V1, endpoint, &data)
131131
.await
132132
}
133133

134-
async fn upsert_file(&self, data: File) -> Result<File, ApiError> {
134+
async fn upsert_file(&self, data: &File) -> Result<File, ApiError> {
135135
let endpoint = "/file";
136136
self.request(&Method::PUT, Backend, V1, endpoint, &data)
137137
.await
@@ -140,15 +140,15 @@ impl ApiClient for LexeApiClient {
140140
// TODO We want to delete channel peers / monitors when channels close
141141
/// Returns "OK" if exactly one row was deleted.
142142
#[allow(dead_code)]
143-
async fn delete_file(&self, data: FileId) -> Result<String, ApiError> {
143+
async fn delete_file(&self, data: &FileId) -> Result<String, ApiError> {
144144
let endpoint = "/file";
145145
self.request(&Method::DELETE, Backend, V1, endpoint, &data)
146146
.await
147147
}
148148

149149
async fn get_directory(
150150
&self,
151-
data: Directory,
151+
data: &Directory,
152152
) -> Result<Vec<File>, ApiError> {
153153
let endpoint = "/directory";
154154
self.request(&Method::GET, Backend, V1, endpoint, &data)

node/src/api/mock.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -153,35 +153,35 @@ impl ApiClient for MockApiClient {
153153

154154
async fn get_file(
155155
&self,
156-
file_id: FileId,
156+
file_id: &FileId,
157157
) -> Result<Option<File>, ApiError> {
158-
let file_opt = self.vfs.lock().unwrap().get(file_id);
158+
let file_opt = self.vfs.lock().unwrap().get(file_id.clone());
159159
Ok(file_opt)
160160
}
161161

162-
async fn create_file(&self, file: File) -> Result<File, ApiError> {
162+
async fn create_file(&self, file: &File) -> Result<File, ApiError> {
163163
let file_opt = self.vfs.lock().unwrap().insert(file.clone());
164164
assert!(file_opt.is_none());
165-
Ok(file)
165+
Ok(file.clone())
166166
}
167167

168-
async fn upsert_file(&self, file: File) -> Result<File, ApiError> {
168+
async fn upsert_file(&self, file: &File) -> Result<File, ApiError> {
169169
self.vfs.lock().unwrap().insert(file.clone());
170-
Ok(file)
170+
Ok(file.clone())
171171
}
172172

173173
/// Returns "OK" if exactly one row was deleted.
174-
async fn delete_file(&self, file_id: FileId) -> Result<String, ApiError> {
175-
let file_opt = self.vfs.lock().unwrap().remove(file_id);
174+
async fn delete_file(&self, file_id: &FileId) -> Result<String, ApiError> {
175+
let file_opt = self.vfs.lock().unwrap().remove(file_id.clone());
176176
assert!(file_opt.is_none());
177177
Ok(String::from("OK"))
178178
}
179179

180180
async fn get_directory(
181181
&self,
182-
dir: Directory,
182+
dir: &Directory,
183183
) -> Result<Vec<File>, ApiError> {
184-
let files_vec = self.vfs.lock().unwrap().get_dir(dir);
184+
let files_vec = self.vfs.lock().unwrap().get_dir(dir.clone());
185185
Ok(files_vec)
186186
}
187187

node/src/api/mod.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,22 @@ pub trait ApiClient {
5454
data: NodeInstanceSeed,
5555
) -> Result<NodeInstanceSeed, ApiError>;
5656

57-
async fn get_file(&self, file_id: FileId)
58-
-> Result<Option<File>, ApiError>;
57+
async fn get_file(
58+
&self,
59+
file_id: &FileId,
60+
) -> Result<Option<File>, ApiError>;
5961

60-
async fn create_file(&self, file: File) -> Result<File, ApiError>;
62+
async fn create_file(&self, file: &File) -> Result<File, ApiError>;
6163

62-
async fn upsert_file(&self, file: File) -> Result<File, ApiError>;
64+
async fn upsert_file(&self, file: &File) -> Result<File, ApiError>;
6365

6466
// TODO We want to delete channel peers / monitors when channels close
6567
/// Returns "OK" if exactly one row was deleted.
66-
async fn delete_file(&self, file_id: FileId) -> Result<String, ApiError>;
68+
async fn delete_file(&self, file_id: &FileId) -> Result<String, ApiError>;
6769

6870
async fn get_directory(
6971
&self,
70-
dir: Directory,
72+
dir: &Directory,
7173
) -> Result<Vec<File>, ApiError>;
7274

7375
async fn notify_runner(

node/src/lexe/persister.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl InnerPersister {
107107
);
108108
let cm_file_opt = self
109109
.api
110-
.get_file(cm_file_id)
110+
.get_file(&cm_file_id)
111111
.await
112112
.context("Could not fetch channel manager from DB")?;
113113

@@ -162,7 +162,7 @@ impl InnerPersister {
162162

163163
let cm_file_vec = self
164164
.api
165-
.get_directory(cm_dir)
165+
.get_directory(&cm_dir)
166166
.await
167167
.context("Could not fetch channel monitors from DB")?;
168168

@@ -209,7 +209,7 @@ impl InnerPersister {
209209
);
210210
let scorer_file_opt = self
211211
.api
212-
.get_file(scorer_file_id)
212+
.get_file(&scorer_file_id)
213213
.await
214214
.context("Could not fetch probabilistic scorer from DB")?;
215215

@@ -244,7 +244,7 @@ impl InnerPersister {
244244
);
245245
let ng_file_opt = self
246246
.api
247-
.get_file(ng_file_id)
247+
.get_file(&ng_file_id)
248248
.await
249249
.context("Could not fetch network graph from DB")?;
250250

@@ -273,7 +273,7 @@ impl InnerPersister {
273273

274274
let cp_file_vec = self
275275
.api
276-
.get_directory(cp_dir)
276+
.get_directory(&cp_dir)
277277
.await
278278
.context("Could not fetch channel peers from DB")?;
279279

@@ -309,7 +309,7 @@ impl InnerPersister {
309309
);
310310

311311
self.api
312-
.create_file(cp_file)
312+
.create_file(&cp_file)
313313
.await
314314
.map(|_| ())
315315
.map_err(|e| e.into())
@@ -333,7 +333,7 @@ impl InnerPersister {
333333
);
334334

335335
self.api
336-
.upsert_file(cm_file)
336+
.upsert_file(&cm_file)
337337
.await
338338
.map(|_| ())
339339
.context("Could not persist channel manager")
@@ -356,7 +356,7 @@ impl InnerPersister {
356356
);
357357

358358
self.api
359-
.upsert_file(file)
359+
.upsert_file(&file)
360360
.await
361361
.map(|_| ())
362362
.context("Could not persist network graph")
@@ -384,7 +384,7 @@ impl InnerPersister {
384384
};
385385

386386
self.api
387-
.upsert_file(scorer_file)
387+
.upsert_file(&scorer_file)
388388
.await
389389
.map(|_| ())
390390
.context("Could not persist scorer")
@@ -415,7 +415,7 @@ impl Persist<SignerType> for InnerPersister {
415415

416416
// Run an async fn inside a sync fn inside a Tokio runtime
417417
Handle::current()
418-
.block_on(async move { self.api.create_file(cm_file).await })
418+
.block_on(async move { self.api.create_file(&cm_file).await })
419419
.map(|_| ())
420420
.map_err(|e| {
421421
// TODO(max): Implement durability then make this err permanent
@@ -448,7 +448,7 @@ impl Persist<SignerType> for InnerPersister {
448448

449449
// Run an async fn inside a sync fn inside a Tokio runtime
450450
Handle::current()
451-
.block_on(async move { self.api.upsert_file(cm_file).await })
451+
.block_on(async move { self.api.upsert_file(&cm_file).await })
452452
.map(|_| ())
453453
.map_err(|e| {
454454
// TODO(max): Implement durability then make this err permanent

0 commit comments

Comments
 (0)