2019-12-16 14:05:17 -07:00
|
|
|
use solana_sdk::{
|
|
|
|
|
hash::Hash,
|
|
|
|
|
pubkey::Pubkey,
|
|
|
|
|
signature::{Keypair, KeypairUtil},
|
|
|
|
|
system_transaction,
|
|
|
|
|
transaction::Transaction,
|
|
|
|
|
};
|
|
|
|
|
use std::{
|
|
|
|
|
io::{Error, ErrorKind},
|
|
|
|
|
net::SocketAddr,
|
|
|
|
|
};
|
2019-03-16 21:47:16 -07:00
|
|
|
|
|
|
|
|
pub fn request_airdrop_transaction(
|
2019-12-16 14:05:17 -07: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();
|
|
|
|
|
let to = Pubkey::new_rand();
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
}
|