Skip to content

Commit

Permalink
Merge pull request #10 from doitian/unisat
Browse files Browse the repository at this point in the history
feature: support unisat wallet
  • Loading branch information
doitian authored Jan 5, 2024
2 parents c2e635d + f6ee959 commit a065d9a
Show file tree
Hide file tree
Showing 47 changed files with 710 additions and 276 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
.env
.env.*
/migrations
/migrations/dev
/migrations/joyid
/migrations/ckb_auth

# CKB
/ckb-miner.toml
Expand Down
65 changes: 39 additions & 26 deletions bin/deploy-to-dev-chain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,42 @@ if ! [ -f specs/miner.key ]; then
echo "d00c06bfd800d27397002dca6fb0993d5ba6399b4238b2f29ee9deb97593d2bc" >specs/miner.key
fi

rm -rf migrations/dev && mkdir -p migrations/dev
GENESIS_TX0="$(ckb list-hashes | sed -n 's/tx_hash = "\(.*\)"/\1/p' | head -1)"
sed "s/0x8f8c79eb6671709633fe6a46de93c0fedc9c1b8a6527a18d3983879542635c9f/$GENESIS_TX0/" deployment.toml >migrations/dev/deployment.toml

ckb-cli deploy gen-txs --from-address ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqwgx292hnvmn68xf779vmzrshpmm6epn4c0cgwga \
--fee-rate 1000 --deployment-config migrations/dev/deployment.toml --info-file migrations/dev/deployment.json --migration-dir migrations/dev

SIGNATURES="$(ckb-cli deploy sign-txs --info-file migrations/dev/deployment.json --privkey-path specs/miner.key --output-format json | sed -n 's/: \("[^"]*"\)/: [\1]/p')"
echo "$SIGNATURES"
CELLS_SIGNATURES="$(echo "$SIGNATURES" | head -1)"
DEP_GROUPS_SIGNATURES="$(echo "$SIGNATURES" | tail -1)"

sed -i.bak \
-e 's/"cell_tx_signatures": {}/"cell_tx_signatures": {'"$CELLS_SIGNATURES"'}/' \
migrations/dev/deployment.json
sed -i.bak \
-e 's/"dep_group_tx_signatures": {}/"dep_group_tx_signatures": {'"$DEP_GROUPS_SIGNATURES"'}/' \
migrations/dev/deployment.json
rm -f migrations/dev/deployment.json.bak

ckb-cli deploy apply-txs --info-file migrations/dev/deployment.json --migration-dir migrations/dev

DEPLOY_RESULT_FILE="$(ls migrations/dev/*.json | grep -v deployment | head -n 1)"
bin/use-env.sh "$DEPLOY_RESULT_FILE" >.env

bin/generate-blocks.sh 3
function deploy() {
local DEPLOY_NAME="$1"
local MIGRATION_DIR="migrations/$DEPLOY_NAME"
local CONFIG_FILE="$MIGRATION_DIR/deployment.toml"
local INFO_FILE="$MIGRATION_DIR/deployment.json"
local TEMPLATE_FILE="migrations/templates/$DEPLOY_NAME.toml"

rm -rf "$MIGRATION_DIR" && mkdir -p "$MIGRATION_DIR"
GENESIS_TX0="$(ckb list-hashes | sed -n 's/tx_hash = "\(.*\)"/\1/p' | head -1)"
sed "s/0x8f8c79eb6671709633fe6a46de93c0fedc9c1b8a6527a18d3983879542635c9f/$GENESIS_TX0/" "$TEMPLATE_FILE" >"$CONFIG_FILE"

ckb-cli deploy gen-txs --from-address ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqwgx292hnvmn68xf779vmzrshpmm6epn4c0cgwga \
--fee-rate 1000 --deployment-config "$CONFIG_FILE" --info-file "$INFO_FILE" --migration-dir "$MIGRATION_DIR"

SIGNATURES="$(ckb-cli deploy sign-txs --info-file "$INFO_FILE" --privkey-path specs/miner.key --output-format json | sed -n 's/: \("[^"]*"\)/: [\1]/p')"
echo "$SIGNATURES"
CELLS_SIGNATURES="$(echo "$SIGNATURES" | head -1)"
DEP_GROUPS_SIGNATURES="$(echo "$SIGNATURES" | tail -1)"

sed -i.bak \
-e 's/"cell_tx_signatures": {}/"cell_tx_signatures": {'"$CELLS_SIGNATURES"'}/' \
"$INFO_FILE"
sed -i.bak \
-e 's/"dep_group_tx_signatures": {}/"dep_group_tx_signatures": {'"$DEP_GROUPS_SIGNATURES"'}/' \
"$INFO_FILE"
rm -f "${INFO_FILE}.bak"

ckb-cli deploy apply-txs --info-file "$INFO_FILE" --migration-dir "$MIGRATION_DIR"
}

deploy joyid
bin/generate-blocks.sh 4
sleep 1

# try twice in case the indexer has not updated yet
deploy ckb_auth || deploy ckb_auth
bin/generate-blocks.sh 4

bin/use-env.sh >.env
3 changes: 3 additions & 0 deletions bin/download-joyid-cells.sh → bin/download-contracts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@ download joyid_dep3 0x95ecf9b41701b45d431657a67bbfa3f07ef7ceb53bf87097f3674e1a4a
# secp256k1 data
# download joyid_dep4 0x8f8c79eb6671709633fe6a46de93c0fedc9c1b8a6527a18d3983879542635c9f 3
download joyid_dep5 0x8b3255491f3c4dcc1cfca33d5c6bcaec5409efe4bbda243900f9580c47e0242e 1

download ckb_auth 0xd4f72f0504373ff8effadf44f92c46a0062774fb585ebcacc24eb47b98e2d66a 0
download unisat_lock 0xe842b43df31c92d448fa345d60a6df3e03aaab19ef88921654bf95c673a26872 0
17 changes: 15 additions & 2 deletions bin/use-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,25 @@ case "${1:-}" in
;;
esac

JOYID_INFO_FILE="$(ls migrations/joyid/*.json | grep -v deployment | head -n 1)"
CKB_AUTH_INFO_FILE="$(ls migrations/ckb_auth/*.json | grep -v deployment | head -n 1)"

sed -n \
-e 's/,$//' \
-e 's/^ *"type_id": /NEXT_PUBLIC_JOYID_CODE_HASH=/p' \
"$@" | head -1
"$JOYID_INFO_FILE" | head -1

sed -n \
-e 's/,$//' \
-e 's/^ *"tx_hash": /NEXT_PUBLIC_JOYID_TX_HASH=/p' \
"$@" | tail -1
"$JOYID_INFO_FILE" | tail -1

sed -n \
-e 's/,$//' \
-e 's/^ *"type_id": "/NEXT_PUBLIC_UNISAT_CODE_HASH="/p' \
"$CKB_AUTH_INFO_FILE" | head -1

sed -n \
-e 's/,$//' \
-e 's/^ *"tx_hash": /NEXT_PUBLIC_AUTH_TX_HASH=/p' \
"$CKB_AUTH_INFO_FILE" | tail -1
6 changes: 3 additions & 3 deletions docs/dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ bin/generate-blocks.sh 20

## Deploy Contracts to the Local Dev Chain

Download JoyID cells
Download contract cells

```bash
bin/download-joyid-cells.sh
bin/download-contracts.sh
```

Deploy using ckb-cli by running the following script
Expand All @@ -51,7 +51,7 @@ Start the local development server.
pnpm dev
```

Connect JoyID and copy the address displayed at the top of the page.
Connect a wallet and copy the CKB address displayed at the top of the page.

Transfer some CKB tokens from the miner account to the copied address. Replace `ckbt1qz...` with the real address in the following command.

Expand Down
19 changes: 19 additions & 0 deletions migrations/templates/ckb_auth.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[[cells]]
name = "ckb_auth"
enable_type_id = false
location = { file = "build/release/ckb_auth" }
[[cells]]
name = "unisat_lock"
enable_type_id = true
location = { file = "build/release/unisat_lock" }

# Dep group cells
[[dep_groups]]
name = "ckb_auth_locks"
cells = ["ckb_auth", "unisat_lock"]

# The lock script set to output cells
[lock]
code_hash = "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8"
args = "0xc8328aabcd9b9e8e64fbc566c4385c3bdeb219d7"
hash_type = "type"
File renamed without changes.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
"@joyid/ckb": "^0.0.2",
"@tailwindcss/typography": "^0.5.10",
"base64-js": "^1.5.1",
"bech32": "^2.0.0",
"bs58": "^5.0.0",
"flowbite": "^2.2.0",
"flowbite-react": "^0.7.2",
"moment": "^2.30.0",
Expand Down
16 changes: 16 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/actions/send-tx.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default async function sendTx(tx, config) {
try {
const txState = await sendTxInner(tx, txHash, config);
if (txState.txStatus.status === "committed") {
revalidatePath("/accounts/[address]", "layout");
revalidatePath("/u/[wallet]/[connection]", "layout");
}
return txState;
} catch (err) {
Expand Down
15 changes: 0 additions & 15 deletions src/app/accounts/[address]/account-header.js

This file was deleted.

21 changes: 0 additions & 21 deletions src/app/accounts/[address]/claim/[txHash]/[index]/page.js

This file was deleted.

14 changes: 0 additions & 14 deletions src/app/accounts/[address]/deposit/page.js

This file was deleted.

21 changes: 0 additions & 21 deletions src/app/accounts/[address]/page.js

This file was deleted.

14 changes: 0 additions & 14 deletions src/app/accounts/[address]/transfer/page.js

This file was deleted.

Loading

0 comments on commit a065d9a

Please sign in to comment.