Skip to content

Commit

Permalink
chore: updated near-* to 0.24.0, bumped up rust version (#381)
Browse files Browse the repository at this point in the history
Resolves: #384
  • Loading branch information
akorchyn authored Aug 13, 2024
1 parent 5adcfae commit ad72da4
Show file tree
Hide file tree
Showing 19 changed files with 607 additions and 1,221 deletions.
1,618 changes: 487 additions & 1,131 deletions Cargo.lock

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ slipped10 = { version = "0.4.6" }
url = { version = "2", features = ["serde"] }
open = "5"
shell-words = "1"
cargo-util = "0.1.1"
cargo-util = "0.2"
indicatif = "0.17.8"
indenter = "0.3"
tracing = "0.1.40"
Expand All @@ -61,7 +61,7 @@ tracing-subscriber = { version = "0.3", features = ["env-filter"] }
wasmparser = "0.211"

semver = { version = "1.0.4", optional = true }
self_update = { version = "0.40.0", features = [
self_update = { version = "0.41.0", features = [
"archive-tar",
"compression-flate2",
], optional = true }
Expand All @@ -73,31 +73,31 @@ bytesize = "1.1.0"
prettytable = "0.10.0"
textwrap = "0.16.1"

near-ledger = { version = "0.7.1", optional = true }
near-ledger = { version = "0.7.2", optional = true }

near-crypto = "0.23"
near-primitives = "0.23"
near-jsonrpc-client = "0.10.1"
near-jsonrpc-primitives = "0.23"
near-crypto = "0.24"
near-primitives = "0.24"
near-jsonrpc-client = "0.11"
near-jsonrpc-primitives = "0.24"

near-gas = { version = "0.2.3", features = [
near-gas = { version = "0.3", features = [
"serde",
"borsh",
"interactive-clap",
] }
near-token = { version = "0.2.0", features = [
near-token = { version = "0.3", features = [
"serde",
"borsh",
"interactive-clap",
] }
near-socialdb-client = "0.3.1"
near-socialdb-client = "0.5"

near-abi = "0.4.2"
zstd = "0.13"

keyring = "2.0.5"
interactive-clap = "0.2.10"
interactive-clap-derive = "0.2.10"
keyring = "3.0.5"
interactive-clap = "0.3"
interactive-clap-derive = "0.3"

rust_decimal = "1.35.0"

Expand Down Expand Up @@ -132,7 +132,7 @@ windows-archive = ".tar.gz"
unix-archive = ".tar.gz"
# Publish jobs to run in CI
pr-run-mode = "upload"
# XXX: In order to use custom GITHUB_TOKEN to trigger npm-publish workflow,
# XXX: In order to use custom GITHUB_TOKEN to trigger npm-publish workflow,
# we allow dirty CI scripts to avoid cargo-dist complains.
allow-dirty = ["ci"]

Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.78
1.80
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl From<SaveKeypairToKeychainContext> for crate::commands::ActionContext {
let account_id = match transaction {
crate::transaction_signature_options::SignedTransactionOrSignedDelegateAction::SignedTransaction(
signed_transaction,
) => signed_transaction.transaction.signer_id.clone(),
) => signed_transaction.transaction.signer_id().clone(),
crate::transaction_signature_options::SignedTransactionOrSignedDelegateAction::SignedDelegateAction(
signed_delegate_action,
) => signed_delegate_action.delegate_action.sender_id.clone()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl From<SaveKeypairToLegacyKeychainContext> for crate::commands::ActionContext
let account_id = match transaction {
crate::transaction_signature_options::SignedTransactionOrSignedDelegateAction::SignedTransaction(
signed_transaction,
) => signed_transaction.transaction.signer_id.clone(),
) => signed_transaction.transaction.signer_id().clone(),
crate::transaction_signature_options::SignedTransactionOrSignedDelegateAction::SignedDelegateAction(
signed_delegate_action,
) => signed_delegate_action.delegate_action.sender_id.clone()
Expand Down
10 changes: 6 additions & 4 deletions src/commands/account/update_social_profile/sign_as.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,19 @@ 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();

if let near_primitives::transaction::Action::FunctionCall(action) =
&mut prepopulated_unsigned_transaction.actions[0]
if let Some(near_primitives::transaction::Action::FunctionCall(action)) =
prepopulated_unsigned_transaction.actions_mut().get_mut(0)
{
action.deposit = get_deposit(
&json_rpc_client,
&signer_account_id,
&prepopulated_unsigned_transaction.public_key,
&public_key,
&account_id,
"profile",
&prepopulated_unsigned_transaction.receiver_id,
&receiver_id,
near_token::NearToken::from_yoctonear(action.deposit),
)?
.as_yoctonear();
Expand Down
6 changes: 3 additions & 3 deletions src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ pub struct PrepopulatedTransaction {
impl From<near_primitives::transaction::Transaction> for PrepopulatedTransaction {
fn from(value: near_primitives::transaction::Transaction) -> Self {
Self {
signer_id: value.signer_id,
receiver_id: value.receiver_id,
actions: value.actions,
signer_id: value.signer_id().clone(),
receiver_id: value.receiver_id().clone(),
actions: value.take_actions(),
}
}
}
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 =
*prepopulated_unsigned_transaction.actions_mut() =
vec![near_primitives::transaction::Action::Delegate(Box::new(
previous_context.signed_delegate_action.clone(),
))];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl Network {
) -> color_eyre::eyre::Result<Option<String>> {
crate::common::input_network_name(
&context.config,
&[context.signed_transaction.transaction.receiver_id.clone()],
&[context.signed_transaction.transaction.receiver_id().clone()],
)
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/commands/transaction/sign_transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 17 additions & 4 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -559,9 +559,9 @@ pub fn print_full_unsigned_transaction(transaction: near_primitives::transaction
transaction.get_hash_and_size().0
);

eprintln!("{:<13} {}", "public_key:", &transaction.public_key);
eprintln!("{:<13} {}", "nonce:", &transaction.nonce);
eprintln!("{:<13} {}", "block_hash:", &transaction.block_hash);
eprintln!("{:<13} {}", "public_key:", &transaction.public_key());
eprintln!("{:<13} {}", "nonce:", &transaction.nonce());
eprintln!("{:<13} {}", "block_hash:", &transaction.block_hash());

let prepopulated = crate::commands::PrepopulatedTransaction::from(transaction);
print_unsigned_transaction(&prepopulated);
Expand Down Expand Up @@ -1104,7 +1104,7 @@ pub fn convert_invalid_tx_error_to_cli_result(
color_eyre::eyre::Result::Err(color_eyre::eyre::eyre!("Error: The attached amount of gas in a FunctionCall action has to be a positive number."))
}
near_primitives::errors::ActionsValidationError::DelegateActionMustBeOnlyOne => {
color_eyre::eyre::Result::Err(color_eyre::eyre::eyre!("Error: DelegateActionMustBeOnlyOne"))
color_eyre::eyre::Result::Err(color_eyre::eyre::eyre!("Error: The transaction contains more than one delegation action"))
}
near_primitives::errors::ActionsValidationError::UnsupportedProtocolFeature { protocol_feature, version } => {
color_eyre::eyre::Result::Err(color_eyre::eyre::eyre!("Error: Protocol Feature {} is unsupported in version {}", protocol_feature, version))
Expand All @@ -1114,6 +1114,19 @@ pub fn convert_invalid_tx_error_to_cli_result(
near_primitives::errors::InvalidTxError::TransactionSizeExceeded { size, limit } => {
color_eyre::eyre::Result::Err(color_eyre::eyre::eyre!("Error: The size ({}) of serialized transaction exceeded the limit ({}).", size, limit))
}
near_primitives::errors::InvalidTxError::InvalidTransactionVersion => {
color_eyre::eyre::Result::Err(color_eyre::eyre::eyre!("Error: Invalid transaction version"))
},
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::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::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
29 changes: 16 additions & 13 deletions src/transaction_signature_options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,26 +141,29 @@ pub fn get_signed_delegate_action(
) -> near_primitives::action::delegate::SignedDelegateAction {
use near_primitives::signable_message::{SignableMessage, SignableMessageType};

let actions = unsigned_transaction
.actions
let mut delegate_action = near_primitives::action::delegate::DelegateAction {
sender_id: unsigned_transaction.signer_id().clone(),
receiver_id: unsigned_transaction.receiver_id().clone(),
actions: vec![],
nonce: unsigned_transaction.nonce(),
max_block_height,
public_key: unsigned_transaction.public_key().clone(),
};

delegate_action.actions = unsigned_transaction
.take_actions()
.into_iter()
.map(near_primitives::action::delegate::NonDelegateAction::try_from)
.collect::<Result<_, _>>()
.expect("Internal error: can not convert the action to non delegate action (delegate action can not be delegated again).");
let delegate_action = near_primitives::action::delegate::DelegateAction {
sender_id: unsigned_transaction.signer_id.clone(),
receiver_id: unsigned_transaction.receiver_id,
actions,
nonce: unsigned_transaction.nonce,
max_block_height,
public_key: unsigned_transaction.public_key,
};

// create a new signature here signing the delegate action + discriminant
let signable = SignableMessage::new(&delegate_action, SignableMessageType::DelegateAction);
let signer =
near_crypto::InMemorySigner::from_secret_key(unsigned_transaction.signer_id, private_key);
let signature = signable.sign(&signer);
let signer = near_crypto::InMemorySigner::from_secret_key(
delegate_action.sender_id.clone(),
private_key,
);
let signature = signable.sign(&near_crypto::Signer::InMemory(signer));

eprintln!("\nYour delegating action was signed successfully.");
eprintln!("Note that the signed transaction is valid until block {max_block_height}. You can change the validity of a transaction by setting a flag in the command: --meta-transaction-valid-for 2000");
Expand Down
5 changes: 3 additions & 2 deletions src/transaction_signature_options/sign_later/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use near_primitives::transaction::TransactionV0;
use strum::{EnumDiscriminants, EnumIter, EnumMessage};

mod display;
Expand Down Expand Up @@ -30,14 +31,14 @@ impl SignLaterContext {
previous_context: crate::commands::TransactionContext,
scope: &<SignLater as interactive_clap::ToInteractiveClapContextScope>::InteractiveClapContextScope,
) -> color_eyre::eyre::Result<Self> {
let unsigned_transaction = near_primitives::transaction::Transaction {
let unsigned_transaction = near_primitives::transaction::Transaction::V0(TransactionV0 {
signer_id: previous_context.prepopulated_transaction.signer_id,
public_key: scope.signer_public_key.clone().into(),
nonce: scope.nonce,
receiver_id: previous_context.prepopulated_transaction.receiver_id,
block_hash: scope.block_hash.into(),
actions: previous_context.prepopulated_transaction.actions,
};
});
Ok(Self {
unsigned_transaction,
})
Expand Down
18 changes: 10 additions & 8 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::TransactionV0;

use crate::common::JsonRpcClientExt;
use crate::common::RpcQueryResponseExt;
Expand Down Expand Up @@ -89,14 +90,15 @@ impl SignAccessKeyFileContext {
)
};

let mut unsigned_transaction = near_primitives::transaction::Transaction {
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 =
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,
});

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

Expand Down
18 changes: 10 additions & 8 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::TransactionV0;
use tracing_indicatif::span_ext::IndicatifSpanExt;

use crate::common::JsonRpcClientExt;
Expand Down Expand Up @@ -159,14 +160,15 @@ impl SignKeychainContext {
.wrap_err("Error current_nonce")?
.nonce;

let mut unsigned_transaction = near_primitives::transaction::Transaction {
public_key: account_json.public_key.clone(),
block_hash: rpc_query_response.block_hash,
nonce: current_nonce + 1,
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 =
near_primitives::transaction::Transaction::V0(TransactionV0 {
public_key: account_json.public_key.clone(),
block_hash: rpc_query_response.block_hash,
nonce: current_nonce + 1,
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)?;

Expand Down
18 changes: 10 additions & 8 deletions src/transaction_signature_options/sign_with_ledger/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use color_eyre::eyre::{ContextCompat, WrapErr};
use inquire::CustomType;
use near_ledger::NEARLedgerError;
use near_primitives::borsh;
use near_primitives::transaction::TransactionV0;

use crate::common::JsonRpcClientExt;
use crate::common::RpcQueryResponseExt;
Expand Down Expand Up @@ -86,14 +87,15 @@ impl SignLedgerContext {
(current_nonce + 1, rpc_query_response.block_hash)
};

let mut unsigned_transaction = near_primitives::transaction::Transaction {
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 =
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,
});

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

Expand Down
18 changes: 10 additions & 8 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::TransactionV0;

use crate::common::JsonRpcClientExt;
use crate::common::RpcQueryResponseExt;
Expand Down Expand Up @@ -195,14 +196,15 @@ impl SignLegacyKeychainContext {
)
};

let mut unsigned_transaction = near_primitives::transaction::Transaction {
public_key: account_json.public_key.clone(),
block_hash,
nonce,
signer_id: previous_context.prepopulated_transaction.signer_id.clone(),
receiver_id: previous_context.prepopulated_transaction.receiver_id,
actions: previous_context.prepopulated_transaction.actions,
};
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,
});

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

Expand Down
Loading

0 comments on commit ad72da4

Please sign in to comment.