Files
serai/substrate/node/src/command_helper.rs
Luke Parker 2ace339975 Tokens pallet (#243)
* Use Monero-compatible additional TX keys

This still sends a fingerprinting flare up if you send to a subaddress which
needs to be fixed. Despite that, Monero no should no longer fail to scan TXs
from monero-serai regarding additional keys.

Previously it failed becuase we supplied one key as THE key, and n-1 as
additional. Monero expects n for additional.

This does correctly select when to use THE key versus when to use the additional
key when sending. That removes the ability for recipients to fingerprint
monero-serai by receiving to a standard address yet needing to use an additional
key.

* Add tokens_primitives

Moves OutInstruction from in-instructions.

Turns Destination into OutInstruction.

* Correct in-instructions DispatchClass

* Add initial tokens pallet

* Don't allow pallet addresses to equal identity

* Add support for InInstruction::transfer

Requires a cargo update due to modifications made to serai-dex/substrate.

Successfully mints a token to a SeraiAddress.

* Bind InInstructions to an amount

* Add a call filter to the runtime

Prevents worrying about calls to the assets pallet/generally tightens things
up.

* Restore Destination

It was meged into OutInstruction, yet it didn't make sense for OutInstruction
to contain a SeraiAddress.

Also deletes the excessively dated Scenarios doc.

* Split PublicKey/SeraiAddress

Lets us define a custom Display/ToString for SeraiAddress.

Also resolves an oddity where PublicKey would be encoded as String, not
[u8; 32].

* Test burning tokens/retrieving OutInstructions

Modularizes processor_coinUpdates into a shared testing utility.

* Misc lint

* Don't use PolkadotExtrinsicParams
2023-01-28 01:47:13 -05:00

93 lines
2.2 KiB
Rust

use std::sync::Arc;
use sp_core::{Encode, Pair};
use sp_keyring::Sr25519Keyring;
use sp_inherents::InherentData;
use sp_runtime::OpaqueExtrinsic;
use sc_cli::Result;
use sc_client_api::BlockBackend;
use serai_runtime::{
VERSION, BlockHashCount,
system::{self, Call as SystemCall},
transaction_payment, RuntimeCall, UncheckedExtrinsic, SignedPayload, Runtime,
};
use crate::service::FullClient;
pub struct RemarkBuilder {
client: Arc<FullClient>,
}
impl RemarkBuilder {
pub fn new(client: Arc<FullClient>) -> Self {
Self { client }
}
}
impl frame_benchmarking_cli::ExtrinsicBuilder for RemarkBuilder {
fn pallet(&self) -> &str {
"system"
}
fn extrinsic(&self) -> &str {
"remark"
}
fn build(&self, nonce: u32) -> std::result::Result<OpaqueExtrinsic, &'static str> {
Ok(OpaqueExtrinsic::from(create_benchmark_extrinsic(
self.client.as_ref(),
Sr25519Keyring::Bob.pair(),
SystemCall::remark { remark: vec![] }.into(),
nonce,
)))
}
}
pub fn create_benchmark_extrinsic(
client: &FullClient,
sender: sp_core::sr25519::Pair,
call: RuntimeCall,
nonce: u32,
) -> UncheckedExtrinsic {
let extra = (
system::CheckNonZeroSender::<Runtime>::new(),
system::CheckSpecVersion::<Runtime>::new(),
system::CheckTxVersion::<Runtime>::new(),
system::CheckGenesis::<Runtime>::new(),
system::CheckEra::<Runtime>::from(sp_runtime::generic::Era::mortal(
u64::from(BlockHashCount::get().checked_next_power_of_two().map(|c| c / 2).unwrap_or(2)),
client.chain_info().best_number.into(),
)),
system::CheckNonce::<Runtime>::from(nonce),
system::CheckWeight::<Runtime>::new(),
transaction_payment::ChargeTransactionPayment::<Runtime>::from(0),
);
UncheckedExtrinsic::new_signed(
call.clone(),
sender.public().into(),
SignedPayload::from_raw(
call,
extra.clone(),
(
(),
VERSION.spec_version,
VERSION.transaction_version,
client.block_hash(0).ok().flatten().unwrap(),
client.chain_info().best_hash,
(),
(),
(),
),
)
.using_encoded(|e| sender.sign(e)),
extra,
)
}
pub fn inherent_benchmark_data() -> Result<InherentData> {
Ok(InherentData::new())
}