Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
c61c477
Introduce a helper function
dmitrylavrenov Jan 9, 2023
c8bc8f9
Merge branch 'master' into jsonrpseeerror-creation
dmitrylavrenov Jan 9, 2023
b00539e
Introduce validator related errors
dmitrylavrenov Jan 9, 2023
0a0d8c5
Rename ValidatorError to ValidatorKeyError
dmitrylavrenov Jan 10, 2023
06ed0c3
Introduce RobonodeError
dmitrylavrenov Jan 10, 2023
bccc884
Introduce TxPoolError
dmitrylavrenov Jan 10, 2023
427e927
Change a way of representation
dmitrylavrenov Jan 10, 2023
ebfb37e
Introduce signer error
dmitrylavrenov Jan 10, 2023
e126798
Add runtime api error
dmitrylavrenov Jan 10, 2023
2f3d444
Add docs
dmitrylavrenov Jan 10, 2023
ebbe219
Use thiserror as a part of the message
dmitrylavrenov Jan 10, 2023
d333484
Move errors into separate crate
dmitrylavrenov Jan 11, 2023
e0d27c4
Use introduced errors ar author-ext-rpc
dmitrylavrenov Jan 11, 2023
b91bbbc
Rename error message
dmitrylavrenov Jan 11, 2023
2f0e6c6
Use native and unexpected options for transaction pool errors
dmitrylavrenov Jan 12, 2023
6096a0d
Add tests for validator errors
dmitrylavrenov Jan 12, 2023
65a993e
Add signer error tests
dmitrylavrenov Jan 12, 2023
bb4d2a4
Add robonode error tests
dmitrylavrenov Jan 12, 2023
29d4dd8
Edit data for MissingValidatorKey
dmitrylavrenov Jan 12, 2023
f3d4d08
Add runtime api error tests
dmitrylavrenov Jan 12, 2023
3a60c6a
Add tx pool error tests
dmitrylavrenov Jan 12, 2023
f26c84b
Reorganize error crate
dmitrylavrenov Jan 12, 2023
7c2eb08
Use a separate crate for validator key rpc logic
dmitrylavrenov Jan 13, 2023
277015f
Define SetKeysError at author-ext-rpc
dmitrylavrenov Jan 26, 2023
d84cc46
Remove unused runtime_api error mod
dmitrylavrenov Jan 26, 2023
178644d
Edit comments for set_keys error
dmitrylavrenov Jan 26, 2023
9de4b46
Refactor tx pool error logic for autho-ext-rpc
dmitrylavrenov Jan 26, 2023
136ebcd
Simplify validator key extraction error logic at author-ext-rpc
dmitrylavrenov Jan 26, 2023
b906270
Refactor author-ext-rpc errors logic
dmitrylavrenov Jan 26, 2023
72e6b08
Use tx pool error as a kind of set keys error
dmitrylavrenov Jan 26, 2023
3ec926a
Edit mod docs
dmitrylavrenov Jan 26, 2023
ed2ca4c
Introduce authenticate errors
dmitrylavrenov Jan 27, 2023
f830f27
Introduce enroll errors
dmitrylavrenov Jan 27, 2023
c8386f3
Introduce bioauth status errors
dmitrylavrenov Jan 27, 2023
8fb4d98
Reimplement bioauth tx poll errors
dmitrylavrenov Jan 27, 2023
ace03e6
Robonode errors separate logic
dmitrylavrenov Jan 27, 2023
ac807a1
Apply redesigned errors to bioauth rpc
dmitrylavrenov Jan 27, 2023
59ba31d
Rename signer to sign and correct use
MOZGIII Jan 27, 2023
ee8d381
Optimise meaningful things in the implementation and other corrections
MOZGIII Jan 28, 2023
ef13695
Refactor author-ext-rpc errors based on review suggestions
dmitrylavrenov Jan 30, 2023
6c56276
Remove prefix from errors
dmitrylavrenov Jan 30, 2023
e043692
Use common lib for utility functions for producing rpc error responses
dmitrylavrenov Jan 30, 2023
9718e35
Remove unused deps
dmitrylavrenov Jan 30, 2023
1e078b7
Edit docs for transaction pool errors
dmitrylavrenov Jan 30, 2023
5f17863
Fix typos
dmitrylavrenov Jan 30, 2023
7ba285a
Edit docs for errors mods
dmitrylavrenov Jan 30, 2023
dbefa90
Add tests for get_validator_public_key method
dmitrylavrenov Jan 31, 2023
d7376b7
Add tests for set_keys method
dmitrylavrenov Jan 31, 2023
9a9f275
Add tests for status method
dmitrylavrenov Jan 31, 2023
c7b6daa
Add tests fpr get_facetec_session_token method
dmitrylavrenov Jan 31, 2023
82c6842
Add tests fpr get_facetec_device_sdk_params method
dmitrylavrenov Jan 31, 2023
c5dcd76
Add tests for enroll method
dmitrylavrenov Jan 31, 2023
b1c8af2
Add tests for authenticate method
dmitrylavrenov Jan 31, 2023
6bc2148
Merge branch 'master' into jsonrpseeerror-creation
dmitrylavrenov Feb 2, 2023
c326cb8
Fix cargo clippy
dmitrylavrenov Feb 2, 2023
f4a804d
Edit docs for rpc-validator-key-logic
dmitrylavrenov Feb 2, 2023
a38376b
Better match catching
dmitrylavrenov Feb 2, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions crates/author-ext-rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@ publish = false
author-ext-api = { version = "0.1", path = "../author-ext-api" }
bioauth-keys = { version = "0.1", path = "../bioauth-keys" }
rpc-deny-unsafe = { path = "../rpc-deny-unsafe" }
rpc-error-response = { path = "../rpc-error-response" }
rpc-validator-key-logic = { version = "0.1", path = "../rpc-validator-key-logic" }

jsonrpsee = { version = "0.15.1", features = ["server", "macros"] }
sc-transaction-pool-api = { git = "https://github.com/humanode-network/substrate", branch = "locked/humanode-2022-11-23" }
serde = "1"
sp-api = { git = "https://github.com/humanode-network/substrate", branch = "locked/humanode-2022-11-23" }
sp-blockchain = { git = "https://github.com/humanode-network/substrate", branch = "locked/humanode-2022-11-23" }
sp-core = { git = "https://github.com/humanode-network/substrate", branch = "locked/humanode-2022-11-23" }
sp-runtime = { git = "https://github.com/humanode-network/substrate", branch = "locked/humanode-2022-11-23" }
tracing = "0.1"

[dev-dependencies]
serde_json = "1"
23 changes: 23 additions & 0 deletions crates/author-ext-rpc/src/error_data.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//! The shapes and variants of the custom error data.

use serde::Serialize;

/// The RPC error context we provide to describe transaction pool errors.
#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct AuthorExtTxErrorDetails {
/// The error kind.
pub kind: AuthorExtTxErrorKind,
/// The human-friendly message for what happened.
pub message: &'static str,
/// The message from the inner transaction pool error.
pub inner_error: String,
}

/// The error kinds that we expose in the RPC that originate from the transaction pool.
#[derive(Debug, Serialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum AuthorExtTxErrorKind {
/// The inability to pay some fees (e.g. account balance too low).
NoFunds,
}
66 changes: 66 additions & 0 deletions crates/author-ext-rpc/src/errors/get_validator_public_key.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
//! The `get_validator_public_key` method error.

use rpc_validator_key_logic::Error as ValidatorKeyError;

use super::api_error_code;

/// The `get_validator_public_key` method error kinds.
#[derive(Debug)]
pub enum Error {
/// An error that can occur during validator key extraction.
KeyExtraction(ValidatorKeyError),
}

impl From<Error> for jsonrpsee::core::Error {
fn from(err: Error) -> Self {
match err {
Error::KeyExtraction(err @ ValidatorKeyError::MissingValidatorKey) => {
rpc_error_response::data(
api_error_code::MISSING_VALIDATOR_KEY,
err.to_string(),
rpc_validator_key_logic::error_data::ValidatorKeyNotAvailable,
)
}
Error::KeyExtraction(err @ ValidatorKeyError::ValidatorKeyExtraction) => {
rpc_error_response::simple(
api_error_code::VALIDATOR_KEY_EXTRACTION,
err.to_string(),
)
}
}
}
}

#[cfg(test)]
mod tests {

use jsonrpsee::types::ErrorObject;

use super::*;

#[test]
fn error_key_extraction_validator_key_extraction() {
let error: jsonrpsee::core::Error =
Error::KeyExtraction(ValidatorKeyError::ValidatorKeyExtraction).into();
let error: ErrorObject = error.into();

let expected_error_message = "{\"code\":600,\"message\":\"unable to extract own key\"}";
assert_eq!(
expected_error_message,
serde_json::to_string(&error).unwrap()
);
}

#[test]
fn error_key_extraction_missing_validator_key() {
let error: jsonrpsee::core::Error =
Error::KeyExtraction(ValidatorKeyError::MissingValidatorKey).into();
let error: ErrorObject = error.into();

let expected_error_message = "{\"code\":500,\"message\":\"validator key not available\",\"data\":{\"validatorKeyNotAvailable\":true}}";
assert_eq!(
expected_error_message,
serde_json::to_string(&error).unwrap()
);
}
}
21 changes: 21 additions & 0 deletions crates/author-ext-rpc/src/errors/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//! All author extension related error kinds that we expose in the RPC.

pub mod get_validator_public_key;
pub mod set_keys;

/// Custom rpc error codes.
pub mod api_error_code {
/// Call to runtime api has failed.
pub const RUNTIME_API: i32 = 300;

/// Authenticate transaction has failed.
pub const TRANSACTION: i32 = 400;

/// Validator key is not available.
pub const MISSING_VALIDATOR_KEY: i32 =
rpc_validator_key_logic::api_error_code::MISSING_VALIDATOR_KEY;

/// Validator key extraction has failed.
pub const VALIDATOR_KEY_EXTRACTION: i32 =
rpc_validator_key_logic::api_error_code::VALIDATOR_KEY_EXTRACTION;
}
Loading