Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

📝 Use name CoBuild and link to the overview doc #47

Merged
merged 1 commit into from
Feb 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# CKB DAO Cobuild PoC
# CKB DAO CoBuild PoC

- [Contributing Guidelines](docs/CONTRIBUTING.md)
- [Guidelines for PoC Reviewers](docs/poc-review-guide.md)

## Disclaimer

- This is a PoC demo showcasing the management of DAO deposits through the use of a new transaction building protocol named **Cobuild**.
- This is a PoC demo showcasing the management of DAO deposits through the use of a new transaction building protocol named [CoBuild](https://talk.nervos.org/t/ckb-transaction-cobuild-protocol-overview/7702).
- There's a [preview](https://ckb-dao-cobuild-poc.vercel.app/) deployed to the testnet, have fun.

## Background

This PoC shows how Cobuild works with type scripts and lock scripts that only support WitnessArgs layout.
This PoC shows how CoBuild works with type scripts and lock scripts that only support WitnessArgs layout.

- [x] It defines the [Cobuild action data schema for DAO](schemas/dao.mol).
- [x] It adopts the transaction building workflow based on the Cobuild data structure [BuildingPacket](src/lib/cobuild/types.js).
- [x] It defines the [CoBuild action data schema for DAO](schemas/dao.mol).
- [x] It adopts the transaction building workflow based on the CoBuild data structure [BuildingPacket](src/lib/cobuild/types.js).
- [x] It uses WitnessArgs layout for lock scripts and the DAO type script.
- [x] It shows how to present the transaction before users sign it.
- [ ] By default, the PoC discards the Cobuild message after building the transaction. However, it provides an opt-in feature to pack the Cobuild message and the example contract to verify the message.
- [ ] By default, the PoC discards the CoBuild message after building the transaction. However, it provides an opt-in feature to pack the CoBuild message and the example contract to verify the message.

## Getting Started

Expand Down
10 changes: 5 additions & 5 deletions docs/poc-review-guide.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# PoC Review Guide

Cobuild is still under active development. Please refer to [ckb-transaction-cobuild-poc](https://github.com/cryptape/ckb-transaction-cobuild-poc) for contract supports.
CoBuild is still under active development. Please refer to the [protocol overview](https://talk.nervos.org/t/ckb-transaction-cobuild-protocol-overview/7702) and [ckb-transaction-cobuild-poc](https://github.com/cryptape/ckb-transaction-cobuild-poc) for more contract demos.

The core principle of the PoC is how the CKB system DAO would look like if it supports Cobuild.
The core principle of the PoC is how the CKB system DAO would look like if it supports CoBuild.

The general workflow to build transactions in Cobuild:
The general workflow to build transactions in CoBuild:

1. Create an empty **BuildingPacket** structure to initiate building a new transaction.
2. (Type Script Phase) Users perform some operations often by submitting forms. For each operation:
Expand All @@ -13,7 +13,7 @@ The general workflow to build transactions in Cobuild:
3. (Fee Estimation Phase) Estimate witnesses size for fee calculation.
- a. Ensure all message **Action**s have been completed.
- b. (Optional) Remove message **Action**s that are experimental. For example, before DAO updates its contract, the DAO operations as message **Action**s are not validated. It's better to remove it to avoid inconsistent data.
- c. For each lock script group: choose Cobuild or WitnessArgs layout and set the witness to enough size for fee estimation.
- c. For each lock script group: choose CoBuild or WitnessArgs layout and set the witness to enough size for fee estimation.
- d. If there're witnesses are using `SighashAll` or `SighashAllOnly`. Set the first of such witnesses to `SighashAll` and put message **Action**s into it, and the remaining to `SighashAllOnly`.
- e. If there's no such witnesses, and there's at least one message **Action**, add a `SighashAll` witness at a position beyond the number of inputs and save message **Action**s in it.
- f. Estimate tx size and pay fee. If there are new cells added, ensure the witness size is correct for fee estimation.
Expand All @@ -30,7 +30,7 @@ The core is the step 2. There will be a framework to handle 1, 3, 4, 5, I just b

This guide is based on the version [v0.0.1](https://github.com/cryptape/ckb-dao-cobuild-poc/tree/v0.0.1).

1. [`src/lib/cobuild/types.js`](../src/lib/cobuild/types.js): Cobuild data structures definition.
1. [`src/lib/cobuild/types.js`](../src/lib/cobuild/types.js): CoBuild data structures definition.
2. [`src/lib/papps/dao`](../src/lib/papps/dao): DAO papp
- a.
- [`src/lib/papps/dao/schema.js`](../src/lib/papps/dao/schema.js): Action.data schema
Expand Down
8 changes: 7 additions & 1 deletion src/app/disclaimer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ export default function Disclaimer({ config: { ckbChain } }) {
<li>
This is a PoC demo showcasing the management of DAO deposits through
the use of a new transaction building protocol named{" "}
<strong>Cobuild</strong>.
<a
target="_blank"
href="https://talk.nervos.org/t/ckb-transaction-cobuild-protocol-overview/7702"
>
CoBuild
</a>
.
</li>
<li>This demo runs in the CKB chain {ckbChain}.</li>
</ul>
Expand Down
2 changes: 1 addition & 1 deletion src/lib/cobuild/general-lock-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export function applyLockAction(buildingPacket, lockAction, seal) {
}

export function chooseWitnessStore(buildingPacket, inputIndices) {
// Use Cobuild when all witnesses are empty
// Use CoBuild when all witnesses are empty
for (const i of inputIndices) {
const witness = buildingPacket.value.payload.witnesses[i];
if (witness !== null && witness !== undefined && witness !== "0x") {
Expand Down
6 changes: 3 additions & 3 deletions src/lib/cobuild/lock-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ const { computeScriptHash } = lumosBaseUtils;

// Generate lockActions.
//
// Do not set any witness in payload to use the Cobuild layout.
// Do not set any witness in payload to use the CoBuild layout.
export function prepareLockActions(buildingPacket, ckbChainConfig) {
// Workaround to pack Cobuild message as the extra witness.
// Workaround to pack CoBuild message as the extra witness.
//
// Before the next action, there's no actual witness set yet. So `finalizeWitnesses` will assume there's no SighashAll witness in the tx and will pack the message as the extra witness. This assumption is currect because this PoC uses WitnessArgs layout for lock actions and DAO type script.
buildingPacket = finalizeWitnesses(buildingPacket, ckbChainConfig);
Expand Down Expand Up @@ -75,7 +75,7 @@ export function finalizeWitnesses(buildingPacket, ckbChainConfig) {
}
}

// if there's a verifier cell, pack the Cobuild message into witness
// if there's a verifier cell, pack the CoBuild message into witness
if (!hasSighashAll && hasVerifierCell(buildingPacket, ckbChainConfig)) {
for (
let i = witnesses.length;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/lumos-adapter/init-lumos-common-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function buildLockInfo(ckbChainConfig, scriptInfo, extraScripts) {
return {
codeHash: scriptInfo.CODE_HASH,
hashType: scriptInfo.HASH_TYPE,
// we'll use cobuild to sign transactions, so don't need to implement functions for signing in lumos.
// we'll use CoBuild to sign transactions, so don't need to implement functions for signing in lumos.
lockScriptInfo: {
CellCollector: class {
constructor(fromInfo, cellProvider, { config, queryOptions }) {
Expand Down
Loading