Skip to content

Commit

Permalink
feat: include NFT asset types
Browse files Browse the repository at this point in the history
  • Loading branch information
hstove committed Mar 8, 2023
1 parent 183b227 commit 22a2ea7
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 14 deletions.
7 changes: 7 additions & 0 deletions .changeset/tiny-meals-breathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"clarigen-deno": minor
---

Updates the `ClarityAbiNonFungibleToken` type to include a JS-native type.

Fixed an issue when fetching variables in projects that use requirements.
15 changes: 11 additions & 4 deletions artifacts/clarigen/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,18 @@ export interface ClarityAbiTypeFungibleToken {
name: string;
}

export interface ClarityAbiTypeNonFungibleToken {
export interface ClarityAbiTypeNonFungibleToken<T = unknown> {
name: string;
type: ClarityAbiType;
_t?: T;
}

export interface ClarityAbi {
functions: ClarityAbiFunction[];
variables: ClarityAbiVariable[];
maps: ClarityAbiMap[];
fungible_tokens: ClarityAbiTypeFungibleToken[];
non_fungible_tokens: ClarityAbiTypeNonFungibleToken[];
non_fungible_tokens: ClarityAbiTypeNonFungibleToken<unknown>[];
}

export type TypedAbi = Readonly<{
Expand All @@ -113,7 +114,7 @@ export type TypedAbi = Readonly<{
[key: string]: unknown;
};
fungible_tokens: Readonly<ClarityAbiTypeFungibleToken[]>;
non_fungible_tokens: Readonly<ClarityAbiTypeNonFungibleToken[]>;
non_fungible_tokens: Readonly<ClarityAbiTypeNonFungibleToken<unknown>[]>;
contractName: string;
contractFile?: string;
}>;
Expand Down Expand Up @@ -210,6 +211,7 @@ export const contracts = {
},
'non_fungible_tokens': [],
'fungible_tokens': [],
'epoch': 'Epoch21',
'clarity_version': 'Clarity2',
contractName: 'counter',
},
Expand All @@ -220,6 +222,7 @@ export const contracts = {
constants: {},
'non_fungible_tokens': [],
'fungible_tokens': [],
'epoch': 'Epoch20',
'clarity_version': 'Clarity1',
contractName: 'ft-trait',
},
Expand Down Expand Up @@ -375,9 +378,13 @@ export const contracts = {
{ 'name': 'namespace', 'type': { 'buffer': { 'length': 20 } } },
],
},
} as ClarityAbiTypeNonFungibleToken,
} as ClarityAbiTypeNonFungibleToken<{
'name': Uint8Array;
'namespace': Uint8Array;
}>,
],
'fungible_tokens': [],
'epoch': 'Epoch20',
'clarity_version': 'Clarity1',
contractName: 'tester',
},
Expand Down
5 changes: 4 additions & 1 deletion src/cli/files/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ export function generateContractMeta(
const variableLines = encodeVariables(variables);

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

return `{
Expand Down
12 changes: 11 additions & 1 deletion src/cli/files/variables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,17 @@ export function getVariables(contract: SessionContract, sessionId: number) {
const deployer = 'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM';
const fakeId = `${getContractName(contract.contract_id)}-vars`;

if (contract.contract_interface.variables.length === 0) return '{}';
if (contract.contract_interface.variables.length === 0) {
const deploy = Tx.deployContract(
getContractName(contract.contract_id, false),
contract.source,
deployer,
);
(deploy.deployContract as any).clarityVersion = 2;
(deploy.deployContract as any).epoch = '2.1';
chain.mineBlock([deploy]);
return '{}';
}

let varFn = `{\n`;

Expand Down
7 changes: 4 additions & 3 deletions src/cli/type-stub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,18 @@ export interface ClarityAbiTypeFungibleToken {
name: string;
}
export interface ClarityAbiTypeNonFungibleToken {
export interface ClarityAbiTypeNonFungibleToken<T = unknown> {
name: string;
type: ClarityAbiType;
_t?: T;
}
export interface ClarityAbi {
functions: ClarityAbiFunction[];
variables: ClarityAbiVariable[];
maps: ClarityAbiMap[];
fungible_tokens: ClarityAbiTypeFungibleToken[];
non_fungible_tokens: ClarityAbiTypeNonFungibleToken[];
non_fungible_tokens: ClarityAbiTypeNonFungibleToken<unknown>[];
}
export type TypedAbi = Readonly<{
Expand All @@ -114,7 +115,7 @@ export type TypedAbi = Readonly<{
[key: string]: unknown;
};
fungible_tokens: Readonly<ClarityAbiTypeFungibleToken[]>;
non_fungible_tokens: Readonly<ClarityAbiTypeNonFungibleToken[]>;
non_fungible_tokens: Readonly<ClarityAbiTypeNonFungibleToken<unknown>[]>;
contractName: string;
contractFile?: string;
}>;
Expand Down
7 changes: 4 additions & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,18 @@ export interface ClarityAbiTypeFungibleToken {
name: string;
}

export interface ClarityAbiTypeNonFungibleToken {
export interface ClarityAbiTypeNonFungibleToken<T = unknown> {
name: string;
type: ClarityAbiType;
_t?: T;
}

export interface ClarityAbi {
functions: ClarityAbiFunction[];
variables: ClarityAbiVariable[];
maps: ClarityAbiMap[];
fungible_tokens: ClarityAbiTypeFungibleToken[];
non_fungible_tokens: ClarityAbiTypeNonFungibleToken[];
non_fungible_tokens: ClarityAbiTypeNonFungibleToken<unknown>[];
}

export type TypedAbi = Readonly<{
Expand All @@ -113,7 +114,7 @@ export type TypedAbi = Readonly<{
[key: string]: unknown;
};
fungible_tokens: Readonly<ClarityAbiTypeFungibleToken[]>;
non_fungible_tokens: Readonly<ClarityAbiTypeNonFungibleToken[]>;
non_fungible_tokens: Readonly<ClarityAbiTypeNonFungibleToken<unknown>[]>;
contractName: string;
contractFile?: string;
}>;
Expand Down
2 changes: 1 addition & 1 deletion tests/counter_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ describe('BDD-style testing', () => {
txOk(counter.decrement(1n), alice),
);
assertEquals(receipt.value, 2n);
assertEquals(chain.blockHeight, 3);
assertEquals(chain.blockHeight, 4);
});
});
2 changes: 1 addition & 1 deletion tests/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// 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.4.15/mod.ts";
import { factory } from "https://deno.land/x/clarigen@v0.4.16/mod.ts";
import { simnet } from "./../artifacts/clarigen/index.ts";

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

0 comments on commit 22a2ea7

Please sign in to comment.