Improve error handling in proc-macros, handle DispatchError etc. (#123)

* Improve error handling.

* Fix build.

* Handle runtime errors.

* Add runtime trait for better type inference.

* Use runtime trait part 1.

* wip

* Add support for sudo.

* Finish error handling.

* Fix tests.

* Fix clippy warnings.
This commit is contained in:
David Craven
2020-06-22 08:39:40 +02:00
committed by GitHub
parent 21d07c6c24
commit 3080ec91a6
23 changed files with 557 additions and 373 deletions
+56 -6
View File
@@ -14,6 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with substrate-subxt. If not, see <http://www.gnu.org/licenses/>.
use codec::Encode;
use sp_runtime::{
generic::Header,
traits::{
@@ -25,15 +26,45 @@ use sp_runtime::{
OpaqueExtrinsic,
};
use crate::frame::{
balances::{
AccountData,
Balances,
use crate::{
extra::{
DefaultExtra,
SignedExtra,
},
contracts::Contracts,
system::System,
frame::{
balances::{
AccountData,
Balances,
},
contracts::Contracts,
sudo::Sudo,
system::System,
},
Encoded,
};
/// Runtime trait.
pub trait Runtime: System + Sized + Send + Sync + 'static {
/// Signature type.
type Signature: Verify + Encode + Send + Sync + 'static;
/// Transaction extras.
type Extra: SignedExtra<Self> + Send + Sync + 'static;
}
/// Extra type.
pub type Extra<T> = <<T as Runtime>::Extra as SignedExtra<T>>::Extra;
/// UncheckedExtrinsic type.
pub type UncheckedExtrinsic<T> = sp_runtime::generic::UncheckedExtrinsic<
<T as System>::Address,
Encoded,
<T as Runtime>::Signature,
Extra<T>,
>;
/// SignedPayload type.
pub type SignedPayload<T> = sp_runtime::generic::SignedPayload<Encoded, Extra<T>>;
/// Concrete type definitions compatible with those in the default substrate `node_runtime`
///
/// # Note
@@ -43,6 +74,11 @@ use crate::frame::{
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct DefaultNodeRuntime;
impl Runtime for DefaultNodeRuntime {
type Signature = MultiSignature;
type Extra = DefaultExtra<Self>;
}
impl System for DefaultNodeRuntime {
type Index = u32;
type BlockNumber = u32;
@@ -61,6 +97,8 @@ impl Balances for DefaultNodeRuntime {
impl Contracts for DefaultNodeRuntime {}
impl Sudo for DefaultNodeRuntime {}
/// Concrete type definitions compatible with the node template.
///
/// # Note
@@ -70,6 +108,11 @@ impl Contracts for DefaultNodeRuntime {}
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct NodeTemplateRuntime;
impl Runtime for NodeTemplateRuntime {
type Signature = MultiSignature;
type Extra = DefaultExtra<Self>;
}
impl System for NodeTemplateRuntime {
type Index = u32;
type BlockNumber = u32;
@@ -86,6 +129,8 @@ impl Balances for NodeTemplateRuntime {
type Balance = u128;
}
impl Sudo for NodeTemplateRuntime {}
/// Concrete type definitions compatible with those for kusama, v0.7
///
/// # Note
@@ -95,6 +140,11 @@ impl Balances for NodeTemplateRuntime {
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct KusamaRuntime;
impl Runtime for KusamaRuntime {
type Signature = MultiSignature;
type Extra = DefaultExtra<Self>;
}
impl System for KusamaRuntime {
type Index = u32;
type BlockNumber = u32;