Skip to content

Commit c8b0b8d

Browse files
committed
fixup! Add Vss KVStore api.
1 parent 633afd9 commit c8b0b8d

File tree

3 files changed

+49
-8
lines changed

3 files changed

+49
-8
lines changed

rust/api/src/error.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,36 @@
11
use std::error::Error;
22
use std::fmt::{Display, Formatter};
33
use std::io;
4-
54
/// When there is an error while writing to VSS storage, the response contains a relevant error code.
6-
/// A mapping from a VSS server error codes. Refer to [`ErrorResponse`] docs for more
5+
/// A mapping for VSS server error codes. Refer to [`ErrorResponse`] docs for more
76
/// information regarding each error code and corresponding use-cases.
7+
///
8+
/// [`ErrorResponse`]: crate::types::ErrorResponse
89
#[derive(Debug)]
910
pub enum VssError {
1011
/// Please refer to [`ErrorCode::NoSuchKeyException`].
12+
///
13+
/// [`ErrorCode::NoSuchKeyException`]: crate::types::ErrorCode::NoSuchKeyException
1114
NoSuchKeyError(String),
1215

1316
/// Please refer to [`ErrorCode::InvalidRequestException`].
17+
///
18+
/// [`ErrorCode::InvalidRequestException`]: crate::types::ErrorCode::InvalidRequestException
1419
InvalidRequestError(String),
1520

1621
/// Please refer to [`ErrorCode::ConflictException`].
22+
///
23+
/// [`ErrorCode::ConflictException`]: crate::types::ErrorCode::ConflictException
1724
ConflictError(String),
1825

1926
/// Please refer to [`ErrorCode::AuthException`].
27+
///
28+
/// [`ErrorCode::AuthException`]: crate::types::ErrorCode::AuthException
2029
AuthError(String),
2130

2231
/// Please refer to [`ErrorCode::InternalServerException`].
32+
///
33+
/// [`ErrorCode::InternalServerException`]: crate::types::ErrorCode::InternalServerException
2334
InternalServerError(String),
2435
}
2536

@@ -30,10 +41,10 @@ impl Display for VssError {
3041
write!(f, "Requested key does not exist: {}", message)
3142
},
3243
VssError::InvalidRequestError(message) => {
33-
write!(f, "Request sent to VSS Storage was invalid: {}", message)
44+
write!(f, "Request sent to VSS was invalid: {}", message)
3445
},
3546
VssError::ConflictError(message) => {
36-
write!(f, "Potential version conflict in write operation: {}", message)
47+
write!(f, "Version conflict in write operation: {}", message)
3748
},
3849
VssError::AuthError(message) => {
3950
write!(f, "Authentication or Authorization failure: {}", message)

rust/api/src/kv_store.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,47 @@
11
use crate::error::VssError;
22
use crate::types::{
3-
DeleteObjectRequest, DeleteObjectResponse, GetObjectRequest, GetObjectResponse, KeyValue,
3+
DeleteObjectRequest, DeleteObjectResponse, GetObjectRequest, GetObjectResponse,
44
ListKeyVersionsRequest, ListKeyVersionsResponse, PutObjectRequest, PutObjectResponse,
55
};
66
use async_trait::async_trait;
7+
8+
#[cfg(test)]
9+
use crate::types::KeyValue;
710
#[cfg(test)]
811
use bytes::Bytes;
912
#[cfg(test)]
1013
use rand::distributions::Alphanumeric;
1114
#[cfg(test)]
1215
use rand::{thread_rng, Rng};
1316

14-
pub const GLOBAL_VERSION_KEY: &str = "global_version";
15-
pub const INITIAL_RECORD_VERSION: i32 = 1;
17+
pub(crate) const GLOBAL_VERSION_KEY: &str = "global_version";
18+
pub(crate) const INITIAL_RECORD_VERSION: i32 = 1;
19+
20+
/// An interface that must be implemented by every backend implementation of VSS.
1621
#[async_trait]
1722
pub trait KvStore: Send + Sync {
23+
/// Retrieves an object based on the provided request and user token.
1824
async fn get(
1925
&self, user_token: String, request: GetObjectRequest,
2026
) -> Result<GetObjectResponse, VssError>;
27+
28+
/// Stores an object with the provided request and user token.
2129
async fn put(
2230
&self, user_token: String, request: PutObjectRequest,
2331
) -> Result<PutObjectResponse, VssError>;
32+
33+
/// Deletes an object based on the provided request and user token.
2434
async fn delete(
2535
&self, user_token: String, request: DeleteObjectRequest,
2636
) -> Result<DeleteObjectResponse, VssError>;
37+
38+
/// Lists the versions of keys based on the provided request and user token.
2739
async fn list_key_versions(
2840
&self, user_token: String, request: ListKeyVersionsRequest,
2941
) -> Result<ListKeyVersionsResponse, VssError>;
3042
}
3143

44+
/// Defines KvStoreTestSuite which is required for an implementation to be VSS protocol compliant.
3245
#[macro_export]
3346
macro_rules! define_kv_store_tests {
3447
($test_suite_name:ident, $store_type:path, $create_store_expr: expr) => {

rust/api/src/lib.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,21 @@
1-
pub mod auth;
1+
//! Hosts API contract for VSS.
2+
//!
3+
//! VSS is an open-source project designed to offer a server-side cloud storage solution specifically
4+
//! tailored for noncustodial Lightning supporting mobile wallets. Its primary objective is to
5+
//! simplify the development process for Lightning wallets by providing a secure means to store
6+
//! and manage the essential state required for Lightning Network (LN) operations.
7+
8+
#![deny(rustdoc::broken_intra_doc_links)]
9+
#![deny(rustdoc::private_intra_doc_links)]
10+
#![deny(missing_docs)]
11+
12+
/// Implements the error type ([`error::VssError`]) which is eventually converted to [`ErrorResponse`] and returned to client.
13+
///
14+
/// [`ErrorResponse`]: crate::types::ErrorResponse
215
pub mod error;
16+
17+
/// Contains [`kv_store::KvStore`] interface which needs to be implemented by every backend implementation of VSS.
318
pub mod kv_store;
19+
20+
/// Contains request/response types generated from the API definition of VSS.
421
pub mod types;

0 commit comments

Comments
 (0)