Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
archseer committed Mar 15, 2024
1 parent fec85ca commit d8297c0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
25 changes: 23 additions & 2 deletions contracts/programs/keystone-forwarder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@ declare_id!("6v9Lm94wiHXJf4HYoWoRj7JGb5YCDnsvybr9Y3seJ7po");

// TODO: ownable

pub const STATE_VERSION: u8 = 1;

#[account]
#[derive(Default)]
pub struct State {
version: u8,
authority_nonce: u8,
}

#[account]
#[derive(Default)]
pub struct ExecutionState {}

#[error_code]
pub enum ErrorCode {
#[msg("Unauthorized")]
Expand All @@ -26,9 +33,15 @@ pub mod keystone_forwarder {
use super::*;

pub fn initialize(ctx: Context<Initialize>) -> Result<()> {
// TODO: store authority_nonce
// Precompute the authority PDA bump
let (_authority_pubkey, authority_nonce) = Pubkey::find_program_address(
&[b"forwarder", ctx.accounts.state.key().as_ref()],
&crate::ID,
);

let state = &mut ctx.accounts.state;
// state.authority_nonce = ctx.bumps.forwarder_authority;
state.version = STATE_VERSION;
state.authority_nonce = authority_nonce;
Ok(())
}

Expand Down Expand Up @@ -105,15 +118,23 @@ pub struct Initialize<'info> {

#[derive(Accounts)]
pub struct Report<'info> {
/// Forwarder state acccount
#[account(mut)]
pub state: Account<'info, State>,

/// Transmitter, signing the current transaction call
pub authority: Signer<'info>,

/// Authority used for signing the receiver invocation
/// CHECK: This is a PDA
#[account(seeds = [b"forwarder", state.key().as_ref()], bump = state.authority_nonce)]
pub forwarder_authority: AccountInfo<'info>,

/// State PDA for the workflow execution represented by this report.
/// TODO: we need to manually verify that it's the correct PDA since we need to unpack meta to get the execution ID
#[account(mut)]
pub execution_state: Account<'info, ExecutionState>,

#[account(executable)]
// we don't use Program<> here since it can be any program, "executable" is enough
pub receiver_program: UncheckedAccount<'info>,
Expand Down
2 changes: 1 addition & 1 deletion shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

pkgs.mkShell {
nativeBuildInputs = with pkgs; [
(rust-bin.stable.latest.default.override { extensions = ["rust-src"]; })
(rust-bin.stable.latest.default.override { extensions = ["rust-src" "rust-analyzer"]; })
# lld_11
llvm_11
stdenv.cc.cc.lib
Expand Down

0 comments on commit d8297c0

Please sign in to comment.