-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: cleanup internals #329
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
776d18d
chore: cleanup Signer
b15592e
upd: cleanup
01520ca
cargo clippy
4ae2469
GasHook as pub(crate)
ac8f815
expt api docs
5d1cb6f
rm from_actions changes
bcaf17d
Merge branch 'main' into chore/cleanup-signer
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ use std::str::FromStr; | |
|
||
use borsh::{BorshDeserialize, BorshSerialize}; | ||
pub use near_account_id::AccountId; | ||
use near_primitives::transaction::{Action, SignedTransaction, Transaction}; | ||
|
||
use serde::{Deserialize, Serialize}; | ||
use sha2::Digest; | ||
|
@@ -27,8 +28,7 @@ use crate::result::Result; | |
|
||
pub use self::account::{AccountDetails, AccountDetailsPatch}; | ||
pub use self::chunk::{Chunk, ChunkHeader}; | ||
|
||
pub use self::gas_meter::{GasHook, GasMeter}; | ||
pub use self::gas_meter::GasMeter; | ||
|
||
/// Nonce is a unit used to determine the order of transactions in the pool. | ||
pub type Nonce = u64; | ||
|
@@ -292,13 +292,6 @@ impl InMemorySigner { | |
SecretKey(signer.secret_key), | ||
)) | ||
} | ||
|
||
pub(crate) fn inner(&self) -> near_crypto::InMemorySigner { | ||
near_crypto::InMemorySigner::from_secret_key( | ||
self.account_id.clone(), | ||
self.secret_key.0.clone(), | ||
) | ||
} | ||
} | ||
|
||
// type taken from near_primitives::hash::CryptoHash. | ||
|
@@ -528,3 +521,26 @@ impl From<Finality> for near_primitives::types::BlockReference { | |
value.into() | ||
} | ||
} | ||
|
||
/// A helper function to create a signed transaction with the given actions. | ||
pub(crate) fn signed_transaction( | ||
signer: &InMemorySigner, | ||
actions: Vec<Action>, | ||
nonce: near_primitives::types::Nonce, | ||
block_hash: near_primitives::hash::CryptoHash, | ||
receiver_id: &AccountId, | ||
) -> SignedTransaction { | ||
let tx = Transaction { | ||
signer_id: signer.account_id.clone(), | ||
public_key: signer.secret_key.public_key().0, | ||
nonce, | ||
receiver_id: receiver_id.clone(), | ||
block_hash: near_primitives::hash::CryptoHash(block_hash.0), | ||
actions, | ||
}; | ||
|
||
SignedTransaction::new( | ||
signer.secret_key.0.sign(tx.get_hash_and_size().0.as_ref()), | ||
tx, | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you shouldn't need to call into |
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer constructor method (
from_actions
or maybe other name) on SignedTransaction over a standalone function as it is harder to discover the function. What is exactly the motivation behind this change?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function is a reimplementation of
from_actions
without requiringSigner trait
as an argument. The hint I took here is that we can condense that implementation and remove the reliance on the trait.I could name it better.