Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(unmerged): contract caller as a chain extension origin #301

Open
wants to merge 117 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
117 commits
Select commit Hold shift + click to select a range
7c2eac2
feat: pallet assets pop api integration
Daanvdplas Apr 5, 2024
418aa63
style: renaming assets example
Daanvdplas Apr 12, 2024
3d385df
refactor: chain extension tests
Daanvdplas Apr 22, 2024
fd46a27
fix: add error handling other than ModuleError
Daanvdplas Jun 4, 2024
1022926
test: add transfer
Daanvdplas Jun 6, 2024
ecc82e2
chore: remove polkadot launch
Daanvdplas Jun 6, 2024
e81f78a
# This is a combination of 8 commits.
Daanvdplas Jun 6, 2024
f824801
refactor: error handling
Daanvdplas Jun 20, 2024
4670503
refactor: clarify todos
Daanvdplas Jun 20, 2024
2283161
refactor: error handling comments part 1
Daanvdplas Jun 24, 2024
f88dd89
refactor: apply comments part 2
Daanvdplas Jun 25, 2024
61b3a17
refactor: tests local fungibles
Daanvdplas Jun 26, 2024
c1616a3
refactor: naming pallet error
Daanvdplas Jun 26, 2024
13e947e
refactor: optimising pop api and additional logic + test
Daanvdplas Jun 26, 2024
7757319
refactor: runtime
Daanvdplas Jul 3, 2024
924df85
refactor: draft final design
Daanvdplas Jul 2, 2024
972e4c9
feat: add more interfaces
Daanvdplas Jul 5, 2024
47e2ea6
refactor: final bits
Daanvdplas Jul 5, 2024
9dcfccb
fix: compiling
Daanvdplas Jul 6, 2024
b067eda
fix: cannot find macro vec error
Daanvdplas Jul 16, 2024
8730f90
refactor: decoding failed and commenting out unimplemented tests
Daanvdplas Jul 17, 2024
b591222
style: renaming
Daanvdplas Jul 17, 2024
c2acbb5
refactor: bits and pieces
Daanvdplas Jul 18, 2024
3639320
docs: add docs to code
Daanvdplas Jul 18, 2024
81e9844
fix: replace test code to api fungibles
Daanvdplas Jul 18, 2024
023d3dc
fix: own review + fixing CI fail
Daanvdplas Jul 18, 2024
e683e16
refactor: add Error variants index + clippy allowance
Daanvdplas Jul 19, 2024
28d971b
feat: api fungibles pallet (#113)
Daanvdplas Jul 26, 2024
4e4512e
refactor: streamline error from the decoded method by returning `Resu…
chungquantin Jul 26, 2024
02dffc6
merge main
Daanvdplas Jul 26, 2024
027cb85
refactor: build chain extension method (#121)
chungquantin Jul 26, 2024
30ff91a
fix: clean up imports (#135)
chungquantin Jul 27, 2024
9820e7f
refactor: remove read state encoding (#122)
Daanvdplas Jul 28, 2024
5ac5a9a
feat: transfer_from and decrease_allowance (#134)
chungquantin Jul 31, 2024
d8ac5bd
refactor: api integration tests (#133)
Daanvdplas Aug 6, 2024
00c5903
refactor: remove bare_call code duplication in integration test (#168)
chungquantin Aug 9, 2024
1acbd21
merge main
Daanvdplas Aug 13, 2024
9ebe162
fix: compilation
Daanvdplas Aug 13, 2024
545bd33
fix: try-runtime error
Daanvdplas Aug 13, 2024
99d0f6d
refactor: generic extension crate to de-duplicate code between runtim…
chungquantin Aug 13, 2024
8b4f595
feat: api events (#153)
Daanvdplas Aug 14, 2024
f13b39c
docs: pop api (#190)
Daanvdplas Aug 16, 2024
7c94284
refactor: extension
Daanvdplas Aug 16, 2024
5934fa8
fix: remove old api code from deprecated examples
Daanvdplas Aug 16, 2024
f2ef7a1
refactor: runtime devnet
Daanvdplas Aug 16, 2024
b3dd993
refactor: fungibles pallet
Daanvdplas Aug 16, 2024
0811598
style: fix tests asset_asset parameter
Daanvdplas Aug 19, 2024
6482a43
fix: invalid imported crates & crate visibility (#214)
chungquantin Aug 19, 2024
1b78c11
ci: add CI script for `pop-api` tests and integration tests (#228)
chungquantin Aug 26, 2024
8d1c085
fix: mutable `self` required for dispatchable ink! methods (#235)
chungquantin Aug 26, 2024
479dbb0
refactor: generic extension (#218)
evilrobot-01 Sep 6, 2024
ec49dc3
chore: resolve conflicts for `daan/api` (#267)
chungquantin Sep 7, 2024
d92a4c5
chore(runtime): use workspace dependencies
evilrobot-01 Sep 7, 2024
114934a
Merge branch 'refs/heads/main' into daan/api
evilrobot-01 Sep 7, 2024
d7cba0a
chore: resolve merge issues
evilrobot-01 Sep 7, 2024
a272657
ci: clear more space
evilrobot-01 Sep 7, 2024
c0ea3ed
ci: disable debug info for coverage
evilrobot-01 Sep 7, 2024
206757b
style: token terminology (#215)
Daanvdplas Sep 9, 2024
07a0731
chore: add sandbox crate
chungquantin Sep 11, 2024
7f04779
fix: taplo formatting
chungquantin Sep 11, 2024
8a1095b
fix: update tests
chungquantin Sep 11, 2024
d23c2b3
fix: test with logger
chungquantin Sep 11, 2024
0ab510f
fix: test with logger
chungquantin Sep 11, 2024
1c06043
fix: revert flipper example changes
chungquantin Sep 11, 2024
f6976b0
fix: fungibles contract
chungquantin Sep 12, 2024
d6408da
refactor: create sandbox for devnet runtime
chungquantin Sep 12, 2024
0399d46
refactor: fungible example contract
chungquantin Sep 12, 2024
5fdf406
refactor: fungible test
chungquantin Sep 12, 2024
ed7146b
fix: fungible contract
chungquantin Sep 12, 2024
7ce0674
test: drink tests for fungible use case
chungquantin Sep 12, 2024
8c1988f
merge daan/api
Daanvdplas Sep 16, 2024
7c4c470
style: token terminology
Daanvdplas Sep 16, 2024
4e44fba
feat: add interfaces for psp22
chungquantin Sep 18, 2024
a32f002
chore: add comments
chungquantin Sep 18, 2024
bf4062d
refactor: separate modules into files
chungquantin Sep 18, 2024
21c6826
refactor: fungible example
chungquantin Sep 18, 2024
894fcf9
feat: refactor example contract to follow spec
chungquantin Sep 18, 2024
817a351
test: psp22error
chungquantin Sep 18, 2024
6042f09
fix: missing String
chungquantin Sep 18, 2024
c8cc9d1
chore: revert example
chungquantin Sep 19, 2024
a8c063c
fix: resolve comments
chungquantin Sep 19, 2024
8176474
fix: revert example contract
chungquantin Sep 19, 2024
1945683
fix: add mod comment
chungquantin Sep 19, 2024
6aede89
fix: result type
chungquantin Sep 19, 2024
b52ad33
fix: update PSP22Metadata
chungquantin Sep 19, 2024
6b2f17a
fix: add comment for Psp22 trait
chungquantin Sep 19, 2024
4a1bf3b
fix: resolve comments
chungquantin Sep 19, 2024
699275c
fix: api integration tests
chungquantin Sep 19, 2024
94ee34e
fix: result type
chungquantin Sep 19, 2024
9bb3be8
fix: comment
chungquantin Sep 19, 2024
f03a5ae
feat: add interfaces for psp22
chungquantin Sep 18, 2024
1bbc3ed
chore: add comments
chungquantin Sep 18, 2024
e8d68a9
refactor: separate modules into files
chungquantin Sep 18, 2024
4ead643
refactor: fungible example
chungquantin Sep 18, 2024
12d1af4
feat: refactor example contract to follow spec
chungquantin Sep 18, 2024
24afd15
test: psp22error
chungquantin Sep 18, 2024
8ecf6d9
fix: missing String
chungquantin Sep 18, 2024
6f521f4
fix: resolve comments
chungquantin Sep 19, 2024
7ce5d52
fix: add mod comment
chungquantin Sep 19, 2024
b29cf17
fix: result type
chungquantin Sep 19, 2024
933c62e
fix: update PSP22Metadata
chungquantin Sep 19, 2024
de80906
fix: add comment for Psp22 trait
chungquantin Sep 19, 2024
8717adb
fix: resolve comments
chungquantin Sep 19, 2024
8ae2c00
fix: api integration tests
chungquantin Sep 19, 2024
97417e3
fix: result type
chungquantin Sep 19, 2024
204ee06
fix: resolve comments
chungquantin Sep 19, 2024
540639a
Merge branch 'chungquantin/feat-psp22_traits' into chungquantin/feat-…
chungquantin Sep 20, 2024
867cc28
feat: drink test for example contract
chungquantin Sep 20, 2024
7dc6047
refactor: add helpers module
chungquantin Sep 20, 2024
b433c67
feat: add event assertions
chungquantin Sep 20, 2024
e018e34
test: event assertion
chungquantin Sep 20, 2024
baab872
refactor: call expect error methods & function constant
chungquantin Sep 20, 2024
cb48a4d
test: add more test cases
chungquantin Sep 20, 2024
ce009a1
fix: extension origin
chungquantin Sep 21, 2024
e5f84aa
test: transfer_from
chungquantin Sep 21, 2024
6f17c09
chore: add TODO
chungquantin Sep 21, 2024
7e23172
fix: formatting
chungquantin Sep 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ license = "Unlicense"
repository = "https://github.com/r0gue-io/pop-node/"

[workspace]
exclude = [ "extension/contract", "pop-api", "tests/contracts" ]
exclude = [
"extension/contract",
"pop-api",
"pop-sandbox",
"tests/contracts",
]
members = [
"integration-tests",
"node",
Expand Down
21 changes: 14 additions & 7 deletions extension/src/environment.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use core::fmt::Debug;

use frame_support::pallet_prelude::Weight;
use pallet_contracts::chain_extension::{BufInBufOutState, ChargedAmount, Result, State};
use pallet_contracts::{
chain_extension::{BufInBufOutState, ChargedAmount, Result, State},
Origin,
};
use sp_std::vec::Vec;

use crate::AccountIdOf;
Expand Down Expand Up @@ -168,14 +171,14 @@
type AccountId;

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we changing this?

}

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

fn address(&self) -> &Self::AccountId {
&()
fn address(&self) -> Self::AccountId {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, why are we changing this?

Copy link
Collaborator Author

@chungquantin chungquantin Sep 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was changed just to test if it works (will be reverted later when we decide the next step with the extension origin). Reason why I don't add the method caller() because it will bring back stuffs that @evilrobot-01 removed before #265 that removed the Config associated type. The caller() method returns OriginFor<Config> so if we want that method, we need to revert the changed Frank made.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be clear, I'm not against adding stuff that is needed, but a useful thing to consider is that taking a trait bound on the whole Config trait makes mocking overly complex. An example is needing to add a mock pallet-contracts impl just to do basic things.

Only expose what is required, nothing more. It may be easier, but has consequences downstream for implementors.

()

Check warning on line 181 in extension/src/environment.rs

View workflow job for this annotation

GitHub Actions / clippy

unneeded unit expression

warning: unneeded unit expression --> extension/src/environment.rs:181:3 | 181 | () | ^^ help: remove the final `()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unused_unit = note: `#[warn(clippy::unused_unit)]` on by default
}
}

Expand All @@ -185,12 +188,16 @@
impl<'a, E: pallet_contracts::chain_extension::Ext> Ext for ExternalEnvironment<'a, E> {
type AccountId = AccountIdOf<E::T>;

fn address(&self) -> &Self::AccountId {
self.0.address()
fn address(&self) -> Self::AccountId {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we not add a function caller instead? This function is to get the address and should not be changed tmo

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explained here: #301 (comment)

// TODO: Need to decide which address to return.
match self.0.caller() {
Origin::Root => self.0.address().clone(),
Origin::Signed(caller) => caller,
}
}
}

#[test]
fn default_ext_works() {
assert_eq!(().address(), &())
assert_eq!(().address(), ())
}
2 changes: 1 addition & 1 deletion extension/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
let charged = env.charge_weight(dispatch_info.weight)?;
log::debug!(target: Logger::LOG_TARGET, "pre-dispatch weight charged: charged={charged:?}");
// Contract is the origin by default.
let origin = RawOrigin::Signed(env.ext().address().clone());
let origin = RawOrigin::Signed(env.ext().address());
log::debug!(target: Logger::LOG_TARGET, "contract origin: origin={origin:?}");
let mut origin: Config::RuntimeOrigin = origin.into();
// Ensure call allowed.
Expand All @@ -80,7 +80,7 @@

/// A function for reading runtime state.
pub struct ReadState<M, C, R, D, F, RC = DefaultConverter<<R as Readable>::Result>, E = (), L = ()>(
PhantomData<(M, C, R, D, F, RC, E, L)>,

Check warning on line 83 in extension/src/functions.rs

View workflow job for this annotation

GitHub Actions / clippy

very complex type used. Consider factoring parts into `type` definitions

warning: very complex type used. Consider factoring parts into `type` definitions --> extension/src/functions.rs:83:2 | 83 | PhantomData<(M, C, R, D, F, RC, E, L)>, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#type_complexity = note: `#[warn(clippy::type_complexity)]` on by default
);
impl<
Matcher: Matches,
Expand Down
4 changes: 2 additions & 2 deletions extension/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,8 @@ pub(crate) struct MockExt {
impl environment::Ext for MockExt {
type AccountId = AccountIdOf<Test>;

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

Expand Down
Empty file modified pop-api/examples/.gitignore
100755 → 100644
Empty file.
28 changes: 0 additions & 28 deletions pop-api/examples/balance-transfer/Cargo.toml

This file was deleted.

135 changes: 0 additions & 135 deletions pop-api/examples/balance-transfer/lib.rs

This file was deleted.

28 changes: 25 additions & 3 deletions pop-api/examples/fungibles/Cargo.toml
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
[package]
authors = [ "[your_name] <[your_email]>" ]
edition = "2021"
name = "fungibles"
name = "api_example_fungibles"
version = "0.1.0"

[dependencies]
ink = { version = "5.0.0", default-features = false }
pop-api = { path = "../../../pop-api", default-features = false, features = [ "fungibles" ] }
ink = { version = "=5.0.0", default-features = false, features = [ "ink-debug" ] }
pop-api = { path = "../../../pop-api", default-features = false, features = [
"fungibles",
] }
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = [
"derive",
] }
scale-info = { version = "2.6", default-features = false, features = [
"derive",
], optional = true }

[dev-dependencies]
env_logger = { version = "0.11.3" }
serde_json = "1.0.114"

# Local
drink = { path = "../../../../pop-drink/drink" }
pop-sandbox = { path = "../../../pop-sandbox", default-features = false }

# Substrate
frame-support = { version = "36.0.0", default-features = false }

[lib]
path = "lib.rs"
Expand All @@ -18,4 +37,7 @@ ink-as-dependency = [ ]
std = [
"ink/std",
"pop-api/std",
"pop-sandbox/std",
"scale-info/std",
"scale/std",
]
Loading
Loading