Skip to content

Commit

Permalink
Merge pull request #926 from tonlabs/abi-2.4
Browse files Browse the repository at this point in the history
Abi 2.4
  • Loading branch information
IgorKoval authored Nov 17, 2023
2 parents 7363698 + 20694fd commit 805323e
Show file tree
Hide file tree
Showing 15 changed files with 663 additions and 391 deletions.
629 changes: 338 additions & 291 deletions Cargo.lock

Large diffs are not rendered by default.

25 changes: 11 additions & 14 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ license = 'Apache-2.0'
name = 'tonos-cli'
readme = 'README.md'
repository = 'https://github.com/tonlabs/tonos-cli'
version = '0.35.8'
version = '0.36.0'
default-run = 'tonos-cli'

[features]
Expand All @@ -27,36 +27,33 @@ async-trait = '0.1.42'
base64 = '0.13'
chrono = '0.4'
clap = '2.32'
crc = '3.0'
ed25519-dalek = '1.0'
failure = '0.1'
futures = '0.3'
hex = '0.4'
indicatif = '0.16'
lazy_static = '1.4'
num-bigint = '0.4'
num-traits = '0.2'
qr2term = '0.2'
regex = '1.5'
reqwest = '0.11'
serde_derive = '1.0'
serde_json = '1.0'
sha2 = '0.9.5'
simplelog = '0.8'
tokio-retry = '0.3'
log = { features = [ 'std' ], version = '0.4' }
serde = { features = [ 'derive' ], version = '1.0' }
tokio = { default-features = false, features = [ 'full' ], version = '1.21' }
url = '2.3.1'
ton_abi = { git = 'https://github.com/tonlabs/ever-abi.git', tag = '2.3.143' }
ton_block = { git = 'https://github.com/tonlabs/ever-block.git', tag = '1.9.101' }
ton_block_json = { git = 'https://github.com/tonlabs/ever-block-json.git', tag = '0.7.184' }
ton_client = { git = 'https://github.com/tonlabs/ever-sdk.git', tag = '1.44.3' }
ton_executor = { git = 'https://github.com/tonlabs/ever-executor.git', tag = '1.16.75' }
ton_labs_assembler = { git = 'https://github.com/tonlabs/ever-assembler.git', tag = '1.4.5' }
ton_sdk = { git = 'https://github.com/tonlabs/ever-sdk.git', tag = '1.44.3' }
ton_types = { git = 'https://github.com/tonlabs/ever-types.git', tag = '2.0.26' }
ton_vm = { git = 'https://github.com/tonlabs/ever-vm.git', tag = '1.8.205' }

ton_abi = { git = 'https://github.com/tonlabs/ever-abi.git', tag = '2.4.0' }
ton_block = { git = 'https://github.com/tonlabs/ever-block.git', tag = '1.9.107' }
ton_block_json = { git = 'https://github.com/tonlabs/ever-block-json.git', tag = '0.7.192' }
ton_client = { git = 'https://github.com/tonlabs/ever-sdk.git', tag = '1.45.0' }
ton_executor = { git = 'https://github.com/tonlabs/ever-executor.git', tag = '1.16.86' }
ton_labs_assembler = { git = 'https://github.com/tonlabs/ever-assembler.git', tag = '1.4.18' }
ton_sdk = { git = 'https://github.com/tonlabs/ever-sdk.git', tag = '1.45.0' }
ton_types = { git = 'https://github.com/tonlabs/ever-types.git', tag = '2.0.29' }
ton_vm = { git = 'https://github.com/tonlabs/ever-vm.git', tag = '1.8.214' }
sold = { git = 'https://github.com/tonlabs/TON-Solidity-Compiler.git', tag = '0.66.0', optional = true }

[dev-dependencies]
Expand Down
42 changes: 22 additions & 20 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
use clap::ArgMatches;
use lazy_static::lazy_static;
use regex::Regex;
use crate::global_config_path;
use crate::helpers::default_config_name;
Expand Down Expand Up @@ -214,21 +213,17 @@ impl Config {
}


lazy_static! {
static ref MAIN_ENDPOINTS: Vec<String> = vec![
"https://mainnet.evercloud.dev".to_string()
];

static ref NET_ENDPOINTS: Vec<String> = vec![
"https://devnet.evercloud.dev".to_string()
];

static ref SE_ENDPOINTS: Vec<String> = vec![
"http://0.0.0.0".to_string(),
"http://127.0.0.1".to_string(),
"http://localhost".to_string(),
];
}
const MAIN_ENDPOINTS: &[&str] = &[
"https://mainnet.evercloud.dev",
];
const NET_ENDPOINTS: &[&str] = &[
"https://devnet.evercloud.dev",
];
const SE_ENDPOINTS: &[&str] = &[
"http://0.0.0.0",
"http://127.0.0.1",
"http://localhost",
];

pub fn resolve_net_name(url: &str) -> Option<String> {
let url_regex = Regex::new(r"^\s*(?:https?://)?(?P<net>\w+\.evercloud\.dev)\s*")
Expand Down Expand Up @@ -277,10 +272,17 @@ impl FullConfig {
}

pub fn default_map() -> BTreeMap<String, Vec<String>> {
[(MAINNET.to_owned(), MAIN_ENDPOINTS.to_owned()),
(TESTNET.to_owned(), NET_ENDPOINTS.to_owned()),
(LOCALNET.to_owned(), SE_ENDPOINTS.to_owned()),
].iter().cloned().collect()
[
(MAINNET, MAIN_ENDPOINTS),
(TESTNET, NET_ENDPOINTS),
(LOCALNET, SE_ENDPOINTS),
]
.iter()
.map(|(k, v)| (
k.to_string(),
v.iter().map(|s| s.to_string()).collect())
)
.collect()
}

pub fn from_file(path: &str) -> FullConfig {
Expand Down
2 changes: 1 addition & 1 deletion src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* limitations under the License.
*/

use sha2::{Sha256, Digest};
use ton_types::Sha256;

pub fn convert_token(amount: &str) -> Result<String, String> {
convert_amount(amount, 9)
Expand Down
6 changes: 3 additions & 3 deletions src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub fn generate_keypair_from_mnemonic(mnemonic: &str) -> Result<KeyPair, String>
let hdk_root = hdkey_derive_from_xprv_path(
client.clone(),
ParamsOfHDKeyDeriveFromXPrvPath {
xprv: hdk_master.xprv,
xprv: hdk_master.xprv.clone(),
path: HD_PATH.to_string(),
..Default::default()
},
Expand All @@ -74,15 +74,15 @@ pub fn generate_keypair_from_mnemonic(mnemonic: &str) -> Result<KeyPair, String>
let secret = hdkey_secret_from_xprv(
client.clone(),
ParamsOfHDKeySecretFromXPrv {
xprv: hdk_root.xprv,
xprv: hdk_root.xprv.clone(),
..Default::default()
},
).map_err(|e| format!("{}", e))?;

let mut keypair: KeyPair = nacl_sign_keypair_from_secret_key(
client,
ParamsOfNaclSignKeyPairFromSecret {
secret: secret.secret,
secret: secret.secret.clone(),
..Default::default()
},
).map_err(|e| format!("failed to get KeyPair from secret key: {}", e))?;
Expand Down
13 changes: 9 additions & 4 deletions src/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* See the License for the specific TON DEV software governing permissions and
* limitations under the License.
*/
use crate::helpers::{create_client_verbose, create_client_local, load_abi, calc_acc_address, now_ms};
use crate::helpers::{create_client_verbose, create_client_local, load_abi, now_ms};
use crate::config::FullConfig;
use crate::crypto::load_keypair;
use crate::call::{
Expand Down Expand Up @@ -145,9 +145,14 @@ pub async fn prepare_deploy_message_params(
keys: Option<KeyPair>,
wc: i32
) -> Result<(ParamsOfEncodeMessage, String), String> {
let tvc_base64 = base64::encode(&tvc_bytes);
let tvc = base64::encode(&tvc_bytes);

let address = calc_acc_address(

// let tvc_cell = ton_types::boc::read_single_root_boc(&tvc_bytes).unwrap();
// let tvc_hash = tvc_cell.repr_hash();
// let address = format!("{}:{}", wc, tvc_hash.as_hex_string());
// TODO DELETE this ?
let address = crate::helpers::calc_acc_address(
tvc_bytes,
wc,
keys.as_ref().map(|k| k.public.clone()),
Expand All @@ -160,7 +165,7 @@ pub async fn prepare_deploy_message_params(
..Default::default()
});
let deploy_set = Some(DeploySet {
tvc: Some(tvc_base64),
tvc: Some(tvc),
workchain_id: Some(wc),
..Default::default()
});
Expand Down
37 changes: 26 additions & 11 deletions src/genaddr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
*/
use crate::config::Config;
use crate::helpers::{create_client_local, read_keys, load_abi, calc_acc_address, load_abi_str};
use ed25519_dalek::PublicKey;
use serde_json::json;
use std::fs::OpenOptions;

Expand Down Expand Up @@ -60,11 +59,7 @@ pub async fn generate_address(
let addr = calc_acc_address(
&contract,
wc,
if keys.is_some() {
Some(keys.clone().unwrap().public)
} else {
None
},
keys.as_ref().map(|v| v.public.clone()),
initial_data,
abi.clone()
).await?;
Expand Down Expand Up @@ -142,17 +137,37 @@ fn calc_userfriendly_address(address: &str, bounce: bool, test: bool) -> Result<

fn update_contract_state(tvc_file: &str, pubkey: &[u8], data: Option<String>, abi: &str) -> Result<(), String> {
use std::io::{Seek, Write};
use ton_abi::Contract;
use ton_sdk::ContractImage;

let data_map_supported : bool = (Contract::load(abi.as_bytes())
.map_err(|e| format!("unable to load abi: {}", e))?).data_map_supported();

let mut state_init = OpenOptions::new().read(true).write(true).open(tvc_file)
.map_err(|e| format!("unable to open contract file: {}", e))?;

let pubkey_object = PublicKey::from_bytes(pubkey)
let pubkey_object = pubkey.try_into()
.map_err(|e| format!("unable to load public key: {}", e))?;

let mut contract_image = ton_sdk::ContractImage::from_state_init_and_key(&mut state_init, &pubkey_object)
.map_err(|e| format!("unable to load contract image: {}", e))?;
let mut contract_image = if data_map_supported {
ContractImage::from_state_init_and_key(&mut state_init, &pubkey_object)
.map_err(|e| format!("unable to load contract image with key: {}", e))?
} else {
ContractImage::from_state_init(&mut state_init)
.map_err(|e| format!("unable to load contract image: {}", e))?
};

if data.is_some() {
contract_image.update_data(&data.unwrap(), abi)
if data_map_supported {
if data.is_some() {
contract_image.update_data(true, &data.unwrap(), abi)
.map_err(|e| format!("unable to update contract image data: {}", e))?;
}
} else {
let js_init_data = crate::helpers::insert_pubkey_to_init_data(
Some(hex::encode(pubkey)),
data.as_deref()
)?;
contract_image.update_data(false, js_init_data.as_str(), abi)
.map_err(|e| format!("unable to update contract image data: {}", e))?;
}

Expand Down
19 changes: 6 additions & 13 deletions src/getconfig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
* limitations under the License.
*/

use ed25519_dalek::{Keypair, PublicKey, SecretKey, Signer};
use num_bigint::BigUint;
use crate::config::Config;
use crate::helpers::{create_client_verbose, query_with_limit, now, now_ms, TonClient};
Expand All @@ -20,7 +19,7 @@ use ton_abi::{Contract, Token, TokenValue, Uint};
use ton_block::{ExternalInboundMessageHeader, Grams, Message, MsgAddressInt, MsgAddressExt, Serializable};
use ton_client::net::{OrderBy, SortDirection};
use ton_client::boc::{get_blockchain_config, ParamsOfGetBlockchainConfig};
use ton_types::{BuilderData, Cell, IBitstring, SliceData};
use ton_types::{BuilderData, Cell, IBitstring, SliceData, ed25519_create_private_key, ed25519_sign_with_secret};

const PREFIX_UPDATE_CONFIG_MESSAGE_DATA: &str = "43665021";

Expand Down Expand Up @@ -422,12 +421,8 @@ fn prepare_message_new_config_param(
cell.append_i32(key_number as i32).unwrap();
cell.checked_append_reference(config_param.clone()).unwrap();

let secret = SecretKey::from_bytes(private_key_of_config_account)
.map_err(|e| format!(r#"failed to read private key from config-master file": {}"#, e))?;
let public = PublicKey::from(&secret);
let keypair = Keypair { secret, public };

let msg_signature = keypair.sign(cell.finalize(0).unwrap().repr_hash().as_slice()).to_bytes();
let msg_signature = ed25519_sign_with_secret(private_key_of_config_account, cell.finalize(0).unwrap().repr_hash().as_slice())
.map_err(|e| format!("Failed to sign: {e}"))?;

let mut cell = BuilderData::default();
cell.append_raw(&msg_signature, 64*8).unwrap();
Expand All @@ -453,10 +448,8 @@ fn prepare_message_new_config_param_solidity(
config_account: SliceData,
private_key_of_config_account: &[u8]
) -> Result<Message, String> {
let secret = SecretKey::from_bytes(private_key_of_config_account)
.map_err(|e| format!(r#"failed to read private key from config-master file": {}"#, e))?;
let public = PublicKey::from(&secret);
let keypair = Keypair { secret, public };
let secret = ed25519_create_private_key(private_key_of_config_account)
.map_err(|err| err.to_string())?;

let config_contract_address = MsgAddressInt::with_standart(None, -1, config_account).unwrap();
let since_the_epoch = now_ms();
Expand All @@ -477,7 +470,7 @@ fn prepare_message_new_config_param_solidity(
let function = contract.function("set_config_param")
.map_err(|err| err.to_string())?;
let body = function
.encode_input(&header, &parameters, false, Some(&keypair), Some(config_contract_address.clone()))
.encode_input(&header, &parameters, false, Some(&secret), Some(config_contract_address.clone()))
.and_then(|builder| SliceData::load_builder(builder))
.map_err(|err| format!("cannot prepare message body {}", err))?;

Expand Down
Loading

0 comments on commit 805323e

Please sign in to comment.