Secure API JSON RPC ID can be integer or string (#314)

* Fix #312

* Fix tests
This commit is contained in:
Quentin Le Sceller
2020-01-24 11:01:16 +00:00
committed by Yeastplume
parent f09c91f626
commit 3091bd9701
3 changed files with 12 additions and 9 deletions
+9 -6
View File
@@ -142,14 +142,15 @@ pub struct EncryptedRequest {
/// method
pub method: String,
/// id
pub id: u32,
#[serde(with = "secp_ser::string_or_u64")]
pub id: u64,
/// Body params, which includes nonce and encrypted request
pub params: EncryptedBody,
}
impl EncryptedRequest {
/// from json
pub fn from_json(id: u32, json_in: &Value, enc_key: &SecretKey) -> Result<Self, Error> {
pub fn from_json(id: u64, json_in: &Value, enc_key: &SecretKey) -> Result<Self, Error> {
Ok(EncryptedRequest {
jsonrpc: "2.0".to_owned(),
method: "encrypted_request_v3".to_owned(),
@@ -187,14 +188,15 @@ pub struct EncryptedResponse {
/// JSON RPC response
pub jsonrpc: String,
/// id
pub id: u32,
#[serde(with = "secp_ser::string_or_u64")]
pub id: u64,
/// result
pub result: HashMap<String, EncryptedBody>,
}
impl EncryptedResponse {
/// from json
pub fn from_json(id: u32, json_in: &Value, enc_key: &SecretKey) -> Result<Self, Error> {
pub fn from_json(id: u64, json_in: &Value, enc_key: &SecretKey) -> Result<Self, Error> {
let mut result_set = HashMap::new();
result_set.insert(
"Ok".to_string(),
@@ -245,14 +247,15 @@ pub struct EncryptionErrorResponse {
/// JSON RPC response
pub jsonrpc: String,
/// id
pub id: u32,
#[serde(with = "secp_ser::string_or_u64")]
pub id: u64,
/// error
pub error: EncryptionError,
}
impl EncryptionErrorResponse {
/// Create new response
pub fn new(id: u32, code: i32, message: &str) -> Self {
pub fn new(id: u64, code: i32, message: &str) -> Self {
EncryptionErrorResponse {
jsonrpc: "2.0".to_owned(),
id: id,