Skip to content

Commit

Permalink
refactor!: Update Cl.serialize to return string instead of bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
janniks committed Oct 25, 2024
1 parent 9b9cd4f commit 5155caf
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
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

0 comments on commit 5155caf

Please sign in to comment.