-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
use solana_client::{ | ||
rpc_client::RpcClient, | ||
transaction::Transaction, | ||
}; | ||
use solana_program::{ | ||
account_info::AccountInfo, | ||
entrypoint, | ||
entrypoint::ProgramResult, | ||
msg, | ||
program_error::ProgramError, | ||
pubkey::Pubkey, | ||
}; | ||
use solana_sdk::{ | ||
signature::{Keypair, Signer}, | ||
transaction::TransactionError, | ||
}; | ||
use std::error::Error; | ||
|
||
// Define the contract program ID | ||
const PROGRAM_ID: &str = "TokenizedAssets1111111111111111111111111111111111"; | ||
|
||
// Define the execute function | ||
fn execute( | ||
rpc_url: &str, | ||
keypair_path: &str, | ||
instruction: &str, | ||
accounts: Vec<String>, | ||
) -> Result<(), Box<dyn Error>> { | ||
// Create a new RPC client | ||
let rpc_client = RpcClient::new(rpc_url); | ||
|
||
// Load the keypair from the file | ||
let keypair = Keypair::from_file(keypair_path)?; | ||
|
||
// Parse the instruction | ||
let instruction_data = match instruction { | ||
"initialize" => vec![0], | ||
"mint" => vec![1], | ||
"burn" => vec![2], | ||
"transfer" => vec![3], | ||
"approve" => vec![4], | ||
_ => { | ||
msg!("Error: Unknown instruction"); | ||
return Err(Box::new(ProgramError::InvalidInstruction)); | ||
} | ||
}; | ||
|
||
// Get the account infos | ||
let mut account_infos = Vec::new(); | ||
for account in accounts { | ||
let pubkey = Pubkey::new_from_string(account.as_str())?; | ||
account_infos.push(AccountInfo::new_readonly(pubkey, false)); | ||
} | ||
|
||
// Create a new transaction | ||
let tx = Transaction::new_signed_with_payer( | ||
&[instruction_data], | ||
Some(&keypair.pubkey()), | ||
&account_infos, | ||
rpc_client.get_latest_blockhash()?, | ||
); | ||
|
||
// Sign the transaction | ||
let signers = &[&keypair]; | ||
tx.partial_sign(&signers, rpc_client.get_latest_blockhash()?)?; | ||
|
||
// Send and confirm the transaction | ||
rpc_client.send_and_confirm_transaction(&tx)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
fn main() { | ||
if let Err(err) = execute( | ||
"https://api.devnet.solana.com", | ||
"path/to/keypair.json", | ||
"mint", | ||
vec![ | ||
"TokenizedAssets1111111111111111111111111111111111".to_string(), | ||
"owner_account_pubkey".to_string(), | ||
"tokenized_asset_account_pubkey".to_string(), | ||
], | ||
) { | ||
msg!("Error: {}", err); | ||
std::process::exit(1); | ||
} | ||
} |