mirror of
https://github.com/logos-blockchain/lssa.git
synced 2026-01-03 05:43:08 +00:00
minor refactor
This commit is contained in:
parent
b1724ec235
commit
8b1d3b478c
@ -2,7 +2,7 @@ use std::collections::HashMap;
|
||||
|
||||
use anyhow::Result;
|
||||
use common::{merkle_tree_public::TreeHashType, transaction::Tag};
|
||||
use k256::AffinePoint;
|
||||
use k256::{ecdsa::VerifyingKey, AffinePoint};
|
||||
use log::info;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use utxo::utxo_core::UTXO;
|
||||
|
||||
@ -10,7 +10,7 @@ use secret_holders::{SeedHolder, TopSecretKeyHolder, UTXOSecretKeyHolder};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::account_core::PublicKey;
|
||||
pub type PublicAccountSecretKey = [u8; 32];
|
||||
pub type PublicAccountSigningKey = [u8; 32];
|
||||
|
||||
pub mod constants_types;
|
||||
pub mod ephemeral_key_holder;
|
||||
@ -23,7 +23,7 @@ pub struct AddressKeyHolder {
|
||||
#[allow(dead_code)]
|
||||
top_secret_key_holder: TopSecretKeyHolder,
|
||||
pub utxo_secret_key_holder: UTXOSecretKeyHolder,
|
||||
pub pub_account_secret_key: PublicAccountSecretKey,
|
||||
pub_account_signing_key: PublicAccountSigningKey,
|
||||
pub address: TreeHashType,
|
||||
pub nullifer_public_key: PublicKey,
|
||||
pub viewing_public_key: PublicKey,
|
||||
@ -54,12 +54,12 @@ impl AddressKeyHolder {
|
||||
address,
|
||||
nullifer_public_key,
|
||||
viewing_public_key,
|
||||
pub_account_secret_key,
|
||||
pub_account_signing_key: pub_account_secret_key,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn pub_account_secret_key(&self) -> SigningKey {
|
||||
let field_bytes = FieldBytes::from_slice(&self.pub_account_secret_key);
|
||||
pub fn get_pub_account_signing_key(&self) -> SigningKey {
|
||||
let field_bytes = FieldBytes::from_slice(&self.pub_account_signing_key);
|
||||
// TODO: remove unwrap
|
||||
SigningKey::from_bytes(&field_bytes).unwrap()
|
||||
}
|
||||
|
||||
@ -226,40 +226,40 @@ impl TransactionBody {
|
||||
}
|
||||
}
|
||||
|
||||
pub type SignaturePrivateKey = SigningKey;
|
||||
pub type SignaturePublicKey = VerifyingKey;
|
||||
type TransactionHash = [u8; 32];
|
||||
pub type TransactionSignature = Signature;
|
||||
|
||||
type TransactionHash = TreeHashType;
|
||||
pub type SignaturePublicKey = VerifyingKey;
|
||||
pub type SignaturePrivateKey = SigningKey;
|
||||
|
||||
/// A transaction with a signature.
|
||||
/// Meant to be sent through the network to the sequencer
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct SignedTransaction {
|
||||
pub body: TransactionBody,
|
||||
signature: (TransactionSignature, SignaturePublicKey),
|
||||
signature: TransactionSignature,
|
||||
public_key: VerifyingKey,
|
||||
}
|
||||
|
||||
impl SignedTransaction {
|
||||
pub fn from_transaction_body(
|
||||
body: TransactionBody,
|
||||
private_key: SignaturePrivateKey,
|
||||
private_key: SigningKey,
|
||||
) -> SignedTransaction {
|
||||
let hash = body.hash();
|
||||
let signature: Signature = private_key.sign(&hash);
|
||||
let signature: TransactionSignature = private_key.sign(&hash);
|
||||
let public_key = VerifyingKey::from(&private_key);
|
||||
Self {
|
||||
body,
|
||||
signature: (signature, public_key),
|
||||
signature,
|
||||
public_key,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn into_authenticated(self) -> Result<AuthenticatedTransaction, TransactionSignatureError> {
|
||||
let hash = self.body.hash();
|
||||
let (signature, public_key) = &self.signature;
|
||||
|
||||
public_key
|
||||
.verify(&hash, signature)
|
||||
self.public_key
|
||||
.verify(&hash, &self.signature)
|
||||
.map_err(|_| TransactionSignatureError::InvalidSignature)?;
|
||||
|
||||
Ok(AuthenticatedTransaction {
|
||||
@ -287,10 +287,6 @@ impl AuthenticatedTransaction {
|
||||
&self.signed_tx.body
|
||||
}
|
||||
|
||||
pub fn signature(&self) -> &TransactionSignature {
|
||||
&self.signed_tx.signature.0
|
||||
}
|
||||
|
||||
pub fn hash(&self) -> &TransactionHash {
|
||||
&self.hash
|
||||
}
|
||||
|
||||
@ -264,8 +264,7 @@ impl NodeCore {
|
||||
sc_addr,
|
||||
state_changes,
|
||||
};
|
||||
// TODO: Change to the correct key once established.
|
||||
let key_to_sign_transaction = account.key_holder.pub_account_secret_key();
|
||||
let key_to_sign_transaction = account.key_holder.get_pub_account_signing_key();
|
||||
|
||||
Ok((
|
||||
SignedTransaction::from_transaction_body(transaction_body, key_to_sign_transaction),
|
||||
@ -362,8 +361,7 @@ impl NodeCore {
|
||||
sc_addr,
|
||||
state_changes,
|
||||
};
|
||||
// TODO: Change to the correct key once established.
|
||||
let key_to_sign_transaction = account.key_holder.pub_account_secret_key();
|
||||
let key_to_sign_transaction = account.key_holder.get_pub_account_signing_key();
|
||||
|
||||
Ok((
|
||||
SignedTransaction::from_transaction_body(transaction_body, key_to_sign_transaction),
|
||||
@ -480,8 +478,7 @@ impl NodeCore {
|
||||
state_changes,
|
||||
};
|
||||
|
||||
// TODO: Change to the correct key once established.
|
||||
let key_to_sign_transaction = account.key_holder.pub_account_secret_key();
|
||||
let key_to_sign_transaction = account.key_holder.get_pub_account_signing_key();
|
||||
|
||||
Ok((
|
||||
SignedTransaction::from_transaction_body(transaction_body, key_to_sign_transaction),
|
||||
@ -627,8 +624,7 @@ impl NodeCore {
|
||||
state_changes,
|
||||
};
|
||||
|
||||
// TODO: Change to the correct key once established.
|
||||
let key_to_sign_transaction = account.key_holder.pub_account_secret_key();
|
||||
let key_to_sign_transaction = account.key_holder.get_pub_account_signing_key();
|
||||
|
||||
Ok((
|
||||
SignedTransaction::from_transaction_body(transaction_body, key_to_sign_transaction),
|
||||
@ -758,8 +754,7 @@ impl NodeCore {
|
||||
state_changes,
|
||||
};
|
||||
|
||||
// TODO: Change to the correct key once established.
|
||||
let key_to_sign_transaction = account.key_holder.pub_account_secret_key();
|
||||
let key_to_sign_transaction = account.key_holder.get_pub_account_signing_key();
|
||||
|
||||
Ok((
|
||||
SignedTransaction::from_transaction_body(transaction_body, key_to_sign_transaction),
|
||||
@ -850,8 +845,7 @@ impl NodeCore {
|
||||
state_changes,
|
||||
};
|
||||
|
||||
// TODO: Change to the correct key once established.
|
||||
let key_to_sign_transaction = account.key_holder.pub_account_secret_key();
|
||||
let key_to_sign_transaction = account.key_holder.get_pub_account_signing_key();
|
||||
|
||||
Ok(SignedTransaction::from_transaction_body(
|
||||
transaction_body,
|
||||
@ -1493,8 +1487,7 @@ impl NodeCore {
|
||||
sc_addr,
|
||||
state_changes,
|
||||
};
|
||||
// TODO: Change to the correct key once established.
|
||||
let key_to_sign_transaction = account.key_holder.pub_account_secret_key();
|
||||
let key_to_sign_transaction = account.key_holder.get_pub_account_signing_key();
|
||||
|
||||
Ok((
|
||||
SignedTransaction::from_transaction_body(transaction_body, key_to_sign_transaction),
|
||||
|
||||
@ -42,7 +42,6 @@ pub const EXECUTE_SCENARIO_MULTIPLE_SEND: &str = "execute_scenario_multiple_send
|
||||
pub const SHOW_ACCOUNT_PUBLIC_BALANCE: &str = "show_account_public_balance";
|
||||
pub const SHOW_ACCOUNT_UTXO: &str = "show_account_utxo";
|
||||
pub const SHOW_TRANSACTION: &str = "show_transaction";
|
||||
// pub const WRITE_DEPOSIT_PUBLIC_BALANCE: &str = "write_deposit_public_balance";
|
||||
pub const WRITE_MINT_UTXO: &str = "write_mint_utxo";
|
||||
pub const WRITE_MINT_UTXO_MULTIPLE_ASSETS: &str = "write_mint_utxo_multiple_assets";
|
||||
pub const WRITE_SEND_UTXO_PRIVATE: &str = "write_send_utxo_private";
|
||||
@ -84,18 +83,10 @@ impl JsonHandler {
|
||||
.subscenario_1()
|
||||
.await
|
||||
.map_err(cast_common_execution_error_into_rpc_error)?,
|
||||
// 2 => store
|
||||
// .subscenario_2()
|
||||
// .await
|
||||
// .map_err(cast_common_execution_error_into_rpc_error)?,
|
||||
3 => store
|
||||
.subscenario_3()
|
||||
.await
|
||||
.map_err(cast_common_execution_error_into_rpc_error)?,
|
||||
// 4 => store
|
||||
// .subscenario_4()
|
||||
// .await
|
||||
// .map_err(cast_common_execution_error_into_rpc_error)?,
|
||||
5 => store
|
||||
.subscenario_5()
|
||||
.await
|
||||
@ -359,36 +350,6 @@ impl JsonHandler {
|
||||
respond(helperstruct)
|
||||
}
|
||||
|
||||
// pub async fn process_write_deposit_public_balance(
|
||||
// &self,
|
||||
// request: Request,
|
||||
// ) -> Result<Value, RpcErr> {
|
||||
// let req = WriteDepositPublicBalanceRequest::parse(Some(request.params))?;
|
||||
//
|
||||
// let acc_addr_hex_dec = hex::decode(req.account_addr.clone()).map_err(|_| {
|
||||
// RpcError::parse_error("Failed to decode account address from hex string".to_string())
|
||||
// })?;
|
||||
//
|
||||
// let acc_addr: [u8; 32] = acc_addr_hex_dec.try_into().map_err(|_| {
|
||||
// RpcError::parse_error("Failed to parse account address from bytes".to_string())
|
||||
// })?;
|
||||
//
|
||||
// {
|
||||
// let mut cover_guard = self.node_chain_store.lock().await;
|
||||
//
|
||||
// cover_guard
|
||||
// .operate_account_deposit_public(acc_addr, req.amount as u128)
|
||||
// .await
|
||||
// .map_err(cast_common_execution_error_into_rpc_error)?;
|
||||
// };
|
||||
//
|
||||
// let helperstruct = WriteDepositPublicBalanceResponse {
|
||||
// status: SUCCESS.to_string(),
|
||||
// };
|
||||
//
|
||||
// respond(helperstruct)
|
||||
// }
|
||||
|
||||
pub async fn process_write_mint_utxo(&self, request: Request) -> Result<Value, RpcErr> {
|
||||
let req = WriteMintPrivateUTXORequest::parse(Some(request.params))?;
|
||||
|
||||
@ -781,9 +742,6 @@ impl JsonHandler {
|
||||
SHOW_ACCOUNT_PUBLIC_BALANCE => self.process_show_account_public_balance(request).await,
|
||||
SHOW_ACCOUNT_UTXO => self.process_show_account_utxo_request(request).await,
|
||||
SHOW_TRANSACTION => self.process_show_transaction(request).await,
|
||||
// WRITE_DEPOSIT_PUBLIC_BALANCE => {
|
||||
// self.process_write_deposit_public_balance(request).await
|
||||
// }
|
||||
WRITE_MINT_UTXO => self.process_write_mint_utxo(request).await,
|
||||
WRITE_MINT_UTXO_MULTIPLE_ASSETS => {
|
||||
self.process_write_mint_utxo_multiple_assets(request).await
|
||||
|
||||
@ -363,7 +363,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_transaction_pre_check_fail_mempool_full() {
|
||||
fn test_push_tx_into_mempool_fails_mempool_full() {
|
||||
let config = SequencerConfig {
|
||||
max_num_tx_in_block: 1,
|
||||
..setup_sequencer_config()
|
||||
@ -381,7 +381,7 @@ mod tests {
|
||||
};
|
||||
sequencer.mempool.push_item(dummy_tx);
|
||||
|
||||
let result = sequencer.transaction_pre_check(tx, tx_roots);
|
||||
let result = sequencer.push_tx_into_mempool_pre_check(tx, tx_roots);
|
||||
|
||||
assert!(matches!(
|
||||
result,
|
||||
|
||||
@ -12,27 +12,6 @@ impl From<AuthenticatedTransaction> for MempoolTransaction {
|
||||
}
|
||||
}
|
||||
|
||||
// impl Serialize for TransactionMempool {
|
||||
// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
// where
|
||||
// S: serde::Serializer,
|
||||
// {
|
||||
// self.tx.serialize(serializer)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// impl<'de> Deserialize<'de> for TransactionMempool {
|
||||
// fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
// where
|
||||
// D: serde::Deserializer<'de>,
|
||||
// {
|
||||
// match TransactionBody::deserialize(deserializer) {
|
||||
// Ok(tx) => Ok(TransactionMempool { tx }),
|
||||
// Err(err) => Err(err),
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
impl MemPoolItem for MempoolTransaction {
|
||||
type Identifier = TreeHashType;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user