Skip to content

Commit

Permalink
feat: improve clarity abi types
Browse files Browse the repository at this point in the history
  • Loading branch information
hstove committed Mar 10, 2023
1 parent 09e87d4 commit 868684c
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 18 deletions.
5 changes: 5 additions & 0 deletions .changeset/thin-hounds-bake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"clarigen-deno": patch
---

Fixes issues with ABI types when using conditionals to infer Clarity type
9 changes: 3 additions & 6 deletions artifacts/clarigen/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export type ClarityAbiTypeResponse = {
};
export type ClarityAbiTypeOptional = { optional: ClarityAbiType };
export type ClarityAbiTypeTuple = {
tuple: { name: string; type: ClarityAbiType }[];
tuple: readonly { name: string; type: ClarityAbiType }[];
};
export type ClarityAbiTypeList = {
list: { type: ClarityAbiType; length: number };
Expand Down Expand Up @@ -97,7 +97,7 @@ export interface ClarityAbi {
variables: ClarityAbiVariable[];
maps: ClarityAbiMap[];
fungible_tokens: ClarityAbiTypeFungibleToken[];
non_fungible_tokens: ClarityAbiTypeNonFungibleToken<unknown>[];
non_fungible_tokens: readonly ClarityAbiTypeNonFungibleToken<unknown>[];
}

export type TypedAbi = Readonly<{
Expand Down Expand Up @@ -378,10 +378,7 @@ export const contracts = {
{ 'name': 'namespace', 'type': { 'buffer': { 'length': 20 } } },
],
},
} as ClarityAbiTypeNonFungibleToken<{
'name': Uint8Array;
'namespace': Uint8Array;
}>,
},
],
'fungible_tokens': [],
'epoch': 'Epoch20',
Expand Down
5 changes: 1 addition & 4 deletions src/cli/files/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ export function generateContractMeta(
const variableLines = encodeVariables(variables);

const nftLines = non_fungible_tokens.map((nft) => {
const keyType = jsTypeFromAbiType(nft.type);
return `${
JSON.stringify(nft)
} as ClarityAbiTypeNonFungibleToken<${keyType}>`;
return JSON.stringify(nft);
});

return `{
Expand Down
4 changes: 2 additions & 2 deletions src/cli/type-stub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export type ClarityAbiTypeResponse = {
};
export type ClarityAbiTypeOptional = { optional: ClarityAbiType };
export type ClarityAbiTypeTuple = {
tuple: { name: string; type: ClarityAbiType }[];
tuple: readonly { name: string; type: ClarityAbiType }[];
};
export type ClarityAbiTypeList = {
list: { type: ClarityAbiType; length: number };
Expand Down Expand Up @@ -98,7 +98,7 @@ export interface ClarityAbi {
variables: ClarityAbiVariable[];
maps: ClarityAbiMap[];
fungible_tokens: ClarityAbiTypeFungibleToken[];
non_fungible_tokens: ClarityAbiTypeNonFungibleToken<unknown>[];
non_fungible_tokens: readonly ClarityAbiTypeNonFungibleToken<unknown>[];
}
export type TypedAbi = Readonly<{
Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export type ClarityAbiTypeResponse = {
};
export type ClarityAbiTypeOptional = { optional: ClarityAbiType };
export type ClarityAbiTypeTuple = {
tuple: { name: string; type: ClarityAbiType }[];
tuple: readonly { name: string; type: ClarityAbiType }[];
};
export type ClarityAbiTypeList = {
list: { type: ClarityAbiType; length: number };
Expand Down Expand Up @@ -97,7 +97,7 @@ export interface ClarityAbi {
variables: ClarityAbiVariable[];
maps: ClarityAbiMap[];
fungible_tokens: ClarityAbiTypeFungibleToken[];
non_fungible_tokens: ClarityAbiTypeNonFungibleToken<unknown>[];
non_fungible_tokens: readonly ClarityAbiTypeNonFungibleToken<unknown>[];
}

export type TypedAbi = Readonly<{
Expand Down
7 changes: 3 additions & 4 deletions tests/helper.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@

// This file is automatically generated by Clarigen.
// Don't make changes to this file, or they'll
// be overwritten.
import { factory } from "https://deno.land/x/clarigen@v0.5.0/mod.ts";
import { simnet } from "./../artifacts/clarigen/index.ts";
import { factory } from '../src/index.ts';
import { simnet } from './../artifacts/clarigen/index.ts';

export const { test, contracts, accounts } = factory(simnet);

export const {
counter,
ftTrait,
tester
tester,
} = contracts;

0 comments on commit 868684c

Please sign in to comment.