Skip to content

Commit

Permalink
chore!: updates near-* dependencies to 0.28 release (#423)
Browse files Browse the repository at this point in the history
Also:
* Bumped up the `thiserror` crate to version 2.
* Changed callback to work with `TransactionV0` instead of the
`Transaction`. As `Transaction` doesn't support the `actions_mut`
function.
* rust-tolchain 1.80 pin to `stable`


@race-of-sloths

---------

Co-authored-by: FroVolod <[email protected]>
  • Loading branch information
akorchyn and FroVolod authored Dec 13, 2024
1 parent 63a9762 commit c19e525
Show file tree
Hide file tree
Showing 17 changed files with 368 additions and 302 deletions.
455 changes: 234 additions & 221 deletions Cargo.lock

Large diffs are not rendered by default.

20 changes: 13 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,17 @@ self_update = { version = "0.41.0", features = [
], optional = true }

color-eyre = "0.6"
thiserror = "1"
thiserror = "2"

bytesize = "1.1.0"
prettytable = "0.10.0"
textwrap = "0.16.1"

near-crypto = "0.27"
near-primitives = "0.27"
near-jsonrpc-client = "0.14"
near-jsonrpc-primitives = "0.27"
near-socialdb-client = "0.8"
near-crypto = "0.28"
near-primitives = "0.28"
near-jsonrpc-client = "0.15"
near-jsonrpc-primitives = "0.28"
near-socialdb-client = "0.9"

near-ledger = { version = "0.8.0", optional = true }

Expand Down Expand Up @@ -129,7 +129,13 @@ installers = ["shell", "powershell", "npm", "msi"]
# Publish jobs to run in CI
publish-jobs = ["npm"]
# Target platforms to build apps for (Rust target-triple syntax)
targets = ["aarch64-apple-darwin", "aarch64-unknown-linux-gnu", "x86_64-apple-darwin", "x86_64-unknown-linux-gnu", "x86_64-pc-windows-msvc"]
targets = [
"aarch64-apple-darwin",
"aarch64-unknown-linux-gnu",
"x86_64-apple-darwin",
"x86_64-unknown-linux-gnu",
"x86_64-pc-windows-msvc",
]
# The archive format to use for windows builds (defaults .zip)
windows-archive = ".tar.gz"
# The archive format to use for non-windows builds (defaults .tar.xz)
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.80
stable
6 changes: 3 additions & 3 deletions src/commands/account/update_social_profile/sign_as.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ impl From<SignerContext> for crate::commands::ActionContext {
let account_id = item.account_id.clone();
move |prepopulated_unsigned_transaction, network_config| {
let json_rpc_client = network_config.json_rpc_client();
let public_key = prepopulated_unsigned_transaction.public_key().clone();
let receiver_id = prepopulated_unsigned_transaction.receiver_id().clone();
let public_key = prepopulated_unsigned_transaction.public_key.clone();
let receiver_id = prepopulated_unsigned_transaction.receiver_id.clone();

if let Some(near_primitives::transaction::Action::FunctionCall(action)) =
prepopulated_unsigned_transaction.actions_mut().get_mut(0)
prepopulated_unsigned_transaction.actions.first_mut()
{
action.deposit = get_deposit(
&json_rpc_client,
Expand Down
12 changes: 11 additions & 1 deletion src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub enum TopLevelCommand {

pub type OnBeforeSigningCallback = std::sync::Arc<
dyn Fn(
&mut near_primitives::transaction::Transaction,
&mut near_primitives::transaction::TransactionV0,
&crate::config::NetworkConfig,
) -> crate::CliResult,
>;
Expand All @@ -68,6 +68,16 @@ pub struct PrepopulatedTransaction {
pub actions: Vec<near_primitives::transaction::Action>,
}

impl From<near_primitives::transaction::TransactionV0> for PrepopulatedTransaction {
fn from(value: near_primitives::transaction::TransactionV0) -> Self {
Self {
signer_id: value.signer_id,
receiver_id: value.receiver_id,
actions: value.actions,
}
}
}

impl From<near_primitives::transaction::Transaction> for PrepopulatedTransaction {
fn from(value: near_primitives::transaction::Transaction) -> Self {
Self {
Expand Down
6 changes: 4 additions & 2 deletions src/commands/transaction/print_transaction/unsigned/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use near_primitives::transaction::Transaction;

#[derive(Debug, Clone, interactive_clap::InteractiveClap)]
#[interactive_clap(input_context = crate::GlobalContext)]
#[interactive_clap(output_context = PrintContext)]
Expand All @@ -14,11 +16,11 @@ impl PrintContext {
_previous_context: crate::GlobalContext,
scope: &<PrintTransaction as interactive_clap::ToInteractiveClapContextScope>::InteractiveClapContextScope,
) -> color_eyre::eyre::Result<Self> {
let unsigned_transaction: near_primitives::transaction::Transaction =
let unsigned_transaction: near_primitives::transaction::TransactionV0 =
scope.unsigned_transaction.clone().into();

eprintln!("\nUnsigned transaction (full):\n");
crate::common::print_full_unsigned_transaction(unsigned_transaction);
crate::common::print_full_unsigned_transaction(Transaction::V0(unsigned_transaction));
eprintln!();

Ok(Self)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl RelayerAccountIdContext {
let on_before_signing_callback: crate::commands::OnBeforeSigningCallback =
std::sync::Arc::new({
move |prepopulated_unsigned_transaction, _network_config| {
*prepopulated_unsigned_transaction.actions_mut() =
prepopulated_unsigned_transaction.actions =
vec![near_primitives::transaction::Action::Delegate(Box::new(
previous_context.signed_delegate_action.clone(),
))];
Expand Down
6 changes: 3 additions & 3 deletions src/commands/transaction/sign_transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl SignTransactionContext {
) -> color_eyre::eyre::Result<Self> {
let get_prepopulated_transaction_after_getting_network_callback: crate::commands::GetPrepopulatedTransactionAfterGettingNetworkCallback =
std::sync::Arc::new({
let unsigned_transaction: near_primitives::transaction::Transaction =
let unsigned_transaction: near_primitives::transaction::TransactionV0 =
scope.unsigned_transaction.clone().into();

move |_network_config| {
Expand All @@ -32,8 +32,8 @@ impl SignTransactionContext {
Ok(Self(crate::commands::ActionContext {
global_context: previous_context,
interacting_with_account_ids: vec![
scope.unsigned_transaction.inner.signer_id().clone(),
scope.unsigned_transaction.inner.receiver_id().clone(),
scope.unsigned_transaction.inner.signer_id.clone(),
scope.unsigned_transaction.inner.receiver_id.clone(),
],
get_prepopulated_transaction_after_getting_network_callback,
on_before_signing_callback: std::sync::Arc::new(
Expand Down
3 changes: 2 additions & 1 deletion src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1192,11 +1192,12 @@ pub fn convert_invalid_tx_error_to_cli_result(
},
near_primitives::errors::InvalidTxError::StorageError(error) => match error {
near_primitives::errors::StorageError::StorageInternalError => color_eyre::eyre::Result::Err(color_eyre::eyre::eyre!("Error: Internal storage error")),
near_primitives::errors::StorageError::MissingTrieValue(_, _) => todo!(),
near_primitives::errors::StorageError::MissingTrieValue(_, hash) => color_eyre::eyre::Result::Err(color_eyre::eyre::eyre!("Error: Requested trie value by its hash ({hash}) which is missing in the storage",)),
near_primitives::errors::StorageError::UnexpectedTrieValue => color_eyre::eyre::Result::Err(color_eyre::eyre::eyre!("Error: Unexpected trie value")),
near_primitives::errors::StorageError::StorageInconsistentState(message) => color_eyre::eyre::Result::Err(color_eyre::eyre::eyre!("Error: The storage is in the incosistent state: {}", message)),
near_primitives::errors::StorageError::FlatStorageBlockNotSupported(message) => color_eyre::eyre::Result::Err(color_eyre::eyre::eyre!("Error: The block is not supported by flat storage: {}", message)),
near_primitives::errors::StorageError::MemTrieLoadingError(message) => color_eyre::eyre::Result::Err(color_eyre::eyre::eyre!("Error: The trie is not loaded in memory: {}", message)),
near_primitives::errors::StorageError::FlatStorageReshardingAlreadyInProgress => color_eyre::eyre::Result::Err(color_eyre::eyre::eyre!("Error: Flat storage resharding is already in progress")),
},
near_primitives::errors::InvalidTxError::ShardCongested { shard_id, congestion_level } => color_eyre::eyre::Result::Err(color_eyre::eyre::eyre!("Error: The shard ({shard_id}) is too congested ({congestion_level:.2}/1.00) and can't accept new transaction")),
near_primitives::errors::InvalidTxError::ShardStuck { shard_id, missed_chunks } => color_eyre::eyre::Result::Err(color_eyre::eyre::eyre!("Error: The shard ({shard_id}) is {missed_chunks} blocks behind and can't accept new transaction until it will be in the sync")),
Expand Down
24 changes: 12 additions & 12 deletions src/js_command_match/account/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,44 +57,44 @@ mod tests {
fn delete_account() {
for (input, expected_output) in [
(
format!("near delete bob.testnet alice.testnet --force"),
format!("account delete-account bob.testnet beneficiary alice.testnet network-config testnet sign-with-keychain send")
"near delete bob.testnet alice.testnet --force".to_string(),
"account delete-account bob.testnet beneficiary alice.testnet network-config testnet sign-with-keychain send".to_string()
),
(
format!("near delete-account bob.testnet alice.testnet --force"),
format!("account delete-account bob.testnet beneficiary alice.testnet network-config testnet sign-with-keychain send")
"near delete-account bob.testnet alice.testnet --force".to_string(),
"account delete-account bob.testnet beneficiary alice.testnet network-config testnet sign-with-keychain send".to_string()
),
(
format!("near delete-account bob.testnet alice.testnet --{} --force", SIGN_WITH_LEDGER_ALIASES[0]),
format!("account delete-account bob.testnet beneficiary alice.testnet network-config testnet sign-with-ledger --seed-phrase-hd-path '44'\\''/397'\\''/0'\\''/0'\\''/1'\\''' send")
"account delete-account bob.testnet beneficiary alice.testnet network-config testnet sign-with-ledger --seed-phrase-hd-path '44'\\''/397'\\''/0'\\''/0'\\''/1'\\''' send".to_string()
),
(
format!("near delete-account bob.testnet alice.testnet --{} --force", SIGN_WITH_LEDGER_ALIASES[1]),
format!("account delete-account bob.testnet beneficiary alice.testnet network-config testnet sign-with-ledger --seed-phrase-hd-path '44'\\''/397'\\''/0'\\''/0'\\''/1'\\''' send")
"account delete-account bob.testnet beneficiary alice.testnet network-config testnet sign-with-ledger --seed-phrase-hd-path '44'\\''/397'\\''/0'\\''/0'\\''/1'\\''' send".to_string()
),
(
format!("near delete-account bob.testnet alice.testnet --{} --force", SIGN_WITH_LEDGER_ALIASES[2]),
format!("account delete-account bob.testnet beneficiary alice.testnet network-config testnet sign-with-ledger --seed-phrase-hd-path '44'\\''/397'\\''/0'\\''/0'\\''/1'\\''' send")
"account delete-account bob.testnet beneficiary alice.testnet network-config testnet sign-with-ledger --seed-phrase-hd-path '44'\\''/397'\\''/0'\\''/0'\\''/1'\\''' send".to_string()
),
(
format!("near delete-account bob.testnet alice.testnet --{} --force", SIGN_WITH_LEDGER_ALIASES[3]),
format!("account delete-account bob.testnet beneficiary alice.testnet network-config testnet sign-with-ledger --seed-phrase-hd-path '44'\\''/397'\\''/0'\\''/0'\\''/1'\\''' send")
"account delete-account bob.testnet beneficiary alice.testnet network-config testnet sign-with-ledger --seed-phrase-hd-path '44'\\''/397'\\''/0'\\''/0'\\''/1'\\''' send".to_string()
),
(
format!("near delete-account bob.testnet alice.testnet --signWithLedger --{} \"44'/397'/0'/0'/2'\" --force", LEDGER_PATH_ALIASES[0]),
format!("account delete-account bob.testnet beneficiary alice.testnet network-config testnet sign-with-ledger --seed-phrase-hd-path '44'\\''/397'\\''/0'\\''/0'\\''/2'\\''' send")
"account delete-account bob.testnet beneficiary alice.testnet network-config testnet sign-with-ledger --seed-phrase-hd-path '44'\\''/397'\\''/0'\\''/0'\\''/2'\\''' send".to_string()
),
(
format!("near delete-account bob.testnet alice.testnet --signWithLedger --{} \"44'/397'/0'/0'/2'\" --force", LEDGER_PATH_ALIASES[1]),
format!("account delete-account bob.testnet beneficiary alice.testnet network-config testnet sign-with-ledger --seed-phrase-hd-path '44'\\''/397'\\''/0'\\''/0'\\''/2'\\''' send")
"account delete-account bob.testnet beneficiary alice.testnet network-config testnet sign-with-ledger --seed-phrase-hd-path '44'\\''/397'\\''/0'\\''/0'\\''/2'\\''' send".to_string()
),
(
format!("near delete-account bob.testnet alice.testnet --signWithLedger --{} mainnet --force", NETWORK_ID_ALIASES[0]),
format!("account delete-account bob.testnet beneficiary alice.testnet network-config mainnet sign-with-ledger --seed-phrase-hd-path '44'\\''/397'\\''/0'\\''/0'\\''/1'\\''' send")
"account delete-account bob.testnet beneficiary alice.testnet network-config mainnet sign-with-ledger --seed-phrase-hd-path '44'\\''/397'\\''/0'\\''/0'\\''/1'\\''' send".to_string()
),
(
format!("near delete-account bob.testnet alice.testnet --signWithLedger --{} mainnet --force", NETWORK_ID_ALIASES[1]),
format!("account delete-account bob.testnet beneficiary alice.testnet network-config mainnet sign-with-ledger --seed-phrase-hd-path '44'\\''/397'\\''/0'\\''/0'\\''/1'\\''' send")
"account delete-account bob.testnet beneficiary alice.testnet network-config mainnet sign-with-ledger --seed-phrase-hd-path '44'\\''/397'\\''/0'\\''/0'\\''/1'\\''' send".to_string()
)
] {
let input_cmd = shell_words::split(&input).expect("Input command must be a valid shell command");
Expand Down
20 changes: 11 additions & 9 deletions src/transaction_signature_options/sign_with_access_key_file/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use color_eyre::eyre::{ContextCompat, WrapErr};
use inquire::CustomType;
use near_primitives::transaction::Transaction;
use near_primitives::transaction::TransactionV0;

use crate::common::JsonRpcClientExt;
Expand Down Expand Up @@ -90,18 +91,19 @@ impl SignAccessKeyFileContext {
)
};

let mut unsigned_transaction =
near_primitives::transaction::Transaction::V0(TransactionV0 {
public_key: account_json.public_key.clone(),
block_hash,
nonce,
signer_id: previous_context.prepopulated_transaction.signer_id,
receiver_id: previous_context.prepopulated_transaction.receiver_id,
actions: previous_context.prepopulated_transaction.actions,
});
let mut unsigned_transaction = TransactionV0 {
public_key: account_json.public_key.clone(),
block_hash,
nonce,
signer_id: previous_context.prepopulated_transaction.signer_id,
receiver_id: previous_context.prepopulated_transaction.receiver_id,
actions: previous_context.prepopulated_transaction.actions,
};

(previous_context.on_before_signing_callback)(&mut unsigned_transaction, &network_config)?;

let unsigned_transaction = Transaction::V0(unsigned_transaction);

let signature = account_json
.private_key
.sign(unsigned_transaction.get_hash_and_size().0.as_ref());
Expand Down
20 changes: 11 additions & 9 deletions src/transaction_signature_options/sign_with_keychain/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use color_eyre::eyre::{ContextCompat, WrapErr};
use inquire::CustomType;
use near_primitives::transaction::Transaction;
use near_primitives::transaction::TransactionV0;
use tracing_indicatif::span_ext::IndicatifSpanExt;

Expand Down Expand Up @@ -181,18 +182,19 @@ impl SignKeychainContext {
)
};

let mut unsigned_transaction =
near_primitives::transaction::Transaction::V0(TransactionV0 {
public_key: account_json.public_key.clone(),
block_hash,
nonce,
signer_id: previous_context.prepopulated_transaction.signer_id,
receiver_id: previous_context.prepopulated_transaction.receiver_id,
actions: previous_context.prepopulated_transaction.actions,
});
let mut unsigned_transaction = TransactionV0 {
public_key: account_json.public_key.clone(),
block_hash,
nonce,
signer_id: previous_context.prepopulated_transaction.signer_id,
receiver_id: previous_context.prepopulated_transaction.receiver_id,
actions: previous_context.prepopulated_transaction.actions,
};

(previous_context.on_before_signing_callback)(&mut unsigned_transaction, &network_config)?;

let unsigned_transaction = Transaction::V0(unsigned_transaction);

let signature = account_json
.private_key
.sign(unsigned_transaction.get_hash_and_size().0.as_ref());
Expand Down
20 changes: 11 additions & 9 deletions src/transaction_signature_options/sign_with_ledger/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use inquire::CustomType;
use near_ledger::NEARLedgerError;
use near_primitives::action::delegate::SignedDelegateAction;
use near_primitives::borsh;
use near_primitives::transaction::Transaction;
use near_primitives::transaction::TransactionV0;

use crate::common::JsonRpcClientExt;
Expand Down Expand Up @@ -101,18 +102,19 @@ impl SignLedgerContext {
)
};

let mut unsigned_transaction =
near_primitives::transaction::Transaction::V0(TransactionV0 {
public_key: scope.signer_public_key.clone().into(),
block_hash,
nonce,
signer_id: previous_context.prepopulated_transaction.signer_id,
receiver_id: previous_context.prepopulated_transaction.receiver_id,
actions: previous_context.prepopulated_transaction.actions,
});
let mut unsigned_transaction = TransactionV0 {
public_key: scope.signer_public_key.clone().into(),
block_hash,
nonce,
signer_id: previous_context.prepopulated_transaction.signer_id,
receiver_id: previous_context.prepopulated_transaction.receiver_id,
actions: previous_context.prepopulated_transaction.actions,
};

(previous_context.on_before_signing_callback)(&mut unsigned_transaction, &network_config)?;

let unsigned_transaction = Transaction::V0(unsigned_transaction);

if network_config.meta_transaction_relayer_url.is_some() {
let max_block_height = block_height
+ scope
Expand Down
20 changes: 11 additions & 9 deletions src/transaction_signature_options/sign_with_legacy_keychain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::str::FromStr;

use color_eyre::eyre::{ContextCompat, WrapErr};
use inquire::{CustomType, Select};
use near_primitives::transaction::Transaction;
use near_primitives::transaction::TransactionV0;

use crate::common::JsonRpcClientExt;
Expand Down Expand Up @@ -176,18 +177,19 @@ impl SignLegacyKeychainContext {
)
};

let mut unsigned_transaction =
near_primitives::transaction::Transaction::V0(TransactionV0 {
public_key: signer_access_key.public_key.clone(),
block_hash,
nonce,
signer_id: previous_context.prepopulated_transaction.signer_id,
receiver_id: previous_context.prepopulated_transaction.receiver_id,
actions: previous_context.prepopulated_transaction.actions,
});
let mut unsigned_transaction = TransactionV0 {
public_key: signer_access_key.public_key.clone(),
block_hash,
nonce,
signer_id: previous_context.prepopulated_transaction.signer_id,
receiver_id: previous_context.prepopulated_transaction.receiver_id,
actions: previous_context.prepopulated_transaction.actions,
};

(previous_context.on_before_signing_callback)(&mut unsigned_transaction, &network_config)?;

let unsigned_transaction = Transaction::V0(unsigned_transaction);

if network_config.meta_transaction_relayer_url.is_some() {
let max_block_height = block_height
+ scope
Expand Down
Loading

0 comments on commit c19e525

Please sign in to comment.