收取交易费用并存入罐中
Collecting transaction fees and store it in pot
想在使用转账的过程中收取更高的交易手续费(5%)存入锅账户?我怎样才能做到这一点?需要修改平衡托盘的传递函数吗
https://github.com/paritytech/substrate/blob/master/frame/balances/src/lib.rs#L257
另外,如何收取额外的交易费用,需要一些帮助来编写代码。
费用由 pallett-transaction-payment
和收集交易付款的 ChargeTransactionPayment
, which is a SingedExtension
收取。
如果您想每次转账收取 x%
,您可以为 pallet-balances
创建一个新的签名扩展,拦截 Call::transfer
并收取一些额外的钱。
请注意,如果您将两者都包含在运行时中,这可能会与 ChargeTransactionPayment
冲突。
代码示例
This won't compile as-is; just showing you the direction.
pub struct TakeFivePercent<T>(PhantomData<T>);
impl<T: Config> SignedExtension for TakeFivePercent<T> {
const IDENTIFIER: &'static str = "TakeFivePercent";
type AccountId = T::AccountId;
type Call = T::Call;
type AdditionalSigned = ();
fn additional_signed(&self) -> sp_std::result::Result<(), TransactionValidityError> { Ok(()) }
fn validate(
&self,
who: &Self::AccountId,
call: &Self::Call,
info: &DispatchInfoOf<Self::Call>,
len: usize,
) -> TransactionValidity {
match call {
Self::Call(Call::Transfer(dest, amount)) => {
// withdraw 5% of amount from dest
}
}
}
// note that we won't implement `pre_dispatch` and let it auto-impl
// to valiadte.
// https://crates.parity.io/src/sp_runtime/traits.rs.html#744-874
}
最后,请注意,您需要将其添加到顶级运行时文件中的已签名扩展元组中,其中 construct_runtime!
所在。
pub type SignedExtensions = (
Foo,
Bar,
..,
..,
TakeFivePercent<Runtime>
)
想在使用转账的过程中收取更高的交易手续费(5%)存入锅账户?我怎样才能做到这一点?需要修改平衡托盘的传递函数吗
https://github.com/paritytech/substrate/blob/master/frame/balances/src/lib.rs#L257
另外,如何收取额外的交易费用,需要一些帮助来编写代码。
费用由 pallett-transaction-payment
和收集交易付款的 ChargeTransactionPayment
, which is a SingedExtension
收取。
如果您想每次转账收取 x%
,您可以为 pallet-balances
创建一个新的签名扩展,拦截 Call::transfer
并收取一些额外的钱。
请注意,如果您将两者都包含在运行时中,这可能会与 ChargeTransactionPayment
冲突。
代码示例
This won't compile as-is; just showing you the direction.
pub struct TakeFivePercent<T>(PhantomData<T>);
impl<T: Config> SignedExtension for TakeFivePercent<T> {
const IDENTIFIER: &'static str = "TakeFivePercent";
type AccountId = T::AccountId;
type Call = T::Call;
type AdditionalSigned = ();
fn additional_signed(&self) -> sp_std::result::Result<(), TransactionValidityError> { Ok(()) }
fn validate(
&self,
who: &Self::AccountId,
call: &Self::Call,
info: &DispatchInfoOf<Self::Call>,
len: usize,
) -> TransactionValidity {
match call {
Self::Call(Call::Transfer(dest, amount)) => {
// withdraw 5% of amount from dest
}
}
}
// note that we won't implement `pre_dispatch` and let it auto-impl
// to valiadte.
// https://crates.parity.io/src/sp_runtime/traits.rs.html#744-874
}
最后,请注意,您需要将其添加到顶级运行时文件中的已签名扩展元组中,其中 construct_runtime!
所在。
pub type SignedExtensions = (
Foo,
Bar,
..,
..,
TakeFivePercent<Runtime>
)