-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implement ownerOf, transfer, approve, transferFrom, getApproved, setApprovalForAll, isApprovedForAll of ERC-721 * Add erc721 example
- Loading branch information
Showing
11 changed files
with
611 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: Example | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
workflow_dispatch: | ||
|
||
jobs: | ||
erc721-example: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
with: | ||
submodules: recursive | ||
|
||
- uses: cachix/install-nix-action@v13 | ||
with: | ||
nix_path: nixpkgs=channel:nixos-21.05-small | ||
|
||
- name: Run test | ||
run: nix-shell --run 'run-example-test erc721' | ||
|
||
- name: Deploy test | ||
run: nix-shell --run 'cli-test erc721' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[target.'cfg(target_arch="wasm32")'] | ||
rustflags = ["-C", "link-arg=--export-table"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
[package] | ||
name = "erc721-contract" | ||
version = "0.1.0" | ||
authors = [] | ||
edition = "2018" | ||
description = "This is an ERC-721 example for SewUp" | ||
|
||
[lib] | ||
path = "src/token.rs" | ||
crate-type = ["cdylib"] | ||
|
||
[dependencies] | ||
sewup ={ version = "*", path = "../../sewup", features = [ "token" ] } | ||
sewup-derive = { version = "*", path = "../../sewup-derive" } | ||
anyhow = "1.0.40" | ||
|
||
[dev-dependencies] | ||
hex-literal = "0.3.1" | ||
|
||
[profile.release] | ||
incremental = false | ||
panic = "abort" | ||
lto = true | ||
opt-level = "z" | ||
|
||
[profile.release.package.erc721-contract] | ||
incremental = false | ||
opt-level = "z" | ||
|
||
[deploy] | ||
url = "http://localhost:8545" | ||
private = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" | ||
address = "0xXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" | ||
|
||
[features] | ||
constructor = [] | ||
constructor-test = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
use sewup_derive::{ewasm_constructor, ewasm_fn, ewasm_fn_sig, ewasm_main, ewasm_test}; | ||
|
||
#[ewasm_constructor] | ||
fn constructor() { | ||
sewup::token::erc721::mint( | ||
"8663DBF0cC68AaF37fC8BA262F2df4c666a41993", | ||
vec![ | ||
"0000000000000000000000000000000000000000000000000000000000000001", | ||
"0000000000000000000000000000000000000000000000000000000000000002", | ||
"0000000000000000000000000000000000000000000000000000000000000003", | ||
], | ||
); | ||
} | ||
|
||
#[ewasm_main] | ||
fn main() -> anyhow::Result<()> { | ||
let contract = sewup::primitives::Contract::new()?; | ||
match contract.get_function_selector()? { | ||
sewup::token::erc721::BALANCE_OF_SIG => sewup::token::erc721::balance_of(&contract), | ||
sewup::token::erc721::OWNER_OF_SIG => sewup::token::erc721::owner_of(&contract), | ||
sewup::token::erc721::TRANSFER_SIG => sewup::token::erc721::transfer(&contract), | ||
sewup::token::erc721::TRANSFER_FROM_SIG => sewup::token::erc721::transfer_from(&contract), | ||
sewup::token::erc721::APPROVE_SIG => sewup::token::erc721::approve(&contract), | ||
sewup::token::erc721::GET_APPROVED_SIG => sewup::token::erc721::get_approved(&contract), | ||
sewup::token::erc721::SET_APPROVAL_FOR_ALL_SIG => { | ||
sewup::token::erc721::set_approval_for_all(&contract) | ||
} | ||
sewup::token::erc721::IS_APPROVED_FOR_ALL_SIG => { | ||
sewup::token::erc721::is_approved_for_all(&contract) | ||
} | ||
_ => (), | ||
}; | ||
Ok(()) | ||
} | ||
|
||
#[ewasm_test] | ||
mod tests { | ||
use super::*; | ||
use hex_literal::hex; | ||
use sewup::erc721::{BALANCE_OF_SIG, OWNER_OF_SIG}; | ||
use sewup_derive::ewasm_assert_eq; | ||
|
||
#[ewasm_test] | ||
fn test_execute_basic_operations() { | ||
let address_input = hex!("8663DBF0cC68AaF37fC8BA262F2df4c666a41993"); | ||
let mut input_data = vec![0u8, 0u8, 0u8, 0u8]; | ||
input_data.extend_from_slice(&address_input); | ||
ewasm_assert_eq!( | ||
balance_of(input_data), | ||
vec![ | ||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
0, 0, 0, 3 | ||
] | ||
); | ||
|
||
let token1 = hex!("0000000000000000000000000000000000000000000000000000000000000001"); | ||
let token2 = hex!("0000000000000000000000000000000000000000000000000000000000000002"); | ||
let token4 = hex!("0000000000000000000000000000000000000000000000000000000000000004"); | ||
|
||
ewasm_assert_eq!( | ||
owner_of(token1), | ||
vec![ | ||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 134, 99, 219, 240, 204, 104, 170, 243, 127, | ||
200, 186, 38, 47, 45, 244, 198, 102, 164, 25, 147 | ||
] | ||
); | ||
ewasm_assert_eq!( | ||
owner_of(token2), | ||
vec![ | ||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 134, 99, 219, 240, 204, 104, 170, 243, 127, | ||
200, 186, 38, 47, 45, 244, 198, 102, 164, 25, 147 | ||
] | ||
); | ||
|
||
ewasm_assert_eq!( | ||
owner_of(token4), | ||
vec![ | ||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
0, 0, 0, 0 | ||
] | ||
); | ||
} | ||
} |
Oops, something went wrong.