2021-01-02 22:40:17 -08:00
|
|
|
use heck::CamelCase;
|
|
|
|
use heck::SnakeCase;
|
|
|
|
|
|
|
|
pub fn virtual_manifest() -> String {
|
|
|
|
r#"[workspace]
|
|
|
|
members = [
|
2021-01-11 09:22:25 -08:00
|
|
|
"programs/*"
|
2021-01-02 22:40:17 -08:00
|
|
|
]
|
|
|
|
"#
|
|
|
|
.to_string()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn cargo_toml(name: &str) -> String {
|
|
|
|
format!(
|
|
|
|
r#"[package]
|
|
|
|
name = "{0}"
|
|
|
|
version = "0.1.0"
|
|
|
|
description = "Created with Anchor"
|
|
|
|
edition = "2018"
|
|
|
|
|
|
|
|
[lib]
|
2021-01-14 15:16:27 -08:00
|
|
|
crate-type = ["cdylib", "lib"]
|
2021-01-02 22:40:17 -08:00
|
|
|
name = "{1}"
|
|
|
|
|
2021-01-14 15:16:27 -08:00
|
|
|
[features]
|
|
|
|
no-entrypoint = []
|
2021-01-29 06:19:00 -08:00
|
|
|
no-idl = []
|
2021-01-14 17:09:15 -08:00
|
|
|
cpi = ["no-entrypoint"]
|
2021-01-29 06:19:00 -08:00
|
|
|
default = []
|
2021-01-14 15:16:27 -08:00
|
|
|
|
2021-01-02 22:40:17 -08:00
|
|
|
[dependencies]
|
2021-01-14 23:19:52 -08:00
|
|
|
anchor-lang = {{ git = "https://github.com/project-serum/anchor", features = ["derive"] }}
|
2021-01-02 22:40:17 -08:00
|
|
|
"#,
|
|
|
|
name,
|
|
|
|
name.to_snake_case(),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-01-27 19:58:26 -08:00
|
|
|
pub fn deploy_script_host(cluster_url: &str, script_path: &str) -> String {
|
2021-01-27 19:31:15 -08:00
|
|
|
format!(
|
|
|
|
r#"
|
|
|
|
const anchor = require('@project-serum/anchor');
|
|
|
|
|
|
|
|
// Deploy script defined by the user.
|
|
|
|
const userScript = require("{0}");
|
|
|
|
|
|
|
|
async function main() {{
|
|
|
|
const url = "{1}";
|
|
|
|
const preflightCommitment = 'recent';
|
|
|
|
const connection = new anchor.web3.Connection(url, preflightCommitment);
|
2021-01-27 19:58:26 -08:00
|
|
|
const wallet = anchor.Wallet.local();
|
2021-01-27 19:31:15 -08:00
|
|
|
|
2021-01-27 19:58:26 -08:00
|
|
|
const provider = new anchor.Provider(connection, wallet, {{
|
2021-01-27 19:31:15 -08:00
|
|
|
preflightCommitment,
|
|
|
|
commitment: 'recent',
|
|
|
|
}});
|
|
|
|
|
|
|
|
// Run the user's deploy script.
|
|
|
|
userScript(provider);
|
|
|
|
}}
|
|
|
|
main();
|
|
|
|
"#,
|
|
|
|
script_path, cluster_url,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-01-27 19:58:26 -08:00
|
|
|
pub fn deploy_script() -> String {
|
|
|
|
return r#"
|
|
|
|
// Migrations are an early feature. Currently, they're nothing more than this
|
|
|
|
// single deploy script that's invoked from the CLI, injecting a provider
|
|
|
|
// configured from the workspace's Anchor.toml.
|
|
|
|
|
|
|
|
const anchor = require("@project-serum/anchor");
|
|
|
|
|
|
|
|
module.exports = async function (provider) {
|
|
|
|
// Configure client to use the provider.
|
|
|
|
anchor.setProvider(provider);
|
|
|
|
|
|
|
|
// Add your deploy script here.
|
|
|
|
}
|
|
|
|
"#
|
|
|
|
.to_string();
|
|
|
|
}
|
2021-01-04 12:27:35 -08:00
|
|
|
pub fn xargo_toml() -> String {
|
2021-01-02 22:40:17 -08:00
|
|
|
r#"[target.bpfel-unknown-unknown.dependencies.std]
|
|
|
|
features = []"#
|
|
|
|
.to_string()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn lib_rs(name: &str) -> String {
|
|
|
|
format!(
|
|
|
|
r#"#![feature(proc_macro_hygiene)]
|
|
|
|
|
2021-01-14 22:35:50 -08:00
|
|
|
use anchor_lang::prelude::*;
|
2021-01-02 22:40:17 -08:00
|
|
|
|
|
|
|
#[program]
|
2021-01-23 00:18:50 -08:00
|
|
|
pub mod {} {{
|
2021-01-11 09:22:25 -08:00
|
|
|
use super::*;
|
|
|
|
pub fn initialize(ctx: Context<Initialize>) -> ProgramResult {{
|
|
|
|
Ok(())
|
|
|
|
}}
|
2021-01-02 22:40:17 -08:00
|
|
|
}}
|
|
|
|
|
|
|
|
#[derive(Accounts)]
|
|
|
|
pub struct Initialize {{}}"#,
|
|
|
|
name.to_snake_case(),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn mocha(name: &str) -> String {
|
|
|
|
format!(
|
|
|
|
r#"const anchor = require('@project-serum/anchor');
|
|
|
|
|
|
|
|
describe('{}', () => {{
|
|
|
|
|
|
|
|
// Configure the client to use the local cluster.
|
2021-01-27 20:07:09 -08:00
|
|
|
anchor.setProvider(anchor.Provider.env());
|
2021-01-02 22:40:17 -08:00
|
|
|
|
|
|
|
it('Is initialized!', async () => {{
|
|
|
|
// Add your test here.
|
|
|
|
const program = anchor.workspace.{};
|
2021-01-05 14:18:55 -08:00
|
|
|
const tx = await program.rpc.initialize();
|
2021-01-02 22:40:17 -08:00
|
|
|
console.log("Your transaction signature", tx);
|
|
|
|
}});
|
|
|
|
}});
|
|
|
|
"#,
|
|
|
|
name,
|
|
|
|
name.to_camel_case(),
|
|
|
|
)
|
|
|
|
}
|