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]]
|
[[package]]
|
||||||
name = "nex-account"
|
name = "nex-account"
|
||||||
version = "0.2.2"
|
version = "0.2.3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base64",
|
"base64",
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "nex-account"
|
name = "nex-account"
|
||||||
version = "0.2.2"
|
version = "0.2.3"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
publish = ["spbr"]
|
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,
|
self, EncSignKeypair, decrypt_and_check, encrypt_and_gen_signature_blocks,
|
||||||
};
|
};
|
||||||
use thiserror::Error;
|
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;
|
pub mod grpc;
|
||||||
|
|
||||||
|
|
@ -62,6 +66,10 @@ pub enum Error {
|
||||||
FutureToken,
|
FutureToken,
|
||||||
#[error("token expired")]
|
#[error("token expired")]
|
||||||
TokenExpired,
|
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>;
|
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))
|
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)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use std::env::set_var;
|
use std::env::set_var;
|
||||||
|
|
|
||||||
20
src/main.rs
20
src/main.rs
|
|
@ -3,15 +3,15 @@ use std::{
|
||||||
net::{Ipv4Addr, SocketAddr, SocketAddrV4},
|
net::{Ipv4Addr, SocketAddr, SocketAddrV4},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use crate::grpc::{
|
||||||
|
ActCreateInfo, ActStageInfo, ActStageReturn, NexKey, Pid,
|
||||||
|
nex_account_service_server::{NexAccountService, NexAccountServiceServer},
|
||||||
|
};
|
||||||
use log::error;
|
use log::error;
|
||||||
|
use md5::{Digest, Md5};
|
||||||
use simplelog::{Config, TerminalMode};
|
use simplelog::{Config, TerminalMode};
|
||||||
use sqlx::{PgPool, query};
|
use sqlx::{PgPool, query};
|
||||||
use tonic::{Response, transport::Server};
|
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;
|
pub mod grpc;
|
||||||
|
|
||||||
|
|
@ -108,10 +108,7 @@ impl NexAccountService for NexAccountServer {
|
||||||
.map_err(db_neverfail)?;
|
.map_err(db_neverfail)?;
|
||||||
|
|
||||||
// deletion query
|
// deletion query
|
||||||
query!(
|
query!("delete from staged_nex_accounts where pid = $1", pid)
|
||||||
"delete from staged_nex_accounts where pid = $1",
|
|
||||||
pid
|
|
||||||
)
|
|
||||||
.execute(&self.pool)
|
.execute(&self.pool)
|
||||||
.await
|
.await
|
||||||
.map_err(db_neverfail)?;
|
.map_err(db_neverfail)?;
|
||||||
|
|
@ -183,7 +180,10 @@ impl NexAccountService for NexAccountServer {
|
||||||
.await
|
.await
|
||||||
.map_err(db_neverfail)?;
|
.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