Skip to content

Commit

Permalink
Merge pull request #15 from 727-Ventures/feature/update-to-ink-4-beta.1
Browse files Browse the repository at this point in the history
Update to ink! 4.0.0-rc
  • Loading branch information
Artemka374 authored Feb 2, 2023
2 parents dc8d03b + 425f1f3 commit c0185bb
Show file tree
Hide file tree
Showing 84 changed files with 286 additions and 204 deletions.
28 changes: 14 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ jobs:
with:
node-version: '16.x'
- uses: actions/checkout@v3
- name: Yarn install dependencies
- name: NPM install dependencies
run: |
yarn
yarn add ts-node
npm i
npm i ts-node
- name: Cache rust artifacts
id: cache-rust-artifacts
Expand All @@ -81,7 +81,7 @@ jobs:
run: |
chown -R root .
chmod -R a+rwx .
yarn build:release
npm run build:release
caching-artifacts:
concurrency:
group: caching-artifacts-${{ github.ref }}
Expand Down Expand Up @@ -144,10 +144,10 @@ jobs:
with:
ref: main

- name: Yarn install dependencies for destination branch
- name: NPM install dependencies for destination branch
run: |
yarn
yarn add ts-node
npm i
npm i ts-node
- name: Cache rust artifacts for destination branch
id: cache-rust-artifacts-destination
Expand All @@ -162,7 +162,7 @@ jobs:
run: |
chown -R root .
chmod -R a+rwx .
yarn build:release
npm run build:release
- name: Find contract data destination branch
id: find-data-destination
Expand Down Expand Up @@ -216,10 +216,10 @@ jobs:
with:
node-version: '16.x'
- uses: actions/checkout@v3
- name: Yarn install dependencies
- name: NPM install dependencies
run: |
yarn
yarn add ts-node
npm i
npm i ts-node
- name: Cache contract artifacts
id: cache-contract-artifacts
Expand All @@ -230,7 +230,7 @@ jobs:

- name: Generate Typechain code
run:
yarn build:release:no-compile
npm run build:release:no-compile

- name: Run Test Mocha
run: |
Expand All @@ -240,13 +240,13 @@ jobs:
do
substrate-contracts-node --tmp --dev & P1=$!;
set +e;
output=$(yarn test:mocha-single ./$test || true);
output=$(npm run test:mocha-single ./$test || true);
set -e;
if echo $output | grep -q 'For async tests and hooks, ensure "done()" is called'; then
echo $output;
has_timeout=true
else
yarn test:mocha-single ./$test
npm run test:mocha-single ./$test
has_timeout=false
fi
kill $P1;
Expand Down
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ exclude = [

[package]
name = "openbrush"
version = "3.0.0-beta"
version = "3.0.0-beta.1"
authors = ["Brushfam <[email protected]>"]
edition = "2018"

Expand All @@ -27,12 +27,12 @@ categories = ["no-std", "embedded"]
include = ["Cargo.toml", "src/**/*.rs"]

[dependencies]
ink = { git = "https://github.com/paritytech/ink", rev = "4655a8b4413cb50cbc38d1b7c173ad426ab06cde", default-features = false}
ink = { version = "~4.0.0-rc", default-features = false}
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
scale-info = { version = "2.3", default-features = false, features = ["derive"], optional = true }

openbrush_contracts = { version = "~3.0.0-beta", path = "contracts", default-features = false }
openbrush_lang = { version = "~3.0.0-beta", path = "lang", default-features = false }
openbrush_contracts = { version = "~3.0.0-beta.1", path = "contracts", default-features = false }
openbrush_lang = { version = "~3.0.0-beta.1", path = "lang", default-features = false }

[lib]
name = "openbrush"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ You can run unit tests by `RUSTFLAGS="-D warnings" cargo +nightly test --workspa
To run integration test you need to start the node with contract-pallet.
- [Setup and start the node with contract-pallet](https://github.com/paritytech/substrate-contracts-node)

After you can run tests by `yarn run test` command. It will build all contracts required for integration tests and run them.
After you can run tests by `npm run test` command. It will build all contracts required for integration tests and run them.

## FAQ

Expand Down
8 changes: 4 additions & 4 deletions contracts/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "openbrush_contracts"
version = "3.0.0-beta"
version = "3.0.0-beta.1"
authors = ["Brushfam <[email protected]>"]
edition = "2021"

Expand All @@ -15,13 +15,13 @@ categories = ["no-std", "embedded"]
include = ["Cargo.toml", "src/**/*.rs"]

[dependencies]
ink = { git = "https://github.com/paritytech/ink", rev = "4655a8b4413cb50cbc38d1b7c173ad426ab06cde", default-features = false}
ink = { version = "~4.0.0-rc", default-features = false}
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
scale-info = { version = "2.3", default-features = false, features = ["derive"], optional = true }

openbrush = { version = "~3.0.0-beta", package = "openbrush_lang", path = "../lang", default-features = false }
openbrush = { version = "~3.0.0-beta.1", package = "openbrush_lang", path = "../lang", default-features = false }

pallet-assets-chain-extension = { git = "https://github.com/727-ventures/pallet-assets-chain-extension", tag = "3.0.0-beta", default-features = false, features = ["ink-lang"] }
pallet-assets-chain-extension = { git = "https://github.com/727-ventures/pallet-assets-chain-extension", branch = "ink-4-beta", default-features = false, features = ["ink-lang"] }

[lib]
name = "openbrush_contracts"
Expand Down
11 changes: 10 additions & 1 deletion contracts/src/access/ownable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,22 @@ pub use ownable::Internal as _;

pub const STORAGE_KEY: u32 = openbrush::storage_unique_key!(Data);

#[derive(Default, Debug)]
#[derive(Debug)]
#[openbrush::upgradeable_storage(STORAGE_KEY)]
pub struct Data {
pub owner: AccountId,
pub _reserved: Option<()>,
}

impl Default for Data {
fn default() -> Self {
Self {
owner: ZERO_ADDRESS.into(),
_reserved: Default::default(),
}
}
}

/// Throws if called by any account other than the owner.
#[modifier_definition]
pub fn only_owner<T, F, R, E>(instance: &mut T, body: F) -> Result<R, E>
Expand Down
7 changes: 3 additions & 4 deletions contracts/src/governance/timelock_controller/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,21 +445,20 @@ where
self.flush();
let result = build_call::<DefaultEnvironment>()
.call_type(
Call::new()
.callee(transaction.callee)
Call::new(transaction.callee)
.gas_limit(transaction.gas_limit)
.transferred_value(transaction.transferred_value),
)
.exec_input(ExecutionInput::new(transaction.selector.into()).push_arg(CallInput(&transaction.input)))
.returns::<()>()
.call_flags(CallFlags::default().set_allow_reentry(true))
.fire()
.try_invoke()
.map_err(|_| TimelockControllerError::UnderlyingTransactionReverted);

// Load the sate of the contract after the cross call.
self.load();

result?;
result?.unwrap();
self._emit_call_executed_event(id, i, transaction);
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/token/psp22/extensions/flashmint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl<T: Storage<psp22::Data>> Internal for T {
let builder =
FlashBorrowerRef::on_flashloan_builder(&receiver_account, Self::env().caller(), token, amount, fee, data)
.call_flags(CallFlags::default().set_allow_reentry(true));
let result = match builder.fire() {
let result = match builder.try_invoke() {
Ok(Ok(Ok(_))) => Ok(()),
Ok(Ok(Err(FlashBorrowerError::FlashloanRejected(message)))) => {
Err(FlashLenderError::BorrowerRejected(message))
Expand Down
16 changes: 13 additions & 3 deletions contracts/src/token/psp22/extensions/wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,29 @@ use openbrush::traits::{
AccountId,
Balance,
Storage,
ZERO_ADDRESS,
};
pub use psp22::Internal as _;
pub use wrapper::Internal as _;

pub const STORAGE_KEY: u32 = openbrush::storage_unique_key!(Data);

#[derive(Default, Debug)]
#[derive(Debug)]
#[openbrush::upgradeable_storage(STORAGE_KEY)]
pub struct Data {
pub underlying: AccountId,
pub _reserved: Option<()>,
}

impl Default for Data {
fn default() -> Self {
Self {
underlying: ZERO_ADDRESS.into(),
_reserved: Default::default(),
}
}
}

impl<T: Storage<psp22::Data> + Storage<Data>> PSP22Wrapper for T {
default fn deposit_for(&mut self, account: AccountId, amount: Balance) -> Result<(), PSP22Error> {
self._deposit(amount)?;
Expand Down Expand Up @@ -94,7 +104,7 @@ impl<T: Storage<psp22::Data> + Storage<Data>> Internal for T {
self._underlying()
.transfer_from_builder(Self::env().caller(), Self::env().account_id(), amount, Vec::<u8>::new())
.call_flags(CallFlags::default().set_allow_reentry(true))
.fire()
.try_invoke()
.unwrap()
.unwrap()
}
Expand All @@ -103,7 +113,7 @@ impl<T: Storage<psp22::Data> + Storage<Data>> Internal for T {
self._underlying()
.transfer_builder(account, amount, Vec::<u8>::new())
.call_flags(CallFlags::default().set_allow_reentry(true))
.fire()
.try_invoke()
.unwrap()
.unwrap()
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/token/psp22/psp22.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ impl<T: Storage<Data>> Internal for T {
data.clone(),
)
.call_flags(CallFlags::default().set_allow_reentry(true));
let result = match builder.fire() {
let result = match builder.try_invoke() {
Ok(Ok(Ok(_))) => Ok(()),
Ok(Ok(Err(e))) => Err(e.into()),
// Means unknown method
Expand Down
19 changes: 15 additions & 4 deletions contracts/src/token/psp22/utils/token_timelock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,31 @@ use openbrush::traits::{
Balance,
Storage,
Timestamp,
ZERO_ADDRESS,
};
pub use psp22::Internal as _;
pub use token_timelock::Internal as _;

pub const STORAGE_KEY: u32 = openbrush::storage_unique_key!(Data);

#[derive(Default, Debug)]
#[derive(Debug)]
#[openbrush::upgradeable_storage(STORAGE_KEY)]
pub struct Data {
token: AccountId,
beneficiary: AccountId,
release_time: Timestamp,
}

impl Default for Data {
fn default() -> Self {
Self {
token: ZERO_ADDRESS.into(),
beneficiary: ZERO_ADDRESS.into(),
release_time: Default::default(),
}
}
}

impl<T: Storage<Data>> PSP22TokenTimelock for T {
/// Returns the token address
default fn token(&self) -> AccountId {
Expand Down Expand Up @@ -101,11 +112,11 @@ pub trait Internal {

impl<T: Storage<Data>> Internal for T {
default fn _withdraw(&mut self, amount: Balance) -> Result<(), PSP22TokenTimelockError> {
let beneficairy = self.beneficiary();
let beneficiary = self.beneficiary();
self._token()
.transfer_builder(beneficairy, amount, Vec::<u8>::new())
.transfer_builder(beneficiary, amount, Vec::<u8>::new())
.call_flags(CallFlags::default().set_allow_reentry(true))
.fire()
.try_invoke()
.unwrap()
.unwrap()?;
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/token/psp34/psp34.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ where
let builder =
PSP34ReceiverRef::before_received_builder(to, operator.clone(), from.clone(), id.clone(), data.clone())
.call_flags(CallFlags::default().set_allow_reentry(true));
let b = builder.fire();
let b = builder.try_invoke();
let result = match b {
Ok(Ok(Ok(_))) => Ok(()),
Ok(Ok(Err(e))) => Err(e.into()),
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/token/psp37/psp37.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ where
data.clone(),
)
.call_flags(CallFlags::default().set_allow_reentry(true));
let result = match builder.fire() {
let result = match builder.try_invoke() {
Ok(Ok(Ok(_))) => Ok(()),
Ok(Ok(Err(e))) => Err(e.into()),
// `NotCallable` means that the receiver is not a contract.
Expand Down
15 changes: 14 additions & 1 deletion contracts/src/traits/timelock_controller/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ use openbrush::traits::{
Balance,
Hash,
Timestamp,
ZERO_ADDRESS,
};

pub type OperationId = Hash;

/// A Transaction is what can be executed by `executor`
#[derive(Default, Debug, Clone, PartialEq, scale::Encode, scale::Decode)]
#[derive(Debug, Clone, PartialEq, scale::Encode, scale::Decode)]
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
pub struct Transaction {
/// The `AccountId` of the contract that is called in this transaction.
Expand All @@ -49,6 +50,18 @@ pub struct Transaction {
pub gas_limit: u64,
}

impl Default for Transaction {
fn default() -> Self {
Self {
callee: ZERO_ADDRESS.into(),
selector: Default::default(),
input: Default::default(),
transferred_value: Default::default(),
gas_limit: Default::default(),
}
}
}

/// TimelockController is AccessControl itself, so creating wrapper for both traits
#[openbrush::wrapper]
pub type TimelockControllerRef = dyn TimelockController + AccessControl;
Expand Down
Loading

0 comments on commit c0185bb

Please sign in to comment.