Skip to content

Commit

Permalink
Merge branch 'sub0' into chungquantin/sub0-pallet_nfts
Browse files Browse the repository at this point in the history
  • Loading branch information
chungquantin authored Oct 28, 2024
2 parents 0460a44 + e0c8745 commit f20d191
Show file tree
Hide file tree
Showing 175 changed files with 31,827 additions and 532 deletions.
318 changes: 287 additions & 31 deletions Cargo.lock

Large diffs are not rendered by default.

39 changes: 35 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ license = "Unlicense"
repository = "https://github.com/r0gue-io/pop-node/"

[workspace]
exclude = [ "extension/contract", "pop-api", "tests/contracts" ]
exclude = [
"extension/contract",
"pop-api",
"tests/contracts",
]
members = [
"integration-tests",
"node",
Expand Down Expand Up @@ -61,12 +65,13 @@ substrate-wasm-builder = "23.0.0"
# Local
pallet-api = { path = "pallets/api", default-features = false }
pallet-nfts = { path = "pallets/nfts", default-features = false }
pallet-incentives = { path = "pallets/incentives", default-features = false }
pop-chain-extension = { path = "./extension", default-features = false }
pop-primitives = { path = "./primitives", default-features = false }
pop-runtime-common = { path = "runtime/common", default-features = false }
pop-runtime-devnet = { path = "runtime/devnet", default-features = true } # default-features=true required for `-p pop-node` builds
pop-runtime-mainnet = { path = "runtime/mainnet", default-features = true } # default-features=true required for `-p pop-node` builds
pop-runtime-testnet = { path = "runtime/testnet", default-features = true } # default-features=true required for `-p pop-node` builds
pop-runtime-devnet = { path = "runtime/devnet", default-features = true } # default-features=true required for `-p pop-node` builds
pop-runtime-mainnet = { path = "runtime/mainnet", default-features = true } # default-features=true required for `-p pop-node` builds
pop-runtime-testnet = { path = "runtime/testnet", default-features = true } # default-features=true required for `-p pop-node` builds

# Substrate
frame-benchmarking = { version = "36.0.0", default-features = false }
Expand Down Expand Up @@ -194,3 +199,29 @@ ismp-parachain-runtime-api = { git = "https://github.com/r0gue-io/ismp", branch
pallet-ismp = { git = "https://github.com/r0gue-io/ismp", branch = "polkadot-v1.14.0", default-features = false }
pallet-ismp-rpc = { git = "https://github.com/r0gue-io/ismp", branch = "polkadot-v1.14.0", default-features = false }
pallet-ismp-runtime-api = { git = "https://github.com/r0gue-io/ismp", branch = "polkadot-v1.14.0", default-features = false }


# revive dependencies
anyhow = { version = "1.0.81" }
array-bytes = { version = "6.2.2", default-features = false }
assert_matches = { version = "1.5.0" }
bitflags = { version = "1.3.2" }
environmental = { version = "1.1.4", default-features = false }
pallet-revive = { path = "pallets/revive", default-features = false }
pallet-revive-fixtures = { path = "pallets/revive/fixtures", default-features = false }
pallet-revive-mock-network = { default-features = false, path = "pallets/revive/mock-network" }
pallet-revive-proc-macro = { path = "pallets/revive/proc-macro", default-features = false }
pallet-revive-uapi = { path = "pallets/revive/uapi", default-features = false }
parity-wasm = { version = "0.45.0" }
paste = { version = "1.0.14", default-features = false }
pretty_assertions = { version = "1.3.0" }
proc-macro2 = { version = "1.0.64" }
quote = { version = "1.0.33" }
rlp = { version = "0.5.2", default-features = false }
sp-tracing = { version = "16.0.0", default-features = false }
syn = { version = "2.0.53" }
tempfile = { version = "3.8.1" }
toml = { version = "0.8.8" }
wat = { version = "1.0.0" }

[workspace.lints.rust]
8 changes: 4 additions & 4 deletions extension/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ log.workspace = true
# Substrate
frame-support.workspace = true
frame-system.workspace = true
pallet-contracts.workspace = true
pallet-revive.workspace = true
sp-core.workspace = true
sp-runtime.workspace = true
sp-std.workspace = true
Expand All @@ -29,7 +29,7 @@ sp-std.workspace = true
contract-build.workspace = true
env_logger.workspace = true
pallet-balances.workspace = true
pallet-contracts.workspace = true
pallet-revive.workspace = true
pallet-timestamp.workspace = true
rand.workspace = true
scale-info.workspace = true
Expand All @@ -41,7 +41,7 @@ runtime-benchmarks = [
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"pallet-contracts/runtime-benchmarks",
"pallet-revive/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
Expand All @@ -51,7 +51,7 @@ std = [
"frame-system/std",
"log/std",
"pallet-balances/std",
"pallet-contracts/std",
"pallet-revive/std",
"pallet-timestamp/std",
"sp-core/std",
"sp-io/std",
Expand Down
3 changes: 2 additions & 1 deletion extension/contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ name = "proxy"
version = "0.1.0"

[dependencies]
ink = { version = "5.0.0", default-features = false }
ink = { git = "https://github.com/r0gue-io/ink", branch = "sub0", default-features = false }
polkavm-derive = "0.11.0"

[lib]
path = "lib.rs"
Expand Down
8 changes: 4 additions & 4 deletions extension/src/decoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ impl<

/// Error to be returned when decoding fails.
pub struct DecodingFailed<C>(PhantomData<C>);
impl<T: pallet_contracts::Config> Get<DispatchError> for DecodingFailed<T> {
impl<T: pallet_revive::Config> Get<DispatchError> for DecodingFailed<T> {
fn get() -> DispatchError {
pallet_contracts::Error::<T>::DecodingFailed.into()
pallet_revive::Error::<T>::DecodingFailed.into()
}
}

Expand Down Expand Up @@ -155,7 +155,7 @@ mod tests {
fn decoding_failed_error_type_works() {
assert_eq!(
DecodingFailed::<Test>::get(),
pallet_contracts::Error::<Test>::DecodingFailed.into()
pallet_revive::Error::<Test>::DecodingFailed.into()
)
}

Expand All @@ -164,7 +164,7 @@ mod tests {
let input = vec![100];
let mut env = MockEnvironment::new(0, input.clone());
let result = EnumDecodes::decode(&mut env);
assert_eq!(result, Err(pallet_contracts::Error::<Test>::DecodingFailed.into()));
assert_eq!(result, Err(pallet_revive::Error::<Test>::DecodingFailed.into()));
}

#[test]
Expand Down
73 changes: 50 additions & 23 deletions extension/src/environment.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
use core::fmt::Debug;

use codec::Decode;
use frame_support::pallet_prelude::Weight;
use pallet_contracts::chain_extension::{BufInBufOutState, ChargedAmount, Result, State};
use pallet_revive::{
chain_extension::{ChargedAmount, Result},
wasm::Memory,
AccountId32Mapper, AddressMapper,
};
use sp_core::crypto::AccountId32;
use sp_std::vec::Vec;

use crate::AccountIdOf;

/// Provides access to the parameters passed to a chain extension and its execution environment.
///
/// A wrapper trait for `pallet_contracts::chain_extension::Environment`. All comments have been
/// A wrapper trait for `pallet_revive::chain_extension::Environment`. All comments have been
/// copied solely for consistent developer experience in line with the wrapped type.
pub trait Environment {
/// The account identifier type for the runtime.
Expand Down Expand Up @@ -55,13 +61,18 @@ pub trait Environment {
fn ext(&mut self) -> impl Ext<AccountId = Self::AccountId>;
}

/// A wrapper type for `pallet_contracts::chain_extension::Environment`.
pub(crate) struct Env<'a, 'b, E: pallet_contracts::chain_extension::Ext, S: State>(
pub(crate) pallet_contracts::chain_extension::Environment<'a, 'b, E, S>,
/// A wrapper type for `pallet_revive::chain_extension::Environment`.
pub(crate) struct Env<'a, 'b, E: pallet_revive::chain_extension::Ext, S: ?Sized + Memory<E::T>>(
pub(crate) pallet_revive::chain_extension::Environment<'a, 'b, E, S>,
);

impl<'a, 'b, E: pallet_contracts::chain_extension::Ext, S: State> Environment
impl<'a, 'b, E: pallet_revive::chain_extension::Ext, S: ?Sized + Memory<E::T>> Environment
for Env<'a, 'b, E, S>
where
E: pallet_revive::chain_extension::Ext,
E::T: frame_system::Config,
<E::T as frame_system::Config>::AccountId: From<AccountId32> + Decode,
E::T: SysConfig<AccountId = AccountId32>,
{
type AccountId = AccountIdOf<E::T>;
type ChargedAmount = ChargedAmount;
Expand Down Expand Up @@ -89,8 +100,8 @@ impl<'a, 'b, E: pallet_contracts::chain_extension::Ext, S: State> Environment

/// A state that uses a buffer as input.
///
/// A wrapper trait for `pallet_contracts::chain_extension::BufIn` related function available on
/// `pallet_contracts::chain_extension::Environment`. All comments have been copied solely for
/// A wrapper trait for `pallet_revive::chain_extension::BufIn` related function available on
/// `pallet_revive::chain_extension::Environment`. All comments have been copied solely for
/// consistent developer experience in line with the wrapped type.
pub trait BufIn {
/// The length of the input as passed in as `input_len`.
Expand All @@ -111,7 +122,9 @@ pub trait BufIn {
fn read(&self, max_len: u32) -> Result<Vec<u8>>;
}

impl<'a, 'b, E: pallet_contracts::chain_extension::Ext> BufIn for Env<'a, 'b, E, BufInBufOutState> {
impl<'a, 'b, E: pallet_revive::chain_extension::Ext, M: ?Sized + Memory<E::T>> BufIn
for Env<'a, 'b, E, M>
{
fn in_len(&self) -> u32 {
self.0.in_len()
}
Expand All @@ -123,8 +136,8 @@ impl<'a, 'b, E: pallet_contracts::chain_extension::Ext> BufIn for Env<'a, 'b, E,

/// A state that uses a buffer as output.
///
/// A wrapper trait for `pallet_contracts::chain_extension::BufOut` related function available on
/// `pallet_contracts::chain_extension::Environment`. All comments have been copied solely for
/// A wrapper trait for `pallet_revive::chain_extension::BufOut` related function available on
/// `pallet_revive::chain_extension::Environment`. All comments have been copied solely for
/// consistent developer experience in line with the wrapped type.
pub trait BufOut {
/// Write the supplied buffer to contract memory.
Expand All @@ -142,8 +155,8 @@ pub trait BufOut {
) -> Result<()>;
}

impl<'a, 'b, E: pallet_contracts::chain_extension::Ext> BufOut
for Env<'a, 'b, E, BufInBufOutState>
impl<'a, 'b, E: pallet_revive::chain_extension::Ext, M: ?Sized + Memory<E::T>> BufOut
for Env<'a, 'b, E, M>
{
fn write(
&mut self,
Expand All @@ -161,36 +174,50 @@ impl<'a, 'b, E: pallet_contracts::chain_extension::Ext> BufOut
/// This interface is specialized to an account of the executing code, so all operations are
/// implicitly performed on that account.
///
/// A wrapper trait for `pallet_contracts::chain_extension::Ext`. All comments have been copied
/// A wrapper trait for `pallet_revive::chain_extension::Ext`. All comments have been copied
/// solely for consistent developer experience in line with the wrapped type.
pub trait Ext {
/// The account identifier type for the runtime.
type AccountId;

/// Returns a reference to the account id of the current contract.
fn address(&self) -> &Self::AccountId;
fn address(&self) -> Self::AccountId;
}

impl Ext for () {
type AccountId = ();

fn address(&self) -> &Self::AccountId {
&()
fn address(&self) -> Self::AccountId {
()
}
}

/// A wrapper type for a type implementing `pallet_contracts::chain_extension::Ext`.
pub(crate) struct ExternalEnvironment<'a, T: pallet_contracts::chain_extension::Ext>(&'a mut T);
/// A wrapper type for a type implementing `pallet_revive::chain_extension::Ext`.
pub(crate) struct ExternalEnvironment<'a, T: pallet_revive::chain_extension::Ext>(&'a mut T);

use pallet_revive::chain_extension::SysConfig;

impl<'a, E: pallet_contracts::chain_extension::Ext> Ext for ExternalEnvironment<'a, E> {
impl<'a, E> Ext for ExternalEnvironment<'a, E>
where
E: pallet_revive::chain_extension::Ext,
E::T: frame_system::Config,
<E::T as frame_system::Config>::AccountId: From<AccountId32> + Decode,
E::T: SysConfig<AccountId = AccountId32>,
{
type AccountId = AccountIdOf<E::T>;

fn address(&self) -> &Self::AccountId {
self.0.address()
fn address(&self) -> Self::AccountId {
// Get the H160 address
let h160_addr = self.0.address();
let account_id = AccountId32Mapper::<E::T>::to_account_id(&h160_addr);
// TODO: hacky way to get AccountId32 to match the Self::AccountId type
// let encoded_addr = AccountId32Mapper::<E::T>::to_account_id(&self.0.address()).encode();
// Self::AccountId::decode(&mut &encoded_addr[..]).unwrap()
account_id.into()
}
}

#[test]
fn default_ext_works() {
assert_eq!(().address(), &())
assert_eq!(().address(), ())
}
Loading

0 comments on commit f20d191

Please sign in to comment.