Skip to content

Commit

Permalink
Merge pull request #168 from tonlabs/replay
Browse files Browse the repository at this point in the history
Add transactions fetch and replay tools
  • Loading branch information
IgorKoval authored Jul 23, 2021
2 parents fc7b33e + bc6ad64 commit fb34d16
Show file tree
Hide file tree
Showing 5 changed files with 585 additions and 3 deletions.
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ readme = "README.md"
license = "Apache-2.0"
keywords = ["TON", "SDK", "smart contract", "tonlabs", "solidity"]
edition = "2018"
version = "0.16.49"
version = "0.16.50"

[dependencies]
async-trait = "0.1.42"
Expand All @@ -20,6 +20,7 @@ clap = "2.32"
crc16 = "0.4.0"
ed25519-dalek = "1.0.0-pre.3"
hex = "0.3.2"
indicatif = "0.16"
lazy_static = "1.4.0"
log = {version = "0.4.11", features = ["std"] }
num-bigint = "0.2.2"
Expand All @@ -32,12 +33,14 @@ serde_json = "1.0"
sha2 = "0.8"
simplelog = "0.8.0"
tokio = { version = "0.2", features = ["full"], default-features = false }
tokio-retry = "0.3"

ton_abi = { git = "https://github.com/tonlabs/ton-labs-abi.git" }
ton_client = { git = 'https://github.com/tonlabs/TON-SDK.git' }
ton_sdk = { git = 'https://github.com/tonlabs/TON-SDK.git' }
ton_types = { git = "https://github.com/tonlabs/ton-labs-types.git" }
ton_block = { git = "https://github.com/tonlabs/ton-labs-block.git" }
ton_executor = { git = "https://github.com/tonlabs/ton-labs-executor.git" }

[dev-dependencies]
assert_cmd = "1.0.3"
Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ tonos-cli <subcommand> -h
- [9.1. Convert tokens to nanotokens](#91-convert-tokens-to-nanotokens)
- [9.2. Get global config](#92-get-global-config)
- [9.3. NodeID](#93-nodeid)
- [10. Fetch and replay commands](#10-fetch-and-replay)

# 1. Installation

Expand Down Expand Up @@ -1805,3 +1806,15 @@ Input arguments:
keypair: dizzy modify exotic daring gloom rival pipe disagree again film neck fuel
50232655f2ad44f026b03ec1834ae8316bfa1f3533732da1e19b3b31c0f04143
```
## 10. Fetch and replay
These two commands are commonly used in pairs to recover a state of account at a specific point before a given transaction.
Example:
```bash
$ tonos-cli fetch -- -1:5555555555555555555555555555555555555555555555555555555555555555 config.txns
$ tonos-cli fetch 0:570ddeb8f632e5f9fde198dd4a799192f149f01c8fd360132b38b04bb7761c5d 570ddeb8.txns
$ tonos-cli replay config.txns 570ddeb8.txns 197ee1fe7876d4e2987b5dd24fb6701e76d76f9d08a5eeceb7fe8ca73d9b8270
```
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,4 +430,4 @@ mod tests {
assert_eq!(resolve_net_name("net.ton.dev"), Some("net.ton.dev".to_owned()));
assert_eq!(resolve_net_name("net.ton.com"), None);
}
}
}
21 changes: 20 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ mod helpers;
mod multisig;
mod sendfile;
mod voting;
mod replay;

use account::{get_account, calc_storage};
use call::{call_contract, call_contract_with_msg, generate_message, parse_params, run_get_method};
Expand All @@ -46,6 +47,7 @@ use getconfig::query_global_config;
use multisig::{create_multisig_command, multisig_command};
use std::{env, path::PathBuf};
use voting::{create_proposal, decode_proposal, vote};
use replay::{fetch_command, replay_command};
use ton_client::abi::{ParamsOfEncodeMessageBody, CallSet};
use crate::config::FullConfig;

Expand Down Expand Up @@ -409,6 +411,17 @@ async fn main_internal() -> Result <(), String> {
(about: "Sends the boc file with an external inbound message to account.")
(@arg BOC: +required +takes_value "Message boc file.")
)
(@subcommand fetch =>
(about: "Fetches account's zerostate and transactions.")
(@arg ADDRESS: +required +takes_value "Account address to fetch zerostate and txns for.")
(@arg OUTPUT: +required +takes_value "Output file name")
)
(@subcommand replay =>
(about: "Replays account's transactions starting from zerostate.")
(@arg CONFIG_TXNS: +required +takes_value "File containing zerostate and txns of -1:555..5 account.")
(@arg INPUT_TXNS: +required +takes_value "File containing zerostate and txns of the account to replay.")
(@arg TXNID: +required +takes_value "Dump account state before this transaction ID and stop replaying.")
)
(@setting SubcommandRequired)
).get_matches();

Expand Down Expand Up @@ -529,6 +542,12 @@ async fn main_internal() -> Result <(), String> {
if let Some(m) = matches.subcommand_matches("debot") {
return debot_command(m, conf).await;
}
if let Some(m) = matches.subcommand_matches("fetch") {
return fetch_command(m, conf).await;
}
if let Some(m) = matches.subcommand_matches("replay") {
return replay_command(m).await;
}
if let Some(_) = matches.subcommand_matches("version") {
println!(
"tonos-cli {}\nCOMMIT_ID: {}\nBUILD_DATE: {}\nCOMMIT_DATE: {}\nGIT_BRANCH: {}",
Expand Down Expand Up @@ -978,4 +997,4 @@ async fn sendfile_command(m: &ArgMatches<'_>, conf: Config) -> Result<(), String
let boc = m.value_of("BOC");
print_args!(boc);
sendfile::sendfile(conf, boc.unwrap()).await
}
}
Loading

0 comments on commit fb34d16

Please sign in to comment.