Skip to content

Commit

Permalink
added 'ct' command (#162)
Browse files Browse the repository at this point in the history
* Added script lookup.

* Added script CreateTransaction.

* Added ctx cmd.

* Added call pattern for ctx.

* Added ct documentation.
  • Loading branch information
RIg410 authored Feb 23, 2021
1 parent 1f29cfc commit fe92040
Show file tree
Hide file tree
Showing 24 changed files with 1,044 additions and 100 deletions.
27 changes: 15 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

91 changes: 90 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,98 @@ Build project:
```shell script
dove build
```

See `./target/` folder to get scripts/modules binaries.


Create transactions:

Command `ct` allows you to create transactions for `polkadot` chain with move vm palette.

`ct` takes script identifier, type parameters, and arguments and creates a transaction file as an artifact of work.

Example:
```shell script
dove ct 'store_u64(60)'
```
This command searches for the script by name 'store_u64' in the script directory. Then it compiles it and creates a transaction file.

This command will fail if:

- There is no script with the name given name 'store_u64'.
- There is more than one script with the name 'store_64'.
- The passed parameters or type parameters do not match the script parameters.
- There are syntax errors in the script.

Type parameters:

You can use type parameters like in the move language.
Example:
```shell script
dove ct 'create_account<0x01::Dfinance::USD, 0x01::Dfinance::BTC>()'
```
You allow can use ss58 address format:
```shell script
dove ct 'create_account<1exaAg2VJRQbyUBAeXcktChCAqjVP9TUxF3zo23R2T6EGdE::Dfinance::USD>()'
```

Types:

numbers (u8, u64, u128): 10, 1024.

bool: true, false.

address: 1exaAg2VJRQbyUBAeXcktChCAqjVP9TUxF3zo23R2T6EGdE, 0x1CF326C5AAA5AF9F0E2791E66310FE8F044FAADAF12567EAA0976959D1F7731F

vector<address>: [1exaAg2VJRQbyUBAeXcktChCAqjVP9TUxF3zo23R2T6EGdE, 0x1CF326C5AAA5AF9F0E2791E66310FE8F044FAADAF12567EAA0976959D1F7731F, 0x01]

vector<u8/u64/128>: [10, 30, 1024]

vector<bool>: [true, false]

You can define or override script names by using '--name' or '-n' parameter.

Example:
Override script name:
```shell script
dove ct 'store_u64(60)' -n store_u126
```
Define script name:
```shell script
dove ct -n store_u126
```

File name:
You can define the file name by using '--file' or '-f' parameter.
With this option 'ct' searches in a specified file. It may be useful when there is more than one script with the same name in different files.
Or the specified file has one script.
```shell script
dove ct 'store_u64(60)' -n store_u126 -f script.move
```
```shell script
dove ct -n store_u126 -f script
```

Type parameters:

You can define or override script type parameters by using '--type' or '-t' parameter.
```shell script
dove ct 'store_u64()' -t 0x01::Dfinance::USD u8
```
```shell script
dove ct -n store_u64 -t 0x01::Dfinance::USD u8
```


arguments:

You can define or override script arguments by using '--args' or '-a' parameter.
```shell script
dove ct 'store_u64()' -a [10, 1024] 10 0x01
```
```shell script
dove ct -n store_u64 -a [10, 1024] 10 0x01
```

## Resource Viewer

See [documentation](/resource-viewer/README.md).
Expand Down
4 changes: 4 additions & 0 deletions dove/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ reqwest = { version = "0.10.4", features = ["blocking", "json"] }
itertools = "0.9.0"
lang = { path = "../lang" }
move-executor = { path = "../executor" }
move-resource-viewer = { path = "../resource-viewer", default-features = false }
git-hash = { path = "../common/git-hash" }
maplit = "1.0.2"
serde_json = "1.0.52"
Expand All @@ -44,14 +45,17 @@ libra_address = [
"libra/libra_address",
"lang/libra_address",
"move-executor/libra_address",
"move-resource-viewer/libra_address",
]
dfinance_address = [
"libra/dfinance_address",
"lang/dfinance_address",
"move-executor/dfinance_address",
"move-resource-viewer/dfinance_address",
]
ps_address = [
"libra/ps_address",
"lang/ps_address",
"move-executor/ps_address",
"move-resource-viewer/ps_address"
]
7 changes: 7 additions & 0 deletions dove/src/bin/dove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use dove::cmd::fetch::Fetch;
use dove::cmd::build::Build;
use dove::cmd::test::Test;
use dove::cmd::run::Run;
use dove::cmd::ct::CreateTransactionCmd;

#[derive(StructOpt, Debug)]
#[structopt(name = "Move compiler.", version = git_hash::crate_version_with_git_hash_short!())]
Expand Down Expand Up @@ -58,6 +59,11 @@ enum Opt {
#[structopt(flatten)]
cmd: Run,
},
#[structopt(about = "Create transaction")]
Ct {
#[structopt(flatten)]
cmd: CreateTransactionCmd,
},
}

fn main() {
Expand All @@ -73,6 +79,7 @@ fn main() {
Opt::Build { cmd } => cmd.execute(),
Opt::Test { cmd } => cmd.execute(),
Opt::Run { cmd } => cmd.execute(),
Opt::Ct { cmd } => cmd.execute(),
});
}

Expand Down
16 changes: 5 additions & 11 deletions dove/src/cmd/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ use crate::cmd::{Cmd, load_dependencies};
use crate::context::Context;
use anyhow::Error;
use structopt::StructOpt;
use crate::index::Index;
use lang::compiler::file::load_move_files;
use lang::builder::{Artifacts, MoveBuilder};
use termcolor::{StandardStream, ColorChoice};
use std::path::PathBuf;
use std::path::Path;
use std::fs::File;
use std::io::Write;
use std::fs;
Expand All @@ -24,17 +23,12 @@ pub struct Build {}

impl Cmd for Build {
fn apply(self, ctx: Context) -> Result<(), Error> {
let dirs: Vec<_> = [
let dirs = ctx.paths_for(&[
&ctx.manifest.layout.script_dir,
&ctx.manifest.layout.module_dir,
]
.iter()
.map(|d| ctx.path_for(&d))
.filter(|p| p.exists())
.collect();
]);

let mut index = Index::load(&ctx)?;
index.build()?;
let mut index = ctx.build_index()?;

let dep_set = index.make_dependency_set(&dirs)?;
let dep_list = load_dependencies(dep_set)?;
Expand Down Expand Up @@ -68,7 +62,7 @@ pub fn verify_and_store(
.into_iter()
.partition(|u| matches!(u, CompiledUnit::Module { .. }));

fn store(units: Vec<CompiledUnit>, base_dir: &PathBuf) -> Result<(), Error> {
fn store(units: Vec<CompiledUnit>, base_dir: &Path) -> Result<(), Error> {
for (idx, unit) in units.into_iter().enumerate() {
let mut path = base_dir.join(format!("{}_{}", idx, unit.name()));
path.set_extension("mv");
Expand Down
Loading

0 comments on commit fe92040

Please sign in to comment.