Skip to content

Commit

Permalink
feat: abiwan integration for TS validation based on ABI
Browse files Browse the repository at this point in the history
  • Loading branch information
haroune-mohammedi committed Jul 24, 2023
1 parent 384db9f commit 2ed2b67
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 1 deletion.
133 changes: 133 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
},
"dependencies": {
"@noble/curves": "~1.0.0",
"abi-wan-kanabi": "github:haroune-mohammedi/abi-wan-kanabi#rebase-contract-functions",
"isomorphic-fetch": "^3.0.0",
"lossless-json": "^2.0.8",
"micro-starknet": "~0.2.1",
Expand Down
8 changes: 7 additions & 1 deletion src/contract/default.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Abi as AbiKanabi } from 'abi-wan-kanabi';

import { AccountInterface } from '../account';
import { ProviderInterface, defaultProvider } from '../provider';
import {
Expand All @@ -22,7 +24,7 @@ import {
import assert from '../utils/assert';
import { CallData, cairo } from '../utils/calldata';
import { createAbiParser } from '../utils/calldata/parser';
import { ContractInterface } from './interface';
import { ContractInterface, TypedContract } from './interface';

export const splitArgsAndOptions = (args: ArgsOrCalldataWithOptions) => {
const options = [
Expand Down Expand Up @@ -326,4 +328,8 @@ export class Contract implements ContractInterface {
public isCairo1(): boolean {
return cairo.isCairo1Abi(this.abi);
}

public typed<TAbi extends AbiKanabi>(tAbi: TAbi): TypedContract<TAbi> {
return this as TypedContract<typeof tAbi>;
}
}
6 changes: 6 additions & 0 deletions src/contract/interface.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Abi as AbiKanabi, TypedContract as AbiWanTypedContract } from 'abi-wan-kanabi';

import { AccountInterface } from '../account';
import { ProviderInterface } from '../provider';
import {
Expand All @@ -14,6 +16,8 @@ import {
Result,
} from '../types';

export type TypedContract<TAbi extends AbiKanabi> = AbiWanTypedContract<TAbi> & ContractInterface;

export abstract class ContractInterface {
public abstract abi: Abi;

Expand Down Expand Up @@ -117,4 +121,6 @@ export abstract class ContractInterface {
* ```
*/
public abstract isCairo1(): boolean;

public abstract typed<TAbi extends AbiKanabi>(tAbi: TAbi): TypedContract<TAbi>;
}

0 comments on commit 2ed2b67

Please sign in to comment.