pub struct InMemorySigner {
pub account_id: AccountId,
pub public_key: PublicKey,
pub secret_key: SecretKey,
}
Expand description
Signer that keeps secret key in memory.
Fields§
§account_id: AccountId
§public_key: PublicKey
§secret_key: SecretKey
Implementations§
Source§impl InMemorySigner
impl InMemorySigner
pub fn from_seed( account_id: AccountId, key_type: KeyType, seed: &str, ) -> InMemorySigner
Sourcepub fn from_secret_key(
account_id: AccountId,
secret_key: SecretKey,
) -> InMemorySigner
pub fn from_secret_key( account_id: AccountId, secret_key: SecretKey, ) -> InMemorySigner
Examples found in repository?
examples/create_account.rs (line 20)
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
async fn main() -> Result<(), Box<dyn std::error::Error>> {
env_logger::init();
let signer_account_id: AccountId = utils::input("Enter the signer Account ID: ")?.parse()?;
let signer_secret_key = utils::input("Enter the signer's private key: ")?.parse()?;
//To-do, implement account exist check.
let new_account_id: AccountId = utils::input("Enter new account name: ")?.parse()?;
let signer = InMemorySigner::from_secret_key(signer_account_id.clone(), signer_secret_key);
// Amount to transfer to the new account
let gas: Gas = 100_000_000_000_000; // Example amount in yoctoNEAR
let amount: Balance = 10_000_000_000_000_000_000_000; // Example amount in yoctoNEAR
let new_secret_key = near_crypto::SecretKey::from_random(near_crypto::KeyType::ED25519);
let provider = Arc::new(JsonRpcProvider::new("https://rpc.testnet.near.org"));
let signer = Arc::new(signer);
let account = Account::new(signer_account_id, signer, provider);
let contract_id: AccountId = "testnet".parse::<AccountId>()?;
let method_name = "create_account".to_string();
let args_json = json!({
"new_account_id": new_account_id,
"new_public_key": new_secret_key.public_key()
});
let result = account
.function_call(contract_id, method_name, args_json, gas, amount)
.await;
println!("response: {:#?}", result);
println!("New Account ID: {}", new_account_id);
println!("Secret Key: {}", new_secret_key);
Ok(())
}
More examples
examples/contract_change_method_commit.rs (line 27)
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
async fn main() -> Result<(), Box<dyn std::error::Error>> {
env_logger::init();
let client = JsonRpcClient::connect("https://rpc.testnet.near.org");
let provider = JsonRpcProvider::new("https://rpc.testnet.near.org");
let signer_account_id = utils::input("Enter the signer Account ID: ")?.parse()?;
let signer_secret_key = utils::input("Enter the signer's private key: ")?.parse()?;
let signer = near_crypto::InMemorySigner::from_secret_key(signer_account_id, signer_secret_key);
let access_key_query_response = client
.call(methods::query::RpcQueryRequest {
block_reference: BlockReference::latest(),
request: near_primitives::views::QueryRequest::ViewAccessKey {
account_id: signer.account_id.clone(),
public_key: signer.public_key.clone(),
},
})
.await?;
let current_nonce = match access_key_query_response.kind {
QueryResponseKind::AccessKey(access_key) => access_key.nonce,
_ => Err("failed to extract current nonce")?,
};
let other_account = utils::input("Enter the account to be rated: ")?;
let rating = utils::input("Enter a rating: ")?.parse::<f32>()?;
let transaction = Transaction {
signer_id: signer.account_id.clone(),
public_key: signer.public_key.clone(),
nonce: current_nonce + 1,
receiver_id: "nosedive.testnet".parse()?,
block_hash: access_key_query_response.block_hash,
actions: vec![Action::FunctionCall(Box::new(FunctionCallAction {
method_name: "rate".to_string(),
args: json!({
"account_id": other_account,
"rating": rating,
})
.to_string()
.into_bytes(),
gas: 100_000_000_000_000, // 100 TeraGas
deposit: 0,
}))],
};
let response = provider.send_transaction(transaction.sign(&signer)).await?;
println!("response: {:#?}", response);
Ok(())
}
pub fn from_file(path: &Path) -> Result<InMemorySigner, Error>
Source§impl InMemorySigner
impl InMemorySigner
pub fn from_random(account_id: AccountId, key_type: KeyType) -> InMemorySigner
Trait Implementations§
Source§impl Clone for InMemorySigner
impl Clone for InMemorySigner
Source§fn clone(&self) -> InMemorySigner
fn clone(&self) -> InMemorySigner
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl<'de> Deserialize<'de> for InMemorySigner
impl<'de> Deserialize<'de> for InMemorySigner
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<InMemorySigner, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<InMemorySigner, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl From<KeyFile> for InMemorySigner
impl From<KeyFile> for InMemorySigner
Source§fn from(key_file: KeyFile) -> InMemorySigner
fn from(key_file: KeyFile) -> InMemorySigner
Converts to this type from the input type.
Source§impl PartialEq for InMemorySigner
impl PartialEq for InMemorySigner
Source§impl Serialize for InMemorySigner
impl Serialize for InMemorySigner
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
Source§impl Signer for InMemorySigner
impl Signer for InMemorySigner
fn public_key(&self) -> PublicKey
fn sign(&self, data: &[u8]) -> Signature
fn compute_vrf_with_proof(&self, data: &[u8]) -> (Value, Proof)
Source§fn write_to_file(&self, path: &Path) -> Result<(), Error>
fn write_to_file(&self, path: &Path) -> Result<(), Error>
Used by test infrastructure, only implement if make sense for testing otherwise raise
unimplemented
.fn verify(&self, data: &[u8], signature: &Signature) -> bool
impl Eq for InMemorySigner
impl StructuralPartialEq for InMemorySigner
Auto Trait Implementations§
impl Freeze for InMemorySigner
impl RefUnwindSafe for InMemorySigner
impl Send for InMemorySigner
impl Sync for InMemorySigner
impl Unpin for InMemorySigner
impl UnwindSafe for InMemorySigner
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.