Skip to content

Commit e0255da

Browse files
authored
feat: add block number parameter for view methods (#99)
1 parent 1fcd320 commit e0255da

File tree

7 files changed

+37
-12
lines changed

7 files changed

+37
-12
lines changed

.github/workflows/cli.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ on:
1010
jobs:
1111
shell_tests:
1212
name: Tests ${{ matrix.interface }} CLI
13-
runs-on: selfhosted-heavy
14-
container:
15-
image: rust:latest
13+
runs-on: k8s-infrastructure-native
14+
container: rust:latest
1615
strategy:
1716
matrix:
1817
interface: [ Advanced, Simple, Silo ]
@@ -32,7 +31,7 @@ jobs:
3231
- name: Install dependencies
3332
run: |
3433
apt update
35-
apt install -y jq python3-venv
34+
apt install -y bash jq python3-venv
3635
- name: Install aurora-cli
3736
uses: actions-rs/cargo@v1
3837
with:

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,7 @@ Commands:
437437

438438
Options:
439439
--network <NETWORK> NEAR network ID [default: localnet]
440+
--block-number <BLOCK_NUMBER> Block number to use for the view command
440441
--engine <ACCOUNT_ID> Aurora EVM account [default: aurora]
441442
--near-key-path <NEAR_KEY_PATH> Path to file with NEAR account id and secret key in JSON format
442443
-h, --help Print help
@@ -1290,4 +1291,4 @@ Options:
12901291
--full-access-pub-key <FULL_ACCESS_PUB_KEY>
12911292
--function-call-pub-key <FUNCTION_CALL_PUB_KEY>
12921293
-h, --help Print help
1293-
```
1294+
```

cli/src/cli/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ pub use advanced::{Cli, run};
1010
pub use simple::{Cli, command, run};
1111

1212
/// NEAR Endpoints.
13-
const NEAR_MAINNET_ENDPOINT: &str = "https://rpc.mainnet.near.org/";
14-
const NEAR_TESTNET_ENDPOINT: &str = "https://rpc.testnet.near.org/";
13+
const NEAR_MAINNET_ENDPOINT: &str = "https://archival-rpc.mainnet.near.org/";
14+
const NEAR_TESTNET_ENDPOINT: &str = "https://archival-rpc.testnet.near.org/";
1515
#[cfg(feature = "simple")]
1616
const NEAR_LOCAL_ENDPOINT: &str = "http://127.0.0.1:3030/";
1717
/// Aurora Endpoints.

cli/src/cli/simple/command/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,7 @@ pub async fn transaction_status(
878878
.transaction_status(tx_hash, wait_until.into())
879879
.await?;
880880

881-
println!("{}", serde_json::to_string_pretty(&rsp)?);
881+
println!("{}", to_string_pretty(&rsp)?);
882882

883883
Ok(())
884884
}
@@ -891,7 +891,7 @@ async fn get_value<T: FromCallResult + Display>(
891891
let result = context
892892
.client
893893
.near()
894-
.view_call(method_name, args.unwrap_or_default())
894+
.view_call_for_block(method_name, args.unwrap_or_default(), context.block_number)
895895
.await?;
896896
let output = T::from_result(result)?;
897897
println!("{output}");

cli/src/cli/simple/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ pub struct Cli {
3636
/// Path to file with NEAR account id and secret key in JSON format
3737
#[arg(long)]
3838
pub near_key_path: Option<String>,
39+
/// NEAR block number to use for getting data
40+
#[arg(long)]
41+
pub block_number: Option<u64>,
3942
#[clap(subcommand)]
4043
pub command: Command,
4144
}
@@ -465,7 +468,7 @@ pub async fn run(args: Cli) -> anyhow::Result<()> {
465468
Network::Localnet => super::NEAR_LOCAL_ENDPOINT,
466469
};
467470
let client = crate::client::Client::new(near_rpc, &args.engine, args.near_key_path);
468-
let context = crate::client::Context::new(client, args.output_format);
471+
let context = crate::client::Context::new(client, args.output_format, args.block_number);
469472

470473
match args.command {
471474
Command::GetChainId => command::get_chain_id(context).await?,

cli/src/client/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,20 @@ type NearCallError = near_jsonrpc_client::errors::JsonRpcError<
3030
pub struct Context {
3131
pub client: Client,
3232
pub output_format: OutputFormat,
33+
pub block_number: Option<u64>,
3334
}
3435

3536
#[cfg(feature = "simple")]
3637
impl Context {
37-
pub const fn new(client: Client, output_format: OutputFormat) -> Self {
38+
pub const fn new(
39+
client: Client,
40+
output_format: OutputFormat,
41+
block_number: Option<u64>,
42+
) -> Self {
3843
Self {
3944
client,
4045
output_format,
46+
block_number,
4147
}
4248
}
4349
}

cli/src/client/near.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,24 @@ impl NearClient {
170170
method_name: &str,
171171
args: Vec<u8>,
172172
) -> anyhow::Result<views::CallResult> {
173+
self.view_call_for_block(method_name, args, None).await
174+
}
175+
176+
pub async fn view_call_for_block(
177+
&self,
178+
method_name: &str,
179+
args: Vec<u8>,
180+
block_number: Option<u64>,
181+
) -> anyhow::Result<views::CallResult> {
182+
let block_reference = block_number.map_or_else(
183+
|| Finality::Final.into(),
184+
|block_number| {
185+
BlockReference::BlockId(near_primitives::types::BlockId::Height(block_number))
186+
},
187+
);
188+
173189
let request = methods::query::RpcQueryRequest {
174-
block_reference: Finality::Final.into(),
190+
block_reference,
175191
request: views::QueryRequest::CallFunction {
176192
account_id: self.engine_account_id.clone(),
177193
method_name: method_name.to_string(),

0 commit comments

Comments
 (0)