diff --git a/e2e/src/main.rs b/e2e/src/main.rs index 5fd5db889..17d7344ec 100644 --- a/e2e/src/main.rs +++ b/e2e/src/main.rs @@ -95,15 +95,15 @@ pub mod tests { Ok(app_extrinsics) } - async fn query_row( + async fn query_rows( rpc: &Rpc, rows: &[usize], block_hash: H256, - ) -> anyhow::Result>>> { + ) -> anyhow::Result>> { let mut params = RpcParams::new(); params.push(rows)?; params.push(Some(block_hash))?; - let rows: Vec>> = rpc.request("kate_queryRows", params).await?; + let rows: Vec> = rpc.request("kate_queryRows", params).await?; Ok(rows) } @@ -179,21 +179,17 @@ pub mod tests { assert_eq!(grid.row(0), extended_grid.row(0)); assert_eq!(grid.row(0), extended_grid.row(1)); - // RPC call - let actual_rows = query_row(rpc, &[0, 1, 2], block_hash).await.unwrap(); + // RPC call: Querying non existing rows should fail + assert!(query_rows(rpc, &[2], block_hash).await.is_err()); - let mut expected_rows: Vec>> = Vec::new(); - let iter = [ - extended_grid.row(0), - extended_grid.row(1), - extended_grid.row(2), - ]; - for row in iter { + // RPC call: Querying existing rows should NOT fail + let actual_rows = query_rows(rpc, &[0, 1], block_hash).await.unwrap(); + + let mut expected_rows: Vec> = Vec::new(); + for row in [extended_grid.row(0), extended_grid.row(1)] { if let Some(row) = row { let flat_row: Vec = row.iter().flat_map(|r| r.to_bytes().unwrap()).collect(); - expected_rows.push(Some(flat_row)) - } else { - expected_rows.push(None); + expected_rows.push(flat_row); } } diff --git a/examples/deno/api_options.ts b/examples/deno/api_options.ts index 2f3aae9a1..3a7203bce 100644 --- a/examples/deno/api_options.ts +++ b/examples/deno/api_options.ts @@ -69,7 +69,7 @@ export const API_RPC = { isOptional: true } ], - type: 'Vec>>', + type: 'Vec>', } } } @@ -87,12 +87,12 @@ export const API_TYPES = { KateCommitment: { rows: 'Compact', cols: 'Compact', - dataRoot: 'H256', - commitment: 'Vec' + commitment: 'Vec', + dataRoot: 'H256' }, V1HeaderExtension: { - commitment: 'KateCommitment', - appLookup: 'DataLookup' + appLookup: 'DataLookup', + commitment: 'KateCommitment' }, VTHeaderExtension: { newField: 'Vec', diff --git a/examples/ts/README.md b/examples/ts/README.md index 9a333a91b..2309d3905 100644 --- a/examples/ts/README.md +++ b/examples/ts/README.md @@ -69,7 +69,7 @@ export default { ``` - Query application data returns data fot the given application id and block hash. ``` - ts-node ts-node query_app_data.ts + ts-node query_app_data.ts ``` - Creation of app_id ``` @@ -78,7 +78,7 @@ export default { Here `i` is the app_id that we would like to create(default is 1). - Submit a proposal using the council. ``` - ts-node ts-node submit_proposal.ts + ts-node submit_proposal.ts ``` You can also use yarn commands to run the scripts. For example - Start by building the project: diff --git a/rpc/kate-rpc/src/lib.rs b/rpc/kate-rpc/src/lib.rs index cf234bec0..bb08a1ca4 100644 --- a/rpc/kate-rpc/src/lib.rs +++ b/rpc/kate-rpc/src/lib.rs @@ -43,7 +43,7 @@ where &self, rows: Vec, at: Option>, - ) -> RpcResult>>>; + ) -> RpcResult>>; #[method(name = "kate_queryAppData")] async fn query_app_data( @@ -271,22 +271,24 @@ where &self, rows: Vec, at: Option>, - ) -> RpcResult>>> { + ) -> RpcResult>> { let signed_block = self.get_signed_and_finalized_block(at)?; let evals = self.get_eval_grid(&signed_block).await?; - let rows: Vec>> = rows - .iter() - .map(|i| { - evals.row(*i as usize).map(|row| { - row.iter() - .flat_map(|a| a.to_bytes().expect("Ser cannot fail")) - .collect::>() - }) - }) - .collect(); + let mut data_rows = Vec::with_capacity(rows.len()); + for index in rows { + let Some(data) = evals.row(index as usize) else { + return Err(internal_err!("Non existing row: {:?}", index)); + }; + let data: Vec = data + .iter() + .flat_map(|a| a.to_bytes().expect("Ser cannot fail")) + .collect(); + + data_rows.push(data); + } - Ok(rows) + Ok(data_rows) } async fn query_app_data(