|
|
@@ -7,10 +7,8 @@ use {
|
|
|
},
|
|
|
clap::Parser,
|
|
|
anyhow::Result,
|
|
|
- std::str::FromStr,
|
|
|
|
|
|
solana_sdk::{
|
|
|
- pubkey::Pubkey,
|
|
|
signature::{
|
|
|
read_keypair_file,
|
|
|
Keypair,
|
|
|
@@ -22,36 +20,47 @@ use {
|
|
|
|
|
|
wormhole::VAA,
|
|
|
wormhole_solana::{
|
|
|
- Account,
|
|
|
- GuardianSet,
|
|
|
- Config as WormholeConfig,
|
|
|
instructions::{
|
|
|
post_vaa,
|
|
|
verify_signatures_txs,
|
|
|
PostVAAData,
|
|
|
},
|
|
|
+ Account,
|
|
|
+ GuardianSet,
|
|
|
+ Config as WormholeConfig,
|
|
|
+ VAA as WormholeSolanaVAA,
|
|
|
+ },
|
|
|
+
|
|
|
+ pyth_solana_receiver::{
|
|
|
+ ID,
|
|
|
+ state::AnchorVaa,
|
|
|
+ accounts::DecodePostedVaa,
|
|
|
+ },
|
|
|
+
|
|
|
+ anchor_client::anchor_lang::{
|
|
|
+ Owner,
|
|
|
+ ToAccountMetas,
|
|
|
+ InstructionData,
|
|
|
+ AnchorDeserialize,
|
|
|
},
|
|
|
|
|
|
solana_client::rpc_client::RpcClient,
|
|
|
- anchor_client::anchor_lang::AnchorDeserialize,
|
|
|
};
|
|
|
|
|
|
fn main() -> Result<()> {
|
|
|
let cli = Cli::parse();
|
|
|
|
|
|
match cli.action {
|
|
|
- Action::PostPriceVAA { vaa, keypair } => {
|
|
|
- println!("PostPriceVAA is invoked with vaa\"{}\"", vaa);
|
|
|
- // Hard-coded strings
|
|
|
+ Action::PostAndReceiveVAA { vaa, keypair } => {
|
|
|
+ let wormhole = AnchorVaa::owner();
|
|
|
let rpc_client = RpcClient::new("https://api.devnet.solana.com");
|
|
|
- // Is RpcClient::new_with_commitment necessary?
|
|
|
- let wormhole = Pubkey::from_str("3u8hJUVTA4jH1wYAyUur7FFZVQ8H635K3tSHHF4ssjQ5").unwrap();
|
|
|
|
|
|
- println!("Decode the VAA");
|
|
|
+ println!("[1/5] Decode the VAA");
|
|
|
let vaa_bytes: Vec<u8> = base64::decode(vaa)?;
|
|
|
let vaa = VAA::from_bytes(vaa_bytes.clone())?;
|
|
|
+ let posted_vaa_key = WormholeSolanaVAA::key(&wormhole, vaa.digest().unwrap().hash);
|
|
|
|
|
|
- println!("Get wormhole guardian set configuration");
|
|
|
+ println!("[2/5] Get wormhole guardian set configuration");
|
|
|
let wormhole_config = WormholeConfig::key(&wormhole, ());
|
|
|
let wormhole_config_data =
|
|
|
WormholeConfig::try_from_slice(&rpc_client.get_account_data(&wormhole_config)?)?;
|
|
|
@@ -60,7 +69,7 @@ fn main() -> Result<()> {
|
|
|
let guardian_set_data =
|
|
|
GuardianSet::try_from_slice(&rpc_client.get_account_data(&guardian_set)?)?;
|
|
|
|
|
|
- println!("Invoke wormhole on solana to verify the VAA");
|
|
|
+ println!("[3/5] Invoke wormhole on solana to verify the VAA");
|
|
|
let payer =
|
|
|
read_keypair_file(&*shellexpand::tilde(&keypair)).expect("Keypair not found");
|
|
|
let signature_set_keypair = Keypair::new();
|
|
|
@@ -77,7 +86,7 @@ fn main() -> Result<()> {
|
|
|
process_transaction(&rpc_client, tx, &vec![&payer, &signature_set_keypair])?;
|
|
|
}
|
|
|
|
|
|
- println!("Upload the VAA data to a solana account");
|
|
|
+ println!("[4/5] Post the VAA data onto a solana account");
|
|
|
let post_vaa_data = PostVAAData {
|
|
|
version: vaa.version,
|
|
|
guardian_set_index: vaa.guardian_set_index,
|
|
|
@@ -100,10 +109,23 @@ fn main() -> Result<()> {
|
|
|
)?],
|
|
|
&vec![&payer],
|
|
|
)?;
|
|
|
- }
|
|
|
|
|
|
- Action::InvokePriceReceiver { keypair } => {
|
|
|
- println!("TBD, keypair={}", keypair);
|
|
|
+ println!("[5/5] Receive and deserialize the VAA on solana");
|
|
|
+ let account_metas = DecodePostedVaa::populate(&payer.pubkey(), &posted_vaa_key)
|
|
|
+ .to_account_metas(None);
|
|
|
+
|
|
|
+ println!("Receiver program ID is {}", ID);
|
|
|
+ let invoke_receiver_instruction = Instruction {
|
|
|
+ program_id: ID,
|
|
|
+ accounts: account_metas,
|
|
|
+ data: pyth_solana_receiver::instruction::DecodePostedVaa.data(),
|
|
|
+ };
|
|
|
+
|
|
|
+ process_transaction(
|
|
|
+ &rpc_client,
|
|
|
+ vec![invoke_receiver_instruction],
|
|
|
+ &vec![&payer],
|
|
|
+ )?;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -118,8 +140,10 @@ pub fn process_transaction(
|
|
|
let mut transaction =
|
|
|
Transaction::new_with_payer(instructions.as_slice(), Some(&signers[0].pubkey()));
|
|
|
transaction.sign(signers, rpc_client.get_latest_blockhash()?);
|
|
|
+
|
|
|
let transaction_signature =
|
|
|
rpc_client.send_and_confirm_transaction_with_spinner(&transaction)?;
|
|
|
println!("Transaction successful : {transaction_signature:?}");
|
|
|
+
|
|
|
Ok(())
|
|
|
}
|