Skip to content
This repository was archived by the owner on Sep 1, 2023. It is now read-only.

Commit 546f268

Browse files
committed
sync 0.0.390
Signed-off-by: Gyuho Lee <[email protected]>
1 parent 39b41bb commit 546f268

File tree

6 files changed

+239
-82
lines changed

6 files changed

+239
-82
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ Cargo.lock
88

99
# These are backup files generated by rustfmt
1010
**/*.rs.bk
11+
12+
.DS_Store

Cargo.toml

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "avalanche-types"
3-
version = "0.0.386" # https://crates.io/crates/avalanche-types
3+
version = "0.0.390" # https://crates.io/crates/avalanche-types
44
edition = "2021"
55
rust-version = "1.69" # use "rustup override set stable" to overwrite current toolchain
66
publish = true
@@ -48,8 +48,8 @@ zeroize = "1.6.0" # for "BLS
4848
secp256k1 = { version = "0.27.0", features = ["global-context", "rand-std", "recovery"], optional = true } # https://crates.io/crates/secp256k1
4949

5050
# [OPTIONAL] for "kms_aws"
51-
aws-manager = { version = "0.27.4", features = ["kms"], optional = true } # https://github.com/gyuho/aws-manager/tags
52-
aws-sdk-kms = { version = "0.27.0", optional = true } # https://crates.io/crates/aws-sdk-kms/versions
51+
aws-manager = { version = "0.28.0", features = ["kms"], optional = true } # https://github.com/gyuho/aws-manager/tags
52+
aws-sdk-kms = { version = "0.28.0", optional = true } # https://crates.io/crates/aws-sdk-kms/versions
5353

5454
# [OPTIONAL] for "message"
5555
flate2 = { version = "1.0.26", optional = true }
@@ -90,7 +90,7 @@ tower-service = { version = "0.3.2", optional = true }
9090
prometheus = { version = "0.13.3", default-features = false, features = ["process"], optional = true }
9191

9292
# [OPTIONAL] for "codec"
93-
base64 = { version = "0.21.0", optional = true } # https://github.com/marshallpierce/rust-base64
93+
base64 = { version = "0.21.1", optional = true } # https://github.com/marshallpierce/rust-base64
9494
num-bigint = { version = "0.4.3", optional = true }
9595

9696
[build-dependencies]

src/evm/eip712/gsn/relay.rs

+122-56
Original file line numberDiff line numberDiff line change
@@ -235,26 +235,26 @@ impl Request {
235235
name.clone()
236236
} else {
237237
return Err(Error::new(
238-
ErrorKind::Other,
239-
"self.forward_request.domain missing 'name' field",
238+
ErrorKind::InvalidInput,
239+
"forward_request.domain missing 'name' field",
240240
));
241241
};
242242

243243
let domain_version = if let Some(version) = &self.forward_request.domain.version {
244244
version.clone()
245245
} else {
246246
return Err(Error::new(
247-
ErrorKind::Other,
248-
"self.forward_request.domain missing 'version' field",
247+
ErrorKind::InvalidInput,
248+
"forward_request.domain missing 'version' field",
249249
));
250250
};
251251

252252
let domain_chain_id = if let Some(chain_id) = &self.forward_request.domain.chain_id {
253253
chain_id
254254
} else {
255255
return Err(Error::new(
256-
ErrorKind::Other,
257-
"self.forward_request.domain missing 'chain_id' field",
256+
ErrorKind::InvalidInput,
257+
"forward_request.domain missing 'chain_id' field",
258258
));
259259
};
260260

@@ -263,144 +263,210 @@ impl Request {
263263
verifying_contract.clone()
264264
} else {
265265
return Err(Error::new(
266-
ErrorKind::Other,
267-
"self.forward_request.domain missing 'verifying_contract' field",
266+
ErrorKind::InvalidInput,
267+
"forward_request.domain missing 'verifying_contract' field",
268268
));
269269
};
270270

271271
let from = if let Some(from) = self.forward_request.message.get("from") {
272272
if let Some(v) = from.as_str() {
273-
H160::from_str(v).unwrap()
273+
H160::from_str(v).map_err(|e| {
274+
Error::new(
275+
ErrorKind::InvalidInput,
276+
format!(
277+
"forward_request.message.from[{v}] H160::from_str parse failed {:?}",
278+
e
279+
),
280+
)
281+
})?
274282
} else {
275283
return Err(Error::new(
276-
ErrorKind::Other,
277-
"self.forward_request.message expected type 'from'",
284+
ErrorKind::InvalidInput,
285+
"forward_request.message expected type 'from'",
278286
));
279287
}
280288
} else {
281289
return Err(Error::new(
282-
ErrorKind::Other,
283-
"self.forward_request.message missing 'from' field",
290+
ErrorKind::InvalidInput,
291+
"forward_request.message missing 'from' field",
284292
));
285293
};
286294

287295
let to = if let Some(to) = self.forward_request.message.get("to") {
288296
if let Some(v) = to.as_str() {
289-
H160::from_str(v).unwrap()
297+
H160::from_str(v).map_err(|e| {
298+
Error::new(
299+
ErrorKind::InvalidInput,
300+
format!(
301+
"forward_request.message.to[{v}] H160::from_str parse failed {:?}",
302+
e
303+
),
304+
)
305+
})?
290306
} else {
291307
return Err(Error::new(
292-
ErrorKind::Other,
293-
"self.forward_request.message expected type 'to'",
308+
ErrorKind::InvalidInput,
309+
"forward_request.message expected type 'to'",
294310
));
295311
}
296312
} else {
297313
return Err(Error::new(
298-
ErrorKind::Other,
299-
"self.forward_request.message missing 'to' field",
314+
ErrorKind::InvalidInput,
315+
"forward_request.message missing 'to' field",
300316
));
301317
};
302318

303319
let value = if let Some(value) = self.forward_request.message.get("value") {
304320
if let Some(v) = value.as_str() {
305321
if v.starts_with("0x") {
306-
U256::from_str_radix(v, 16).unwrap()
322+
U256::from_str_radix(v, 16).map_err(|e| {
323+
Error::new(
324+
ErrorKind::InvalidInput,
325+
format!("forward_request.message.value[{v}] U256::from_str_radix parse failed {:?}", e),
326+
)
327+
})?
307328
} else {
308-
U256::from_str(v).unwrap()
329+
U256::from_str(v).map_err(|e| {
330+
Error::new(
331+
ErrorKind::InvalidInput,
332+
format!("forward_request.message.value[{v}] U256::from_str parse failed {:?}", e),
333+
)
334+
})?
309335
}
310336
} else {
311337
return Err(Error::new(
312-
ErrorKind::Other,
313-
"self.forward_request.message expected type 'value'",
338+
ErrorKind::InvalidInput,
339+
"forward_request.message expected type 'value'",
314340
));
315341
}
316342
} else {
317343
return Err(Error::new(
318-
ErrorKind::Other,
319-
"self.forward_request.message missing 'value' field",
344+
ErrorKind::InvalidInput,
345+
"forward_request.message missing 'value' field",
320346
));
321347
};
322348

323349
let gas = if let Some(gas) = self.forward_request.message.get("gas") {
324350
if let Some(v) = gas.as_str() {
325351
if v.starts_with("0x") {
326-
U256::from_str_radix(v, 16).unwrap()
352+
U256::from_str_radix(v, 16).map_err(|e| {
353+
Error::new(
354+
ErrorKind::InvalidInput,
355+
format!("forward_request.message.gas[{v}] U256::from_str_radix parse failed {:?}", e),
356+
)
357+
})?
327358
} else {
328-
U256::from_str(v).unwrap()
359+
U256::from_str(v).map_err(|e| {
360+
Error::new(
361+
ErrorKind::InvalidInput,
362+
format!(
363+
"forward_request.message.gas[{v}] U256::from_str parse failed {:?}",
364+
e
365+
),
366+
)
367+
})?
329368
}
330369
} else {
331370
return Err(Error::new(
332-
ErrorKind::Other,
333-
"self.forward_request.message expected type 'gas'",
371+
ErrorKind::InvalidInput,
372+
"forward_request.message expected type 'gas'",
334373
));
335374
}
336375
} else {
337376
return Err(Error::new(
338-
ErrorKind::Other,
339-
"self.forward_request.message missing 'gas' field",
377+
ErrorKind::InvalidInput,
378+
"forward_request.message missing 'gas' field",
340379
));
341380
};
342381

343382
let nonce = if let Some(nonce) = self.forward_request.message.get("nonce") {
344383
if let Some(v) = nonce.as_str() {
345384
if v.starts_with("0x") {
346-
U256::from_str_radix(v, 16).unwrap()
385+
U256::from_str_radix(v, 16).map_err(|e| {
386+
Error::new(
387+
ErrorKind::InvalidInput,
388+
format!("forward_request.message.nonce[{v}] U256::from_str_radix parse failed {:?}", e),
389+
)
390+
})?
347391
} else {
348-
U256::from_str(v).unwrap()
392+
U256::from_str(v).map_err(|e| {
393+
Error::new(
394+
ErrorKind::InvalidInput,
395+
format!("forward_request.message.nonce[{v}] U256::from_str parse failed {:?}", e),
396+
)
397+
})?
349398
}
350399
} else {
351400
return Err(Error::new(
352-
ErrorKind::Other,
353-
"self.forward_request.message expected type 'nonce'",
401+
ErrorKind::InvalidInput,
402+
"forward_request.message expected type 'nonce'",
354403
));
355404
}
356405
} else {
357406
return Err(Error::new(
358-
ErrorKind::Other,
359-
"self.forward_request.message missing 'nonce' field",
407+
ErrorKind::InvalidInput,
408+
"forward_request.message missing 'nonce' field",
360409
));
361410
};
362411

363412
let data = if let Some(data) = self.forward_request.message.get("data") {
364413
if let Some(v) = data.as_str() {
365414
hex::decode(v.trim_start_matches("0x")).map_err(|e| {
366415
Error::new(
367-
ErrorKind::Other,
416+
ErrorKind::InvalidInput,
368417
format!("failed hex::decode on 'data' field '{}'", e),
369418
)
370419
})?
371420
} else {
372421
return Err(Error::new(
373-
ErrorKind::Other,
374-
"self.forward_request.message expected type 'data'",
422+
ErrorKind::InvalidInput,
423+
"forward_request.message expected type 'data'",
375424
));
376425
}
377426
} else {
378427
return Err(Error::new(
379-
ErrorKind::Other,
380-
"self.forward_request.message missing 'data' field",
428+
ErrorKind::InvalidInput,
429+
"forward_request.message missing 'data' field",
381430
));
382431
};
383432

384-
let valid_until_time =
385-
if let Some(valid_until_time) = self.forward_request.message.get("validUntilTime") {
386-
if let Some(v) = valid_until_time.as_str() {
387-
if v.starts_with("0x") {
388-
U256::from_str_radix(v, 16).unwrap()
389-
} else {
390-
U256::from_str(v).unwrap()
391-
}
433+
let valid_until_time = if let Some(valid_until_time) =
434+
self.forward_request.message.get("validUntilTime")
435+
{
436+
if let Some(v) = valid_until_time.as_str() {
437+
if v.starts_with("0x") {
438+
U256::from_str_radix(v, 16).map_err(|e| {
439+
Error::new(
440+
ErrorKind::InvalidInput,
441+
format!(
442+
"forward_request.message.validUntilTime[{v}] U256::from_str_radix parse failed {:?}",
443+
e
444+
),
445+
)
446+
})?
392447
} else {
393-
return Err(Error::new(
394-
ErrorKind::Other,
395-
"self.forward_request.message expected type 'validUntilTime'",
396-
));
448+
U256::from_str(v).map_err(|e| {
449+
Error::new(
450+
ErrorKind::InvalidInput,
451+
format!(
452+
"forward_request.message.validUntilTime[{v}] U256::from_str parse failed {:?}",
453+
e
454+
),
455+
)
456+
})?
397457
}
398458
} else {
399459
return Err(Error::new(
400-
ErrorKind::Other,
401-
"self.forward_request.message missing 'validUntilTime' field",
460+
ErrorKind::InvalidInput,
461+
"forward_request.message expected type 'validUntilTime'",
402462
));
403-
};
463+
}
464+
} else {
465+
return Err(Error::new(
466+
ErrorKind::InvalidInput,
467+
"forward_request.message missing 'validUntilTime' field",
468+
));
469+
};
404470

405471
Ok(super::Tx::new()
406472
.domain_name(domain_name)

src/jsonrpc/admin.rs

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#[allow(dead_code)]
2+
3+
/// The chain alias method name
4+
const ALIAS_METHOD: &str = "admin.aliasChain";
5+
6+
/// The request to alias a chain via the admin API.
7+
/// Ref: https://docs.avax.network/apis/avalanchego/apis/admin#adminaliaschain
8+
struct ChainAliasRequest {
9+
/// Jsonrpc version
10+
pub jsonrpc: String,
11+
/// Id of request
12+
pub id: u32,
13+
/// Method (admin.aliasChain)
14+
pub method: String,
15+
/// Alias parameters
16+
pub params: Option<ChainAliasParams>,
17+
}
18+
19+
impl Default for ChainAliasRequest {
20+
fn default() -> Self {
21+
Self {
22+
jsonrpc: String::from(super::DEFAULT_VERSION),
23+
id: super::DEFAULT_ID,
24+
method: ALIAS_METHOD.to_string(),
25+
params: None,
26+
}
27+
}
28+
}
29+
30+
/// Parameters for the alias request.
31+
struct ChainAliasParams {
32+
/// The long-form chain ID
33+
pub chain: String,
34+
/// The newly issues alias
35+
pub alias: String,
36+
}
37+
38+
/// Response for the alias request.
39+
struct ChainAliasResponse {
40+
/// Jsonrpc version
41+
pub jsonrpc: String,
42+
/// Id of request
43+
pub id: u32,
44+
/// Result (empty)
45+
pub result: (),
46+
}

src/jsonrpc/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
pub mod admin;
12
pub mod avm;
23
pub mod common;
34
pub mod evm;

0 commit comments

Comments
 (0)