-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathlib.rs
More file actions
1319 lines (1132 loc) · 48.2 KB
/
Copy pathlib.rs
File metadata and controls
1319 lines (1132 loc) · 48.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#![cfg_attr(not(feature = "std"), no_std)]
// `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256.
#![recursion_limit = "256"]
// Make the WASM binary available.
#[cfg(feature = "std")]
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
use beefy_primitives::{crypto::AuthorityId as BeefyId, mmr::MmrLeafVersion, ValidatorSet};
pub use frame_support::{
construct_runtime,
pallet_prelude::{
DispatchClass, Encode, InherentData, TransactionPriority, TransactionSource,
TransactionValidity, Weight,
},
parameter_types,
traits::fungibles::Inspect,
traits::{Everything, KeyOwnerProofSystem, StorageInfo},
weights::{
constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},
IdentityFee,
},
PalletId,
};
use frame_system::{
self,
limits::{BlockLength, BlockWeights},
EnsureNever,
};
pub use pallet_balances::Call as BalancesCall;
use pallet_deip::{ProjectId, H160};
use pallet_grandpa::{
fg_primitives, AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList,
};
use pallet_im_online::sr25519::AuthorityId as ImOnlineId;
use pallet_session::historical as pallet_session_historical;
pub use pallet_timestamp::Call as TimestampCall;
use pallet_transaction_payment::CurrencyAdapter;
use sp_api::{impl_runtime_apis, BlockT, NumberFor, RuntimeVersion};
use sp_core::OpaqueMetadata;
#[cfg(any(feature = "std", test))]
pub use sp_runtime::BuildStorage;
use sp_runtime::{
create_runtime_str,
generic::{self, Era},
impl_opaque_keys,
traits::{
AccountIdLookup, BlakeTwo256, ConvertInto, Extrinsic, IdentifyAccount, Keccak256,
OpaqueKeys, SaturatedConversion, StaticLookup, Verify,
},
ApplyExtrinsicResult, KeyTypeId, MultiSignature,
};
pub use sp_runtime::{Perbill, Permill};
use sp_std::prelude::*;
#[cfg(feature = "std")]
use sp_version::NativeVersion;
mod asset_transfer;
pub mod deip_account;
/// An index to a block.
pub type BlockNumber = u32;
/// Alias to 512-bit hash when used in the context of a transaction signature on the chain.
pub type Signature = MultiSignature;
/// Some way of identifying an account on the chain. We intentionally make it equivalent
/// to the public key of our transaction signing scheme.
pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::AccountId;
/// Balance of an account.
pub type Balance = u128;
pub type DeipAssetId = H160;
pub type AssetId = u32;
/// Balance of an UIAs.
pub type AssetBalance = u128;
pub type AssetExtra = ();
/// Identifier for the class of the NFT asset.
pub type NftClassId = u32; // ??? what is class id right type
/// Deip indentifier for the class of the NFT asset.
pub type DeipNftClassId = H160;
/// The type used to identify a unique asset within an asset class.
pub type InstanceId = u32; // ??? correct type
/// Type used for expressing timestamp.
pub type Moment = u64;
/// Index of a transaction in the chain.
pub type Index = u32;
/// A hash of some data used by the chain.
pub type Hash = sp_core::H256;
/// Digest item type.
// pub type DigestItem = generic::DigestItem<Hash>;
/// Opaque types. These are used by the CLI to instantiate machinery that don't need to know
/// the specifics of the runtime. They can then be made to be agnostic over specific formats
/// of data like extrinsics, allowing for them to continue syncing the network through upgrades
/// to even the core data structures.
pub mod opaque {
use super::*;
use sp_runtime::OpaqueExtrinsic as UncheckedExtrinsic;
/// Opaque block header type.
pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
/// Opaque block type.
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
/// Opaque block identifier type.
pub type BlockId = generic::BlockId<Block>;
impl_opaque_keys! {
pub struct SessionKeys {
pub babe: Babe,
pub grandpa: Grandpa,
pub im_online: ImOnline,
pub beefy: Beefy,
pub octopus: OctopusAppchain,
}
}
}
// To learn more about runtime versioning and what each of the following value means:
// https://substrate.dev/docs/en/knowledgebase/runtime/upgrades#runtime-versioning
#[sp_version::runtime_version]
pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("appchain"),
impl_name: create_runtime_str!("appchain-deip"),
authoring_version: 1,
// The version of the runtime specification. A full node will not attempt to use its native
// runtime in substitute for the on-chain Wasm runtime unless all of `spec_name`,
// `spec_version`, and `authoring_version` are the same between Wasm and native.
// This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use
// the compatible custom types.
spec_version: 105,
impl_version: 1,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
};
/// Since BABE is probabilistic this is the average expected block time that
/// we are targeting. Blocks will be produced at a minimum duration defined
/// by `SLOT_DURATION`, but some slots will not be allocated to any
/// authority and hence no block will be produced. We expect to have this
/// block time on average following the defined slot duration and the value
/// of `c` configured for BABE (where `1 - c` represents the probability of
/// a slot being empty).
/// This value is only used indirectly to define the unit constants below
/// that are expressed in blocks. The rest of the code should use
/// `SLOT_DURATION` instead (like the Timestamp pallet for calculating the
/// minimum period).
///
/// If using BABE with secondary slots (default) then all of the slots will
/// always be assigned, in which case `MILLISECS_PER_BLOCK` and
/// `SLOT_DURATION` should have the same value.
///
/// <https://research.web3.foundation/en/latest/polkadot/block-production/Babe.html#-6.-practical-results>
pub const MILLISECS_PER_BLOCK: Moment = 6000;
pub const SECS_PER_BLOCK: Moment = MILLISECS_PER_BLOCK / 1000;
// NOTE: Currently it is not possible to change the slot duration after the chain has started.
// Attempting to do so will brick block production.
pub const SLOT_DURATION: Moment = MILLISECS_PER_BLOCK;
// 1 in 4 blocks (on average, not counting collisions) will be primary BABE blocks.
pub const PRIMARY_PROBABILITY: (u64, u64) = (1, 4);
// NOTE: Currently it is not possible to change the epoch duration after the chain has started.
// Attempting to do so will brick block production.
pub const EPOCH_DURATION_IN_BLOCKS: BlockNumber = 4 * HOURS;
pub const EPOCH_DURATION_IN_SLOTS: u64 = {
const SLOT_FILL_RATE: f64 = MILLISECS_PER_BLOCK as f64 / SLOT_DURATION as f64;
(EPOCH_DURATION_IN_BLOCKS as f64 * SLOT_FILL_RATE) as u64
};
// These time units are defined in number of blocks.
pub const MINUTES: BlockNumber = 60 / (SECS_PER_BLOCK as BlockNumber);
pub const HOURS: BlockNumber = MINUTES * 60;
pub const DAYS: BlockNumber = HOURS * 24;
pub mod currency {
use super::Balance;
pub const OCTS: Balance = 1_000_000_000_000_000_000;
pub const UNITS: Balance = 1_000_000_000_000_000_000;
pub const DOLLARS: Balance = UNITS;
pub const CENTS: Balance = DOLLARS / 100;
pub const MILLICENTS: Balance = CENTS / 1_000;
pub const EXISTENSIAL_DEPOSIT: Balance = CENTS;
pub const fn deposit(items: u32, bytes: u32) -> Balance {
items as Balance * 15 * CENTS + (bytes as Balance) * 6 * CENTS
}
}
/// The BABE epoch configuration at genesis.
pub const BABE_GENESIS_EPOCH_CONFIG: sp_consensus_babe::BabeEpochConfiguration =
sp_consensus_babe::BabeEpochConfiguration {
c: PRIMARY_PROBABILITY,
allowed_slots: sp_consensus_babe::AllowedSlots::PrimaryAndSecondaryPlainSlots,
};
/// The version information used to identify this runtime when compiled natively.
#[cfg(feature = "std")]
pub fn native_version() -> NativeVersion {
NativeVersion { runtime_version: VERSION, can_author_with: Default::default() }
}
/// We assume that ~10% of the block weight is consumed by `on_initialize` handlers.
/// This is used to limit the maximal weight of a single extrinsic.
const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(10);
/// We allow `Normal` extrinsics to fill up the block up to 75%, the rest can be used
/// by Operational extrinsics.
const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
/// We allow for 2 seconds of compute with a 6 second average block time.
const MAXIMUM_BLOCK_WEIGHT: Weight = 2 * WEIGHT_PER_SECOND;
parameter_types! {
pub const BlockHashCount: BlockNumber = 2400;
pub const Version: RuntimeVersion = VERSION;
pub RuntimeBlockLength: BlockLength =
BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
pub RuntimeBlockWeights: BlockWeights = BlockWeights::builder()
.base_block(BlockExecutionWeight::get())
.for_class(DispatchClass::all(), |weights| {
weights.base_extrinsic = ExtrinsicBaseWeight::get();
})
.for_class(DispatchClass::Normal, |weights| {
weights.max_total = Some(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT);
})
.for_class(DispatchClass::Operational, |weights| {
weights.max_total = Some(MAXIMUM_BLOCK_WEIGHT);
// Operational transactions have some extra reserved space, so that they
// are included even if block reached `MAXIMUM_BLOCK_WEIGHT`.
weights.reserved = Some(
MAXIMUM_BLOCK_WEIGHT - NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT
);
})
.avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO)
.build_or_panic();
pub const SS58Prefix: u16 = 42;
}
// Configure FRAME pallets to include in runtime.
use frame_support::traits::Contains;
pub struct CallFilter;
impl Contains<Call> for CallFilter {
fn contains(_t: &Call) -> bool {
true
}
}
impl frame_system::Config for Runtime {
/// The basic call filter to use in dispatchable.
type BaseCallFilter = CallFilter;
/// Block & extrinsics weights: base values and limits.
type BlockWeights = RuntimeBlockWeights;
/// The maximum length of a block (in bytes).
type BlockLength = RuntimeBlockLength;
/// The identifier used to distinguish between accounts.
type AccountId = AccountId;
/// The aggregated dispatch type that is available for extrinsics.
type Call = Call;
/// The lookup mechanism to get account ID from whatever is passed in dispatchers.
type Lookup = AccountIdLookup<AccountId, ()>;
/// The index type for storing how many extrinsics an account has signed.
type Index = Index;
/// The index type for blocks.
type BlockNumber = BlockNumber;
/// The type for hashing blocks and tries.
type Hash = Hash;
/// The hashing algorithm used.
type Hashing = BlakeTwo256;
/// The header type.
type Header = generic::Header<BlockNumber, BlakeTwo256>;
/// The ubiquitous event type.
type Event = Event;
/// The ubiquitous origin type.
type Origin = Origin;
/// Maximum number of block number to block hash mappings to keep (oldest pruned first).
type BlockHashCount = BlockHashCount;
/// The weight of database operations that the runtime can invoke.
type DbWeight = RocksDbWeight;
/// Version of the runtime.
type Version = Version;
/// Converts a module to the index of the module in `construct_runtime!`.
///
/// This type is being generated by `construct_runtime!`.
type PalletInfo = PalletInfo;
/// What to do if a new account is created.
type OnNewAccount = ();
/// What to do if an account is fully reaped from the system.
type OnKilledAccount = ();
/// The data to be stored in an account.
type AccountData = pallet_balances::AccountData<Balance>;
/// Weight information for the extrinsics of this pallet.
type SystemWeightInfo = ();
/// This is used as an identifier of the chain. 42 is the generic substrate prefix.
type SS58Prefix = SS58Prefix;
/// The set code logic, just the default since we're not a parachain.
type OnSetCode = ();
}
impl pallet_randomness_collective_flip::Config for Runtime {}
impl pallet_grandpa::Config for Runtime {
type Event = Event;
type Call = Call;
type KeyOwnerProofSystem = Historical;
type KeyOwnerProof =
<Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(KeyTypeId, GrandpaId)>>::Proof;
type KeyOwnerIdentification = <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(
KeyTypeId,
GrandpaId,
)>>::IdentificationTuple;
type HandleEquivocation =
pallet_grandpa::EquivocationHandler<Self::KeyOwnerIdentification, (), ReportLongevity>;
type WeightInfo = ();
type MaxAuthorities = MaxAuthorities;
}
parameter_types! {
pub const MinimumPeriod: Moment = SLOT_DURATION / 2;
}
impl pallet_timestamp::Config for Runtime {
/// A timestamp: milliseconds since the unix epoch.
type Moment = Moment;
type OnTimestampSet = Babe;
type MinimumPeriod = MinimumPeriod;
type WeightInfo = ();
}
parameter_types! {
pub const ExistentialDeposit: Balance = currency::EXISTENSIAL_DEPOSIT;
// For weight estimation, we assume that the most locks on an individual account will be 50.
// This number may need to be adjusted in the future if this assumption no longer holds true.
pub const MaxLocks: u32 = 50;
pub const MaxReserves: u32 = 50;
}
impl pallet_balances::Config for Runtime {
type MaxLocks = MaxLocks;
type MaxReserves = MaxReserves;
type ReserveIdentifier = [u8; 8];
/// The type for recording an account's balance.
type Balance = Balance;
/// The ubiquitous event type.
type Event = Event;
type DustRemoval = ();
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = System;
type WeightInfo = pallet_balances::weights::SubstrateWeight<Runtime>;
}
parameter_types! {
pub const TransactionByteFee: Balance = 10 * currency::MILLICENTS;
pub const OperationalFeeMultiplier: u8 = 5;
}
impl pallet_deip_ecosystem_fund::Config for Runtime {}
use pallet_deip_ecosystem_fund::DontBurnFee;
impl pallet_transaction_payment::Config for Runtime {
type OnChargeTransaction = CurrencyAdapter<Balances, DontBurnFee<(Self, Balances)>>;
type TransactionByteFee = TransactionByteFee;
type WeightToFee = IdentityFee<Balance>;
type FeeMultiplierUpdate = ();
type OperationalFeeMultiplier = OperationalFeeMultiplier;
}
parameter_types! {
// NOTE: Currently it is not possible to change the epoch duration after the chain has started.
// Attempting to do so will brick block production.
pub const EpochDuration: u64 = EPOCH_DURATION_IN_SLOTS;
pub const ExpectedBlockTime: Moment = MILLISECS_PER_BLOCK;
pub const ReportLongevity: u64 =
BondingDuration::get() as u64 * SessionsPerEra::get() as u64 * EpochDuration::get();
pub const MaxAuthorities: u32 = 100;
}
impl pallet_babe::Config for Runtime {
type EpochDuration = EpochDuration;
type ExpectedBlockTime = ExpectedBlockTime;
type EpochChangeTrigger = pallet_babe::ExternalTrigger;
type DisabledValidators = Session;
type KeyOwnerProofSystem = Historical;
type KeyOwnerProof = <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(
KeyTypeId,
pallet_babe::AuthorityId,
)>>::Proof;
type KeyOwnerIdentification = <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(
KeyTypeId,
pallet_babe::AuthorityId,
)>>::IdentificationTuple;
type HandleEquivocation =
pallet_babe::EquivocationHandler<Self::KeyOwnerIdentification, (), ReportLongevity>;
type WeightInfo = ();
type MaxAuthorities = MaxAuthorities;
}
parameter_types! {
pub const UncleGenerations: BlockNumber = 0;
}
impl pallet_authorship::Config for Runtime {
type FindAuthor = pallet_session::FindAccountFromAuthorIndex<Self, Babe>;
type UncleGenerations = UncleGenerations;
type FilterUncle = ();
type EventHandler = (OctopusLpos, ImOnline);
}
parameter_types! {
pub const DisabledValidatorsThreshold: Perbill = Perbill::from_percent(17);
}
impl pallet_session::Config for Runtime {
type Event = Event;
type ValidatorId = <Self as frame_system::Config>::AccountId;
type ValidatorIdOf = ConvertInto;
type ShouldEndSession = Babe;
type NextSessionRotation = Babe;
type SessionManager = pallet_session_historical::NoteHistoricalRoot<Self, OctopusLpos>;
type SessionHandler = <opaque::SessionKeys as OpaqueKeys>::KeyTypeIdProviders;
type Keys = opaque::SessionKeys;
// type DisabledValidatorsThreshold = DisabledValidatorsThreshold;
type WeightInfo = pallet_session::weights::SubstrateWeight<Runtime>;
}
impl pallet_session_historical::Config for Runtime {
type FullIdentification = u128;
type FullIdentificationOf = pallet_octopus_lpos::ExposureOf<Runtime>;
}
parameter_types! {
pub const ImOnlineUnsignedPriority: TransactionPriority = TransactionPriority::max_value();
// /// We prioritize im-online heartbeats over election solution submission.
// pub const StakingUnsignedPriority: TransactionPriority = TransactionPriority::max_value() / 2;
pub const MaxKeys: u32 = 10_000;
pub const MaxPeerInHeartbeats: u32 = 10_000;
pub const MaxPeerDataEncodingSize: u32 = 1_000;
}
impl<LocalCall> frame_system::offchain::CreateSignedTransaction<LocalCall> for Runtime
where
Call: From<LocalCall>,
{
fn create_transaction<C: frame_system::offchain::AppCrypto<Self::Public, Self::Signature>>(
call: Call,
public: <Signature as Verify>::Signer,
account: AccountId,
nonce: Index,
) -> Option<(Call, <UncheckedExtrinsic as 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::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 = <Self as frame_system::Config>::Lookup::unlookup(account);
let (call, extra, _) = raw_payload.deconstruct();
Some((call, (address, signature, extra)))
}
}
impl frame_system::offchain::SigningTypes for Runtime {
type Public = <Signature as Verify>::Signer;
type Signature = Signature;
}
impl<C> frame_system::offchain::SendTransactionTypes<C> for Runtime
where
Call: From<C>,
{
type Extrinsic = UncheckedExtrinsic;
type OverarchingCall = Call;
}
impl pallet_im_online::Config for Runtime {
type AuthorityId = ImOnlineId;
type Event = Event;
type NextSessionRotation = Babe;
type ValidatorSet = Historical;
type ReportUnresponsiveness = ();
type UnsignedPriority = ImOnlineUnsignedPriority;
type WeightInfo = pallet_im_online::weights::SubstrateWeight<Runtime>;
type MaxKeys = MaxKeys;
type MaxPeerInHeartbeats = MaxPeerInHeartbeats;
type MaxPeerDataEncodingSize = MaxPeerDataEncodingSize;
}
type MmrHash = <Keccak256 as sp_runtime::traits::Hash>::Output;
/// A BEEFY consensus digest item with MMR root hash.
pub struct DepositLog;
impl pallet_mmr::primitives::OnNewRoot<MmrHash> for DepositLog {
fn on_new_root(root: &Hash) {
let digest = generic::DigestItem::Consensus(
beefy_primitives::BEEFY_ENGINE_ID,
codec::Encode::encode(&beefy_primitives::ConsensusLog::<BeefyId>::MmrRoot(*root)),
);
<frame_system::Pallet<Runtime>>::deposit_log(digest);
}
}
impl pallet_mmr::Config for Runtime {
const INDEXING_PREFIX: &'static [u8] = b"mmr";
type Hashing = Keccak256;
type Hash = MmrHash;
type LeafData = pallet_beefy_mmr::Pallet<Self>;
type OnNewRoot = pallet_beefy_mmr::DepositBeefyDigest<Self>;
type WeightInfo = ();
}
parameter_types! {
pub const AssetDeposit: Balance = 100 * currency::UNITS;
pub const ApprovalDeposit: Balance = 1 * currency::UNITS;
pub const StringLimit: u32 = 200;
pub const MetadataDepositBase: Balance = 10 * currency::UNITS;
pub const MetadataDepositPerByte: Balance = 1 * currency::UNITS;
}
impl pallet_assets::Config for Runtime {
type Event = Event;
type Balance = AssetBalance;
type AssetId = AssetId;
type Currency = Balances;
type ForceOrigin = EnsureNever<AccountId>;
type AssetDeposit = AssetDeposit;
type MetadataDepositBase = MetadataDepositBase;
type MetadataDepositPerByte = MetadataDepositPerByte;
type ApprovalDeposit = ApprovalDeposit;
type StringLimit = StringLimit;
type Freezer = ();
type Extra = AssetExtra;
type WeightInfo = pallet_assets::weights::SubstrateWeight<Runtime>;
}
impl deip_projects_info::DeipProjectsInfo<AccountId> for Runtime {
type ProjectId = pallet_deip::ProjectId;
type InvestmentId = pallet_deip_investment_opportunity::crowdfunding::CrowdfundingId;
fn try_get_project_team(id: &Self::ProjectId) -> Option<AccountId> {
Deip::try_get_project_team(id)
}
fn project_id(source: &[u8]) -> Self::ProjectId {
Self::ProjectId::from_slice(source)
}
}
parameter_types! {
pub const WipePeriod: BlockNumber = DAYS;
}
pub struct AssetIdInit;
impl deip_asset_system::AssetIdInitT<DeipAssetId> for AssetIdInit {
fn asset_id(raw: &[u8]) -> DeipAssetId {
DeipAssetId::from_slice(raw)
}
}
impl pallet_deip_assets::Config for Runtime {}
impl pallet_deip_balances::Config for Runtime {}
parameter_types! {
/// The basic amount of funds that must be reserved for an asset class.
pub const ClassDeposit: Balance = 10 * currency::UNITS;
/// The basic amount of funds that must be reserved for an asset instance.
pub const InstanceDeposit: Balance = 10 * currency::UNITS;
/// The basic amount of funds that must be reserved when adding an attribute to an asset.
pub const AttributeDepositBase: Balance = 10 * currency::UNITS;
/// The additional funds that must be reserved for the number of bytes store in metadata,
/// either "normal" metadata or attribute metadata.
pub const DepositPerByte: Balance = 10 * currency::UNITS;
/// The maximum length of an attribute key.
pub const KeyLimit: u32 = 100;
/// The maximum length of an attribute value.
pub const ValueLimit: u32 = 200;
/// Greater class ids will be reserved for `deip_*` calls.
pub const MaxOriginClassId: NftClassId = NftClassId::MAX / 2;
}
impl pallet_uniques::Config for Runtime {
type Event = Event;
type ClassId = NftClassId;
type InstanceId = InstanceId;
type Currency = Balances;
type ForceOrigin = EnsureNever<AccountId>;
type ClassDeposit = ClassDeposit;
type InstanceDeposit = InstanceDeposit;
type MetadataDepositBase = MetadataDepositBase; // ??? is it correct to reuse const from assets
type AttributeDepositBase = AttributeDepositBase;
type DepositPerByte = DepositPerByte;
type StringLimit = StringLimit; // ??? is it correct to reuse const from assets
type KeyLimit = KeyLimit;
type ValueLimit = ValueLimit;
type WeightInfo = pallet_uniques::weights::SubstrateWeight<Runtime>;
}
impl pallet_deip_uniques::Config for Runtime {}
impl pallet_beefy::Config for Runtime {
type BeefyId = BeefyId;
}
parameter_types! {
pub LeafVersion: MmrLeafVersion = MmrLeafVersion::new(0,0);
}
impl pallet_beefy_mmr::Config for Runtime {
type LeafVersion = LeafVersion;
type BeefyAuthorityToMerkleLeaf = pallet_beefy_mmr::BeefyEcdsaToEthereum;
type ParachainHeads = ();
}
pub struct OctopusAppCrypto;
impl frame_system::offchain::AppCrypto<<Signature as Verify>::Signer, Signature>
for OctopusAppCrypto
{
type RuntimeAppPublic = pallet_octopus_appchain::AuthorityId;
type GenericSignature = sp_core::sr25519::Signature;
type GenericPublic = sp_core::sr25519::Public;
}
parameter_types! {
pub const OctopusAppchainPalletId: PalletId = PalletId(*b"py/octps");
pub const GracePeriod: u32 = 10;
pub const UnsignedPriority: u64 = 1 << 21;
pub const RequestEventLimit: u32 = 10;
pub const UpwardMessagesLimit: u32 = 10;
}
impl pallet_octopus_appchain::Config for Runtime {
type AuthorityId = OctopusAppCrypto;
type Event = Event;
type Call = Call;
type PalletId = OctopusAppchainPalletId;
type LposInterface = OctopusLpos;
type UpwardMessagesInterface = OctopusUpwardMessages;
type Currency = Balances;
type Assets = Assets; // @TODO replace with deip assets
type AssetBalance = AssetBalance;
type AssetId = AssetId;
type AssetIdByName = OctopusAppchain;
type GracePeriod = GracePeriod;
type UnsignedPriority = UnsignedPriority;
type RequestEventLimit = RequestEventLimit;
type WeightInfo = pallet_octopus_appchain::weights::SubstrateWeight<Runtime>;
}
parameter_types! {
pub const SessionsPerEra: sp_staking::SessionIndex = 6;
pub const BondingDuration: pallet_octopus_lpos::EraIndex = 24 * 28;
// pub OffchainRepeat: BlockNumber = 5;
pub const BlocksPerEra: u32 = EPOCH_DURATION_IN_BLOCKS * 6;
}
impl pallet_octopus_lpos::Config for Runtime {
type Currency = Balances;
type UnixTime = Timestamp;
type Event = Event;
type Reward = (); // rewards are minted from the void
type SessionsPerEra = SessionsPerEra;
type BondingDuration = BondingDuration;
type BlocksPerEra = BlocksPerEra;
type SessionInterface = Self;
type AppchainInterface = OctopusAppchain;
type UpwardMessagesInterface = OctopusUpwardMessages;
type PalletId = OctopusAppchainPalletId;
type ValidatorsProvider = OctopusAppchain;
type WeightInfo = pallet_octopus_lpos::weights::SubstrateWeight<Runtime>;
}
impl pallet_octopus_upward_messages::Config for Runtime {
type Event = Event;
type Call = Call;
type UpwardMessagesLimit = UpwardMessagesLimit;
type WeightInfo = pallet_octopus_upward_messages::weights::SubstrateWeight<Runtime>;
}
impl pallet_sudo::Config for Runtime {
type Event = Event;
type Call = Call;
}
pub type TransactionCtx = pallet_deip_portal::PortalCtxOf<Runtime>;
pub type TransactionCtxId = pallet_deip_portal::TransactionCtxId<TransactionCtx>;
parameter_types! {
pub const MaxNdaParties: u16 = 50;
pub const MaxCrowdfundingShares: u16 = 10;
}
impl pallet_deip::Config for Runtime {
type TransactionCtx = TransactionCtx;
type Event = Event;
type DeipAccountId = deip_account::DeipAccountId<Self::AccountId>;
type Currency = Balances;
type DeipWeightInfo = pallet_deip::Weights<Self>;
type MaxNdaParties = MaxNdaParties;
}
use deip_asset_system::NFTokenFraction;
impl pallet_deip_investment_opportunity::Config for Runtime {
type DeipInvestmentWeightInfo = pallet_deip_investment_opportunity::weights::Weights<Self>;
type Event = Event;
type TransactionCtx = TransactionCtx;
type DeipAccountId = deip_account::DeipAccountId<Self::AccountId>;
type MaxShares = MaxCrowdfundingShares;
type Currency = Balances;
type Crowdfunding =
pallet_deip_investment_opportunity::crowdfunding::SimpleCrowdfundingV2<Self>;
type AssetAmount = <Self as pallet_assets::Config>::Balance;
type AssetId = Self::Hash;
type AssetImpl = DeipFNFT;
type Asset = NFTokenFraction<Self::AssetImpl>;
}
parameter_types! {
pub const ProposalTtl: Moment = 7 * DAYS as Moment * MILLISECS_PER_BLOCK;
pub const ProposalExpirePeriod: BlockNumber = HOURS;
}
impl pallet_deip_proposal::pallet::Config for Runtime {
type TransactionCtx = TransactionCtx;
type Event = Event;
type Call = Call;
type DeipAccountId = deip_account::DeipAccountId<Self::AccountId>;
type Ttl = ProposalTtl;
type ExpirePeriod = ProposalExpirePeriod;
type WeightInfo = pallet_deip_proposal::CallWeight<Self>;
}
parameter_types! {
pub const DaoMaxSignatories: u16 = 50;
}
impl pallet_deip_dao::Config for Runtime {
type Event = Event;
type Call = Call;
type DaoId = pallet_deip_dao::DaoId;
type DeipDaoWeightInfo = pallet_deip_dao::weights::Weights<Self>;
type MaxSignatories = DaoMaxSignatories;
}
parameter_types! {
pub const RelativeThresholdLimit: <Assets as Inspect<AccountId>>::Balance = 100000000;
pub const MaxVotesPerAccountAsset: u16 = 5;
}
impl pallet_deip_stake_voting::Config for Runtime {
type Event = Event;
type Call = Call;
type Currency = Balances;
type DepositBase = DepositBase;
type AssetId = Self::Hash;
type AssetBalance = <Self as pallet_assets::Config>::Balance;
type Assets = DeipFNFT;
type RelativeThresholdLimit = RelativeThresholdLimit;
type MaxVotesPerAccountAsset = MaxVotesPerAccountAsset;
type WeightInfo = pallet_deip_stake_voting::weights::Weights<Runtime>;
}
parameter_types! {
// One storage item; key size is 32; value is size 4+4+16+32 bytes = 56 bytes.
pub const DepositBase: Balance = currency::deposit(1, 88);
// Additional storage item size of 32 bytes.
pub const DepositFactor: Balance = currency::deposit(0, 32);
pub const MaxSignatories: u16 = 100;
}
impl pallet_multisig::Config for Runtime {
type Event = Event;
type Call = Call;
type Currency = Balances;
type DepositBase = DepositBase;
type DepositFactor = DepositFactor;
type MaxSignatories = MaxSignatories;
type WeightInfo = pallet_multisig::weights::SubstrateWeight<Runtime>;
}
impl pallet_utility::Config for Runtime {
type Event = Event;
type Call = Call;
type WeightInfo = pallet_utility::weights::SubstrateWeight<Runtime>;
type PalletsOrigin = OriginCaller;
}
impl pallet_deip_portal::Config for Runtime {
type TenantLookup = Self;
type PortalId = <Runtime as pallet_deip_dao::Config>::DaoId;
type Portal = pallet_deip_portal::Portal<Self>;
type Call = Call;
type UnsignedValidator = Self;
type UncheckedExtrinsic = UncheckedExtrinsic;
type DeipPortalWeightInfo = pallet_deip_portal::weights::Weights<Self>;
}
impl pallet_deip_portal::TenantLookupT<AccountId> for Runtime {
type TenantId = <Self as pallet_deip_portal::Config>::PortalId;
fn lookup(key: &AccountId) -> Option<Self::TenantId> {
DeipDao::lookup_dao(key)
}
}
parameter_types! {
pub const MinVestedTransfer: u64 = 1;
}
impl pallet_deip_vesting::Config for Runtime {
type Event = Event;
type Currency = Balances;
type UnixTime = Timestamp;
type MinVestedTransfer = MinVestedTransfer;
type U64ToBalance = ConvertInto;
type VestingWeightInfo = pallet_deip_vesting::weights::SubstrateWeight<Runtime>;
}
impl pallet_deip_f_nft::Config for Runtime {
type Event = Event;
type NFTCollectionId = sp_core::H160;
type NFTCollectionSize = InstanceId;
type NFTItemId = Hash;
type NFTFractionAmount = Balance;
type InternalCollectionId = NftClassId;
type InternalFTokenId = AssetId;
type Fungibles = pallet_deip_f_nft::Pallet<Self>;
}
parameter_types! {
pub const MinOfferPrice: u64 = 1000000;
}
impl pallet_deip_market::Config for Runtime {
type Event = Event;
type Currency = Balances;
type Token = Hash;
type Tokens = DeipFNFT;
type MinOfferPrice = MinOfferPrice;
type WeightInfo = pallet_deip_market::weights::Weights<Runtime>;
}
// Create the runtime by composing the FRAME pallets that were previously configured.
construct_runtime!(
pub enum Runtime
where
Block = Block,
NodeBlock = opaque::Block,
UncheckedExtrinsic = UncheckedExtrinsic,
{
System: frame_system,
Babe: pallet_babe,
Timestamp: pallet_timestamp,
Authorship: pallet_authorship,
Balances: pallet_balances,
DeipBalances: pallet_deip_balances::{Pallet},
TransactionPayment: pallet_transaction_payment,
OctopusAppchain: pallet_octopus_appchain::{Pallet, Call, Storage, Config<T>, Event<T>, ValidateUnsigned},
OctopusLpos: pallet_octopus_lpos,
OctopusUpwardMessages: pallet_octopus_upward_messages::{Pallet, Call, Storage, Event<T>},
Session: pallet_session,
Grandpa: pallet_grandpa,
Sudo: pallet_sudo,
ImOnline: pallet_im_online,
Historical: pallet_session_historical::{Pallet},
RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Storage},
Assets: pallet_assets::{Pallet, Storage, Event<T>},
Uniques: pallet_uniques::{Pallet, Storage, Event<T>},
Mmr: pallet_mmr::{Pallet, Storage},
Beefy: pallet_beefy::{Pallet, Config<T>},
MmrLeaf: pallet_beefy_mmr,
Multisig: pallet_multisig::{Pallet, Call, Storage, Event<T>},
Utility: pallet_utility::{Pallet, Call, Event},
Deip: pallet_deip::{Pallet, Call, Storage, Event<T>, Config},
DeipProposal: pallet_deip_proposal::{Pallet, Call, Storage, Event<T>, Config, ValidateUnsigned},
DeipDao: pallet_deip_dao::{Pallet, Call, Storage, Event<T>, Config},
DeipStakeVoting: pallet_deip_stake_voting::{Pallet, Call, Storage, Event<T>},
DeipPortal: pallet_deip_portal::{Pallet, Call, Storage, Config, ValidateUnsigned},
DeipVesting: pallet_deip_vesting::{Pallet, Call, Storage, Event<T>, Config<T>},
DeipEcosystemFund: pallet_deip_ecosystem_fund::{Pallet, Config<T>, Storage},
DeipInvestmentOpportunity: pallet_deip_investment_opportunity,
DeipFNFT: pallet_deip_f_nft,
DeipMarket: pallet_deip_market::{Pallet, Call, Storage, Event<T>},
// deprecated
DeipAssets: pallet_deip_assets::{Pallet, Storage},
DeipUniques: pallet_deip_uniques::{Pallet, Storage},
}
);
/// The address format for describing accounts.
pub type Address = sp_runtime::MultiAddress<AccountId, ()>;
/// Block header type as expected by this runtime.
pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
/// Block type as expected by this runtime.
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
/// The SignedExtension to the basic transaction logic.
pub type SignedExtra = (
frame_system::CheckSpecVersion<Runtime>,
frame_system::CheckTxVersion<Runtime>,
frame_system::CheckGenesis<Runtime>,
frame_system::CheckEra<Runtime>,
frame_system::CheckNonce<Runtime>,
frame_system::CheckWeight<Runtime>,
pallet_transaction_payment::ChargeTransactionPayment<Runtime>,
);
/// Unchecked extrinsic type as expected by this runtime.
pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>;
/// The payload being signed in transactions.
pub type SignedPayload = generic::SignedPayload<Call, SignedExtra>;
/// Executive: handles dispatch to the various modules.
pub type Executive = frame_executive::Executive<
Runtime,
Block,
frame_system::ChainContext<Runtime>,
Runtime,
AllPallets,
>;
/// MMR helper types.
mod mmr {
use super::Runtime;
pub use pallet_mmr::primitives::*;
pub type Leaf = <<Runtime as pallet_mmr::Config>::LeafData as LeafDataProvider>::LeafData;
pub type Hash = <Runtime as pallet_mmr::Config>::Hash;
pub type Hashing = <Runtime as pallet_mmr::Config>::Hashing;
}
impl_runtime_apis! {
impl sp_api::Core<Block> for Runtime {
fn version() -> RuntimeVersion {
VERSION
}
fn execute_block(block: Block) {
Executive::execute_block(block);
}
fn initialize_block(header: &<Block as BlockT>::Header) {
Executive::initialize_block(header)
}
}
impl sp_api::Metadata<Block> for Runtime {