mirror of
https://github.com/logos-blockchain/lssa.git
synced 2026-08-26 07:11:13 +00:00
fix: public context structure added
This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
use std::{collections::HashMap, path::Path};
|
||||
use std::{
|
||||
collections::{BTreeMap, HashMap},
|
||||
path::Path,
|
||||
};
|
||||
|
||||
use accounts::account_core::{Account, AccountAddress};
|
||||
use anyhow::Result;
|
||||
use block_store::NodeBlockStore;
|
||||
use elliptic_curve::group::GroupEncoding;
|
||||
use k256::AffinePoint;
|
||||
use public_context::PublicSCContext;
|
||||
use storage::{
|
||||
block::Block,
|
||||
merkle_tree_public::merkle_tree::{PublicTransactionMerkleTree, UTXOCommitmentsMerkleTree},
|
||||
@@ -18,6 +22,7 @@ use crate::ActionData;
|
||||
|
||||
pub mod accounts_store;
|
||||
pub mod block_store;
|
||||
pub mod public_context;
|
||||
|
||||
pub struct NodeChainStore {
|
||||
pub acc_map: HashMap<AccountAddress, Account>,
|
||||
@@ -149,4 +154,21 @@ impl NodeChainStore {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn produce_context(&self, caller: AccountAddress) -> PublicSCContext {
|
||||
let mut account_masks = BTreeMap::new();
|
||||
|
||||
for (acc_addr, acc) in &self.acc_map {
|
||||
account_masks.insert(*acc_addr, acc.make_account_public_mask());
|
||||
}
|
||||
|
||||
PublicSCContext {
|
||||
caller_address: caller,
|
||||
caller_balance: self.acc_map.get(&caller).unwrap().balance,
|
||||
account_masks,
|
||||
nullifier_store_root: self.nullifier_store.curr_root.unwrap_or([0; 32]),
|
||||
comitment_store_root: self.utxo_commitments_store.get_root().unwrap_or([0; 32]),
|
||||
pub_tx_store_root: self.pub_tx_store.get_root().unwrap_or([0; 32]),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use accounts::account_core::{AccountAddress, AccountPublicMask};
|
||||
use storage::{merkle_tree_public::TreeHashType, AccountId};
|
||||
|
||||
///Strucutre, representing context, given to a smart contract on a call
|
||||
pub struct PublicSCContext {
|
||||
pub caller_address: AccountAddress,
|
||||
pub caller_balance: u64,
|
||||
pub account_masks: BTreeMap<AccountAddress, AccountPublicMask>,
|
||||
pub nullifier_store_root: TreeHashType,
|
||||
pub comitment_store_root: TreeHashType,
|
||||
pub pub_tx_store_root: TreeHashType,
|
||||
}
|
||||
Reference in New Issue
Block a user