From 866f57f67a250dc88d602c7054cbc627390fbba9 Mon Sep 17 00:00:00 2001 From: Emilia Hane Date: Thu, 26 Sep 2024 19:41:00 +0200 Subject: [PATCH 1/3] Add conversion TxKind -> Option
--- crates/primitives/src/common.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/crates/primitives/src/common.rs b/crates/primitives/src/common.rs index 4eef86cd78..eda6cb9783 100644 --- a/crates/primitives/src/common.rs +++ b/crates/primitives/src/common.rs @@ -35,6 +35,17 @@ impl From
for TxKind { } } +impl From for Option
{ + /// Returns the address of the contract that will be called or will receive the transfer. + #[inline] + fn from(value: TxKind) -> Self { + match value { + TxKind::Create => None, + TxKind::Call(addr) => Some(addr), + } + } +} + impl TxKind { /// Returns the address of the contract that will be called or will receive the transfer. pub const fn to(&self) -> Option<&Address> { From 46fd0c4e3e523f0bb2ce1e01e8b41789d8f3d05f Mon Sep 17 00:00:00 2001 From: Emilia Hane Date: Sat, 28 Sep 2024 02:26:02 +0200 Subject: [PATCH 2/3] Simplify syntax Co-authored-by: DaniPopes <57450786+DaniPopes@users.noreply.github.com> --- crates/primitives/src/common.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/crates/primitives/src/common.rs b/crates/primitives/src/common.rs index eda6cb9783..0c5da9300f 100644 --- a/crates/primitives/src/common.rs +++ b/crates/primitives/src/common.rs @@ -39,11 +39,7 @@ impl From for Option
{ /// Returns the address of the contract that will be called or will receive the transfer. #[inline] fn from(value: TxKind) -> Self { - match value { - TxKind::Create => None, - TxKind::Call(addr) => Some(addr), - } - } + value.to().copied() } impl TxKind { From ea898b6340dd3e9ba383a285ec0d87095136527c Mon Sep 17 00:00:00 2001 From: Emilia Hane Date: Sat, 28 Sep 2024 03:53:03 +0200 Subject: [PATCH 3/3] Fix lint --- crates/primitives/src/common.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/primitives/src/common.rs b/crates/primitives/src/common.rs index 0c5da9300f..355165173d 100644 --- a/crates/primitives/src/common.rs +++ b/crates/primitives/src/common.rs @@ -40,6 +40,7 @@ impl From for Option
{ #[inline] fn from(value: TxKind) -> Self { value.to().copied() + } } impl TxKind {