Skip to content

Commit

Permalink
Merge pull request toncenter#37 from slavafomin/types
Browse files Browse the repository at this point in the history
Updated type declarations
  • Loading branch information
tolya-yanot authored Mar 22, 2022
2 parents ec0aed8 + 6a00947 commit cfb50a0
Show file tree
Hide file tree
Showing 22 changed files with 143 additions and 60 deletions.
8 changes: 5 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
.idea/
/.idea/
/coverage/
/node_modules/
/test-reports/
.DS_Store
node_modules
*.iml
*.iml
10 changes: 4 additions & 6 deletions dist/types/boc/bit-string.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import BN from 'bn.js';
import { Address } from '../utils/Address';
import { Address } from '../utils/address';
export declare class BitString {
/**
* A length of bit string in bits.
Expand All @@ -10,6 +10,7 @@ export declare class BitString {
length: number;
array: Uint8Array;
cursor: number;
private textEncoder;
constructor(
/**
* A length of bit string in bits.
Expand Down Expand Up @@ -100,14 +101,11 @@ export declare class BitString {
*/
writeBytes(values: Uint8Array): void;
/**
* Represents the specified ASCII string as bytes and writes
* Represents the specified multibyte string as bytes and writes
* them to the bit-string, starting at the current index and
* advances the current index cursor by the number of bits written.
* Using non-ASCII characters will cause an error.
*
* @todo: detect non-ASCII characters and throw more specific error?
*/
writeString(asciiString: string): void;
writeString(value: string): void;
/**
* Writes the specified amount in nanograms to the
* bit-string, starting at the current index and advances
Expand Down
2 changes: 1 addition & 1 deletion dist/types/contract/contract.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import BN from 'bn.js';
import { Cell } from '../boc/cell';
import { HttpProvider } from '../providers/http-provider';
import { Address, AddressType } from '../utils/Address';
import { Address, AddressType } from '../utils/address';
export interface ContractOptions {
code?: Cell;
address?: AddressType;
Expand Down
2 changes: 1 addition & 1 deletion dist/types/contract/subscription-contract.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import BN from 'bn.js';
import { Cell } from '../boc/cell';
import { HttpProvider } from '../providers/http-provider';
import { Address } from '../utils/Address';
import { Address } from '../utils/address';
import { Contract, ContractMethods, ContractOptions, Method } from './contract';
export interface SubscriptionContractOptions extends ContractOptions {
wallet?: Address;
Expand Down
29 changes: 29 additions & 0 deletions dist/types/contract/token/ft/jetton-minter.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,38 @@
import BN from 'bn.js';
import { Cell } from '../../../boc/cell';
import { HttpProvider } from '../../../providers/http-provider';
import { Address } from '../../../utils/address';
import { Contract, ContractMethods, ContractOptions } from '../../contract';
export interface JettonMinterOptions extends ContractOptions {
wc?: 0;
adminAddress: Address;
jettonContentUri: string;
jettonWalletCodeHex: string;
}
export interface JettonMinterMethods extends ContractMethods {
}
export interface MintBodyParams {
tokenAmount: BN;
destination: Address;
amount: BN;
queryId?: number;
}
export interface JettonData {
totalSupply: BN;
isMutable: boolean;
jettonContentUri: string;
tokenWalletCode: Cell;
adminAddress?: Address;
}
/**
* ATTENTION: this is a DRAFT, there will be changes.
*/
export declare class JettonMinter extends Contract<JettonMinterOptions, JettonMinterMethods> {
constructor(provider: HttpProvider, options: JettonMinterOptions);
createMintBody(params: MintBodyParams): Cell;
getJettonData(): Promise<JettonData>;
/**
* Returns cell that contains jetton minter data.
*/
protected createDataCell(): Cell;
}
36 changes: 36 additions & 0 deletions dist/types/contract/token/ft/jetton-wallet.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,45 @@
import BN from 'bn.js';
import { Cell } from '../../../boc/cell';
import { HttpProvider } from '../../../providers/http-provider';
import { Address } from '../../../utils/address';
import { Contract, ContractMethods, ContractOptions } from '../../contract';
export interface JettonWalletOptions extends ContractOptions {
wc?: 0;
}
export interface JettonWalletMethods extends ContractMethods {
}
export interface WalletData {
balance: BN;
ownerAddress: Address;
jettonMinterAddress: Address;
tokenWalletCode: Cell;
}
export interface TransferBodyParams {
queryId?: number;
tokenAmount: BN;
toAddress: Address;
responseAddress: Address;
forwardAmount: BN;
forwardPayload: Uint8Array;
}
export interface BurnBodyParams {
queryId?: number;
tokenAmount: BN;
responseAddress: Address;
}
/**
* ATTENTION: this is a DRAFT, there will be changes.
*/
export declare class JettonWallet extends Contract<JettonWalletOptions, JettonWalletMethods> {
static codeHex: string;
constructor(provider: HttpProvider, options: JettonWalletOptions);
getData(): Promise<WalletData>;
/**
* @todo: should it be async?
*/
createTransferBody(params: TransferBodyParams): Promise<Cell>;
/**
* @todo: should it be async?
*/
createBurnBody(params: BurnBodyParams): Promise<Cell>;
}
3 changes: 1 addition & 2 deletions dist/types/contract/token/nft/nft-collection.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import BN from 'bn.js';
import { Cell } from '../../../boc/cell';
import { HttpProvider } from '../../../providers/http-provider';
import { Address } from '../../../utils/Address';
import { Address } from '../../../utils/address';
import { Contract, ContractMethods, ContractOptions } from '../../contract';
import { NftItem } from './nft-item';
export interface NftCollectionOptions extends ContractOptions {
Expand All @@ -11,7 +11,6 @@ export interface NftCollectionOptions extends ContractOptions {
nftItemCodeHex?: string;
royalty?: number;
royaltyAddress?: Address;
cell?: Cell;
}
export interface NftCollectionMethods extends ContractMethods {
getCollectionData: () => Promise<CollectionData>;
Expand Down
2 changes: 1 addition & 1 deletion dist/types/contract/token/nft/nft-item.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import BN from 'bn.js';
import { Cell } from '../../../boc/cell';
import { HttpProvider } from '../../../providers/http-provider';
import { Address } from '../../../utils/Address';
import { Address } from '../../../utils/address';
import { Contract, ContractMethods, ContractOptions } from '../../contract';
export interface NftItemOptions extends ContractOptions {
index?: number;
Expand Down
2 changes: 1 addition & 1 deletion dist/types/contract/token/nft/nft-marketplace.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Cell } from '../../../boc/cell';
import { HttpProvider } from '../../../providers/http-provider';
import { Address } from '../../../utils/Address';
import { Address } from '../../../utils/address';
import { Contract, ContractMethods, ContractOptions } from '../../contract';
export interface NftMarketplaceOptions extends ContractOptions {
ownerAddress?: Address;
Expand Down
2 changes: 1 addition & 1 deletion dist/types/contract/token/nft/nft-sale.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import BN from 'bn.js';
import { Cell } from '../../../boc/cell';
import { HttpProvider } from '../../../providers/http-provider';
import { Address } from '../../../utils/Address';
import { Address } from '../../../utils/address';
import { Contract, ContractMethods, ContractOptions } from '../../contract';
export interface NftSaleOptions extends ContractOptions {
marketplaceAddress?: Address;
Expand Down
2 changes: 1 addition & 1 deletion dist/types/contract/token/nft/utils.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Cell } from '../../../boc/cell';
import { Address } from '../../../utils/Address';
import { Address } from '../../../utils/address';
export declare const SNAKE_DATA_PREFIX = 0;
export declare const CHUNK_DATA_PREFIX = 1;
export declare const ONCHAIN_CONTENT_PREFIX = 0;
Expand Down
7 changes: 7 additions & 0 deletions dist/types/contract/wallet/common/signing.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Cell } from '../../../boc/cell';
/**
* Writes current timestamp to the specified signing message,
* or the placeholder value if the specified `seqno` value
* is equal to zero.
*/
export declare function writeTimestampToSigningMessage(message: Cell, seqno: number): void;
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { HttpProvider } from '../../../providers/http-provider';
import { ContractOptions } from '../../contract';
import { WalletContract } from '../wallet-contract';
import { WalletContract, WalletContractOptions } from '../wallet-contract';
/**
* Attention: no seqno get-method in this wallet.
*/
export declare class SimpleWalletContractR1 extends WalletContract {
constructor(provider: HttpProvider, options: ContractOptions);
constructor(provider: HttpProvider, options: WalletContractOptions);
getName(): string;
}
2 changes: 1 addition & 1 deletion dist/types/contract/wallet/v4/wallet-v4-contract-r2.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import BN from 'bn.js';
import { Cell } from '../../../boc/cell';
import { HttpProvider } from '../../../providers/http-provider';
import { AddressType } from '../../../utils/Address';
import { AddressType } from '../../../utils/address';
import { Method } from '../../contract';
import { ExternalMessage } from '../wallet-contract';
import { WalletV4ContractBase, WalletV4ContractMethods, WalletV4ContractOptions } from './wallet-v4-contract-base';
Expand Down
24 changes: 7 additions & 17 deletions dist/types/contract/wallet/wallet-contract.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import BN from 'bn.js';
import { Contract, ContractMethods, ContractOptions, Method } from '../contract';
import { Contract, ContractMethods, ContractOptions, Method, Query } from '../contract';
import { Cell } from '../../boc/cell';
import { HttpProvider } from '../../providers/http-provider';
import { Address, AddressType } from '../../utils/Address';
import { Address, AddressType } from '../../utils/address';
export interface WalletContractOptions extends ContractOptions {
publicKey?: Uint8Array;
}
Expand All @@ -11,8 +11,8 @@ export interface TransferMethodParams {
toAddress: AddressType;
amount: (BN | number);
seqno: number;
payload: (string | Uint8Array | Cell);
sendMode: number;
payload?: (string | Uint8Array | Cell);
sendMode?: number;
stateInit?: Cell;
}
export interface WalletContractMethods extends ContractMethods {
Expand Down Expand Up @@ -46,19 +46,9 @@ export declare class WalletContract<WalletType extends WalletContractOptions = W
*/
getName(): string;
/**
* External message for initialization
* @param secretKey {Uint8Array} nacl.KeyPair.secretKey
* @return {{address: Address, message: Cell, body: Cell, sateInit: Cell, code: Cell, data: Cell}}
* Creates external message for contract initialization.
*/
createInitExternalMessage(secretKey: any): Promise<{
address: Address;
message: Cell;
body: Cell;
signingMessage: Cell;
stateInit: Cell;
code: Cell;
data: Cell;
}>;
createInitExternalMessage(secretKey: Uint8Array): Promise<Query>;
createTransferMessage(
/**
* `nacl.KeyPair.secretKey`
Expand All @@ -76,5 +66,5 @@ export declare class WalletContract<WalletType extends WalletContractOptions = W
* @todo: improve the description
*/
secretKey: Uint8Array, seqno: number, dummySignature?: boolean): Promise<ExternalMessage>;
private parsePayload;
private serializePayload;
}
15 changes: 8 additions & 7 deletions dist/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import { InMemoryBlockStorage } from './providers/block-subscription/in-memory-b
export { BlockHandler, BlockSubscriptionOptions, } from './providers/block-subscription/block-subscription';
export { LogFunction, } from './providers/block-subscription/in-memory-block-storage';
export { ShardBlock, BlockStorage, } from './providers/block-subscription/block-storage';
import { Address, AddressType } from './utils/Address';
export { AddressType } from './utils/Address';
import { ParsedTransferUrl } from './utils/common';
import { Address, AddressType } from './utils/address';
export { AddressType } from './utils/address';
import { formatTransferUrl, parseTransferUrl } from './utils/transfer-url';
export { ParsedTransferUrl } from './utils/transfer-url';
import { BitString } from './boc/bit-string';
import { Cell } from './boc/cell';
import { Contract } from './contract/contract';
Expand Down Expand Up @@ -45,6 +46,8 @@ export default class TonWeb {
BN: typeof BN;
nacl: nacl;
Address: typeof Address;
formatTransferUrl: typeof formatTransferUrl;
parseTransferUrl: typeof parseTransferUrl;
sha256(bytes: Uint8Array): Promise<ArrayBuffer>;
toNano(amount: string | number | BN): BN;
fromNano(amount: string | number | BN): string;
Expand All @@ -60,8 +63,6 @@ export default class TonWeb {
stringToBase64(str: string): string;
base64ToBytes(base64: string): Uint8Array;
readNBytesUIntFromArray(n: number, ui8array: Uint8Array): number;
parseTransferUrl(url: string): ParsedTransferUrl;
formatTransferUrl(address: string, amount?: string, text?: string): string;
};
static Address: typeof Address;
static boc: {
Expand Down Expand Up @@ -108,6 +109,8 @@ export default class TonWeb {
BN: typeof BN;
nacl: nacl;
Address: typeof Address;
formatTransferUrl: typeof formatTransferUrl;
parseTransferUrl: typeof parseTransferUrl;
sha256(bytes: Uint8Array): Promise<ArrayBuffer>;
toNano(amount: string | number | BN): BN;
fromNano(amount: string | number | BN): string;
Expand All @@ -123,8 +126,6 @@ export default class TonWeb {
stringToBase64(str: string): string;
base64ToBytes(base64: string): Uint8Array;
readNBytesUIntFromArray(n: number, ui8array: Uint8Array): number;
parseTransferUrl(url: string): ParsedTransferUrl;
formatTransferUrl(address: string, amount?: string, text?: string): string;
};
Address: typeof Address;
boc: {
Expand Down
2 changes: 1 addition & 1 deletion dist/types/ledger/app-ton.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import BN from 'bn.js';
import { Method } from '../contract/contract';
import { WalletContract } from '../contract/wallet/wallet-contract';
import TonWeb, { AddressType } from '../index';
import { Address } from '../utils/Address';
import { Address } from '../utils/address';
export interface AppConfiguration {
version: string;
}
Expand Down
6 changes: 5 additions & 1 deletion dist/types/providers/http-provider.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export declare class HttpProvider {
/**
* @todo: change params type to Array<any>
*/
send(method: string, params: any): Promise<any>;
send(method: string, params: any): Promise<Response>;
/**
* Use this method to get information about address:
* balance, code, data, last_transaction_id.
Expand Down Expand Up @@ -102,6 +102,8 @@ export declare class HttpProvider {
/**
* Invokes get-method of smart contract.
*
* @todo: rename to `runGetMethodRaw()`
*
* {@link https://toncenter.com/api/v2/#/run%20method/run_get_method_runGetMethod_post}
*/
call(
Expand All @@ -120,6 +122,8 @@ export declare class HttpProvider {
/**
* Invokes get-method of smart contract.
*
* @todo: rename to `runGetMethod()`
*
* {@link https://toncenter.com/api/v2/#/run%20method/run_get_method_runGetMethod_post}
*/
call2(
Expand Down
14 changes: 10 additions & 4 deletions dist/types/utils/Address.d.ts → dist/types/utils/address.d.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import { Workchain } from './workchain';
export declare type AddressType = (Address | string);
export declare class Address {
static isValid(anyForm: AddressType): boolean;
wc: number;
wc: Workchain;
hashPart: Uint8Array;
isTestOnly: boolean;
isUserFriendly: boolean;
isBounceable: boolean;
isUrlSafe: boolean;
constructor(address: AddressType);
toString(isUserFriendly?: boolean, isUrlSafe?: boolean, isBounceable?: boolean, isTestOnly?: boolean): string;
/**
* @param anyForm {string | Address}
* Copies the address data from the specified Address
* instance to this instance.
*/
constructor(anyForm: AddressType);
toString(isUserFriendly?: boolean, isUrlSafe?: boolean, isBounceable?: boolean, isTestOnly?: boolean): string;
private initFromInstance;
private initFromString;
private parseFriendlyAddress;
private checkWorkchainOrThrow;
}
Loading

0 comments on commit cfb50a0

Please sign in to comment.