Skip to content

Commit

Permalink
Fix compilation error
Browse files Browse the repository at this point in the history
  • Loading branch information
dastansam committed Feb 11, 2024
1 parent 51a24f8 commit 6f24225
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 7 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions pallets/iso-8583/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,17 @@ pub mod crypto {
};
app_crypto!(sr25519, KEY_TYPE);

pub struct TestAuthId;
pub struct Iso8583AuthId;

impl frame_system::offchain::AppCrypto<MultiSigner, MultiSignature> for TestAuthId {
impl frame_system::offchain::AppCrypto<MultiSigner, MultiSignature> for Iso8583AuthId {
type RuntimeAppPublic = Public;
type GenericSignature = sp_core::sr25519::Signature;
type GenericPublic = sp_core::sr25519::Public;
}

// implemented for mock runtime in test
impl frame_system::offchain::AppCrypto<<Sr25519Signature as Verify>::Signer, Sr25519Signature>
for TestAuthId
for Iso8583AuthId
{
type RuntimeAppPublic = Public;
type GenericSignature = sp_core::sr25519::Signature;
Expand Down
2 changes: 1 addition & 1 deletion pallets/iso-8583/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ where
}

impl crate::Config for Test {
type AuthorityId = crypto::TestAuthId;
type AuthorityId = crypto::Iso8583AuthId;
type RuntimeEvent = RuntimeEvent;
type Currency = Balances;
type PalletAccount = PalletAccount;
Expand Down
2 changes: 2 additions & 0 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
codec = { workspace = true, package = "parity-scale-codec" }
scale-info = { workspace = true }
log = { workspace = true }

pallet-aura = { workspace = true }
pallet-balances = { workspace = true }
Expand Down Expand Up @@ -85,6 +86,7 @@ std = [
"sp-transaction-pool/std",
"sp-version/std",
"substrate-wasm-builder",
"log/std",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
Expand Down
68 changes: 65 additions & 3 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@
#[cfg(feature = "std")]
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));

use codec::Encode;
use frame_support::PalletId;
use pallet_grandpa::AuthorityId as GrandpaId;
use sp_api::impl_runtime_apis;
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
create_runtime_str,
generic::{self, Era},
impl_opaque_keys,
traits::{
AccountIdConversion, AccountIdLookup, BlakeTwo256, Block as BlockT, IdentifyAccount,
NumberFor, One, Verify,
NumberFor, One, SaturatedConversion, Verify,
},
transaction_validity::{TransactionSource, TransactionValidity},
ApplyExtrinsicResult, MultiSignature,
Expand Down Expand Up @@ -216,7 +219,7 @@ impl pallet_timestamp::Config for Runtime {
}

/// Existential deposit.
pub const EXISTENTIAL_DEPOSIT: u128 = 500;
pub const EXISTENTIAL_DEPOSIT: u128 = 1;

impl pallet_balances::Config for Runtime {
type MaxLocks = ConstU32<50>;
Expand Down Expand Up @@ -257,6 +260,64 @@ impl pallet_sudo::Config for Runtime {
type WeightInfo = pallet_sudo::weights::SubstrateWeight<Runtime>;
}

impl frame_system::offchain::SigningTypes for Runtime {
type Public = <Signature as Verify>::Signer;
type Signature = Signature;
}

impl<LocalCall> frame_system::offchain::SendTransactionTypes<LocalCall> for Runtime
where
RuntimeCall: From<LocalCall>,
{
type OverarchingCall = RuntimeCall;
type Extrinsic = UncheckedExtrinsic;
}

impl<LocalCall> frame_system::offchain::CreateSignedTransaction<LocalCall> for Runtime
where
RuntimeCall: From<LocalCall>,
{
fn create_transaction<C: frame_system::offchain::AppCrypto<Self::Public, Self::Signature>>(
call: RuntimeCall,
public: <Signature as sp_runtime::traits::Verify>::Signer,
account: AccountId,
nonce: Nonce,
) -> Option<(
RuntimeCall,
<UncheckedExtrinsic as sp_runtime::traits::Extrinsic>::SignaturePayload,
)> {
let tip = 0;
// take the biggest period possible.
let period =
BlockHashCount::get().checked_next_power_of_two().map(|c| c / 2).unwrap_or(2) as u64;
let current_block = System::block_number()
.saturated_into::<u64>()
// The `System::block_number` is initialized with `n+1`,
// so the actual block number is `n`.
.saturating_sub(1);
let era = Era::mortal(period, current_block);
let extra = (
frame_system::CheckNonZeroSender::<Runtime>::new(),
frame_system::CheckSpecVersion::<Runtime>::new(),
frame_system::CheckTxVersion::<Runtime>::new(),
frame_system::CheckGenesis::<Runtime>::new(),
frame_system::CheckEra::<Runtime>::from(era),
frame_system::CheckNonce::<Runtime>::from(nonce),
frame_system::CheckWeight::<Runtime>::new(),
pallet_transaction_payment::ChargeTransactionPayment::<Runtime>::from(tip),
);
let raw_payload = SignedPayload::new(call, extra)
.map_err(|e| {
log::warn!("Unable to create signed payload: {:?}", e);
})
.ok()?;
let signature = raw_payload.using_encoded(|payload| C::sign(payload, public))?;
let address = sp_runtime::MultiAddress::Id(account);
let (call, extra, _) = raw_payload.deconstruct();
Some((call, (address, signature, extra)))
}
}

parameter_types! {
/// Pallet account ID
pub PalletAccount: AccountId = PalletId(*b"py/iso85").into_account_truncating();
Expand All @@ -267,6 +328,7 @@ parameter_types! {
impl pallet_iso_8583::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Currency = Balances;
type AuthorityId = pallet_iso_8583::crypto::Iso8583AuthId;
type PalletAccount = PalletAccount;
type MaxStringSize = ConstU32<1024>;
type WeightToFee = WeightToFee;
Expand Down

0 comments on commit 6f24225

Please sign in to comment.