diff --git a/web3.js/README.md b/web3.js/README.md index 328524f947..67d42756d5 100644 --- a/web3.js/README.md +++ b/web3.js/README.md @@ -65,6 +65,18 @@ console.log(solanaWeb3); console.log(solanaWeb3); ``` +## Flow + +A Flow library definition file is provided at +[module.flow.js](https://github.com/solana-labs/solana-web3.js/tree/master/module.flow.js). +Add the following line under the [libs] section of your project's .flowconfig to +activate it: +```ini +[libs] +node_modules/@solana/web3.js/module.flow.js +``` + + ## Examples See the [examples/](https://github.com/solana-labs/solana-web3.js/tree/master/examples) directory for small snippets. diff --git a/web3.js/module.flow.js b/web3.js/module.flow.js new file mode 100644 index 0000000000..2221cd6b1a --- /dev/null +++ b/web3.js/module.flow.js @@ -0,0 +1,89 @@ +/** + * Flow Library definition for @solana/web3.js + * + * This file is manually generated from the contents of src/ + * + * Usage: add the following line under the [libs] section of your project's + * .flowconfig: + * [libs] + * node_modules/@solana/web3.js/module.flow.js + * + */ + +declare module '@solana/web3.js' { + declare type PublicKey = string; + + // === src/account.js === + declare export class Account { + constructor(secretKey: ?Buffer): Account; + publicKey: PublicKey; + secretKey: PublicKey; + } + + // === src/budget-program.js === + /* TODO */ + + // === src/connection.js === + declare type AccountInfo = { + tokens: number, + programId: PublicKey, + userdata: Buffer | null, + } + + declare type SignatureStatus = 'Confirmed' | 'SignatureNotFound' | 'ProgramRuntimeError' | 'GenericFailure'; + + declare export class Connection { + constructor(endpoint: string): Connection; + getBalance(publicKey: PublicKey): Promise; + getAccountInfo(publicKey: PublicKey): Promise; + confirmTransaction(signature: TransactionSignature): Promise; + getSignatureStatus(signature: TransactionSignature): Promise; + getTransactionCount(): Promise; + getLastId(): Promise; + getFinality(): Promise; + requestAirdrop(to: PublicKey, amount: number): Promise; + sendTransaction(from: Account, transaction: Transaction): Promise; + } + + // === src/system-program.js === + declare export class SystemProgram { + static programId: PublicKey; + + static createAccount( + from: PublicKey, + newAccount: PublicKey, + tokens: number, + space: number, + programId: PublicKey + ): Transaction; + static move(from: PublicKey, to: PublicKey, amount: number): Transaction; + static assign(from: PublicKey, programId: PublicKey): Transaction; + } + + // === src/transaction.js === + declare type TransactionSignature = string; + declare type TransactionId = string; + + declare type TransactionCtorFields = {| + signature?: Buffer; + keys?: Array; + programId?: PublicKey; + fee?: number; + userdata?: Buffer; + |}; + + + declare export class Transaction { + signature: ?Buffer; + keys: Array; + programId: ?PublicKey; + lastId: ?TransactionId; + fee: number; + userdata: Buffer; + + constructor(opts?: TransactionCtorFields): Transaction; + sign(from: Account): void; + serialize(): Buffer; + static serializePublicKey(key: PublicKey): Buffer; + } +}