Skip to content

Commit

Permalink
Fix WASM build
Browse files Browse the repository at this point in the history
This requird refactoring the assets pallet into 3 separate crates:
rpc, runtime-api, and pallet
so that there weren't non-wasm compatable dependencies in the runtime.
  • Loading branch information
benluelo committed Jan 14, 2022
1 parent e385f33 commit 4587b38
Show file tree
Hide file tree
Showing 25 changed files with 318 additions and 236 deletions.
46 changes: 37 additions & 9 deletions Cargo.lock

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

323 changes: 162 additions & 161 deletions Cargo.toml

Large diffs are not rendered by default.

23 changes: 11 additions & 12 deletions frame/assets/Cargo.toml → frame/assets/pallet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,49 +17,48 @@ frame-system = { default-features = false, git = "https://github.com/paritytech/

# substrate primitives
sp-api = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13" }
sp-blockchain = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13" }
sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13" }
sp-arithmetic = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13" }
# sp-arithmetic = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13" }
sp-io = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13" }
sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13" }
sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13" }

# local
composable-traits = { path = "../composable-traits", default-features = false }
composable-traits = { path = "../../composable-traits", default-features = false }

orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", rev = "17a791edf431d7d7aee1ea3dfaeeb7bc21944301", default-features = false }
num-traits = { version = "0.2.14", default-features = false }
scale-info = { version = "1.0", default-features = false, features = [
"derive",
] }

# rpc
jsonrpc-core = "18.0.0"
jsonrpc-core-client = "18.0.0"
jsonrpc-derive = "18.0.0"

# misc
serde = { version = "1.0.133", features = ["derive"], optional = true }
serde = { version = "1.0.133", default-features = false, features = [
"derive",
], optional = true }
codec = { default-features = false, features = [
"derive",
], package = "parity-scale-codec", version = "2.0.0" }


[dev-dependencies]
pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13" }
orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", rev = "17a791edf431d7d7aee1ea3dfaeeb7bc21944301" }
governance-registry = { package = "pallet-governance-registry", path = "../governance-registry", default-features = false }
pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13", default-features = false }
orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", rev = "17a791edf431d7d7aee1ea3dfaeeb7bc21944301", default-features = false }
governance-registry = { package = "pallet-governance-registry", path = "../../governance-registry", default-features = false }

[package.metadata.cargo-udeps.ignore]
development = ["governance-registry"]

[features]
default = ["std"]
std = [
"pallet-balances/std",
"orml-tokens/std",
"composable-traits/std",
"codec/std",
"frame-support/std",
"sp-runtime/std",
"sp-api/std",
"orml-traits/std",
"num-traits/std",
]
Expand Down
File renamed without changes.
2 changes: 0 additions & 2 deletions frame/assets/src/lib.rs → frame/assets/pallet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@
pub use pallet::*;

mod orml;
pub mod rpc;
pub mod runtime_api;

#[cfg(test)]
mod mocks;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
64 changes: 64 additions & 0 deletions frame/assets/rpc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
[package]
name = "assets-rpc"
version = "0.0.1"
authors = ["Composable Developers"]
homepage = "https://composable.finance"
edition = "2021"
rust-version = "1.56"

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
# FRAME
frame-benchmarking = { default-features = false, optional = true, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.13' }
frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13" }
frame-system = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13" }

# substrate primitives
sp-api = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13" }
sp-blockchain = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13" }
sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13" }
sp-arithmetic = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13" }
sp-io = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13" }
sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13" }
sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13" }

# local
composable-traits = { path = "../../composable-traits", default-features = false }

orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", rev = "17a791edf431d7d7aee1ea3dfaeeb7bc21944301", default-features = false }
num-traits = { version = "0.2.14", default-features = false }
scale-info = { version = "1.0", default-features = false, features = [
"derive",
] }

assets-runtime-api = {path="../runtime-api"}

# rpc
jsonrpc-core = "18.0.0"
jsonrpc-core-client = "18.0.0"
jsonrpc-derive = "18.0.0"

# misc
serde = { version = "1.0.133", default-features = false, features = ["derive"], optional = true }
codec = { default-features = false, features = [
"derive",
], package = "parity-scale-codec", version = "2.0.0" }

[features]
default = ["std"]
std = [
"composable-traits/std",
"codec/std",
"frame-support/std",
"sp-runtime/std",
"sp-api/std",
"orml-traits/std",
"num-traits/std",
]
runtime-benchmarks = [
"frame-benchmarking",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
]
2 changes: 1 addition & 1 deletion frame/assets/src/rpc.rs → frame/assets/rpc/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::runtime_api::AssetsRuntimeApi;
use assets_runtime_api::AssetsRuntimeApi;
use codec::Codec;
use jsonrpc_core::{Error as RpcError, ErrorCode, Result as RpcResult};
use jsonrpc_derive::rpc;
Expand Down
22 changes: 22 additions & 0 deletions frame/assets/runtime-api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[package]
name = "assets-runtime-api"
version = "0.0.1"
authors = ["Composable Developers"]
homepage = "https://composable.finance"
edition = "2021"
rust-version = "1.56"

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
sp-api = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13" }
codec = { default-features = false, features = [
"derive",
], package = "parity-scale-codec", version = "2.0.0" }

[features]
default = ["std"]
std = [
"sp-api/std",
]
File renamed without changes.
4 changes: 2 additions & 2 deletions frame/dutch-auction/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ sp-io = { default-features = false, git = "https://github.com/paritytech/substr
sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13" }
sp-arithmetic = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13" }
smallvec = "1.7.0"
serde = { version = "1.0.130", optional = true }
serde = { version = "1.0.130", optional = true }
scale-info = { version = "1.0", default-features = false, features = ["derive"] }
orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", rev = "17a791edf431d7d7aee1ea3dfaeeb7bc21944301", default-features = false }
num-traits = { version = "0.2.14", default-features = false }
Expand All @@ -36,7 +36,7 @@ proptest = "1.0"
pallet-timestamp = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13" }
pallet-currency-factory = { path = "../currency-factory" }
pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13" }
pallet-assets = { path = '../assets', default-features = false}
pallet-assets = { path = '../assets/pallet', default-features = false}
orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", rev = "17a791edf431d7d7aee1ea3dfaeeb7bc21944301" }
hex-literal = {version = "0.3.3", default-features = false }
composable-tests-helpers = { path = "../composable-tests-helpers" }
Expand Down
2 changes: 1 addition & 1 deletion frame/lending/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pallet-currency-factory = { path = "../currency-factory" }
pallet-liquidations = { path = "../liquidations" }
pallet-dutch-auction = { path = "../dutch-auction", default-features = false }
composable-tests-helpers = { path = "../composable-tests-helpers", default-features = false }
pallet-assets = { path = '../assets', default-features = false}
pallet-assets = { path = '../assets/pallet', default-features = false}


[features]
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ composable-traits = { path = "../frame/composable-traits" , default-features = f
call-filter = { package = "pallet-call-filter", path = "../frame/call-filter", default-features = false }
assets-registry = { package = "pallet-assets-registry", path = "../frame/assets-registry", default-features = false, optional = true}
governance-registry = { package = "pallet-governance-registry", path = "../frame/governance-registry", default-features = false, optional = true}
assets = { package = "pallet-assets", path = "../frame/assets", default-features = false, optional = true}
assets = { package = "pallet-assets", path = "../frame/assets/pallet", default-features = false, optional = true}

# Used for the node template's RPCs
system-rpc-runtime-api = { package = "frame-system-rpc-runtime-api", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13", default-features = false }
Expand Down
4 changes: 3 additions & 1 deletion node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ composable-runtime = { path = "../runtime/composable", optional = true }
dali-runtime = { path = "../runtime/dali", optional = true }
common = { path = "../runtime/common" }
primitives = { path = "../runtime/primitives" }
pallet-assets = { path = "../frame/assets" }
pallet-assets = { path = "../frame/assets/pallet" }
assets-rpc = { path = "../frame/assets/rpc" }
assets-runtime-api = { path = "../frame/assets/runtime-api" }

# FRAME Dependencies
frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13" }
Expand Down
4 changes: 2 additions & 2 deletions node/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
use primitives::currency::CurrencyId;
use std::sync::Arc;

use assets_rpc::{Assets, AssetsApi};
use common::{AccountId, AccountIndex, Balance};
use pallet_assets::rpc::{Assets, AssetsApi};
pub use sc_rpc_api::DenyUnsafe;
use sc_transaction_pool_api::TransactionPool;
use sp_api::ProvideRuntimeApi;
Expand All @@ -36,7 +36,7 @@ where
C: Send + Sync + 'static,
C::Api: substrate_frame_rpc_system::AccountNonceApi<B, AccountId, AccountIndex>,
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<B, Balance>,
C::Api: pallet_assets::runtime_api::AssetsRuntimeApi<B, CurrencyId, AccountId, Balance>,
C::Api: assets_runtime_api::AssetsRuntimeApi<B, CurrencyId, AccountId, Balance>,
C::Api: BlockBuilder<B>,
P: TransactionPool + 'static,
{
Expand Down
4 changes: 2 additions & 2 deletions node/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub trait HostRuntimeApis:
+ sp_block_builder::BlockBuilder<Block>
+ substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>
+ pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance>
+ pallet_assets::runtime_api::AssetsRuntimeApi<Block, CurrencyId, AccountId, Balance>
+ assets_runtime_api::AssetsRuntimeApi<Block, CurrencyId, AccountId, Balance>
+ sp_api::Metadata<Block>
+ sp_consensus_aura::AuraApi<Block, sp_consensus_aura::sr25519::AuthorityId>
+ sp_offchain::OffchainWorkerApi<Block>
Expand All @@ -28,7 +28,7 @@ where
+ sp_block_builder::BlockBuilder<Block>
+ substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>
+ pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance>
+ pallet_assets::runtime_api::AssetsRuntimeApi<Block, CurrencyId, AccountId, Balance>
+ assets_runtime_api::AssetsRuntimeApi<Block, CurrencyId, AccountId, Balance>
+ sp_api::Metadata<Block>
+ sp_consensus_aura::AuraApi<Block, sp_consensus_aura::sr25519::AuthorityId>
+ sp_offchain::OffchainWorkerApi<Block>
Expand Down
4 changes: 2 additions & 2 deletions runtime/composable/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ smallvec = "1.6.1"

# local modules
assets-registry = { package = "pallet-assets-registry", path = '../../frame/assets-registry', default-features = false, optional = true }
assets = { package = "pallet-assets", path = '../../frame/assets', default-features = false, optional = true }
assets = { package = "pallet-assets", path = '../../frame/assets/pallet', default-features = false }

common = { path = "../common", default-features = false }
primitives = { path = "../primitives", default-features = false }
Expand All @@ -78,6 +78,7 @@ call-filter = { package = "pallet-call-filter", path = "../../frame/call-filter"
# Used for the node template's RPCs
system-rpc-runtime-api = { package = "frame-system-rpc-runtime-api", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13", default-features = false }
transaction-payment-rpc-runtime-api = { package = "pallet-transaction-payment-rpc-runtime-api", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13", default-features = false }
assets-runtime-api = { path = '../../frame/assets/runtime-api', default-features = false }

# Used for runtime benchmarking
benchmarking = { package = "frame-benchmarking", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13", default-features = false, optional = true }
Expand Down Expand Up @@ -176,7 +177,6 @@ std = [
"orml-xcm-support/std",
"orml-unknown-tokens/std",
"assets-registry/std",
"assets/std",
"governance-registry/std",
]
runtime-benchmarks = [
Expand Down
2 changes: 1 addition & 1 deletion runtime/composable/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ pub type Executive =
executive::Executive<Runtime, Block, system::ChainContext<Runtime>, Runtime, AllPallets>;

impl_runtime_apis! {
impl assets::runtime_api::AssetsRuntimeApi<Block, CurrencyId, AccountId, Balance> for Runtime {
impl assets_runtime_api::AssetsRuntimeApi<Block, CurrencyId, AccountId, Balance> for Runtime {
fn balance_of(asset_id: CurrencyId, account_id: AccountId) -> Balance {
<Assets as support::traits::fungibles::Inspect::<AccountId>>::balance(asset_id, &account_id)
}
Expand Down
3 changes: 2 additions & 1 deletion runtime/dali/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ smallvec = "1.6.1"

# local modules
assets-registry = { package = "pallet-assets-registry", path = '../../frame/assets-registry', default-features = false }
assets = { package = "pallet-assets", path = '../../frame/assets', default-features = false }
assets = { package = "pallet-assets", path = '../../frame/assets/pallet', default-features = false }
crowdloan-rewards = { package = "pallet-crowdloan-rewards", path = '../../frame/crowdloan-rewards', default-features = false }
bonded-finance = { package = "pallet-bonded-finance", path = "../../frame/bonded-finance", default-features = false }
vesting = { package = "pallet-vesting", path = "../../frame/vesting", default-features = false }
Expand All @@ -83,6 +83,7 @@ call-filter = { package = "pallet-call-filter", path = "../../frame/call-filter"
# Used for the node template's RPCs
system-rpc-runtime-api = { package = "frame-system-rpc-runtime-api", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13", default-features = false }
transaction-payment-rpc-runtime-api = { package = "pallet-transaction-payment-rpc-runtime-api", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13", default-features = false }
assets-runtime-api = { path = '../../frame/assets/runtime-api', default-features = false }

# Used for runtime benchmarking
benchmarking = { package = "frame-benchmarking", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13", default-features = false, optional = true }
Expand Down
Loading

0 comments on commit 4587b38

Please sign in to comment.