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

Use pallet-contracts-uapi #2038

Merged
merged 49 commits into from
Jan 24, 2024
Merged
Changes from 1 commit
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
2be8da5
rm stuff
pgherveou Dec 8, 2023
5d25207
wip
pgherveou Jan 2, 2024
79c3814
rm dead code
pgherveou Jan 2, 2024
2d1db8b
match existing calls
pgherveou Jan 2, 2024
e891996
wip
pgherveou Jan 2, 2024
76acdca
Fixes
pgherveou Jan 4, 2024
a59d065
Fix tests
pgherveou Jan 4, 2024
a0fac1d
fix
pgherveou Jan 4, 2024
4339ef0
Update architecture
pgherveou Jan 5, 2024
dd7a7c0
use git dep for now
pgherveou Jan 5, 2024
33175c2
fmt
pgherveou Jan 5, 2024
1685260
fmt
pgherveou Jan 5, 2024
ea60dfa
Add ink-debug
pgherveou Jan 5, 2024
1c67ad8
fix
pgherveou Jan 5, 2024
5ce8c4f
update clippy
pgherveou Jan 5, 2024
7e88004
fmt
pgherveou Jan 5, 2024
76d93b2
fix
pgherveou Jan 5, 2024
7431342
fix fmt
pgherveou Jan 5, 2024
ee10340
fix clippy error
pgherveou Jan 5, 2024
eebb2c0
update lock
pgherveou Jan 5, 2024
b7e58b6
fix
pgherveou Jan 5, 2024
a998813
fix clippy
pgherveou Jan 5, 2024
a354db0
fix
pgherveou Jan 5, 2024
e1cddd0
fix fmt
pgherveou Jan 5, 2024
fc85d3f
Fix doc
pgherveou Jan 5, 2024
fdabcd6
fix docstring
pgherveou Jan 6, 2024
0464b72
wip
pgherveou Jan 8, 2024
c99afd6
Fix
pgherveou Jan 8, 2024
bb5e710
fix
pgherveou Jan 8, 2024
66de170
update cargo.toml
pgherveou Jan 8, 2024
fb30f38
fix lock
pgherveou Jan 8, 2024
62502f1
fix
pgherveou Jan 8, 2024
e951fa7
Test bump uapi branch
pgherveou Jan 9, 2024
9c38942
Test with add-fixtures-test-size
pgherveou Jan 10, 2024
71a7080
Test do not compose errors
pgherveou Jan 10, 2024
3519e2c
use inline_always_uapi branch
pgherveou Jan 10, 2024
064e3f2
Bump locks
pgherveou Jan 10, 2024
133dee5
Bump lockwq
pgherveou Jan 11, 2024
1675bd8
tweak generator / ReturnFlags
pgherveou Jan 11, 2024
825601d
Revert "Test do not compose errors"
pgherveou Jan 11, 2024
686d1c8
generator dispatch fix
pgherveou Jan 11, 2024
6b74370
fix
pgherveou Jan 11, 2024
f5db4ef
fix
pgherveou Jan 11, 2024
945c7e3
fix lock
pgherveou Jan 11, 2024
9914c7c
rm EnvError alias
pgherveou Jan 23, 2024
a21837c
PR review
pgherveou Jan 23, 2024
f73fbae
Use crates.io package
pgherveou Jan 23, 2024
49d49dc
Fix clippy
pgherveou Jan 23, 2024
987e869
use ink-pallet-contracts-uapi until newer version get published
pgherveou Jan 23, 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
Prev Previous commit
Next Next commit
wip
  • Loading branch information
pgherveou committed Jan 8, 2024
commit 5d252075cedec8c4f630704b4565151ed738f246
1 change: 1 addition & 0 deletions ARCHITECTURE.md
Original file line number Diff line number Diff line change
@@ -153,6 +153,7 @@ If you look at the implementations you'll see a common pattern of
for contract developers.

### The pallet API
// TODO update doc
The function signature of the `pallet-contracts` API functions is defined in
[`ink_env/src/engine/on_chain/ext.rs`](https://github.com/paritytech/ink/blob/master/crates/env/src/engine/on_chain/ext.rs).
You'll see that we import different versions of API functions, something
41 changes: 41 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions crates/engine/Cargo.toml
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@ include = ["Cargo.toml", "src/**/*.rs", "README.md", "LICENSE"]
[dependencies]
ink_primitives = { workspace = true }
scale = { workspace = true }
pallet-contracts-uapi = { workspace = true }
derive_more = { workspace = true, features = ["from", "display"] }

sha2 = { workspace = true }
77 changes: 1 addition & 76 deletions crates/engine/src/ext.rs
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@
//! See [the documentation for the `contract` module](https://docs.rs/crate/pallet-contracts)
//! for more information.

use pallet_contracts_uapi::ReturnErrorCode as Error;
use crate::{
chain_extension::ChainExtensionHandler,
database::Database,
@@ -34,82 +35,6 @@ use crate::{
use scale::Encode;
use std::panic::panic_any;

macro_rules! define_error_codes {
(
$(
$( #[$attr:meta] )*
$name:ident = $discr:literal,
)*
) => {
/// Every error that can be returned to a contract when it calls any of the host functions.
#[cfg_attr(test, derive(PartialEq, Eq))]
#[derive(Debug)]
#[repr(u32)]
pub enum Error {
$(
$( #[$attr] )*
$name = $discr,
)*
/// Returns if an unknown error was received from the host module.
Unknown,
}

impl From<ReturnCode> for Result<(), Error> {
#[inline]
fn from(return_code: ReturnCode) -> Self {
match return_code.0 {
0 => Ok(()),
$(
$discr => Err(Error::$name),
)*
_ => Err(Error::Unknown),
}
}
}
};
}
define_error_codes! {
/// The called function trapped and has its state changes reverted.
/// In this case no output buffer is returned.
/// Can only be returned from `call` and `instantiate`.
CalleeTrapped = 1,
/// The called function ran to completion but decided to revert its state.
/// An output buffer is returned when one was supplied.
/// Can only be returned from `call` and `instantiate`.
CalleeReverted = 2,
/// The passed key does not exist in storage.
KeyNotFound = 3,
/// Deprecated and no longer returned: There is only the minimum balance.
_BelowSubsistenceThreshold = 4,
/// Transfer failed for other not further specified reason. Most probably
/// reserved or locked balance of the sender that was preventing the transfer.
TransferFailed = 5,
/// Deprecated and no longer returned: Endowment is no longer required.
_EndowmentTooLow = 6,
/// No code could be found at the supplied code hash.
CodeNotFound = 7,
/// The account that was called is no contract.
NotCallable = 8,
/// The call to `debug_message` had no effect because debug message
/// recording was disabled.
LoggingDisabled = 9,
/// ECDSA public key recovery failed. Most probably wrong recovery id or signature.
EcdsaRecoveryFailed = 11,
/// sr25519 signature verification failed. This may be because of an invalid public key, invalid message or invalid signature.
Sr25519VerifyFailed = 12,
}

/// The raw return code returned by the host side.
#[repr(transparent)]
pub struct ReturnCode(u32);

impl ReturnCode {
/// Returns the raw underlying `u32` representation.
pub fn into_u32(self) -> u32 {
self.0
}
}

/// The off-chain engine.
pub struct Engine {
/// The environment database.
2 changes: 2 additions & 0 deletions crates/env/Cargo.toml
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@ ink_allocator = { workspace = true }
ink_storage_traits = { workspace = true }
ink_prelude = { workspace = true }
ink_primitives = { workspace = true }
pallet-contracts-uapi = { workspace = true }

scale = { workspace = true }
derive_more = { workspace = true, features = ["from", "display"] }
@@ -39,6 +40,7 @@ ink_engine = { workspace = true, default-features = true, optional = true }
sha2 = { workspace = true, optional = true }
sha3 = { workspace = true, optional = true }
blake2 = { workspace = true, optional = true }
pallet-contracts-uapi = { workspace = true }

# ECDSA for the off-chain environment.
secp256k1 = { workspace = true, features = ["recovery", "global-context"], optional = true }
2 changes: 1 addition & 1 deletion crates/env/src/api.rs
Original file line number Diff line number Diff line change
@@ -17,7 +17,6 @@
use crate::{
backend::{
EnvBackend,
ReturnFlags,
TypedEnvBackend,
},
call::{
@@ -42,6 +41,7 @@ use crate::{
Result,
};
use ink_storage_traits::Storable;
use pallet_contracts_uapi::ReturnFlags;

/// Returns the address of the caller of the executed contract.
///
Loading