diff --git a/types/iost-contract/base.d.ts b/types/iost-contract/base.d.ts new file mode 100755 index 0000000000..0e8eb94129 --- /dev/null +++ b/types/iost-contract/base.d.ts @@ -0,0 +1,6 @@ +// base definnitions for all IOST contract modules that are not specific to any version of TypeScript +/// +/// +/// +/// +/// diff --git a/types/iost-contract/block.d.ts b/types/iost-contract/block.d.ts new file mode 100755 index 0000000000..b5f24c2f60 --- /dev/null +++ b/types/iost-contract/block.d.ts @@ -0,0 +1,10 @@ +declare namespace IOSTContract { + interface Block { + number: number; + parent_hash: string; + witness: string; + time: number; + } +} + +declare const block: IOSTContract.Block; diff --git a/types/iost-contract/blockchain.d.ts b/types/iost-contract/blockchain.d.ts new file mode 100755 index 0000000000..b0f1b6c5a2 --- /dev/null +++ b/types/iost-contract/blockchain.d.ts @@ -0,0 +1,17 @@ +declare namespace IOSTContract { + interface Blockchain { + transfer(from: string, to: string, amount: string, memo: string): void; + withdraw(to: string, amount: string, memo: string): void; + deposit(from: string, amount: string, memo: string): void; + contractName(): string; + publisher(): string; + contractOwner(): string; + call(contract: string, abi: string, args: string[] | string): string[]; + callWithAuth(contract: string, abi: string, args: string[] | string): string[]; + requireAuth(account: string, permission: string): boolean; + receipt(data: string): void; + event(data: string): void; + } +} + +declare const blockchain: IOSTContract.Blockchain; diff --git a/types/iost-contract/index.d.ts b/types/iost-contract/index.d.ts new file mode 100755 index 0000000000..acc7e95ef5 --- /dev/null +++ b/types/iost-contract/index.d.ts @@ -0,0 +1,8 @@ +// Type definitions for non-npm package IOST contract API 3.4 +// Project: https://github.com/iost-official/ +// Definitions by: Masaki Muranaka +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +// TypeScript Version: 2.2 + +/// diff --git a/types/iost-contract/iost-contract-tests.ts b/types/iost-contract/iost-contract-tests.ts new file mode 100755 index 0000000000..7fa105fa8e --- /dev/null +++ b/types/iost-contract/iost-contract-tests.ts @@ -0,0 +1,11 @@ +// $ExpectType number +block.number; + +// $ExpectType string +block.parent_hash; + +// $ExpectType number +block.time; + +// $ExpectType string +block.witness; diff --git a/types/iost-contract/iostcrypto.d.ts b/types/iost-contract/iostcrypto.d.ts new file mode 100755 index 0000000000..9484f1f54b --- /dev/null +++ b/types/iost-contract/iostcrypto.d.ts @@ -0,0 +1,15 @@ +declare namespace IOSTContract { + interface Block { + number: number; + parent_hash: string; + witness: string; + time: number; + } + + interface _IOSTCrypto { + sha3(data: string): string; + verify(algo: string, message: string, signature: string, pubkey: string): number; + } +} + +declare const IOSTCrypto: IOSTContract._IOSTCrypto; diff --git a/types/iost-contract/storage.d.ts b/types/iost-contract/storage.d.ts new file mode 100755 index 0000000000..3d9e344376 --- /dev/null +++ b/types/iost-contract/storage.d.ts @@ -0,0 +1,26 @@ +declare namespace IOSTContract { + interface LocalStorage { + put(key: string, value: string, payer?: string): any; + get(key: string): string | null; + has(key: string): boolean; + del(key: string): void; + mapPut(key: string, field: string, value: string, payer?: string): void; + mapGet(key: string, field: string): string | null; + mapHas(key: string, field: string): boolean; + mapKeys(key: string): string[]; + mapLen(key: string): number; + mapDel(key: string, field: string): void; + } + interface GlobalStorage { + globalHas(contract: string, key: string): boolean; + globalGet(contract: string, key: string): string | null; + globalMapHas(contract: string, key: string, field: string): boolean; + globalMapGet(contract: string, key: string, field: string): string | null; + globalMapLen(contract: string, key: string): number; + globalMapKeys(contract: string, key: string): string[]; + } + interface Storage extends LocalStorage, GlobalStorage { + } +} + +declare const storage: IOSTContract.Storage; diff --git a/types/iost-contract/tsconfig.json b/types/iost-contract/tsconfig.json new file mode 100755 index 0000000000..49a7dc071d --- /dev/null +++ b/types/iost-contract/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "iost-contract-tests.ts" + ] +} diff --git a/types/iost-contract/tslint.json b/types/iost-contract/tslint.json new file mode 100755 index 0000000000..3db14f85ea --- /dev/null +++ b/types/iost-contract/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/iost-contract/tx.d.ts b/types/iost-contract/tx.d.ts new file mode 100755 index 0000000000..0d60b25d56 --- /dev/null +++ b/types/iost-contract/tx.d.ts @@ -0,0 +1,15 @@ +// + +declare namespace IOSTContract { + interface Tx { + time: number; + hash: string; + expiration: number; + gas_limit: number; + gas_ratio: number; + auth_list: object; + publisher: string; + } +} + +declare const tx: IOSTContract.Tx;