diff --git a/near-accounts/examples/multi-thread.rs b/near-accounts/examples/multi-thread.rs new file mode 100644 index 0000000..b543fd2 --- /dev/null +++ b/near-accounts/examples/multi-thread.rs @@ -0,0 +1,62 @@ +use near_accounts::Account; +use near_crypto::{InMemorySigner,SecretKey}; +use near_primitives::{types::Gas, views::FinalExecutionOutcomeViewEnum}; +use near_providers::JsonRpcProvider; +use std::sync::Arc; +mod utils; +use near_primitives::types::{AccountId, Balance}; +use serde_json::json; + +#[tokio::main] +async fn main() -> Result<(), Box> { + env_logger::init(); + + // Initialization and user inputs as before + + let signer_account_id: AccountId = "near-api-rs.testnet".parse::()?; + let signer_secret_key = "ed25519:29nYmQCZMsQeYtztXZzm57ayQt2uBHXdn2SAjK4ccMGSQaNUFNJ7Aoteno81eKTex9cGBbk1FuDuqJRsdzx34xDY".parse::()?; + + let provider = Arc::new(JsonRpcProvider::new("https://rpc.testnet.near.org")); + //let provider = JsonRpcProvider::new("https://rpc.testnet.near.org"); + let signer = Arc::new(InMemorySigner::from_secret_key(signer_account_id.clone(), signer_secret_key)); + let account = Account::new(signer_account_id, signer.clone(), provider.clone()); + + let contract_id: AccountId = "contract.near-api-rs.testnet".parse::()?; + + // This spawns a new asynchronous task to handle account creation + let handle = tokio::spawn(async move { + + let method_name = "set_status".to_string(); + let args_json = json!({"message": "working1"}); + + // 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 result = account + .function_call(&contract_id, method_name, args_json, gas, amount) + .await; + //.await.expect("Reason") + //.transact() + //.await; + + // match result { + // Ok(res) => match &res.final_execution_outcome { + // Some(FinalExecutionOutcomeViewEnum::FinalExecutionOutcome(outcome)) => { + // println!("Final Execution outcome: {:?}", outcome); + // }, + // Some(FinalExecutionOutcomeViewEnum::FinalExecutionOutcomeWithReceipt(outcome_receipt)) => { + // println!("Final Execution outcome with receipt: {:?}", outcome_receipt); + // }, + // None => println!("No Final execution outcome."), + // }, + // Err(err) => println!("Error: {:#?}", err), + // } + println!("Result - {:#?}",result); + }); + + // You can do more work here or wait for the handle if needed + handle.await?; + + Ok(()) +} diff --git a/near-accounts/src/accounts.rs b/near-accounts/src/accounts.rs index 44df053..2731d3d 100644 --- a/near-accounts/src/accounts.rs +++ b/near-accounts/src/accounts.rs @@ -112,8 +112,10 @@ impl TransactionSender { /// Represents a NEAR account, encapsulating account ID, signer, and provider for blockchain interaction. pub struct Account { pub account_id: AccountId, - pub signer: Arc, // Use your Signer abstraction - pub provider: Arc, // Use your Provider abstraction + //pub signer: Arc, // Use your Signer abstraction + pub signer: Arc, // Use your Signer abstraction + //pub provider: Arc, // Use your Provider abstraction + provider: Arc, } /// Represents the balance details of a NEAR account. @@ -139,8 +141,8 @@ impl Account { /// A new `Account` instance. pub fn new( account_id: AccountId, - signer: Arc, - provider: Arc, + signer: Arc, + provider: Arc, ) -> Self { Self { account_id,