From c3a07911307ff9c3026edc9d47770c4f671cfc06 Mon Sep 17 00:00:00 2001 From: Marcio Diaz Date: Mon, 8 Jul 2019 18:41:58 +0200 Subject: [PATCH 1/7] Init Api --- core/client/src/lib.rs | 1 + core/client/src/transaction_builder/mod.rs | 22 +++++++++++++ .../transaction_builder.rs | 31 +++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 core/client/src/transaction_builder/mod.rs create mode 100644 core/client/src/transaction_builder/transaction_builder.rs diff --git a/core/client/src/lib.rs b/core/client/src/lib.rs index 8062fae500199..f5d1298f941bb 100644 --- a/core/client/src/lib.rs +++ b/core/client/src/lib.rs @@ -35,6 +35,7 @@ pub mod in_mem; #[cfg(feature = "std")] pub mod genesis; pub mod block_builder; +pub mod transaction_builder; #[cfg(feature = "std")] pub mod light; #[cfg(feature = "std")] diff --git a/core/client/src/transaction_builder/mod.rs b/core/client/src/transaction_builder/mod.rs new file mode 100644 index 0000000000000..599580a41403c --- /dev/null +++ b/core/client/src/transaction_builder/mod.rs @@ -0,0 +1,22 @@ +// Copyright 2019 Parity Technologies (UK) Ltd. +// This file is part of Substrate. + +// Substrate is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Substrate is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Substrate. If not, see . + +//! Utility struct to build a transaction. + +#[cfg(feature = "std")] +mod transaction_builder; +#[cfg(feature = "std")] +pub use transaction_builder::*; diff --git a/core/client/src/transaction_builder/transaction_builder.rs b/core/client/src/transaction_builder/transaction_builder.rs new file mode 100644 index 0000000000000..bdecf0609ca9c --- /dev/null +++ b/core/client/src/transaction_builder/transaction_builder.rs @@ -0,0 +1,31 @@ +// Copyright 2019 Parity Technologies (UK) Ltd. +// This file is part of Substrate. + +// Substrate is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Substrate is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Substrate. If not, see . + +//! The runtime api for building transactions. + +use runtime_primitives::AnySignature; +use sr_api_macros::decl_runtime_apis; + +decl_runtime_apis! { + /// The `TransactionBuilder` trait that provides required functions + /// for building a transaction from a Call for the runtime. + pub trait TransactionBuilder { + /// Construct the payload. + fn signing_payload(encoded_call: &[u8], account_id: &[u8]) -> Vec; + /// Build the transaction. + fn build_transaction(signing_payload: &[u8], signature: AnySignature) -> Vec; + } +} \ No newline at end of file From 8aaa0d0e2780da3cd79576e6e4ec47daae78c0e2 Mon Sep 17 00:00:00 2001 From: Marcio Diaz Date: Thu, 18 Jul 2019 11:38:08 +0200 Subject: [PATCH 2/7] Add possible crypto method; use Vec --- .../client/src/transaction_builder/transaction_builder.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/core/client/src/transaction_builder/transaction_builder.rs b/core/client/src/transaction_builder/transaction_builder.rs index bdecf0609ca9c..9af32bf7f9259 100644 --- a/core/client/src/transaction_builder/transaction_builder.rs +++ b/core/client/src/transaction_builder/transaction_builder.rs @@ -16,16 +16,18 @@ //! The runtime api for building transactions. -use runtime_primitives::AnySignature; use sr_api_macros::decl_runtime_apis; +use runtime_primitives::KeyTypeId; decl_runtime_apis! { /// The `TransactionBuilder` trait that provides required functions /// for building a transaction from a Call for the runtime. pub trait TransactionBuilder { /// Construct the payload. - fn signing_payload(encoded_call: &[u8], account_id: &[u8]) -> Vec; + fn signing_payload(encoded_call: Vec, account_id: Vec) -> Vec; /// Build the transaction. - fn build_transaction(signing_payload: &[u8], signature: AnySignature) -> Vec; + fn build_transaction(signing_payload: Vec, signature: Vec) -> Vec; + /// Get list of supported crypto types. + fn possible_crypto() -> Vec; } } \ No newline at end of file From 94202c83814190687f780e08125c16be74e282b0 Mon Sep 17 00:00:00 2001 From: Marcio Diaz Date: Thu, 18 Jul 2019 11:58:37 +0200 Subject: [PATCH 3/7] Remove std --- core/client/src/transaction_builder/mod.rs | 2 -- core/client/src/transaction_builder/transaction_builder.rs | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/core/client/src/transaction_builder/mod.rs b/core/client/src/transaction_builder/mod.rs index 599580a41403c..e2c705a1670bd 100644 --- a/core/client/src/transaction_builder/mod.rs +++ b/core/client/src/transaction_builder/mod.rs @@ -16,7 +16,5 @@ //! Utility struct to build a transaction. -#[cfg(feature = "std")] mod transaction_builder; -#[cfg(feature = "std")] pub use transaction_builder::*; diff --git a/core/client/src/transaction_builder/transaction_builder.rs b/core/client/src/transaction_builder/transaction_builder.rs index 9af32bf7f9259..230256d4f0e31 100644 --- a/core/client/src/transaction_builder/transaction_builder.rs +++ b/core/client/src/transaction_builder/transaction_builder.rs @@ -24,9 +24,9 @@ decl_runtime_apis! { /// for building a transaction from a Call for the runtime. pub trait TransactionBuilder { /// Construct the payload. - fn signing_payload(encoded_call: Vec, account_id: Vec) -> Vec; + fn signing_payload(encoded_call: Vec, encoded_account_id: Vec) -> Vec; /// Build the transaction. - fn build_transaction(signing_payload: Vec, signature: Vec) -> Vec; + fn build_transaction(signing_payload: Vec, encoded_account_id: Vec, signature: Vec) -> Vec; /// Get list of supported crypto types. fn possible_crypto() -> Vec; } From ff5ce4dc1533a9f3bd6e7f5b46bd3b8a00ad57ae Mon Sep 17 00:00:00 2001 From: Marcio Diaz Date: Thu, 18 Jul 2019 12:02:29 +0200 Subject: [PATCH 4/7] Import Vec --- core/client/src/transaction_builder/transaction_builder.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/core/client/src/transaction_builder/transaction_builder.rs b/core/client/src/transaction_builder/transaction_builder.rs index 230256d4f0e31..8ae857465a34b 100644 --- a/core/client/src/transaction_builder/transaction_builder.rs +++ b/core/client/src/transaction_builder/transaction_builder.rs @@ -18,6 +18,7 @@ use sr_api_macros::decl_runtime_apis; use runtime_primitives::KeyTypeId; +use rstd::vec::Vec; decl_runtime_apis! { /// The `TransactionBuilder` trait that provides required functions @@ -26,7 +27,11 @@ decl_runtime_apis! { /// Construct the payload. fn signing_payload(encoded_call: Vec, encoded_account_id: Vec) -> Vec; /// Build the transaction. - fn build_transaction(signing_payload: Vec, encoded_account_id: Vec, signature: Vec) -> Vec; + fn build_transaction( + signing_payload: Vec, + encoded_account_id: Vec, // TODO: rename to extra_payload? + signature: Vec, + ) -> Vec; /// Get list of supported crypto types. fn possible_crypto() -> Vec; } From 5c083ef3316d223d3b1bd8c5cf41fd8a9442707d Mon Sep 17 00:00:00 2001 From: Marcio Diaz Date: Sat, 27 Jul 2019 13:34:46 +0200 Subject: [PATCH 5/7] Leave just the file --- .../transaction_builder.rs | 0 core/client/src/transaction_builder/mod.rs | 20 ------------------- 2 files changed, 20 deletions(-) rename core/client/src/{transaction_builder => }/transaction_builder.rs (100%) delete mode 100644 core/client/src/transaction_builder/mod.rs diff --git a/core/client/src/transaction_builder/transaction_builder.rs b/core/client/src/transaction_builder.rs similarity index 100% rename from core/client/src/transaction_builder/transaction_builder.rs rename to core/client/src/transaction_builder.rs diff --git a/core/client/src/transaction_builder/mod.rs b/core/client/src/transaction_builder/mod.rs deleted file mode 100644 index e2c705a1670bd..0000000000000 --- a/core/client/src/transaction_builder/mod.rs +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2019 Parity Technologies (UK) Ltd. -// This file is part of Substrate. - -// Substrate is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Substrate is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Substrate. If not, see . - -//! Utility struct to build a transaction. - -mod transaction_builder; -pub use transaction_builder::*; From 25ae60a3a85c52e3e24aadb13507eb97c8753696 Mon Sep 17 00:00:00 2001 From: Marcio Diaz Date: Sat, 27 Jul 2019 14:52:28 +0200 Subject: [PATCH 6/7] Add line --- core/client/src/transaction_builder.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/client/src/transaction_builder.rs b/core/client/src/transaction_builder.rs index 8ae857465a34b..5eaadb441092f 100644 --- a/core/client/src/transaction_builder.rs +++ b/core/client/src/transaction_builder.rs @@ -35,4 +35,4 @@ decl_runtime_apis! { /// Get list of supported crypto types. fn possible_crypto() -> Vec; } -} \ No newline at end of file +} From 9691ffd80a7834ff069ba7c8c214697badf4394e Mon Sep 17 00:00:00 2001 From: Marcio Diaz Date: Wed, 31 Jul 2019 12:35:52 +0200 Subject: [PATCH 7/7] Fix nits --- core/client/src/transaction_builder.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/client/src/transaction_builder.rs b/core/client/src/transaction_builder.rs index 5eaadb441092f..700de8c4c7456 100644 --- a/core/client/src/transaction_builder.rs +++ b/core/client/src/transaction_builder.rs @@ -26,12 +26,14 @@ decl_runtime_apis! { pub trait TransactionBuilder { /// Construct the payload. fn signing_payload(encoded_call: Vec, encoded_account_id: Vec) -> Vec; + /// Build the transaction. fn build_transaction( signing_payload: Vec, - encoded_account_id: Vec, // TODO: rename to extra_payload? + encoded_account_id: Vec, signature: Vec, ) -> Vec; + /// Get list of supported crypto types. fn possible_crypto() -> Vec; }