mirror of
https://github.com/d0zingcat/ore.git
synced 2026-06-05 23:26:46 +00:00
new events
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -2460,6 +2460,7 @@ dependencies = [
|
|||||||
name = "ore-api"
|
name = "ore-api"
|
||||||
version = "3.7.0"
|
version = "3.7.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"base64 0.22.1",
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
"const-crypto",
|
"const-crypto",
|
||||||
"mpl-token-metadata",
|
"mpl-token-metadata",
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ keywords = ["solana", "crypto", "mining"]
|
|||||||
|
|
||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
anyhow = "1.0"
|
anyhow = "1.0"
|
||||||
|
base64 = "0.22.1"
|
||||||
bincode = "1.3.3"
|
bincode = "1.3.3"
|
||||||
bytemuck = "1.14.3"
|
bytemuck = "1.14.3"
|
||||||
bytemuck_derive = "1.7.0"
|
bytemuck_derive = "1.7.0"
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ repository.workspace = true
|
|||||||
keywords.workspace = true
|
keywords.workspace = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
base64.workspace = true
|
||||||
bytemuck.workspace = true
|
bytemuck.workspace = true
|
||||||
const-crypto.workspace = true
|
const-crypto.workspace = true
|
||||||
mpl-token-metadata.workspace = true
|
mpl-token-metadata.workspace = true
|
||||||
|
|||||||
@@ -260,3 +260,23 @@ event!(WithdrawEvent);
|
|||||||
event!(UncommitEvent);
|
event!(UncommitEvent);
|
||||||
event!(MineEvent);
|
event!(MineEvent);
|
||||||
event!(CloseEvent);
|
event!(CloseEvent);
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
use base64::{prelude::BASE64_STANDARD, Engine};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_parse_commit_event() {
|
||||||
|
// Create sample return data
|
||||||
|
let data = "BQAAAAAAAAB9607Qp9I2VxNo2rSPHAz/tR2pJzGu9om7qHP71TpKqciMAwAAAAAAAAAAAAAAAAA2CwUAAAAAAADodkgXAAAAAAAAAAAAAAAAAAAAAAAAADYLBQAAAAAAAB7cDBcAAAAAypo7AAAAAMMQW2gAAAAA";
|
||||||
|
let bytes = BASE64_STANDARD.decode(data).unwrap();
|
||||||
|
|
||||||
|
// Parse into CommitEvent
|
||||||
|
let event: &SwapEvent = bytemuck::try_from_bytes(&bytes).unwrap();
|
||||||
|
|
||||||
|
// Verify fields
|
||||||
|
println!("{:?}", event);
|
||||||
|
assert!(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -93,6 +93,8 @@ pub fn mine(signer: Pubkey, id: u64, amount: u64) -> Instruction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// let [signer_info, block_info, commitment_info, market_info, miner_info, mint_info, permit_info, sender_info, system_program, token_program] =
|
||||||
|
|
||||||
pub fn commit(
|
pub fn commit(
|
||||||
signer: Pubkey,
|
signer: Pubkey,
|
||||||
amount: u64,
|
amount: u64,
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use ore_api::prelude::*;
|
use ore_api::prelude::*;
|
||||||
|
use solana_program::log::sol_log;
|
||||||
use steel::*;
|
use steel::*;
|
||||||
|
|
||||||
/// Commit to a block.
|
/// Commit to a block.
|
||||||
@@ -17,18 +18,25 @@ pub fn process_commit(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResul
|
|||||||
return Err(ProgramError::NotEnoughAccountKeys);
|
return Err(ProgramError::NotEnoughAccountKeys);
|
||||||
};
|
};
|
||||||
signer_info.is_signer()?;
|
signer_info.is_signer()?;
|
||||||
|
sol_log("A");
|
||||||
let block = block_info
|
let block = block_info
|
||||||
.as_account_mut::<Block>(&ore_api::ID)?
|
.as_account_mut::<Block>(&ore_api::ID)?
|
||||||
.assert_mut(|b| clock.slot < b.start_slot)?;
|
.assert_mut(|b| clock.slot < b.start_slot)?;
|
||||||
|
sol_log("B");
|
||||||
commitment_info.as_associated_token_account(block_info.key, mint_info.key)?;
|
commitment_info.as_associated_token_account(block_info.key, mint_info.key)?;
|
||||||
|
sol_log("C");
|
||||||
let market = market_info
|
let market = market_info
|
||||||
.as_account::<Market>(&ore_api::ID)?
|
.as_account::<Market>(&ore_api::ID)?
|
||||||
.assert(|m| m.id == block.id)?;
|
.assert(|m| m.id == block.id)?;
|
||||||
|
sol_log("D");
|
||||||
mint_info.has_address(&market.base.mint)?.as_mint()?;
|
mint_info.has_address(&market.base.mint)?.as_mint()?;
|
||||||
|
sol_log("E");
|
||||||
let sender = sender_info
|
let sender = sender_info
|
||||||
.is_writable()?
|
.is_writable()?
|
||||||
.as_associated_token_account(signer_info.key, &mint_info.key)?;
|
.as_associated_token_account(signer_info.key, &mint_info.key)?;
|
||||||
|
sol_log("F");
|
||||||
system_program.is_program(&system_program::ID)?;
|
system_program.is_program(&system_program::ID)?;
|
||||||
|
sol_log("G");
|
||||||
token_program.is_program(&spl_token::ID)?;
|
token_program.is_program(&spl_token::ID)?;
|
||||||
|
|
||||||
// Normalize amount.
|
// Normalize amount.
|
||||||
|
|||||||
Reference in New Issue
Block a user