use std::collections::{HashSet, HashMap};
use hotstuff_rs::types::{CryptoHash, BlockHeight};
use crate::{Transaction, Serializable, Block, BlockHeader, Receipt, PublicAddress, Stake, Deserializable, CommandReceipt};
#[derive(borsh::BorshSerialize, borsh::BorshDeserialize)]
pub struct SubmitTransactionRequest {
pub transaction: Transaction
}
#[derive(borsh::BorshSerialize, borsh::BorshDeserialize, Debug)]
pub struct SubmitTransactionResponse {
pub error: Option<SubmitTransactionError>,
}
#[derive(Debug, borsh::BorshSerialize, borsh::BorshDeserialize)]
pub enum SubmitTransactionError {
UnacceptableNonce,
MempoolFull,
Other,
}
#[derive(borsh::BorshSerialize, borsh::BorshDeserialize)]
pub struct TransactionRequest {
pub transaction_hash: CryptoHash,
pub include_receipt: bool,
}
#[derive(borsh::BorshSerialize, borsh::BorshDeserialize, Debug)]
pub struct TransactionResponse {
pub transaction: Option<Transaction>,
pub receipt: Option<Receipt>,
pub block_hash: Option<CryptoHash>,
pub position: Option<u32>,
}
#[derive(borsh::BorshSerialize, borsh::BorshDeserialize)]
pub struct TransactionPositionRequest {
pub transaction_hash: CryptoHash,
}
#[derive(borsh::BorshSerialize, borsh::BorshDeserialize, Debug)]
pub struct TransactionPositionResponse {
pub transaction_hash: Option<CryptoHash>,
pub block_hash: Option<CryptoHash>,
pub position: Option<u32>,
}
#[derive(borsh::BorshSerialize, borsh::BorshDeserialize)]
pub struct ReceiptRequest {
pub transaction_hash: CryptoHash,
}
#[derive(borsh::BorshSerialize, borsh::BorshDeserialize, Debug)]
pub struct ReceiptResponse {
pub transaction_hash: CryptoHash,
pub receipt: Option<Receipt>,
pub block_hash: Option<CryptoHash>,
pub position: Option<u32>,
}
#[derive(borsh::BorshSerialize, borsh::BorshDeserialize)]
pub struct BlockRequest {
pub block_hash: CryptoHash
}
#[derive(borsh::BorshSerialize, borsh::BorshDeserialize)]
pub struct BlockResponse {
pub block: Option<Block>,
}
#[derive(borsh::BorshSerialize, borsh::BorshDeserialize)]
pub struct BlockHeaderRequest {
pub block_hash: CryptoHash
}
#[derive(borsh::BorshSerialize, borsh::BorshDeserialize)]
pub struct BlockHeaderResponse {
pub block_header: Option<BlockHeader>,
}
#[derive(borsh::BorshSerialize, borsh::BorshDeserialize)]
pub struct BlockHeightByHashRequest {
pub block_hash: CryptoHash,
}
#[derive(borsh::BorshSerialize, borsh::BorshDeserialize, Debug)]
pub struct BlockHeightByHashResponse {
pub block_hash: CryptoHash,
pub block_height: Option<BlockHeight>,
}
#[derive(borsh::BorshSerialize, borsh::BorshDeserialize)]
pub struct BlockHashByHeightRequest {
pub block_height: BlockHeight,
}
#[derive(borsh::BorshSerialize, borsh::BorshDeserialize, Debug)]
pub struct BlockHashByHeightResponse {
pub block_height: BlockHeight,
pub block_hash: Option<CryptoHash>,
}
#[derive(borsh::BorshSerialize, borsh::BorshDeserialize, Debug)]
pub struct HighestCommittedBlockResponse {
pub block_hash: Option<CryptoHash>
}
#[derive(borsh::BorshSerialize, borsh::BorshDeserialize)]
pub struct StateRequest {
pub accounts: HashSet<PublicAddress>,
pub include_contract: bool,
pub storage_keys: HashMap<PublicAddress, HashSet<Vec<u8>>>,
}
#[derive(borsh::BorshSerialize, borsh::BorshDeserialize, Debug)]
pub struct StateResponse {
pub accounts: HashMap<PublicAddress, Account>,
pub storage_tuples: HashMap<PublicAddress, HashMap<Vec<u8>, Vec<u8>>>,
pub block_hash: CryptoHash,
}
#[derive(borsh::BorshSerialize, borsh::BorshDeserialize)]
pub struct ValidatorSetsRequest {
pub include_prev: bool,
pub include_prev_delegators: bool,
pub include_curr: bool,
pub include_curr_delegators: bool,
pub include_next: bool,
pub include_next_delegators: bool,
}
#[derive(borsh::BorshSerialize, borsh::BorshDeserialize, Debug)]
pub struct ValidatorSetsResponse {
pub previous_validator_set: Option<Option<ValidatorSet>>,
pub current_validator_set: Option<ValidatorSet>,
pub next_validator_set: Option<ValidatorSet>,
pub block_hash: CryptoHash,
}
#[derive(borsh::BorshSerialize, borsh::BorshDeserialize)]
pub struct PoolsRequest {
pub operators: HashSet<Operator>,
pub include_stakes: bool,
}
#[derive(borsh::BorshSerialize, borsh::BorshDeserialize, Debug)]
pub struct PoolsResponse {
pub pools: HashMap<Operator, Option<Pool>>,
pub block_hash: CryptoHash,
}
#[derive(borsh::BorshSerialize, borsh::BorshDeserialize)]
pub struct StakesRequest {
pub stakes: HashSet<(Operator, Owner)>,
}
#[derive(borsh::BorshSerialize, borsh::BorshDeserialize, Debug)]
pub struct StakesResponse {
pub stakes: HashMap<(Operator, Owner), Option<Stake>>,
pub block_hash: CryptoHash,
}
#[derive(borsh::BorshSerialize, borsh::BorshDeserialize)]
pub struct DepositsRequest {
pub stakes: HashSet<(Operator, Owner)>,
}
#[derive(borsh::BorshSerialize, borsh::BorshDeserialize, Debug)]
pub struct DepositsResponse {
pub deposits: HashMap<(Operator, Owner), Option<Deposit>>,
pub block_hash: CryptoHash,
}
#[derive(borsh::BorshSerialize, borsh::BorshDeserialize, Debug)]
pub struct Deposit {
pub owner: PublicAddress,
pub balance: u64,
pub auto_stake_rewards: bool,
}
#[derive(borsh::BorshSerialize, borsh::BorshDeserialize, Debug)]
pub enum Account {
WithContract(AccountWithContract),
WithoutContract(AccountWithoutContract)
}
#[derive(borsh::BorshSerialize, borsh::BorshDeserialize, Debug)]
pub struct AccountWithContract {
pub nonce: u64,
pub balance: u64,
pub contract: Option<Vec<u8>>,
pub cbi_version: Option<u32>,
pub storage_hash: Option<CryptoHash>,
}
#[derive(borsh::BorshSerialize, borsh::BorshDeserialize, Debug)]
pub struct AccountWithoutContract {
pub nonce: u64,
pub balance: u64,
pub cbi_version: Option<u32>,
pub storage_hash: Option<CryptoHash>,
}
#[derive(borsh::BorshSerialize, borsh::BorshDeserialize)]
pub struct ViewRequest {
pub target: PublicAddress,
pub method: Vec<u8>,
pub arguments: Option<Vec<Vec<u8>>>
}
#[derive(borsh::BorshSerialize, borsh::BorshDeserialize, Debug)]
pub struct ViewResponse {
pub receipt: CommandReceipt
}
#[derive(borsh::BorshSerialize, borsh::BorshDeserialize, Debug)]
pub enum ValidatorSet {
WithDelegators(Vec<PoolWithDelegators>),
WithoutDelegators(Vec<PoolWithoutDelegators>),
}
pub type Operator = PublicAddress;
pub type Owner = PublicAddress;
#[derive(borsh::BorshSerialize, borsh::BorshDeserialize, Debug)]
pub struct PoolWithDelegators {
pub operator: PublicAddress,
pub power: u64,
pub commission_rate: u8,
pub operator_stake: Option<Stake>,
pub delegated_stakes: Vec<Stake>,
}
#[derive(borsh::BorshSerialize, borsh::BorshDeserialize, Debug)]
pub struct PoolWithoutDelegators {
pub operator: PublicAddress,
pub power: u64,
pub commission_rate: u8,
pub operator_stake: Option<Stake>,
}
#[derive(borsh::BorshSerialize, borsh::BorshDeserialize, Debug)]
pub enum Pool {
WithStakes(PoolWithDelegators),
WithoutStakes(PoolWithoutDelegators),
}
macro_rules! define_serde {
($($t:ty),*) => {
$(
impl Serializable for $t {}
impl Deserializable for $t {}
)*
}
}
define_serde!(
SubmitTransactionRequest, SubmitTransactionResponse,
TransactionRequest, TransactionResponse,
TransactionPositionRequest, TransactionPositionResponse,
ReceiptRequest, ReceiptResponse,
BlockRequest, BlockResponse,
BlockHeaderRequest, BlockHeaderResponse,
BlockHeightByHashRequest, BlockHeightByHashResponse,
BlockHashByHeightRequest, BlockHashByHeightResponse,
HighestCommittedBlockResponse,
StateRequest, StateResponse,
ValidatorSetsRequest, ValidatorSetsResponse,
PoolsRequest, PoolsResponse,
StakesRequest, StakesResponse,
DepositsRequest, DepositsResponse,
ViewRequest, ViewResponse
);