CoBuild is still under active development. Please refer to the protocol overview and 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 general workflow to build transactions in CoBuild:
- Create an empty BuildingPacket structure to initiate building a new transaction.
- (Type Script Phase) Users perform some operations often by submitting forms. For each operation:
- a. Find the corresponding papp (name for dapp in Cobuid) and create an Action.
- b. Let the papp process the Action. Update transaction in the BuildingPacket structure and add the Action as a message Action to
BuildingPacketV1.message.actions
- (Fee Estimation Phase) Estimate witnesses size for fee calculation.
- a. Ensure all message Actions have been completed.
- b. (Optional) Remove message Actions that are experimental. For example, before DAO updates its contract, the DAO operations as message Actions 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.
- d. If there're witnesses are using
SighashAll
orSighashAllOnly
. Set the first of such witnesses toSighashAll
and put message Actions into it, and the remaining toSighashAllOnly
. - 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 Actions in it. - f. Estimate tx size and pay fee. If there are new cells added, ensure the witness size is correct for fee estimation.
- (Lock Script Phase) Prepare to finalize the transaction. For each lock script group:
- a. Set witness for digest computation.
- b. Compute the digest for the script group.
- c. Connect wallet to create signatures from digests.
- d. Store the signature into the witness.
- Finish, send the transaction to CKB.
The core is the step 2. There will be a framework to handle 1, 3, 4, 5, I just build a minimal framework to make the PoC work.
This guide is based on the version v0.0.1.
src/lib/cobuild/types.js
: CoBuild data structures definition.src/lib/papps/dao
: DAO papp- a.
src/lib/papps/dao/schema.js
: Action.data schemasrc/lib/papps/dao/action-creators.js
: Functions to create Action.data for DAO.
- b.
src/lib/papps/dao/lumos-callbacks.js
: Build transactions based on DAO message actions.
- a.
src/lib/cobuild/fee-manager.js
: See the functionpayFee
andstoreWitnessForFeeEstimation
src/lib/cobuild/lock-actions.js
: See the functionprepareLockActions
.- a/b.
src/lib/cobuild/general-lock-actions.js
: See the functionprepareLockActionWithWitnessStore
- c.
src/lib/wallet/selector.js
acts as a gateway to connect different wallets and create signatures. - c.
src/lib/cobuild/general-lock-actions.js
: See the functionapplyLockAction
- a/b.
src/app/u/[wallet]/[connection]/submit-building-packet.js
: a simple UI to send tx and query its status.
Remarks:
src/lib/cobuild/react/building-packet-review.js
: UI to review the building packet for signing.