version bump and add new functions
This commit is contained in:
parent
44d6cf1b2f
commit
cb9bd4cb26
4 changed files with 45 additions and 25 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
|
@ -959,7 +959,7 @@ checksum = "1d87ecb2933e8aeadb3e3a02b828fed80a7528047e68b4f424523a0981a3a084"
|
|||
|
||||
[[package]]
|
||||
name = "nex-account"
|
||||
version = "0.2.2"
|
||||
version = "0.2.3"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"bytemuck",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "nex-account"
|
||||
version = "0.2.2"
|
||||
version = "0.2.3"
|
||||
edition = "2024"
|
||||
publish = ["spbr"]
|
||||
|
||||
|
|
|
|||
22
src/lib.rs
22
src/lib.rs
|
|
@ -12,8 +12,12 @@ use spbr_common::crypto::encsign::{
|
|||
self, EncSignKeypair, decrypt_and_check, encrypt_and_gen_signature_blocks,
|
||||
};
|
||||
use thiserror::Error;
|
||||
use tonic::transport::Channel;
|
||||
|
||||
use crate::Error::{FutureToken, KeypairUnset, PaddingNonzero, TokenExpired};
|
||||
use crate::{
|
||||
Error::{FutureToken, GrpcUrlNotSet, KeypairUnset, PaddingNonzero, TokenExpired},
|
||||
grpc::nex_account_service_client::NexAccountServiceClient,
|
||||
};
|
||||
|
||||
pub mod grpc;
|
||||
|
||||
|
|
@ -62,6 +66,10 @@ pub enum Error {
|
|||
FutureToken,
|
||||
#[error("token expired")]
|
||||
TokenExpired,
|
||||
#[error("NEX_ACCOUNT_GRPC_URL has not been set")]
|
||||
GrpcUrlNotSet,
|
||||
#[error("tonic transport error occurred: {0}")]
|
||||
GrpcTonicTransportError(#[from] tonic::transport::Error),
|
||||
}
|
||||
|
||||
type Result<T, E = Error> = result::Result<T, E>;
|
||||
|
|
@ -131,6 +139,18 @@ pub fn decode_nexact_token(data: &str) -> Result<(PID, NexKey)> {
|
|||
Ok((token_data.pid, token_data.nex_key))
|
||||
}
|
||||
|
||||
static GRPC_URL: LazyLock<Option<String>> =
|
||||
LazyLock::new(|| env::var("NEX_ACCOUNT_GRPC_URL").ok()?.parse().ok());
|
||||
|
||||
pub async fn grpc_client() -> Result<NexAccountServiceClient<Channel>> {
|
||||
Ok(
|
||||
grpc::nex_account_service_client::NexAccountServiceClient::connect(
|
||||
GRPC_URL.as_ref().ok_or(GrpcUrlNotSet)?.as_str(),
|
||||
)
|
||||
.await?,
|
||||
)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use std::env::set_var;
|
||||
|
|
|
|||
22
src/main.rs
22
src/main.rs
|
|
@ -3,15 +3,15 @@ use std::{
|
|||
net::{Ipv4Addr, SocketAddr, SocketAddrV4},
|
||||
};
|
||||
|
||||
use crate::grpc::{
|
||||
ActCreateInfo, ActStageInfo, ActStageReturn, NexKey, Pid,
|
||||
nex_account_service_server::{NexAccountService, NexAccountServiceServer},
|
||||
};
|
||||
use log::error;
|
||||
use md5::{Digest, Md5};
|
||||
use simplelog::{Config, TerminalMode};
|
||||
use sqlx::{PgPool, query};
|
||||
use tonic::{Response, transport::Server};
|
||||
use crate::grpc::{
|
||||
ActCreateInfo, NexKey, Pid, ActStageInfo, ActStageReturn,
|
||||
nex_account_service_server::{NexAccountService, NexAccountServiceServer},
|
||||
};
|
||||
use md5::{Digest, Md5};
|
||||
|
||||
pub mod grpc;
|
||||
|
||||
|
|
@ -108,10 +108,7 @@ impl NexAccountService for NexAccountServer {
|
|||
.map_err(db_neverfail)?;
|
||||
|
||||
// deletion query
|
||||
query!(
|
||||
"delete from staged_nex_accounts where pid = $1",
|
||||
pid
|
||||
)
|
||||
query!("delete from staged_nex_accounts where pid = $1", pid)
|
||||
.execute(&self.pool)
|
||||
.await
|
||||
.map_err(db_neverfail)?;
|
||||
|
|
@ -134,7 +131,7 @@ impl NexAccountService for NexAccountServer {
|
|||
.await
|
||||
.map_err(db_neverfail)?;
|
||||
|
||||
Ok(Response::new(NexKey { key: row.nex_key}))
|
||||
Ok(Response::new(NexKey { key: row.nex_key }))
|
||||
}
|
||||
|
||||
async fn get_nex_key_by_pid(
|
||||
|
|
@ -183,7 +180,10 @@ impl NexAccountService for NexAccountServer {
|
|||
.await
|
||||
.map_err(db_neverfail)?;
|
||||
|
||||
Ok(Response::new(ActStageReturn{ pid: next_pid, nex_key: nex_key.into() }))
|
||||
Ok(Response::new(ActStageReturn {
|
||||
pid: next_pid,
|
||||
nex_key: nex_key.into(),
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue