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

docs: Refactor pausable for erc721 example #414

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
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
39 changes: 20 additions & 19 deletions docs/modules/ROOT/pages/erc721-pausable.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use openzeppelin_stylus::{

sol_storage! {
#[entrypoint]
struct Erc721Example {
struct PausableErc721 {
#[borrow]
Erc721 erc721;
#[borrow]
Expand All @@ -28,20 +28,16 @@ sol_storage! {

#[public]
#[inherit(Erc721, Pausable)]
impl Erc721Example {
impl PausableErc721 {
pub fn burn(&mut self, token_id: U256) -> Result<(), Vec<u8>> {
// ...
self.pausable.when_not_paused()?;
// ...
self.erc721.burn(token_id)?;
self._update(Address::ZERO, token_id, msg::sender())?;
Ok(())
}

pub fn mint(&mut self, to: Address, token_id: U256) -> Result<(), Vec<u8>> {
// ...
self.pausable.when_not_paused()?;
let previous_owner = self._update(to, token_id, Address::ZERO)?;
// ...
self.erc721._mint(to, token_id)?;
Ok(())
}

Expand All @@ -51,11 +47,7 @@ impl Erc721Example {
to: Address,
token_id: U256,
) -> Result<(), Vec<u8>> {
// ...
self.pausable.when_not_paused()?;
// ...
self.erc721.safe_transfer_from(from, to, token_id)?;
Ok(())
self.safe_transfer_from_with_data(from, to, token_id, vec![].into())
}

#[selector(name = "safeTransferFrom")]
Expand All @@ -66,10 +58,8 @@ impl Erc721Example {
token_id: U256,
data: Bytes,
) -> Result<(), Vec<u8>> {
self.transfer_from(from, to, token_id)?;
// ...
self.pausable.when_not_paused()?;
// ...
self.erc721.safe_transfer_from_with_data(from, to, token_id, data)?;
Ok(())
}

Expand All @@ -80,19 +70,30 @@ impl Erc721Example {
token_id: U256,
) -> Result<(), Vec<u8>> {
// ...
self.pausable.when_not_paused()?;
let previous_owner = self._update(to, token_id, msg::sender())?;
// ...
self.erc721.transfer_from(from, to, token_id)?;
Ok(())
}
}

impl PausableErc721 {
fn _update(
&mut self,
to: Address,
token_id: U256,
auth: Address,
) -> Result<Address, Vec<u8>> {
self.pausable.when_not_paused()?;
Ok(self.erc721._update(to, token_id, auth)?)
}
}
----

Additionally, you need to ensure proper initialization during xref:deploy.adoc[contract deployment]. Make sure to include the following code in your Solidity Constructor:

[source,solidity]
----
contract Erc721Example {
contract PausableErc721 {
bool private _paused;

constructor() {
Expand Down
Loading