2021-04-06 00:01:05 -07:00
|
|
|
use {
|
|
|
|
solana_sdk::{
|
|
|
|
hash::Hash, pubkey::Pubkey, signature::Keypair, system_transaction,
|
|
|
|
transaction::Transaction,
|
|
|
|
},
|
|
|
|
std::{
|
|
|
|
io::{Error, ErrorKind},
|
|
|
|
net::SocketAddr,
|
|
|
|
},
|
2019-12-16 13:05:17 -08:00
|
|
|
};
|
2019-03-16 21:47:16 -07:00
|
|
|
|
|
|
|
pub fn request_airdrop_transaction(
|
2019-12-16 13:05:17 -08:00
|
|
|
_faucet_addr: &SocketAddr,
|
2019-03-16 21:47:16 -07:00
|
|
|
_id: &Pubkey,
|
|
|
|
lamports: u64,
|
|
|
|
_blockhash: Hash,
|
|
|
|
) -> Result<Transaction, Error> {
|
|
|
|
if lamports == 0 {
|
2019-10-02 18:04:18 -07:00
|
|
|
Err(Error::new(ErrorKind::Other, "Airdrop failed"))
|
|
|
|
} else {
|
|
|
|
let key = Keypair::new();
|
2020-10-19 12:12:08 -07:00
|
|
|
let to = solana_sdk::pubkey::new_rand();
|
2019-10-02 18:04:18 -07:00
|
|
|
let blockhash = Hash::default();
|
2019-10-23 22:01:22 -07:00
|
|
|
let tx = system_transaction::transfer(&key, &to, lamports, blockhash);
|
2019-10-02 18:04:18 -07:00
|
|
|
Ok(tx)
|
2019-03-16 21:47:16 -07:00
|
|
|
}
|
|
|
|
}
|