-
Notifications
You must be signed in to change notification settings - Fork 23
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
Add Molecule related features #33
Comments
@homura will start this issue next week |
I need to postpone addressing this issue because of higher-priority tasks. I'll likely start it next week |
Let me break down the codec feature request. In CCC, the code is organized using the OO pattern with many classes such as The enhancer should take any
type Constructor<
Instance,
Arguments extends unknown[] = any[]
> = new (...args: Arguments) => Instance;
type ToBytes<Instance> = Instance & { toBytes(): Bytes }
type FromBytes<Class, Instance> = Class & { fromBytes(bytes: Bytes): Instance } Therefore, a type Codec<Class> =
// take any class
Class extends Constructor<infer OriginInstance>
? // add a static `fromBytes` method and a new constructor to create the new instance
FromBytes<Class, ToBytes<OriginInstance>> & Constructor<ToBytes<OriginInstance>>
: // ignore for non-class
never; To handle the To handle the declare function enhance<T extends Constructor<any>>(
class_: T,
fromBytes: (bytes: Bytes) => ConstructorParameters<T>,
toBytes: (instance: InstanceType<T>) => Bytes,
): Codec<T>; TBD: the |
Currently, using the decorator does not allow for creating a well-typed class. Perhaps CCC should consider using a higher-order approach to achieve this feature. For example, consider the following demonstration: class InternalScript {
// ...
}
// Enhance an existing class like this
const Script = enhance(InternalScript)
// Or define a class like this
const Script = enhance(class Script {
// ...
}) @Hanssen0 What do you think about this? |
I see no problem. The mixin approach gives us all we want. |
We can propose the draft PR first so the progress would be more clear @homura |
I have submitted PR #81 to simplify the creation of a CCC class using a helper function. It works with molecule-es and Lumos as a transition program. To make it work smoother with CCC, we should consider the following steps:
Once these changes are implemented, creating CCC classes would be similar to the case. @Hanssen0 Do you think these changes meet the requirements? |
Yes. This is a good transition plan. |
Background
In the CKB ecosystem, molecule is widely used. We initially have moleculec-es to generate molecule codecs for JS, but it's written in Golang, so it can not run in a JS runtime.
Later, we have related features in the Lumos, see @ckb-lumos/codec and @ckb-lumos/molecule. These two offer compile-time, runtime molecule parsing, and molecule schema defining in JS.
Nowadays, CCC plans to be a successor of Lumos to provide a better developer experience. So, we also want to add the molecule-related feature in CCC.
Plan
@ckb-ccc/core
. Similar to@ckb-lumos/codec
but with CCC types.@ckb-ccc/molecule
based on codecs. Similar to@ckb-lumos/molecule
.This helps developers to use Molecule.
The text was updated successfully, but these errors were encountered: