mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-15 13:45:44 +00:00
Extract unsigned tx from the SignParam structure (#1561)
* change sign_transaction method * clippy * rustup update && clippy * remove redudnant clone
This commit is contained in:
committed by
Bastian Köcher
parent
effe0f11c8
commit
f35b4f4897
@@ -15,7 +15,9 @@
|
||||
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use bp_messages::MessageNonce;
|
||||
use bp_runtime::{Chain as ChainBase, EncodedOrDecodedCall, HashOf, TransactionEraOf};
|
||||
use bp_runtime::{
|
||||
Chain as ChainBase, EncodedOrDecodedCall, HashOf, TransactionEra, TransactionEraOf,
|
||||
};
|
||||
use codec::{Codec, Encode};
|
||||
use frame_support::weights::{Weight, WeightToFeePolynomial};
|
||||
use jsonrpsee::core::{DeserializeOwned, Serialize};
|
||||
@@ -158,12 +160,14 @@ pub struct UnsignedTransaction<C: Chain> {
|
||||
pub nonce: C::Index,
|
||||
/// Tip included into transaction.
|
||||
pub tip: C::Balance,
|
||||
/// Transaction era used by the chain.
|
||||
pub era: TransactionEraOf<C>,
|
||||
}
|
||||
|
||||
impl<C: Chain> UnsignedTransaction<C> {
|
||||
/// Create new unsigned transaction with given call, nonce and zero tip.
|
||||
/// Create new unsigned transaction with given call, nonce, era and zero tip.
|
||||
pub fn new(call: EncodedOrDecodedCall<C::Call>, nonce: C::Index) -> Self {
|
||||
Self { call, nonce, tip: Zero::zero() }
|
||||
Self { call, nonce, era: TransactionEra::Immortal, tip: Zero::zero() }
|
||||
}
|
||||
|
||||
/// Set transaction tip.
|
||||
@@ -172,13 +176,20 @@ impl<C: Chain> UnsignedTransaction<C> {
|
||||
self.tip = tip;
|
||||
self
|
||||
}
|
||||
|
||||
/// Set transaction era.
|
||||
#[must_use]
|
||||
pub fn era(mut self, era: TransactionEraOf<C>) -> Self {
|
||||
self.era = era;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
/// Account key pair used by transactions signing scheme.
|
||||
pub type AccountKeyPairOf<S> = <S as TransactionSignScheme>::AccountKeyPair;
|
||||
|
||||
/// Substrate-based chain transactions signing scheme.
|
||||
pub trait TransactionSignScheme {
|
||||
pub trait TransactionSignScheme: 'static {
|
||||
/// Chain that this scheme is to be used.
|
||||
type Chain: Chain;
|
||||
/// Type of key pairs used to sign transactions.
|
||||
@@ -187,7 +198,10 @@ pub trait TransactionSignScheme {
|
||||
type SignedTransaction: Clone + Debug + Codec + Send + 'static;
|
||||
|
||||
/// Create transaction for given runtime call, signed by given account.
|
||||
fn sign_transaction(param: SignParam<Self>) -> Result<Self::SignedTransaction, crate::Error>
|
||||
fn sign_transaction(
|
||||
param: SignParam<Self>,
|
||||
unsigned: UnsignedTransaction<Self::Chain>,
|
||||
) -> Result<Self::SignedTransaction, crate::Error>
|
||||
where
|
||||
Self: Sized;
|
||||
|
||||
@@ -213,10 +227,6 @@ pub struct SignParam<T: TransactionSignScheme> {
|
||||
pub genesis_hash: <T::Chain as ChainBase>::Hash,
|
||||
/// Signer account
|
||||
pub signer: T::AccountKeyPair,
|
||||
/// Transaction era used by the chain.
|
||||
pub era: TransactionEraOf<T::Chain>,
|
||||
/// Transaction before it is signed.
|
||||
pub unsigned: UnsignedTransaction<T::Chain>,
|
||||
}
|
||||
|
||||
impl<Block: BlockT> BlockWithJustification<Block::Header> for SignedBlock<Block> {
|
||||
|
||||
Reference in New Issue
Block a user