mirror of
https://github.com/d0zingcat/ore.git
synced 2026-06-02 07:36:48 +00:00
pda
This commit is contained in:
@@ -12,6 +12,7 @@ use solana_sdk::{
|
|||||||
signature::{read_keypair_file, Signer},
|
signature::{read_keypair_file, Signer},
|
||||||
transaction::Transaction,
|
transaction::Transaction,
|
||||||
};
|
};
|
||||||
|
use spl_token::amount_to_ui_amount;
|
||||||
use steel::{AccountDeserialize, Clock, Discriminator};
|
use steel::{AccountDeserialize, Clock, Discriminator};
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
@@ -87,13 +88,17 @@ fn print_block(block: Block) {
|
|||||||
println!(" Id: {:?}", block.id);
|
println!(" Id: {:?}", block.id);
|
||||||
println!(" Start slot: {:?}", block.start_slot);
|
println!(" Start slot: {:?}", block.start_slot);
|
||||||
println!(" Best miner: {:?}", block.best_miner);
|
println!(" Best miner: {:?}", block.best_miner);
|
||||||
println!(" Reward: {:?}", block.reward);
|
println!(
|
||||||
|
" Reward: {:?}",
|
||||||
|
amount_to_ui_amount(block.reward, TOKEN_DECIMALS)
|
||||||
|
);
|
||||||
println!(" Slot hash: {:?}", block.slot_hash);
|
println!(" Slot hash: {:?}", block.slot_hash);
|
||||||
println!(" Best hash: {:?}\n", block.best_hash);
|
println!(" Best hash: {:?}\n", block.best_hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn log_blocks(rpc: &RpcClient) -> Result<(), anyhow::Error> {
|
async fn log_blocks(rpc: &RpcClient) -> Result<(), anyhow::Error> {
|
||||||
let blocks = get_blocks(&rpc).await?;
|
let mut blocks = get_blocks(&rpc).await?;
|
||||||
|
blocks.sort_by_key(|(_, block)| block.id);
|
||||||
for (_, block) in blocks {
|
for (_, block) in blocks {
|
||||||
print_block(block);
|
print_block(block);
|
||||||
}
|
}
|
||||||
@@ -186,9 +191,12 @@ where
|
|||||||
Ok(accounts) => {
|
Ok(accounts) => {
|
||||||
let accounts = accounts
|
let accounts = accounts
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(pubkey, account)| {
|
.filter_map(|(pubkey, account)| {
|
||||||
let account = T::try_from_bytes(&account.data).unwrap().clone();
|
if let Ok(account) = T::try_from_bytes(&account.data) {
|
||||||
(pubkey, account)
|
Some((pubkey, account.clone()))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
Ok(accounts)
|
Ok(accounts)
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
use steel::*;
|
use steel::*;
|
||||||
|
|
||||||
|
use crate::state::block_pda;
|
||||||
|
|
||||||
use super::OreAccount;
|
use super::OreAccount;
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
@@ -27,4 +29,10 @@ pub struct Block {
|
|||||||
pub total_hashes: u64,
|
pub total_hashes: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Block {
|
||||||
|
pub fn pda(&self) -> (Pubkey, u8) {
|
||||||
|
block_pda(self.id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
account!(OreAccount, Block);
|
account!(OreAccount, Block);
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
use steel::*;
|
use steel::*;
|
||||||
|
|
||||||
|
use crate::state::config_pda;
|
||||||
|
|
||||||
use super::OreAccount;
|
use super::OreAccount;
|
||||||
|
|
||||||
// TODO Config stuff
|
// TODO Config stuff
|
||||||
@@ -8,4 +10,10 @@ use super::OreAccount;
|
|||||||
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
|
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
|
||||||
pub struct Config {}
|
pub struct Config {}
|
||||||
|
|
||||||
|
impl Config {
|
||||||
|
pub fn pda() -> (Pubkey, u8) {
|
||||||
|
config_pda()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
account!(OreAccount, Config);
|
account!(OreAccount, Config);
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
use steel::*;
|
use steel::*;
|
||||||
|
|
||||||
|
use crate::state::miner_pda;
|
||||||
|
|
||||||
use super::OreAccount;
|
use super::OreAccount;
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
@@ -21,4 +23,10 @@ pub struct Miner {
|
|||||||
pub total_rewards: u64,
|
pub total_rewards: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Miner {
|
||||||
|
pub fn pda(&self) -> (Pubkey, u8) {
|
||||||
|
miner_pda(self.authority)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
account!(OreAccount, Miner);
|
account!(OreAccount, Miner);
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
use steel::*;
|
use steel::*;
|
||||||
|
|
||||||
|
use crate::state::treasury_pda;
|
||||||
|
|
||||||
use super::OreAccount;
|
use super::OreAccount;
|
||||||
|
|
||||||
/// Treasury is a singleton account which is the mint authority for the ORE token and the authority of
|
/// Treasury is a singleton account which is the mint authority for the ORE token and the authority of
|
||||||
@@ -8,4 +10,10 @@ use super::OreAccount;
|
|||||||
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
|
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
|
||||||
pub struct Treasury {}
|
pub struct Treasury {}
|
||||||
|
|
||||||
|
impl Treasury {
|
||||||
|
pub fn pda() -> (Pubkey, u8) {
|
||||||
|
treasury_pda()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
account!(OreAccount, Treasury);
|
account!(OreAccount, Treasury);
|
||||||
|
|||||||
Reference in New Issue
Block a user