Run ens-polyjuice

Github link

polyjuice https://github.com/TheWaWaR/ens-polyjuice/tree/live-demo

ens-polyjuice

Run CKB Dev Chain ( on macOS )

  • Download binary https://github.com/nervosnetwork/ckb/releases

  • ckb init --chain dev

  • modify [block_assembler]
    [block_assembler]
    code_hash = “0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8” // Do not change this.
    args = “0x8d627decece439977a3a0a97815b63debaff2874” // Change this to your lock_arg value.
    hash_type = “type” // Do not change this.
    message = “A 0x-prefixed hex string” // Change this to “0x” to supply an empty message.

  • Change the Mining Interval: (optional)
    [[miner.workers]]
    worker_type = “Dummy”
    delay_type = “Constant”
    value = 5000 # The unit of measurement is “ms”.

  • ckb run

  • ckb miner

Prepare account

  • create account: ckb-cli account new
  • export privkey: ckb-cli account export --lock-arg <LOCK_ARG> --extended-privkey-path privkey

##Deploy cell deps and run polyjuice

Clone polyjuice project

Build validator contract

  • cd c
  • make all-via-docker
  • cd …

Install polyjuice to ~/.cargo/bin

  • cargo install --force --path .

Deploy validator

  • ckb-cli wallet transfer --privkey-path privkey-0xa2cd8463100b470fa911772860525f0e743a6d6d --to-address ckt1qyqwdae9hlzsg8se950c0xqf7cnw8ke2durq5s79ul --tx-fee 0.01 --capacity 300000 --to-data-path ./c/build/validator

validator tx hash:0x8724fdf6b6afc49e14c967e84c01da367c6bd6ecc57483440cb7e197aeb3d092

deploy always success lock script

lock script is required for every cell and we want anyone can use the contract, here we deploy an always success contract for polyjuice cell’s lock script

  • ckb-cli wallet transfer --privkey-path privkey-0xa2cd8463100b470fa911772860525f0e743a6d6d --to-address ckt1qyqwdae9hlzsg8se950c0xqf7cnw8ke2durq5s79ul --tx-fee 0.01 --capacity 600 --to-data 0x7f454c460201010000000000000000000200f3000100000078000100000000004000000000000000980000000000000005000000400038000100400003000200010000000500000000000000000000000000010000000000000001000000000082000000000000008200000000000000001000000000000001459308d00573000000002e7368737472746162002e74657874000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b000000010000000600000000000000780001000000000078000000000000000a0000000000000000000000000000000200000000000000000000000000000001000000030000000000000000000000000000000000000082000000000000001100000000000000000000000000000001000000000000000000000000000000

always success tx hash:0x5ee24ec8f5d13c95d7d16588f95b1e2ee722cfe530c2cb6b68b77b4c0afd113a

validator’s code hash

ckb-cli util blake2b --binary-path ./c/build/validator

blake2h hash: 0xf27e46faed9fae74a3552e8495bd1a1677fa2b8237616f30132510e67dff831f

cat > run_config.json << _RUN_CONFIG_
{
    "type_dep": {
        "out_point": {
            "tx_hash": "${VALIDATOR_TX_HASH}",
            "index": "0x0"
        },
        "dep_type": "code"
    },
    "type_script": {
        "code_hash": "${VALIDATOR_CODE_HASH}",
        "hash_type": "data",
        "args": "0x"
    },
    "lock_dep": {
        "out_point": {
            "tx_hash": "${ALWAYS_SUCCESS_TX_HASH}",
            "index": "0x0"
        },
        "dep_type": "code"
    },
    "lock_script": {
        "code_hash": "0x28e83a1277d48add8e72fadaa9248559e1b632bab2bd60b27955ebc4c03800a5",  //always_success's code hash
        "hash_type": "data",
        "args": "0x"
    }
}_RUN_CONFIG_

Run polyjuice

  • RUST_LOG=polyjuice=debug ./target/release/polyjuice run --generator ./c/build/generator --config ./run_config.json

  • ./ckb-cli account
    miner:
    address:
    mainnet: ckb1qyq29nvyvvgqk3c04yghw2rq2f0suap6d4ksptf0k0
    testnet: ckt1qyq29nvyvvgqk3c04yghw2rq2f0suap6d4ksuwhs6n
    lock_arg: 0xa2cd8463100b470fa911772860525f0e743a6d6d
    lock_hash: 0xaa0bcd5feb1635592499a196e376e3581ebfbb64567ad8561fcfc851f56976f3

  • privkey:43a41b54de995a1d01f1e98e3d67fbbc0bbf9d9911adbc801470ce56e9ea3b14
    08e4434bd76caf8655311a8fa6db0df9a15c2c0df7306481683c92bec2d848dd

  • Ethereum address: 0xa2cd8463100b470fa911772860525f0e743a6d6d (The same with lock_arg)

  • wallet transfer validator:
    address:
    mainnet: ckb1qyqfq5v7rr205tndjargrfx5v7dmxh9zrwxq5zk957
    testnet: ckt1qyqfq5v7rr205tndjargrfx5v7dmxh9zrwxqf8g6cz
    lock_arg: 0x90519e18d4fa2e6d974681a4d4679bb35ca21b8c
    lock_hash: 0xd065b73902666e74f061c1293bd5677b205e9f33d50c15758af3dfe817ac261a

Run ens-polyjuice

Install node first.

(required version v10.22.0 (lts/dubnium))

Clone and compile contracts

Install python dependencies

  • sudo pip3 install crypto flask-jsonrpc flask-cors
  • sudo pip3 uninstall cffi
  • sudo pip3 uninstall pycryptodome
  • sudo pip3 install pycryptodome

Deploy ENS contracts

  • python3 deploy.py /Users/zengbing/Documents/Developer-Tools/Atalk1014/ens-polyjuice/tmp /Users/zengbing/Documents/Developer-Tools/Atalk1014/ckb_v0.36.0_x86_64-apple-darwin/ckb http://localhost:8114 http://localhost:8214

========================================================================
ENSRegistry                 : 0xb03db5688a23542da0cf4d9322eb040bf1294cc7
PublicResolver              : 0x51bd9d48c0bd9be6798cdb10d800ba49b3f23fcd
BaseRegistrarImplementation : 0x0a042a5b31b56f5d5d2d60dedebb773a6bbf2e95
ReverseRegistrar            : 0x463f285e25ae1f523fc1eef2172749ae88bff7c8
DummyPriceOracle            : 0x33eacbfc0dc0228f5f336b9f7592d31686eb56f0
Controller                  : 0x1c77f47e8b9ab8899fab30582f98a303c2b1fedf

=========================================================================

Run polyjuice proxy server

python3 server.py 8545 /Users/zengbing/Documents/Developer-Tools/Atalk1014/ens-polyjuice/tmp /Users/zengbing/Documents/Developer-Tools/Atalk1014/ckb_v0.36.0_x86_64-apple-darwin/ckb http://localhost:8114 http://localhost:8214

Run GraphQL server

run graph-node

Then register ENS Subgraph:

Run ENS manager app (Web UI)

we need import some environement variables to let the app connect to local service:

export REACT_APP_STAGE=local
export REACT_APP_MIGRATION_COMPLETE=True
* ENSRegistry address*
export REACT_APP_ENS_ADDRESS=0xb03db5688a23542da0cf4d9322eb040bf1294cc7
export REACT_APP_LABELS='{"4f5b812789fc606be1b3b16908db13fc7a9adf7ca72641f84d75b47069d3d7f0":"eth"}'
* The graph-node listen address*
export REACT_APP_GRAPH_NODE_URI=http://127.0.0.1:8000/subgraphs/name/graphprotocol/ens

start the app

yarn start

Tips

  • rust 升级到最新:
    • rustup update stable
    • rustup default stable
  • 如果之前跑过 dev chain 需要清除之前的索引,索引不一致了:
    rm -rf ~/.ckb-cli/index-v1/0x823b2ff5785b12da8b1363cac9a5cbe566d8b715a4311441b119c39a0367488c
    https://github.com/nervosnetwork/ckb/blob/develop/docs/hashes.toml#L134
  • dev chain 出块太多,需要清链:删除 data 文件夹
  • 清除编译缓存:cargo clean
  • miner 出块太多,server 容易卡住,可以停掉 ckb miner
  • 运行的时候最好不要开网络加速器,清除代理设置:
    • unset https_proxy
    • unset http_proxy
    • export all_proxy=
  • 测试 docker :
    • 开一个终端:nc -l 0.0.0.0 3333
    • 开另一个终端:docker run -it --rm busybox
      nc host.docker.internal 3333 输入 hello 回车
  • mac 上查看并杀死进程:https://www.jianshu.com/p/59b62e024072
  • docker data 如果清除, ens-graph 要重新 yarn setup

Reference:


3 Likes