量化合约项目系统开发技术丨合约量化系统开发流程方案

简介: 量化合约项目系统开发技术丨合约量化系统开发流程方案

1.实现Instance类型
instantiable pallets必须调用decl_storage!宏才能Instance创建类型。

Instance在 Config trait、Event 类型和 Store trait 中添加一个泛型类型。 下面的代码片段显示了pallet的Config和Store trait所需的修改:

pub trait Config<I: Instance>: frame_system::Config {
type Event: From<Event> + Into<::Event>;
}
/// Include the I: Instance type parameter in storage declaration
decl_storage! {
trait Store for Module<T: Config, I: Instance> as MintToken {
/ --snip-- /
配置你的运行时
包括mint_tokenin 的两个实例runtime/src/lib.rs:
/ --snip-- /
// Instance1 of mint_token
impl mint_token::Config<mint_token::Instance1> for Runtime {

type Event = Event;

}

// Instance2 of mint_token
impl mint_token::Config<mint_token::Instance2> for Runtime {

type Event = Event;

}

/ --snip-- /
MintToken1: mint_token::::{Pallet, Call, Storage, Event},
MintToken2: mint_token::::{Pallet, Call, Storage, Event},
/ --snip-- /
示例-波卡的运行时

// Copyright 2017-2020 Parity Technologies (UK) Ltd.
// This file is part of Polkadot.

// Polkadot is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Polkadot is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see http://www.gnu.org/licenses/.

//! The Polkadot runtime. This can be compiled with #[no_std], ready for Wasm.

![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"]

use pallet_transaction_payment::CurrencyAdapter;
use runtime_common::{

auctions, claims, crowdloan, impl_runtime_weights, impls::DealWithFees, paras_registrar,
prod_or_fast, slots, BlockHashCount, BlockLength, CurrencyToVote, SlowAdjustingFeeUpdate,

};

use runtime_parachains::{

configuration as parachains_configuration, disputes as parachains_disputes,
dmp as parachains_dmp, hrmp as parachains_hrmp, inclusion as parachains_inclusion,
initializer as parachains_initializer, origin as parachains_origin, paras as parachains_paras,
paras_inherent as parachains_paras_inherent, reward_points as parachains_reward_points,
runtime_api_impl::v2 as parachains_runtime_api_impl, scheduler as parachains_scheduler,
session_info as parachains_session_info, shared as parachains_shared, ump as parachains_ump,

};

use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId;
use beefy_primitives::crypto::AuthorityId as BeefyId;
use frame_election_provider_support::{generate_solution_type, onchain, SequentialPhragmen};
use frame_support::{

construct_runtime, parameter_types,
traits::{
    Contains, EitherOfDiverse, InstanceFilter, KeyOwnerProofSystem, LockIdentifier,
    PrivilegeCmp,
},
weights::ConstantMultiplier,
PalletId, RuntimeDebug,

};
use frame_system::EnsureRoot;
use pallet_grandpa::{fg_primitives, AuthorityId as GrandpaId};
use pallet_im_online::sr25519::AuthorityId as ImOnlineId;
use pallet_session::historical as session_historical;
use pallet_transaction_payment::{FeeDetails, RuntimeDispatchInfo};
use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
use primitives::v2::{

AccountId, AccountIndex, Balance, BlockNumber, CandidateEvent, CandidateHash,
CommittedCandidateReceipt, CoreState, DisputeState, GroupRotationInfo, Hash, Id as ParaId,
InboundDownwardMessage, InboundHrmpMessage, Moment, Nonce, OccupiedCoreAssumption,
PersistedValidationData, ScrapedOnChainVotes, SessionInfo, Signature, ValidationCode,
ValidationCodeHash, ValidatorId, ValidatorIndex,

};
use sp_core::OpaqueMetadata;
use sp_mmr_primitives as mmr;
use sp_runtime::{

create_runtime_str,
curve::PiecewiseLinear,
generic, impl_opaque_keys,
traits::{
    AccountIdLookup, BlakeTwo256, Block as BlockT, ConvertInto, Extrinsic as ExtrinsicT,
    OpaqueKeys, SaturatedConversion, Verify,
},
transaction_validity::{TransactionPriority, TransactionSource, TransactionValidity},
ApplyExtrinsicResult, KeyTypeId, Perbill, Percent, Permill,

};
use sp_staking::SessionIndex;
use sp_std::{cmp::Ordering, collections::btree_map::BTreeMap, prelude::*};

[cfg(any(feature = "std", test))]

use sp_version::NativeVersion;
use sp_version::RuntimeVersion;
use static_assertions::const_assert;

pub use frame_system::Call as SystemCall;
pub use pallet_balances::Call as BalancesCall;
pub use pallet_election_provider_multi_phase::Call as EPMCall;

[cfg(feature = "std")]

pub use pallet_staking::StakerStatus;
pub use pallet_timestamp::Call as TimestampCall;

[cfg(any(feature = "std", test))]

pub use sp_runtime::BuildStorage;

相关文章
|
云栖大会 开发者
收到阿里云【乘风者计划】博主证书和奖励
收到阿里云【乘风者计划】博主证书和奖励 2023年2月对我来说是一个很好的开端,因为我在1号就收到了阿里云寄给我的【乘风者计划】博主证书和奖励。好兆头啊! 我收到的是我获得的【技术博主】【星级博主】【专家博主】三个的奖品和证书,一快给我寄过来哒!
3559 2
收到阿里云【乘风者计划】博主证书和奖励
|
缓存 开发工具 git
【已解决】git pull 显示 Already up-to-date,但文件并没有更新
git pull 显示 Already up-to-date,但文件并没有更新
2934 0
|
5月前
|
弹性计算 NoSQL 关系型数据库
2026年阿里云新用户优惠权益:优惠券、云服务器38元起、域名1元注册等活动介绍
2026年阿里云为新注册用户推出多重优惠政策。优惠券方面,提供迁云补贴、折扣券、学生专属300元无门槛券等多种选择。云服务器低至38元/年,涵盖经济型e实例99元/年、轻量应用服务器38元起、u1实例199元/年及第九代c9i/g9i/r9i六八折等。云数据库方面,RDS、PolarDB、Redis等均享六折起优惠。域名注册1元起,支持.com、.cn等主流后缀及建站组合套餐。此外,160余款核心云产品提供免费试用,ECS最高可免3个月。
2026年阿里云新用户优惠权益:优惠券、云服务器38元起、域名1元注册等活动介绍
|
6月前
|
人工智能 缓存 自然语言处理
2026年阿里云百炼Token Plan全解析:功能、计费与配置详解
阿里云百炼Token Plan是面向团队与企业推出的AI大模型订阅服务,以Credits作为统一计量积分,覆盖文本生成、图像生成、代码开发等全场景模型调用,兼容主流AI编程与智能体工具,提供团队管理、预算管控、数据安全等企业级能力。2026年,该服务进一步优化计费逻辑与功能配置,形成标准化、可扩展的团队AI服务方案,满足不同规模团队的AI使用需求。
893 0
|
6月前
|
人工智能 搜索推荐 SEO
外贸机械企业AI搜索曝光提升3倍:AB客GEO介入全过程复盘
本文剖析外贸机械企业如何应对AI搜索变革:传统SEO已不足,需转向GEO(生成式搜索引擎优化)。通过构建企业数字人格、建立客户采购问题库、重构FAQ/产品/案例内容、增强结构化数据,使AI能理解、信任并引用企业。某企业实践后,AI搜索曝光提升约3倍,实现从“争排名”到“进答案”的跃迁。
452 0
|
存储 JavaScript Java
医院患者随访系统源码,支持患者档案管理、随访计划制定、智能提醒、多方式随访执行及数据统计分析
Java版医院随访系统源码,B/S前后端分离架构,自主版权,含落地案例。基于SpringBoot+Vue+Ant-Design+MySQL,支持患者档案管理、随访计划制定、智能提醒、多方式随访执行及数据统计分析,助力医疗机构实现患者全周期健康管理。
514 0
|
Java 项目管理 Maven
Maven项目管理与构建自动化完全指南
Maven彻底改变了Java项目管理方式,通过POM模型、依赖管理和标准化构建流程,大幅提升开发效率。本文深入解析其核心概念、多模块管理、私服搭建及与Spring Boot、Docker等现代技术栈的集成实践,助力开发者实现高效、规范的项目构建与团队协作。
1603 156
Maven项目管理与构建自动化完全指南
|
域名解析 网络协议 Ubuntu
DHCP与DNS的配置
通过这些步骤,您可以在Linux环境下成功配置和验证DHCP和DNS服务。希望这些内容对您的学习和工作有所帮助。
1723 27
|
Linux
Linux 文件权限详解
Linux 文件权限用于控制文件和目录的访问,分为读、写、执行三种权限,并针对文件所有者、所属组和其他用户分别设置。使用 `ls -l` 查看权限信息,`chmod` 修改权限。符号方式(如 `u+rwx`)和数字方式(如 755)均可设置权限。例如,`chmod +x filename` 添加执行权限给所有用户,`chmod 644 filename` 设置所有者读写、其他用户只读权限。
799 13
|
存储 数据采集 数据格式
Python自动化Office文档处理全攻略
本文介绍如何使用Python自动化处理Word、Excel和PDF文档,提升办公效率。通过安装`python-docx`、`openpyxl`、`pandas`、`PyPDF2`和`pdfplumber`等库,可以轻松实现读取、修改、创建和批量处理这些文档。具体包括:自动化处理Word文档(如读取、修改内容、调整样式),Excel文档(如读取、清洗、汇总数据),以及PDF文档(如提取文本和表格数据)。结合代码示例和实战案例,帮助你掌握高效办公技巧,减少手动操作的错误率。
1631 1