Skip to content

Commit

Permalink
Merge branch 'release/0.0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
doitian committed Jan 10, 2024
2 parents 70c54aa + 87ffb02 commit 918c390
Show file tree
Hide file tree
Showing 31 changed files with 215 additions and 90 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: "🐛 Bug"
description: File a bug/issue
title: "[BUG] <title>"
title: ":bug: <title>"
labels: ["bug", "triage"]
# projects: []
# assignees: []
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/feature.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: "✨ Feature"
description: Request a feature
title: "[Feature] <title>"
title: ":sparkles: <title>"
labels: ["feature", "triage"]
# projects: []
# assignees: []
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
.env.*
/migrations/dev
/migrations/joyid
/migrations/ckb_auth
/migrations/omnilock

# CKB
/ckb-miner.toml
Expand Down
2 changes: 1 addition & 1 deletion bin/deploy-to-dev-chain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ bin/generate-blocks.sh 4
sleep 1

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

bin/use-env.sh >.env
7 changes: 7 additions & 0 deletions bin/dev-faucet.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

set -e
set -u
[ -n "${DEBUG:-}" ] && set -x || true

ckb-cli wallet transfer --skip-check-to-address --to-address "$1" --capacity 300000 --privkey-path specs/miner.key
3 changes: 1 addition & 2 deletions bin/download-contracts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,4 @@ download joyid_dep3 0x95ecf9b41701b45d431657a67bbfa3f07ef7ceb53bf87097f3674e1a4a
# download joyid_dep4 0x8f8c79eb6671709633fe6a46de93c0fedc9c1b8a6527a18d3983879542635c9f 3
download joyid_dep5 0x8b3255491f3c4dcc1cfca33d5c6bcaec5409efe4bbda243900f9580c47e0242e 1

download ckb_auth 0xd4f72f0504373ff8effadf44f92c46a0062774fb585ebcacc24eb47b98e2d66a 0
download unisat_lock 0xe842b43df31c92d448fa345d60a6df3e03aaab19ef88921654bf95c673a26872 0
download omnilock 0xff234bf2fb0ad2ab5b356ceda317d3dee3efb2c55b9427ef55d9dcbf6eecbf9f 0
1 change: 1 addition & 0 deletions bin/generate-blocks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ CKB_RPC_URL="${CKB_RPC_URL:-http://127.0.0.1:8114}"

function generate_one() {
curl --request POST \
-H "Content-Type: application/json" \
--url "$CKB_RPC_URL" \
--data '{
"id": 42,
Expand Down
1 change: 1 addition & 0 deletions bin/generate-epochs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ CKB_RPC_URL="${CKB_RPC_URL:-http://127.0.0.1:8114}"
function generate() {
local n="$(printf '%x' "${1:-1}")"
curl --request POST \
-H "Content-Type: application/json" \
--url http://127.0.0.1:8114/ \
--data '{
"id": 42,
Expand Down
1 change: 1 addition & 0 deletions bin/run-dev-miner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ set -u

function has_tx() {
curl --request POST \
-H "Content-Type: application/json" \
--silent \
--url http://127.0.0.1:8114/ \
--data '{
Expand Down
10 changes: 5 additions & 5 deletions bin/use-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ 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)"
OMNILOCK_INFO_FILE="$(ls migrations/omnilock/*.json | grep -v deployment | head -n 1)"

sed -n \
-e 's/,$//' \
Expand All @@ -38,10 +38,10 @@ sed -n \

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

sed -n \
-e 's/,$//' \
-e 's/^ *"tx_hash": /NEXT_PUBLIC_AUTH_TX_HASH=/p' \
"$CKB_AUTH_INFO_FILE" | tail -1
-e 's/^ *"tx_hash": /NEXT_PUBLIC_OMNILOCK_TX_HASH=/p' \
"$OMNILOCK_INFO_FILE" | tail -1
2 changes: 1 addition & 1 deletion docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ We love your input! We want to make contributing to this project as easy and tra

We use github to host code, to track issues and feature requests, as well as accept pull requests.

## Pull Requests and [Changesets](https://github.com/changesets/changesets)
## Pull Requests

Pull requests are the best way to propose changes to the codebase. We actively welcome your pull requests:

Expand Down
2 changes: 1 addition & 1 deletion docs/dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ 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.

```bash
ckb-cli wallet transfer --skip-check-to-address --to-address ckt1qz... --capacity 300000 --privkey-path specs/miner.key
bin/dev-faucet.sh ckt1qz...
```

Mine some blocks to commit the transfer transaction.
Expand Down
19 changes: 0 additions & 19 deletions migrations/templates/ckb_auth.toml

This file was deleted.

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

# The lock script set to output cells
[lock]
code_hash = "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8"
args = "0xc8328aabcd9b9e8e64fbc566c4385c3bdeb219d7"
hash_type = "type"
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ckb-dao-cobuild-poc",
"type": "module",
"version": "0.0.1",
"version": "0.0.2",
"private": true,
"scripts": {
"dev": "next dev",
Expand Down
2 changes: 1 addition & 1 deletion src/app/connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export default function Connector() {
connections = await walletSelector.connect(wallet);
} catch (err) {
console.error(err.stack);
reset(err.toString());
reset(err.message ?? err.toString());
return;
}

Expand Down
9 changes: 4 additions & 5 deletions src/app/u/[wallet]/[connection]/account-header.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import * as walletSelector from "@/lib/wallet/selector";
import SignOut from "./sign-out";

export default function AccountHeader({
address,
wallet,
connection,
config: { ckbChain },
config: { ckbChain, ckbChainConfig },
}) {
const walletName = walletSelector.walletName(wallet);

return (
<header>
<SignOut
walletName={walletName}
wallet={wallet}
connection={connection !== address ? connection : null}
address={address}
ckbChainConfig={ckbChainConfig}
/>

<p className="break-all">
Expand Down
2 changes: 1 addition & 1 deletion src/app/u/[wallet]/[connection]/sign-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default function SignForm({
);
} catch (err) {
console.error(err.stack);
setError(err.toString());
setError(err.message ?? err.toString());
}
};

Expand Down
65 changes: 60 additions & 5 deletions src/app/u/[wallet]/[connection]/sign-out.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,71 @@
"use client";

import { useRouter } from "next/navigation";
import * as walletSelector from "@/lib/wallet/selector";
import { Dropdown } from "flowbite-react";
import { useRouter } from "next/navigation";
import * as lumosHelpers from "@ckb-lumos/helpers";

export function LockScriptName({ lockScriptName, address, ckbChainConfig }) {
if (
ckbChainConfig.EXPLORER_URL !== null &&
ckbChainConfig.EXPLORER_URL !== undefined
) {
const script = lumosHelpers.addressToScript(address, {
config: ckbChainConfig,
});
const href = `${ckbChainConfig.EXPLORER_URL}/script/${script.codeHash}/${script.hashType}`;
return (
<a
className="inline-flex items-center font-medium text-blue-600 hover:underline"
href={href}
rel="noopener noreferrer"
target="_blank"
>
{lockScriptName}
<svg
class="w-4 h-4 ms-2 rtl:rotate-180"
aria-hidden="true"
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 14 10"
>
<path
stroke="currentColor"
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M1 5h12m0 0L9 1m4 4L9 9"
/>
</svg>
</a>
);
}
return <span>{lockScriptName}</span>;
}

export default function SignOut({
wallet,
connection,
address,
ckbChainConfig,
}) {
const walletName = walletSelector.walletName(wallet);
const lockScriptNameProps = {
lockScriptName: walletSelector.lockScriptName(wallet),
address,
ckbChainConfig,
};

export default function SignOut({ walletName, connection }) {
const router = useRouter();
return (
<aside className="not-prose relative flex justify-end">
<Dropdown inline label={walletName}>
{connection !== null ? (
<Dropdown.Header className="break-all">{connection}</Dropdown.Header>
) : null}
<Dropdown.Header className="break-all flex flex-col gap-2">
{connection !== null ? <p>{connection}</p> : null}
<p>
Via <LockScriptName {...lockScriptNameProps} />
</p>
</Dropdown.Header>
<Dropdown.Item onClick={() => router.push("/")}>Sign Out</Dropdown.Item>
</Dropdown>
</aside>
Expand Down
7 changes: 5 additions & 2 deletions src/lib/cobuild/fee-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,15 @@ function storeWitnessForFeeEstimation(
// Variable length, but 500 is usually enough.
() => bytes.hexify(new Uint8Array(500)),
);
} else if (script.codeHash === ckbChainConfig.SCRIPTS.UNISAT.CODE_HASH) {
} else if (
script.codeHash === ckbChainConfig.SCRIPTS.OMNILOCK_CUSTOM.CODE_HASH
) {
return generalLockActions.storeWitnessForFeeEstimation(
buildingPacket,
scriptHash,
inputIndices,
() => `0x${"0".repeat(65 * 2)}`,
// 85 = 65 signature in OmnilockWitnessLock
() => `0x${"0".repeat(85 * 2)}`,
);
}

Expand Down
7 changes: 5 additions & 2 deletions src/lib/cobuild/lock-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ function dispatchLockActions(
},
() => `0x${"0".repeat(129 * 2)}`,
);
} else if (script.codeHash === ckbChainConfig.SCRIPTS.UNISAT.CODE_HASH) {
} else if (
script.codeHash === ckbChainConfig.SCRIPTS.OMNILOCK_CUSTOM.CODE_HASH
) {
return generalLockActions.prepareLockActionWithWitnessStore(
buildingPacket,
scriptHash,
Expand All @@ -99,7 +101,8 @@ function dispatchLockActions(
inputIndices,
},
},
() => `0x${"0".repeat(65 * 2)}`,
// 85 = 65 signature in OmnilockWitnessLock
() => `0x${"0".repeat(85 * 2)}`,
);
}

Expand Down
10 changes: 10 additions & 0 deletions src/lib/cobuild/react/building-packet-review.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,16 @@ export function TxSection({

return (
<dl className="divide-y divide-gray-100">
{process.env.DEBUG !== undefined ? (
<div className="x-4 py-3 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-0">
<dt className="leading-6 text-gray-900">Hash</dt>
<dd className="text-gray-700 sm:col-span-2 sm:mt-0 break-all">
<pre className="font-mono p-4 bg-slate-800 text-slate-300 rounded overflow-scroll">
{JSON.stringify(buildingPacket, null, 2)}
</pre>
</dd>
</div>
) : null}
<div className="x-4 py-3 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-0">
<dt className="leading-6 text-gray-900">Hash</dt>
<dd className="text-gray-700 sm:col-span-2 sm:mt-0 break-all">
Expand Down
30 changes: 12 additions & 18 deletions src/lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const CKB_CHAINS_CONFIGS = {
EXPLORER_URL: "https://pudge.explorer.nervos.org",
SCRIPTS: {
...predefined.AGGRON4.SCRIPTS,

JOYID: {
CODE_HASH:
"0xd23761b364210735c19c60561d213fb3beae2fd6172743719eff6920e020baac",
Expand All @@ -15,18 +16,14 @@ const CKB_CHAINS_CONFIGS = {
INDEX: "0x0",
DEP_TYPE: "depGroup",
},
AUTH: {
TX_HASH:
"0xd4f72f0504373ff8effadf44f92c46a0062774fb585ebcacc24eb47b98e2d66a",
INDEX: "0x0",
DEP_TYPE: "code",
},
UNISAT: {
// Disable OMNILOCK bundled in lumos
OMNILOCK: undefined,
OMNILOCK_CUSTOM: {
CODE_HASH:
"0xd7aac16927b2d572b3803c1f68e49d082d3acc2af2614c9be752ff9cec5dc3ea",
HASH_TYPE: "data1",
"0xf329effd1c475a2978453c8600e1eaf0bc2087ee093c3ee64cc96ec6847752cb",
HASH_TYPE: "type",
TX_HASH:
"0xe842b43df31c92d448fa345d60a6df3e03aaab19ef88921654bf95c673a26872",
"0xff234bf2fb0ad2ab5b356ceda317d3dee3efb2c55b9427ef55d9dcbf6eecbf9f",
INDEX: "0x0",
DEP_TYPE: "code",
},
Expand Down Expand Up @@ -62,13 +59,11 @@ function buildCkbChainConfig(ckbChain) {
TX_HASH: presence(process.env.NEXT_PUBLIC_JOYID_TX_HASH),
},
);
const UNISAT = assign(
{ ...template.SCRIPTS.JOYID },
const OMNILOCK_CUSTOM = assign(
{ ...template.SCRIPTS.OMNILOCK_CUSTOM },
{
CODE_HASH: presence(process.env.NEXT_PUBLIC_UNISAT_CODE_HASH),
HASH_TYPE: "type",
TX_HASH: presence(process.env.NEXT_PUBLIC_AUTH_TX_HASH),
DEP_TYPE: "depGroup",
CODE_HASH: presence(process.env.NEXT_PUBLIC_OMNILOCK_CODE_HASH),
TX_HASH: presence(process.env.NEXT_PUBLIC_OMNILOCK_TX_HASH),
},
);

Expand All @@ -84,8 +79,7 @@ function buildCkbChainConfig(ckbChain) {
EXPLORER_URL: null,
SCRIPTS: {
JOYID,
UNISAT,
AUTH: template.SCRIPTS.AUTH,
OMNILOCK_CUSTOM,
DAO: {
...template.SCRIPTS.DAO,
TX_HASH: tx0,
Expand Down
Loading

0 comments on commit 918c390

Please sign in to comment.