add ability to get nex keys for staged accounts
Some checks failed
Build and Test / nex-account (push) Failing after 52s
Some checks failed
Build and Test / nex-account (push) Failing after 52s
This commit is contained in:
parent
6882a0dd5b
commit
dcc0d1b2b7
4 changed files with 33 additions and 3 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
|
@ -959,7 +959,7 @@ checksum = "1d87ecb2933e8aeadb3e3a02b828fed80a7528047e68b4f424523a0981a3a084"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "nex-account"
|
name = "nex-account"
|
||||||
version = "0.2.3"
|
version = "0.2.4"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base64",
|
"base64",
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "nex-account"
|
name = "nex-account"
|
||||||
version = "0.2.3"
|
version = "0.2.4"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
publish = ["spbr"]
|
publish = ["spbr"]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,5 +29,6 @@ message NexKey {
|
||||||
service NexAccountService {
|
service NexAccountService {
|
||||||
rpc CreateNewSequentialOrUpdateAndGetAccount(ActCreateInfo) returns (NexKey);
|
rpc CreateNewSequentialOrUpdateAndGetAccount(ActCreateInfo) returns (NexKey);
|
||||||
rpc GetNexKeyByPid(PID) returns (NexKey);
|
rpc GetNexKeyByPid(PID) returns (NexKey);
|
||||||
|
rpc GetNexKeyByPidMaybeStaged(PID) returns (NexKey);
|
||||||
rpc StageNewAccount(ActStageInfo) returns (ActStageReturn);
|
rpc StageNewAccount(ActStageInfo) returns (ActStageReturn);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
31
src/main.rs
31
src/main.rs
|
|
@ -69,7 +69,6 @@ pub fn derive_key(pid: i32, password: &[u8]) -> [u8; 16] {
|
||||||
|
|
||||||
key
|
key
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tonic::async_trait]
|
#[tonic::async_trait]
|
||||||
impl NexAccountService for NexAccountServer {
|
impl NexAccountService for NexAccountServer {
|
||||||
async fn create_new_sequential_or_update_and_get_account(
|
async fn create_new_sequential_or_update_and_get_account(
|
||||||
|
|
@ -153,6 +152,36 @@ impl NexAccountService for NexAccountServer {
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
async fn get_nex_key_by_pid_maybe_staged(
|
||||||
|
&self,
|
||||||
|
request: tonic::Request<Pid>,
|
||||||
|
) -> Result<Response<NexKey>, tonic::Status> {
|
||||||
|
let pid = request.into_inner().pid;
|
||||||
|
|
||||||
|
let sql_res = query!("select nex_key from nex_accounts where pid = $1", pid)
|
||||||
|
.fetch_optional(&self.pool)
|
||||||
|
.await
|
||||||
|
.map_err(db_neverfail)?;
|
||||||
|
|
||||||
|
if let Some(res) = sql_res {
|
||||||
|
return Ok(Response::new(NexKey { key: res.nex_key }));
|
||||||
|
}
|
||||||
|
let sql_res = query!(
|
||||||
|
"select nex_key from staged_nex_accounts where pid = $1",
|
||||||
|
pid
|
||||||
|
)
|
||||||
|
.fetch_optional(&self.pool)
|
||||||
|
.await
|
||||||
|
.map_err(db_neverfail)?;
|
||||||
|
|
||||||
|
if let Some(res) = sql_res {
|
||||||
|
Ok(Response::new(NexKey { key: res.nex_key }))
|
||||||
|
} else {
|
||||||
|
Err(tonic::Status::not_found(
|
||||||
|
"nex account with provided pid does not exist",
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
async fn stage_new_account(
|
async fn stage_new_account(
|
||||||
&self,
|
&self,
|
||||||
request: tonic::Request<ActStageInfo>,
|
request: tonic::Request<ActStageInfo>,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue