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

refactor!: Update Cl.serialize to return string instead of bytes #1753

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
4 changes: 2 additions & 2 deletions packages/cli/tests/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ describe('decode_cv', () => {

test('Should decode from hex to repr', async () => {
const list = Cl.list([1, 2, 3].map(Cl.int));
const serialized = bytesToHex(Cl.serialize(list));
const serialized = Cl.serialize(list);
const result = await decodeCV(mainnetNetwork, [serialized, 'repr']);
expect(result).toEqual('(list 1 2 3)');
});

test('Should decode from hex to pretty print', async () => {
const list = Cl.list([1, 2, 3].map(Cl.int));
const serialized = bytesToHex(Cl.serialize(list));
const serialized = Cl.serialize(list);
const result = await decodeCV(mainnetNetwork, [serialized, 'pretty']);
expect(result).toEqual('(list\n 1\n 2\n 3\n)');
});
Expand Down
6 changes: 3 additions & 3 deletions packages/transactions/src/cl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
noneCV,
responseErrorCV,
responseOkCV,
serializeCVBytes,
serializeCV,
someCV,
standardPrincipalCV,
stringAsciiCV,
Expand Down Expand Up @@ -270,15 +270,15 @@ export const tuple = tupleCV;
/**
* `Cl.serialize` — Serializes a Clarity JS object to the equivalent hex-encoded representation
*
* Alias for {@link serializeCVBytes}
* Alias for {@link serializeCV}
* @example
* ```
* import { Cl } from '@stacks/transactions';
* Cl.serialize(Cl.uint(100));
* ```
* @see {@link deserialize}
*/
export const serialize = serializeCVBytes;
export const serialize = serializeCV;
/**
* `Cl.deserialize` — Deserializes a hex string to the equivalent Clarity JS object
*
Expand Down
1 change: 1 addition & 0 deletions packages/transactions/src/clarity/serialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ function serializeStringUtf8CV(cv: StringUtf8CV) {
export function serializeCV(value: ClarityValue): string {
return bytesToHex(serializeCVBytes(value));
}

/** @ignore */
export function serializeCVBytes(value: ClarityValue): Uint8Array {
switch (value.type) {
Expand Down
Loading