2020-01-09 23:58:13 -08:00
|
|
|
solana_sdk::declare_id!("LibraPay11111111111111111111111111111111111");
|
2019-07-27 12:11:51 -07:00
|
|
|
|
|
|
|
pub mod librapay_instruction;
|
|
|
|
pub mod librapay_transaction;
|
|
|
|
|
2019-11-20 16:32:19 -08:00
|
|
|
extern crate solana_move_loader_program;
|
2019-07-27 12:11:51 -07:00
|
|
|
|
2020-04-20 23:37:54 -07:00
|
|
|
use solana_move_loader_program::account_state::LibraAccountState;
|
2019-07-27 12:11:51 -07:00
|
|
|
use solana_runtime::loader_utils::load_program;
|
2020-01-09 23:58:13 -08:00
|
|
|
use solana_sdk::{
|
|
|
|
client::Client,
|
|
|
|
message::Message,
|
|
|
|
pubkey::Pubkey,
|
2020-02-20 14:28:55 -07:00
|
|
|
signature::{Keypair, Signer},
|
2020-01-09 23:58:13 -08:00
|
|
|
system_instruction,
|
|
|
|
};
|
2019-07-27 12:11:51 -07:00
|
|
|
|
2019-10-29 10:39:10 -07:00
|
|
|
use types::account_config;
|
2019-07-27 12:11:51 -07:00
|
|
|
|
2019-11-18 16:47:01 -08:00
|
|
|
pub fn create_genesis<T: Client>(from: &Keypair, client: &T, amount: u64) -> Keypair {
|
|
|
|
let genesis = Keypair::new();
|
2019-07-30 23:43:12 -07:00
|
|
|
|
|
|
|
let instruction = system_instruction::create_account(
|
2019-11-18 16:47:01 -08:00
|
|
|
&from.pubkey(),
|
|
|
|
&genesis.pubkey(),
|
2019-07-30 23:43:12 -07:00
|
|
|
1,
|
2019-10-15 22:40:31 -07:00
|
|
|
bincode::serialized_size(&LibraAccountState::create_genesis(amount).unwrap()).unwrap()
|
|
|
|
as u64,
|
2019-10-29 17:14:07 -07:00
|
|
|
&solana_sdk::move_loader::id(),
|
2019-07-30 23:43:12 -07:00
|
|
|
);
|
2019-11-08 15:57:35 +05:30
|
|
|
|
|
|
|
client
|
2020-03-11 14:37:23 -07:00
|
|
|
.send_message(&[&from, &genesis], Message::new(&[instruction]))
|
2019-11-08 15:57:35 +05:30
|
|
|
.unwrap();
|
2019-07-30 23:43:12 -07:00
|
|
|
|
2019-11-18 16:47:01 -08:00
|
|
|
let instruction = librapay_instruction::genesis(&genesis.pubkey(), amount);
|
2020-03-11 14:37:23 -07:00
|
|
|
let message = Message::new_with_payer(&[instruction], Some(&from.pubkey()));
|
2019-11-18 16:47:01 -08:00
|
|
|
client.send_message(&[from, &genesis], message).unwrap();
|
2019-07-30 23:43:12 -07:00
|
|
|
|
2019-11-18 16:47:01 -08:00
|
|
|
genesis
|
2019-07-30 23:43:12 -07:00
|
|
|
}
|
|
|
|
|
2019-11-18 16:47:01 -08:00
|
|
|
pub fn publish_module<T: Client>(from: &Keypair, client: &T, code: &str) -> Pubkey {
|
2019-10-29 10:39:10 -07:00
|
|
|
let address = account_config::association_address();
|
2019-11-18 16:47:01 -08:00
|
|
|
let account_state = LibraAccountState::create_module(&address, code, vec![]);
|
|
|
|
let bytes = bincode::serialize(&account_state).unwrap();
|
2019-07-27 12:11:51 -07:00
|
|
|
|
2019-11-18 16:47:01 -08:00
|
|
|
load_program(client, &from, &solana_sdk::move_loader::id(), bytes)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn upload_script<T: Client>(from: &Keypair, client: &T, code: &str) -> Pubkey {
|
|
|
|
let address = account_config::association_address();
|
|
|
|
let account_state = LibraAccountState::create_script(&address, code, vec![]);
|
|
|
|
let bytes = bincode::serialize(&account_state).unwrap();
|
|
|
|
|
|
|
|
load_program(client, &from, &solana_sdk::move_loader::id(), bytes)
|
2019-07-27 12:11:51 -07:00
|
|
|
}
|
|
|
|
|
2019-11-18 16:47:01 -08:00
|
|
|
pub fn upload_mint_script<T: Client>(from: &Keypair, client: &T) -> Pubkey {
|
2019-07-27 12:11:51 -07:00
|
|
|
let code = "
|
|
|
|
import 0x0.LibraAccount;
|
|
|
|
import 0x0.LibraCoin;
|
|
|
|
main(payee: address, amount: u64) {
|
|
|
|
LibraAccount.mint_to_address(move(payee), move(amount));
|
|
|
|
return;
|
|
|
|
}";
|
2019-11-18 16:47:01 -08:00
|
|
|
upload_script(from, client, code)
|
2019-07-27 12:11:51 -07:00
|
|
|
}
|
2019-11-18 16:47:01 -08:00
|
|
|
pub fn upload_payment_script<T: Client>(from: &Keypair, client: &T) -> Pubkey {
|
2019-07-27 12:11:51 -07:00
|
|
|
let code = "
|
|
|
|
import 0x0.LibraAccount;
|
|
|
|
import 0x0.LibraCoin;
|
|
|
|
main(payee: address, amount: u64) {
|
|
|
|
LibraAccount.pay_from_sender(move(payee), move(amount));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
";
|
|
|
|
|
2019-11-18 16:47:01 -08:00
|
|
|
upload_script(from, client, code)
|
2019-07-27 12:11:51 -07:00
|
|
|
}
|