difftreelog
Merge branch 'master' of https://github.com/usetech-llc/nft_parachain
in: master
5 files changed
.gitattributesdiffbeforeafterboth--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,2 @@
+* text=auto
+*.sh text eol=lf
Dockerfilediffbeforeafterboth--- a/Dockerfile
+++ b/Dockerfile
@@ -1,20 +1,41 @@
-FROM rust:latest
+# ===== BUILD ======
-EXPOSE 9944
+FROM phusion/baseimage:0.10.2 as builder
+LABEL maintainer="gz@usetech.com"
-# Install build tools
-RUN apt-get update && apt-get -y install -y cmake pkg-config libssl-dev git gcc build-essential clang libclang-dev curl
-RUN curl https://getsubstrate.io -sSf | bash -s -- --fast
-RUN rustup update nightly
-RUN rustup target add wasm32-unknown-unknown --toolchain nightly
-RUN rustup update
+ENV WASM_TOOLCHAIN=nightly
+
+ARG PROFILE=release
+
+RUN apt-get update && \
+ apt-get dist-upgrade -y -o Dpkg::Options::="--force-confold" && \
+ apt-get install -y cmake pkg-config libssl-dev git clang
# Get project and run it
-RUN git clone https://github.com/usetech-llc/nft_parachain
+RUN git clone https://github.com/usetech-llc/nft_parachain /nft_parachain
WORKDIR /nft_parachain
-RUN cargo build
-RUN cargo test --all
+RUN curl https://sh.rustup.rs -sSf | sh -s -- -y && \
+ export PATH="$PATH:$HOME/.cargo/bin" && \
+ rustup toolchain install $WASM_TOOLCHAIN && \
+ rustup target add wasm32-unknown-unknown --toolchain $WASM_TOOLCHAIN && \
+ rustup default stable && \
+ rustup target list --installed && \
+ rustup show && \
+ cargo build "--$PROFILE"
+
+RUN cd target/release && ls -la
+
+# ===== RUN ======
+
+FROM phusion/baseimage:0.10.2
+ARG PROFILE=release
+
+COPY --from=builder /nft_parachain/target/$PROFILE/nft /usr/local/bin
+
+EXPOSE 9944
+VOLUME ["/chain-data"]
+
# Copy and run start script
COPY ["./run.sh", "./run.sh"]
RUN chmod +x ./run.sh
doc/demo_milestone1-2.mddiffbeforeafterboth1# Manual Demos23Milestone 1 and 2 deliverables are marked by tag [release1](https://github.com/usetech-llc/nft_parachain/tree/release1)45## Milestone 167### A running chain89**Substrate based blockchain node to host NFT Tracking Module created with substrate-up scripts (currently substrate-up only support Substrate 1.0)**1011We have created chain based on both versions of substrate: 1 and 2. Nonetheless, the substrate 1 is not being widely used and we decided to obsolete this branch of code. The code still exists in [substrate1](https://github.com/usetech-llc/nft_parachain/tree/substrate1) branch, but this delivery document is based on substrate 2 version.1213The node can be run using docker container:14```15TBD16```1718#### NFT Tracking Module19Open extrinsics tab of the [standard UI](https://polkadot.js.org/apps/#/extrinsics) and find "nft" in the module list. This proves that NFT module is deployed.2021#### Balances Module, Other modules included by default 22The [same UI](https://polkadot.js.org/apps/#/extrinsics) allows verification that all other modules are also installed as needed.2324#### Configuration of runtime as needed (e.g. for hot module updates)2526The `set_code` method worked out of the box and we did not need to perform any additional customizations to upload an updated WASM version of NFT palette.2728### NFT Tracking Module2930Before we continue, we need to do some preparations in the UI: Add NFT Data types so that the UI knows how to decode them. Go to [Settings-Developer Tab](https://polkadot.js.org/apps/#/settings/developer) and add following types to the JSON object in there:31```32{33 "NftItemType": {34 "Collection": "u64",35 "Owner": "AccountId",36 "Data": "Vec<u8>"37 },38 "CollectionType": {39 "Owner": "AccountId",40 "NextItemId": "u64",41 "CustomDataSize": "u32"42 },43 "Address": "AccountId",44 "LookupSource": "AccountId",45 "Weight": "u32"46}47```4849**Note:** In the future we will likely switch to substrate "2.0.0-alpha.7", in which case Weight type should be `u64`.5051#### CreateCollection5253Before running test, open [chain state tab](https://polkadot.js.org/apps/#/chainstate) and read `nft`.`nextCollectionId` state variable, which shows how many collections were created so far. If you just started the chain, this should equal 0. 5455Open extrinsics tab of the [standard UI](https://polkadot.js.org/apps/#/extrinsics) and select ALICE account. Select `nft` module and `createCollection` method. Put 1 in `custom_data_sz` and run the transaction. After it is finalized, read the `nft`.`nextCollectionId` state variable. It will be equal 1.5657Also, read the state variable `nft`.`collection` with ID = 1 (Because everything in NFT Palette is numbered from 1, not from 0). You will see something like this:5859```60nft.collection: CollectionType61{62 Owner: 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY,63 NextItemId: 1,64 CustomDataSize: 165}66```6768### ChangeCollectionOwner6970Open extrinsics tab of the [standard UI](https://polkadot.js.org/apps/#/extrinsics). Select `nft` module and `changeCollectionOwner` method. First, try to execute it to change owner to BOB for collection 1 from some different account than ALICE - FERDIE to see that it is not possible because ALICE owns collection 1 and FERDIE is not allowed to give it to BOB. Second, select ALICE as transaction signer and run it again. This time the collection owner changes, which will be reflected if you read the state variable `nft`.`collection` with ID = 1:7172```73nft.collection: CollectionType74{75 Owner: 5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty,76 NextItemId: 1,77 CustomDataSize: 178}79```8081Change the ownership back to ALICE to continue with this demo.8283### DestroyCollection8485**Note: Before destroying collection, you can see Milestone 2 deliverables to avoid creating collection again**8687Run `nft`.`destroyCollection` with collection ID = 1, and then read collection from state. The returned fields will have default values, which indicates that collection does not exsit anymore: 88```89nft.collection: CollectionType90{91 Owner: 5C4hrfjw9DjXZTzV3MwzrrAr9P1MJhSrvWGWqi1eSuyUpnhM,92 NextItemId: 0,93 CustomDataSize: 094}95```9697### End user documentation9899See [application_development.md](application_development.md)100101### Docker images for running deliverables for acceptance102103**Substrate Node (in dev mode), Unit tests for NFT Module**104105See above, the unit tests are run before the node starts within the same image.106107### Acceptance instructions108109**using Polkadot UI from https://substrate-ui.parity.io/**110111This document, except we are using Substrate v2, so we can use the newer version of the UI: https://polkadot.js.org/apps/#112113## Milestone 2114### NFT Tracking Module115**Note:** If you have destroyed collection, create it again using `nft`.`createCollection` method.116117**Note 2:** The order of items in this section is different from the original spec to make the acceptance workflow more natural.118119If you did not destroy collection while looking at Milestone 1 deliverables, use collection ID 1 in the further examples, otherwise use collection ID = 2.120121#### CreateItem122Before creating an NFT item, let's read ALICE balance for your collection, which indicates how many NFT tokens ALICE owns in this collection. Read the chain state `nft`.`balance(<Collection ID>, ALICE)`, and it will be 0.123124Execute extrinsic `nft`.`createItem` from ALICE account. Set properties to `0x01`. Now if you read the chain state `nft`.`balance(<Collection ID>, ALICE)`, it will be equal to 1. Also, you can read chain state `nft`.`itemList(<Collection ID>, 1)`, and it will return data for the token 1:125126```127nft.itemList: NftItemType128{129 Collection: 1,130 Owner: 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY,131 Data: 0x01132}133```134135#### GetOwner136Reading the ownership is done by reading chainstate `nft`.`itemList(<Collection ID>, 1)`. One of the returned fields is Owner:137```138nft.itemList: NftItemType139{140 Collection: 1,141 Owner: 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY,142 Data: 0x01143}144```145146#### Transfer147Execute `nft`.`transfer` from ALICE address to transfer token 1 to BOB and check the ownership again:148```149nft.itemList: NftItemType150{151 Collection: 1,152 Owner: 5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty,153 Data: 0x01154}155```156157Transfer the token 1 back to ALICE to enable further demo actions.158159#### BalanceOf160161Read the chain state `nft`.`balance` for ALICE address and see that she owns 1 token:162```163nft.balance: u641641165```166167#### AddCollectionAdmin168Execute `nft`.`AddCollectionAdmin` from ALICE account and let CHARLIE be an admin. Now you can see that CHARLIE can transfer ALICE's token from ALICE's account to EVE and back. Also, you can read admin list from chain state and see that it is not empty:169170```171nft.adminList: Vec<AccountId>172[173 5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y174]175```176177#### RemoveCollectionAdmin178Execute `nft`.`RemoveCollectionAdmin` from ALICE account to remove CHARLIE from admins. Now you can see that CHARLIE cannot transfer ALICE's tokens anymore. If you read the chan state `nft`.`adminList`, the response will be empty:179180```181nft.adminList: Vec<AccountId>182[]183```184185#### BurnItem186Execute `nft`.`burnItem` from ALICE account to burn token 1, and then read the chain state `nft`.`itemList(<Collection ID>, 1)`. This time the chain state returns default values in fields because token does not exist anymore. You can also check ALICE balance in chain state, now it is equal 0 again.187```188nft.itemList: NftItemType189{190 Collection: 0,191 Owner: 5C4hrfjw9DjXZTzV3MwzrrAr9P1MJhSrvWGWqi1eSuyUpnhM,192 Data: 0x193}194```195196### Economic Model Specification197[Economic Model Specification](economic_model.md)198199### Contracts Module Specification200https://docs.google.com/document/d/1gDtYjPR9C1VZChxEA-xAdQWQyEvMg245XrZR_MpE3cg/edit?usp=sharing201202### Bonus goal203204**Basic demo - Cryptopunks representation on the Substrate Chain.**205206See this repo, it has running and playing instructions:207https://github.com/usetech-llc/substrapunksdocker-compose.ymldiffbeforeafterboth--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -1,4 +1,4 @@
-version: "3"
+version: "3.5"
services:
node:
@@ -10,3 +10,10 @@
dockerfile: Dockerfile
volumes:
- ./chain-data:/chain-data
+ networks:
+ - substrate_network
+
+networks:
+ substrate_network:
+ driver: bridge
+ name: substrate_network
run.shdiffbeforeafterboth--- a/run.sh
+++ b/run.sh
@@ -1 +1,3 @@
-cargo run -- --dev --ws-external --rpc-external --base-path=./chain-data
\ No newline at end of file
+ls -la /nft_parachain/target/release
+
+/usr/local/bin/nft --dev --ws-external --rpc-external --base-path=/chain-data