abi-wan-kanabi
Advanced tools
Comparing version 1.0.0 to 1.0.1
90
index.js
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const ABI = [ | ||
{ | ||
"members": [ | ||
{ | ||
"name": "low", | ||
"offset": 0, | ||
"type": "felt" | ||
}, | ||
{ | ||
"name": "high", | ||
"offset": 1, | ||
"type": "felt" | ||
} | ||
], | ||
"name": "Uint256", | ||
"size": 2, | ||
"type": "struct" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"name": "par1", | ||
"type": "felt" | ||
}, | ||
{ | ||
"name": "symbol", | ||
"type": "felt" | ||
}, | ||
{ | ||
"name": "decimals", | ||
"type": "felt" | ||
}, | ||
{ | ||
"name": "initial_supply", | ||
"type": "Uint256" | ||
}, | ||
{ | ||
"name": "recipient", | ||
"type": "felt" | ||
} | ||
], | ||
"name": "constructor", | ||
"outputs": [], | ||
"type": "constructor" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "fun1", | ||
"outputs": [ | ||
{ | ||
"name": "par1", | ||
"type": "felt" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [{ "name": "x", "type": "felt" }, { "name": "y", "type": "felt" }], | ||
"name": "fun2", | ||
"outputs": [ | ||
{ | ||
"name": "par1", | ||
"type": "felt" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"name": "account", | ||
"type": "felt" | ||
} | ||
], | ||
"name": "balanceOf", | ||
"outputs": [ | ||
{ | ||
"name": "balance", | ||
"type": "Uint256" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
]; | ||
exports.call = void 0; | ||
function call(abi, f, args) { | ||
throw new Error('todo'); | ||
} | ||
const [balance] = call(ABI, 'balanceOf', [123]); | ||
exports.call = call; |
94
index.ts
import {Abi, ExtractAbiFunctionName, FunctionArgs, FunctionRet} from './kanabi'; | ||
const ABI = [ | ||
{ | ||
"members": [ | ||
{ | ||
"name": "low", | ||
"offset": 0, | ||
"type": "felt" | ||
}, | ||
{ | ||
"name": "high", | ||
"offset": 1, | ||
"type": "felt" | ||
} | ||
], | ||
"name": "Uint256", | ||
"size": 2, | ||
"type": "struct" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"name": "par1", | ||
"type": "felt" | ||
}, | ||
{ | ||
"name": "symbol", | ||
"type": "felt" | ||
}, | ||
{ | ||
"name": "decimals", | ||
"type": "felt" | ||
}, | ||
{ | ||
"name": "initial_supply", | ||
"type": "Uint256" | ||
}, | ||
{ | ||
"name": "recipient", | ||
"type": "felt" | ||
} | ||
], | ||
"name": "constructor", | ||
"outputs": [], | ||
"type": "constructor" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "fun1", | ||
"outputs": [ | ||
{ | ||
"name": "par1", | ||
"type": "felt" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [{"name": "x", "type": "felt"}, {"name": "y", "type": "felt"}], | ||
"name": "fun2", | ||
"outputs": [ | ||
{ | ||
"name": "par1", | ||
"type": "felt" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"name": "account", | ||
"type": "felt" | ||
} | ||
], | ||
"name": "balanceOf", | ||
"outputs": [ | ||
{ | ||
"name": "balance", | ||
"type": "Uint256" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
] as const | ||
function call<TAbi extends Abi, TFunctionName extends ExtractAbiFunctionName<TAbi>>(abi: TAbi, f: TFunctionName, args: FunctionArgs<TAbi, TFunctionName>): FunctionRet<TAbi, TFunctionName> { | ||
export function call<TAbi extends Abi, TFunctionName extends ExtractAbiFunctionName<TAbi>>(abi: TAbi, f: TFunctionName, args: FunctionArgs<TAbi, TFunctionName>): FunctionRet<TAbi, TFunctionName> { | ||
throw new Error('todo') | ||
} | ||
const [balance] = call(ABI, 'balanceOf', [123]); | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const ABI = [ | ||
{ | ||
"members": [ | ||
{ | ||
"name": "low", | ||
"offset": 0, | ||
"type": "felt" | ||
}, | ||
{ | ||
"name": "high", | ||
"offset": 1, | ||
"type": "felt" | ||
} | ||
], | ||
"name": "Uint256", | ||
"size": 2, | ||
"type": "struct" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"name": "par1", | ||
"type": "felt" | ||
}, | ||
{ | ||
"name": "symbol", | ||
"type": "felt" | ||
}, | ||
{ | ||
"name": "decimals", | ||
"type": "felt" | ||
}, | ||
{ | ||
"name": "initial_supply", | ||
"type": "Uint256" | ||
}, | ||
{ | ||
"name": "recipient", | ||
"type": "felt" | ||
} | ||
], | ||
"name": "constructor", | ||
"outputs": [], | ||
"type": "constructor" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "fun1", | ||
"outputs": [ | ||
{ | ||
"name": "par1", | ||
"type": "felt" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [{ "name": "x", "type": "felt" }, { "name": "y", "type": "felt" }], | ||
"name": "fun2", | ||
"outputs": [ | ||
{ | ||
"name": "par1", | ||
"type": "felt" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"name": "account", | ||
"type": "felt" | ||
} | ||
], | ||
"name": "balanceOf", | ||
"outputs": [ | ||
{ | ||
"name": "balance", | ||
"type": "Uint256" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
]; | ||
const xxx = () => { return { low: 0, high: 0 }; }; | ||
let a; |
153
kanabi.ts
@@ -18,15 +18,2 @@ type Felt = 'felt' | ||
type _BuildArgs<TAbi extends Abi, TAbiParam extends readonly AbiParameter[], R extends unknown[]> = | ||
R['length'] extends TAbiParam['length'] ? R : _BuildArgs<TAbi, TAbiParam, [...R, AbiParameterToPrimitiveType<TAbi, TAbiParam[R['length']]>]> | ||
export type FunctionArgs<TAbi extends Abi, TFunctionName extends ExtractAbiFunctionName<TAbi>> = | ||
_BuildArgs<TAbi, ExtractAbiFunction<TAbi, TFunctionName>['inputs'], []> | ||
export type FunctionRet<TAbi extends Abi, TFunctionName extends ExtractAbiFunctionName<TAbi>> = | ||
_BuildArgs<TAbi, ExtractAbiFunction<TAbi, TFunctionName>['outputs'], []> | ||
type Func = 'balanceOf' | ||
type XXX = FunctionArgs<typeof ABI, Func> | ||
type YYY = FunctionRet<typeof ABI, Func> | ||
type AbiType = Felt | CairoFunction | CairoTuple | ||
@@ -72,5 +59,12 @@ | ||
/// Demo | ||
type T1 = Extract<string | 1 | (() => void | (()=> string)), number>; | ||
/// Implement | ||
type _BuildArgs<TAbi extends Abi, TAbiParam extends readonly AbiParameter[], R extends unknown[]> = | ||
R['length'] extends TAbiParam['length'] ? R : _BuildArgs<TAbi, TAbiParam, [...R, AbiParameterToPrimitiveType<TAbi, TAbiParam[R['length']]>]> | ||
export type FunctionArgs<TAbi extends Abi, TFunctionName extends ExtractAbiFunctionName<TAbi>> = | ||
_BuildArgs<TAbi, ExtractAbiFunction<TAbi, TFunctionName>['inputs'], []> | ||
export type FunctionRet<TAbi extends Abi, TFunctionName extends ExtractAbiFunctionName<TAbi>> = | ||
_BuildArgs<TAbi, ExtractAbiFunction<TAbi, TFunctionName>['outputs'], []> | ||
export type ExtractAbiFunctions<TAbi extends Abi> = Extract<TAbi[number], { type: 'function' }> | ||
@@ -117,129 +111,2 @@ | ||
} | ||
: unknown | ||
const ABI = [ | ||
{ | ||
"members": [ | ||
{ | ||
"name": "low", | ||
"offset": 0, | ||
"type": "felt" | ||
}, | ||
{ | ||
"name": "high", | ||
"offset": 1, | ||
"type": "felt" | ||
} | ||
], | ||
"name": "Uint256", | ||
"size": 2, | ||
"type": "struct" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"name": "par1", | ||
"type": "felt" | ||
}, | ||
{ | ||
"name": "symbol", | ||
"type": "felt" | ||
}, | ||
{ | ||
"name": "decimals", | ||
"type": "felt" | ||
}, | ||
{ | ||
"name": "initial_supply", | ||
"type": "Uint256" | ||
}, | ||
{ | ||
"name": "recipient", | ||
"type": "felt" | ||
} | ||
], | ||
"name": "constructor", | ||
"outputs": [], | ||
"type": "constructor" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "fun1", | ||
"outputs": [ | ||
{ | ||
"name": "par1", | ||
"type": "felt" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [{"name": "x", "type": "felt"}, {"name": "y", "type": "felt"}], | ||
"name": "fun2", | ||
"outputs": [ | ||
{ | ||
"name": "par1", | ||
"type": "felt" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"name": "account", | ||
"type": "felt" | ||
} | ||
], | ||
"name": "balanceOf", | ||
"outputs": [ | ||
{ | ||
"name": "balance", | ||
"type": "Uint256" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
] as const | ||
type T2 = ExtractAbiFunctions<typeof ABI> | ||
type T3 = ExtractAbiFunctionName<typeof ABI> | ||
type T4 = ExtractAbiFunction<typeof ABI, 'balanceOf'> | ||
type TPar = T4['inputs'][0] | ||
type TRet = T4['outputs'][0] | ||
type TFunc = (...x: [AbiParameterToPrimitiveType<typeof ABI, TPar>]) => AbiParameterToPrimitiveType<typeof ABI, TRet> | ||
const xxx: TFunc = () => { return {low: 0, high: 0}} | ||
type T5 = ExtractAbiStructs<typeof ABI> | ||
type T6 = ExtractAbiStructNames<typeof ABI> | ||
type T7 = ExtractAbiStruct<typeof ABI,T6> | ||
type T8 = AbiTypeToPrimitiveType<typeof ABI, Felt> | ||
type T9 = AbiParameterToPrimitiveType<typeof ABI, { name: 'balance'; type: 'Uint256' }> | ||
let a: T2; | ||
/// function defitnion Demo | ||
type testOutput = { | ||
"name": "par1", | ||
"type": "felt" | ||
} | ||
type testInput = { | ||
"name": "account", | ||
"type": "felt" | ||
} | ||
type params = testInput['name'] | ||
type AbiFns = { | ||
demo: (name: string) => string, | ||
fn: (a: string) => void | ||
} | ||
: unknown |
{ | ||
"name": "abi-wan-kanabi", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Abi parser for Cairo smart contracts, based on wagmi abitype", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14
2421532
49584