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

feat: rewrite spore-sdk in ccc #43

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

ashuralyk
Copy link

@ashuralyk ashuralyk commented Sep 10, 2024

Description

  1. rewrite spore-sdk in ccc, only contain features for spore and cluster
  2. add type-burn and lock-proxy as known scripts
  3. add DOB related tools
  4. add examples

Copy link

changeset-bot bot commented Sep 10, 2024

🦋 Changeset detected

Latest commit: 4afc10a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 14 packages
Name Type
@ckb-ccc/spore Minor
@ckb-ccc/core Minor
@ckb-ccc/ccc Patch
@ckb-ccc/eip6963 Patch
@ckb-ccc/joy-id Patch
@ckb-ccc/lumos-patches Patch
@ckb-ccc/nip07 Patch
@ckb-ccc/okx Patch
@ckb-ccc/rei Patch
@ckb-ccc/uni-sat Patch
@ckb-ccc/utxo-global Patch
ckb-ccc Patch
@ckb-ccc/connector Patch
@ckb-ccc/connector-react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@ashuralyk ashuralyk changed the title feat: rewrite spore-sdk in ccc (no test) feat: rewrite spore-sdk in ccc Sep 12, 2024
signer: ccc.Signer,
tx: ccc.TransactionLike,
cobuildActions: UnpackResult<typeof ActionVec>,
feeRate: number = 1000,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The feeRate should not be set by default. Developers / Users should set this dynamically to avoid on-chain attackers.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I'll leave comment to tell users 1000 is the minimum fee rate

import { ccc } from "@ckb-ccc/core";
import { bytes, UnpackResult } from "@ckb-lumos/codec";
import { Action, ActionVec, SporeAction, WitnessLayout } from "./codec";
import { buildProtoclScript, SporeScriptInfo } from "./predefined";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For commonjs compatibility, please add .js extension at the end of files path.

cobuildActions: UnpackResult<typeof ActionVec>,
feeRate: number = 1000,
): Promise<ccc.Transaction> {
if (feeRate < 1000) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check should be done by the node / UI.


// change cell
let txSkeleton = ccc.Transaction.from(tx);
txSkeleton.addOutput({ lock });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not necessary to add a change cell here. we can use completeFeeBy.

sporeOutput: ccc.CellOutputLike,
sporeData: ccc.BytesLike,
): UnpackResult<typeof Action> {
const sporeType = ccc.Script.from(sporeOutput.type!);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check if the type is null here instead of ignoring it. (And also below)

...liveCell,
}),
);
txSkeleton.witnesses.push("0x");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to use Signer.prepareTransaction after collecting all inputs? Extra witnesses don't look necessary.

tx: ccc.TransactionLike,
outputIndex: number,
): ccc.Hex {
const firstInput = tx.inputs ? tx.inputs[0] : void 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tx.inputs always exist.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inputs is nullable in TransactionLike

args,
...scriptInfo[procotol],
});
} else {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

else here is not needed because we returned before.

@@ -0,0 +1,17 @@
import { defineConfig } from "vitest/config";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test framework for CCC is jest. CCC is also built for backend developers.

pnpm-lock.yaml Outdated
@@ -1,4 +1,4 @@
lockfileVersion: '9.0'
lockfileVersion: '6.0'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please upgrade your pnpm version.

@ashuralyk
Copy link
Author

@Hanssen0 I've solved all reported issues in comment, new commit has been committed, please repeat your review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants