mirror of
https://github.com/logos-blockchain/lssa.git
synced 2026-08-26 23:31:19 +00:00
add example and instructions for pda
This commit is contained in:
+62
@@ -0,0 +1,62 @@
|
||||
use nssa::{
|
||||
AccountId, PublicTransaction,
|
||||
program::Program,
|
||||
public_transaction::{Message, WitnessSet},
|
||||
};
|
||||
use nssa_core::program::PdaSeed;
|
||||
use wallet::{WalletCore, helperfunctions::fetch_config};
|
||||
|
||||
// Before running this example, compile the `simple_tail_call.rs` guest program with:
|
||||
//
|
||||
// cargo risczero build --manifest-path examples/program_deployment/methods/guest/Cargo.toml
|
||||
//
|
||||
// Note: you must run the above command from the root of the `lssa` repository.
|
||||
// Note: The compiled binary file is stored in
|
||||
// methods/guest/target/riscv32im-risc0-zkvm-elf/docker/simple_tail_call.bin
|
||||
//
|
||||
//
|
||||
// Usage:
|
||||
// cargo run --bin run_hello_world_with_authorization_through_tail_call_with_pda
|
||||
// /path/to/guest/binary <account_id>
|
||||
//
|
||||
// Example:
|
||||
// cargo run --bin run_hello_world_with_authorization_through_tail_call_with_pda \
|
||||
// methods/guest/target/riscv32im-risc0-zkvm-elf/docker/tail_call_with_pda.bin
|
||||
|
||||
const PDA_SEED: PdaSeed = PdaSeed::new([37; 32]);
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
// Load wallet config and storage
|
||||
let wallet_config = fetch_config().await.unwrap();
|
||||
let wallet_core = WalletCore::start_from_config_update_chain(wallet_config)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
// Parse arguments
|
||||
// First argument is the path to the program binary
|
||||
let program_path = std::env::args_os().nth(1).unwrap().into_string().unwrap();
|
||||
|
||||
// Load the program
|
||||
let bytecode: Vec<u8> = std::fs::read(program_path).unwrap();
|
||||
let program = Program::new(bytecode).unwrap();
|
||||
|
||||
// Compute the PDA to pass it as input account to the public execution
|
||||
let pda = AccountId::from((&program.id(), &PDA_SEED));
|
||||
let account_ids = vec![pda];
|
||||
let instruction_data = ();
|
||||
let nonces = vec![];
|
||||
let signing_keys = [];
|
||||
let message = Message::try_new(program.id(), account_ids, nonces, instruction_data).unwrap();
|
||||
let witness_set = WitnessSet::for_message(&message, &signing_keys);
|
||||
let tx = PublicTransaction::new(message, witness_set);
|
||||
|
||||
// Submit the transaction
|
||||
let _response = wallet_core
|
||||
.sequencer_client
|
||||
.send_tx_public(tx)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
println!("The program derived account id is: {pda}");
|
||||
}
|
||||
Reference in New Issue
Block a user