diff --git a/test/unit/chain/index.test.js b/test/unit/chain/index.test.js index 4edfe17f..0fcaaae2 100644 --- a/test/unit/chain/index.test.js +++ b/test/unit/chain/index.test.js @@ -3,7 +3,7 @@ import RequestManager from '../../../src/util/requestManage'; import HttpProvider from '../../../src/util/httpProvider'; import AElf from '../../../src'; import { noop } from '../../../src/util/utils'; -const stageEndpoint = 'https://explorer-test-tdvw.aelf.io/chain'; +const stageEndpoint = 'https://tdvw-test-node.aelf.io/'; let httpProvider, requestManager, chain; describe('chain should work', () => { diff --git a/test/unit/contract/contractMethod.test.js b/test/unit/contract/contractMethod.test.js index 1feeb672..94fc06d8 100644 --- a/test/unit/contract/contractMethod.test.js +++ b/test/unit/contract/contractMethod.test.js @@ -2,7 +2,7 @@ import ContractMethod from '../../../src/contract/contractMethod'; import ContractFactory from '../../../src/contract/index'; import AElf from '../../../src/index'; import { noop } from '../../../src/util/utils'; -const stageEndpoint = 'https://explorer-test-tdvw.aelf.io/chain'; +const stageEndpoint = 'https://tdvw-test-node.aelf.io/'; describe('token contract with transfer method', () => { const aelf = new AElf(new AElf.providers.HttpProvider(stageEndpoint)); const wallet = AElf.wallet.getWalletByPrivateKey( diff --git a/test/unit/contract/index.test.js b/test/unit/contract/index.test.js index b8c25a79..c2fe7fdd 100644 --- a/test/unit/contract/index.test.js +++ b/test/unit/contract/index.test.js @@ -1,5 +1,5 @@ import ContractFactory from '../../../src/contract/index'; -const stageEndpoint = 'https://explorer-test-tdvw.aelf.io/chain'; +const stageEndpoint = 'https://tdvw-test-node.aelf.io'; import AElf from '../../../src/index'; describe('contract factory', () => { const aelf = new AElf(new AElf.providers.HttpProvider(stageEndpoint)); diff --git a/test/unit/index.test.js b/test/unit/index.test.js index a21ea3cb..0746b9c2 100644 --- a/test/unit/index.test.js +++ b/test/unit/index.test.js @@ -1,5 +1,5 @@ import AElf from '../../src/index'; -const stageEndpoint = 'https://explorer-test-tdvw.aelf.io/chain'; +const stageEndpoint = 'https://tdvw-test-node.aelf.io'; describe('test AElf', () => { test('test AElf is connected', () => { const aelf = new AElf(new AElf.providers.HttpProvider(stageEndpoint)); diff --git a/types/chain/index.d.ts b/types/chain/index.d.ts index 0eda0684..31d23085 100644 --- a/types/chain/index.d.ts +++ b/types/chain/index.d.ts @@ -1,8 +1,14 @@ import { Contract } from 'types/contract'; import { RequestManager } from 'types/util/requestManage'; -import * as Bip39 from 'bip39'; import { IWalletInfo } from '../wallet'; import { IExtractArgumentsIntoObjectResult, TExtractArg } from './chainMethod'; +import { + TAddress, + TBlockHash, + TBlockHeight, + TChainId, + TTransactionId, +} from '../util/proto'; export interface IError { Error: { Code: string | null; @@ -22,27 +28,27 @@ export interface IError { }; } export interface IChainStatus { - ChainId: string; + TChainId: TChainId; Branches: { [key in string]: number; }; NotLinkedBlocks: { [key in string]: number; }; - LongestChainHeight: number; - LongestChainHash: string; - GenesisBlockHash: string; - GenesisContractAddress: string; - LastIrreversibleBlockHash: string; - LastIrreversibleBlockHeight: number; - BestChainHash: string; - BestChainHeight: number; + LongestChainHeight: TBlockHeight; + LongestChainHash: TBlockHash; + GenesisBlockHash: TBlockHash; + GenesisContractAddress: TAddress; + LastIrreversibleBlockHash: TBlockHash; + LastIrreversibleBlockHeight: TBlockHeight; + BestChainHash: TBlockHash; + BestChainHeight: TBlockHeight; } export interface IChainState { - BlockHash: string; - PreviousHash: string; - BlockHeight: number; + BlockHash: TBlockHash; + PreviousHash: TBlockHash; + BlockHeight: TBlockHeight; Changes: { [key in string]: string; }; @@ -50,37 +56,16 @@ export interface IChainState { } export interface IBlock { - BlockHash: string; + BlockHash: TBlockHash; Header: { - PreviousBlockHash: string; + PreviousBlockHash: TBlockHash; MerkleTreeRootOfTransactions: string; MerkleTreeRootOfWorldState: string; MerkleTreeRootOfTransactionState: string; Extra: string; - Height: number; + Height: TBlockHeight; Time: string; - ChainId: string; - Bloom: string; - SignerPubkey: string; - }; - Body: { - TransactionsCount: number; - Transactions: string[]; - }; - BlockSize: number; -} - -export interface IBlockByHeight { - BlockHash: string; - Header: { - PreviousBlockHash: string; - MerkleTreeRootOfTransactions: string; - MerkleTreeRootOfWorldState: string; - MerkleTreeRootOfTransactionState: string; - Extra: string; - Height: number; - Time: string; - ChainId: string; + ChainId: TChainId; Bloom: string; SignerPubkey: string; }; @@ -92,21 +77,21 @@ export interface IBlockByHeight { } export interface ITransactionResult { - TransactionId: string; + TransactionId: TTransactionId; Status: string; Logs: { - Address: string; + Address: TAddress; Name: string; Indexed: string[]; NonIndexed: string; }[]; Bloom: string; - BlockNumber: number; - BlockHash: string; + BlockNumber: TBlockHeight; + BlockHash: TBlockHash; Transaction: { - From: string; - To: string; - RefBlockNumber: number; + From: TAddress; + To: TAddress; + RefBlockNumber: TBlockHeight; RefBlockPrefix: string; MethodName: string; Params: string; @@ -118,7 +103,7 @@ export interface ITransactionResult { } export interface IMerklePathByTxId { MerklePathNodes: { - Hash: string; + Hash: TBlockHash; IsLeftChildNode: boolean; }[]; } @@ -137,7 +122,7 @@ export interface ITransactionPoolStatus { } export interface IPeer { - IpAddress: string; + IpAddress: TAddress; ProtocolVersion: number; ConnectionTime: number; ConnectionStatus: string; @@ -163,48 +148,50 @@ declare class Chain { args: TExtractArg[] ): IExtractArgumentsIntoObjectResult; public contractAt( - address: string, + address: TAddress, wallet: IWalletInfo, args: { [k in string]: any } ): Contract | Promise; public getMerklePath( txId: string, - height: number, + height: TBlockHeight, ...args: { [k in string]: any }[] ): any[] | null | Promise; getChainStatus(): Promise; getChainState(blockHash: string): Promise; getContractFileDescriptorSet(address: string): Promise; - getBlockHeight(): number; + getBlockHeight(): TBlockHeight; getBlock( - blockHash: string, + blockHash: TBlockHash, includeTransactions: boolean ): Promise; getBlockByHeight( - blockHeight: number, + blockHeight: TBlockHeight, includeTransactions?: boolean - ): Promise; - getTxResult(transactionId: string): Promise; + ): Promise; + getTxResult( + transactionId: TTransactionId + ): Promise; getTxResults( - blockHash: string, + blockHash: TBlockHash, offset: number, limit: number ): Promise; getMerklePathByTxId( - transactionId: string + transactionId: TTransactionId ): Promise; getTransactionPoolStatus(): Promise; sendTransaction( - RawTransaction: string - ): Promise<{ TransactionId: string } & IError>; + RawTransaction: TRawTransaction + ): Promise<{ TransactionId: TTransactionId } & IError>; sendTransactions(RawTransaction: string): Promise; calculateTransactionFee( - RawTransaction: string + RawTransaction: TRawTransaction ): Promise; - callReadOnly(RawTransaction: string): Promise; + callReadOnly(RawTransaction: TRawTransaction): Promise; getPeers(withMetrics?: boolean): Promise; - addPeer(Address: string): Promise; - removePeer(address: string): Promise; + addPeer(Address: TAddress): Promise; + removePeer(address: TAddress): Promise; networkInfo(): Promise< { Version: string; diff --git a/types/contract/contractMethod.d.ts b/types/contract/contractMethod.d.ts index 0ceb0a7b..d4143cb9 100644 --- a/types/contract/contractMethod.d.ts +++ b/types/contract/contractMethod.d.ts @@ -1,7 +1,13 @@ import Chain from '../chain'; import { IWalletInfo } from '../wallet'; import * as protobuf from '@aelfqueen/protobufjs'; -import { ITransaction } from '../util/proto'; +import { + ITransaction, + TAddress, + TBlockHash, + TBlockHeight, + TTransactionId, +} from '../util/proto'; import { Contract } from '.'; import { GenericFunction } from '../util/utils'; export type TRawTx = ITransaction & { @@ -23,7 +29,7 @@ declare class ContractMethod { constructor( chain: Chain, method: protobuf.Method, - contractAddress: string, + contractAddress: TAddress, walletInstance: IWalletInfo ); public packInput(input?: any): Buffer | null; @@ -32,13 +38,19 @@ declare class ContractMethod { ): any; public unpackOutput(output?: ArrayBuffer | SharedArrayBuffer | null): any; public packOutput(result?: any): Buffer | null; - public handleTransaction(height: string, hash: string, encoded: any): string; + public handleTransaction( + height: TBlockHeight, + hash: TBlockHash, + encoded: any + ): string; public prepareParametersAsync(args: Array): Promise; public prepareParameters(args: Array): string; public prepareParametersWithBlockInfo(args: Array): string; public sendTransaction( ...args: Array - ): { TransactionId: string } | Promise<{ TransactionId: string }>; + ): + | { TransactionId: TTransactionId } + | Promise<{ TransactionId: TTransactionId }>; public callReadOnly(...args: Array): any; public extractArgumentsIntoObject( ...args: Array @@ -46,8 +58,8 @@ declare class ContractMethod { public getSignedTx(...args: Array): string; public getRawTx( - blockHeightInput: string, - blockHashInput: string, + blockHeightInput: TBlockHeight, + blockHashInput: TBlockHash, packedInput: any ): TRawTx; public request(...args: Array): IRequestResult; diff --git a/types/contract/index.d.ts b/types/contract/index.d.ts index 91dd452c..5dd8cd44 100644 --- a/types/contract/index.d.ts +++ b/types/contract/index.d.ts @@ -3,13 +3,14 @@ import { IFileDescriptorSet } from '@aelfqueen/protobufjs/ext/descriptor'; import * as protobuf from '@aelfqueen/protobufjs/light'; import { IWalletInfo } from '../wallet'; import { GenericFunction } from '../util/utils'; +import { TAddress } from '../util/proto'; export class Contract { constructor(chain: Chain, services: Array, address: string); } interface IContractFactory { // just describe the public side of the class - at(address: string, callback: GenericFunction): Contract; + at(address: TAddress, callback: GenericFunction): Contract; } declare class ContractFactory implements IContractFactory { constructor( @@ -22,7 +23,7 @@ declare class ContractFactory implements IContractFactory { wallet: IWalletInfo ): void; - public at(address: string, callback: GenericFunction): Contract; + public at(address: TAddress, callback: GenericFunction): Contract; } export default ContractFactory; diff --git a/types/util/bloom.d.ts b/types/util/bloom.d.ts index b0a58bc9..8c73c34f 100644 --- a/types/util/bloom.d.ts +++ b/types/util/bloom.d.ts @@ -1,4 +1,6 @@ -export declare function isInBloom(bloom: string, hash: string): boolean; +import { TAddress, TBlockHash } from './proto'; + +export declare function isInBloom(bloom: string, hash: TBlockHash): boolean; export declare function isEventInBloom( bloom: string, eventName: string @@ -9,5 +11,5 @@ export declare function isIndexedInBloom( ): boolean; export declare function isAddressInBloom( bloom: string, - address: string + address: TAddress ): boolean; diff --git a/types/util/formatters.d.ts b/types/util/formatters.d.ts index 8822a1f8..1204db23 100644 --- a/types/util/formatters.d.ts +++ b/types/util/formatters.d.ts @@ -1,5 +1,4 @@ import { Message } from '@aelfqueen/protobufjs'; -export function inputAddressFormatter(address: string): string; -export function outputFileDescriptorSetFormatter( - result: string -): Message; +import { IAddress, TAddress } from './proto'; +export function inputAddressFormatter(address: TAddress | IAddress): string; +export function outputFileDescriptorSetFormatter(result: string): Message<{}>; diff --git a/types/util/keyStore.d.ts b/types/util/keyStore.d.ts index 3443a092..5aad0ac1 100644 --- a/types/util/keyStore.d.ts +++ b/types/util/keyStore.d.ts @@ -1,4 +1,5 @@ import { IWalletInfo } from '../wallet'; +import { TAddress } from './proto'; interface IOptions { dklen: number; @@ -33,7 +34,7 @@ interface IkeyStore { version: number; type: string; nickName?: string; - address: string; + address: TAddress; crypto: ICrypto; } export declare function getKeystore( diff --git a/types/util/proto.d.ts b/types/util/proto.d.ts index 49f035bf..a73ef2e5 100644 --- a/types/util/proto.d.ts +++ b/types/util/proto.d.ts @@ -1,4 +1,11 @@ import * as protobuf from '@aelfqueen/protobufjs/light'; + +export type TChainId = string; +export type TBlockHash = string; +export type TBlockHeight = number; +export type TAddress = string; +export type TTransactionId = string; +export type TRawTransaction = string; export interface IAddress { value: Buffer; } @@ -21,7 +28,7 @@ export function getFee( ): { [k: string]: any } | undefined | null; interface ILog { - Address: string; + Address: TAddress; Name: string; Indexed: Array | null; NonIndexed: string; @@ -49,8 +56,8 @@ export function getHashFromHex( export function getHashObjectFromHex(hex: string): { [k: string]: any }; export function encodeTransaction(tx: { [k: string]: any }): Uint8Array; export function getTransaction( - from: string, - to: string, + from: TAddress, + to: TAddress, methodName: string, params: any ): protobuf.Message<{ diff --git a/types/util/utils.d.ts b/types/util/utils.d.ts index 77470621..9abca570 100644 --- a/types/util/utils.d.ts +++ b/types/util/utils.d.ts @@ -1,5 +1,6 @@ import BigNumber from 'bignumber.js'; import * as protobuf from '@aelfqueen/protobufjs/light'; +import { TAddress } from './proto'; export type GenericFunction = (...args: any[]) => any; export interface IBase58 { @@ -21,7 +22,7 @@ export declare function padRight( charLen: number, sign?: string ): string; -export declare function decodeAddressRep(address: string): string; +export declare function decodeAddressRep(address: TAddress): string; export declare function encodeAddressRep(hex: string): string; export declare function isBigNumber(object: any): boolean; export declare function isString(object: any): boolean; diff --git a/types/wallet/index.d.ts b/types/wallet/index.d.ts index 0fa9d6a9..65ce45c8 100644 --- a/types/wallet/index.d.ts +++ b/types/wallet/index.d.ts @@ -1,22 +1,25 @@ import HDNode = require('hdkey'); import * as Bip39 from 'bip39'; import { ec, curve } from 'elliptic'; -import { ITransaction } from '../util/proto'; +import { ITransaction, TAddress } from '../util/proto'; import * as KeyStore from '../util/keyStore'; -import { TRawTx } from 'types/contract/contractMethod'; +import { TRawTx } from '../contract/contractMethod'; +type TBIP44Path = string; +type TMnemonic = string; +type TPrivateKey = string; interface ISignature { signature: Uint8Array; } type TSignTransaction = ISignature & TRawTx; export interface IWalletInfo { - BIP44Path: string; - address: string; + BIP44Path: TBIP44Path; + address: TAddress; childWallet: IWalletInfo | string; keyPair: ec.KeyPair; - mnemonic: string; - privateKey: string; + mnemonic: TMnemonic; + privateKey: TPrivateKey; } interface IWallet { @@ -28,13 +31,13 @@ interface IWallet { AESDescrypt(input: string, password: string): string; getSignature(bytesToBeSign: string, keyPair: ec.KeyPair): Buffer; getAddressFromPubKey(pubKey: curve.base.BasePoint): string; - createNewWallet(BIP44Path?: string): IWalletInfo; - getWalletByMnemonic(mnemonic: string, BIP44Path: string): IWalletInfo; - getWalletByPrivateKey(privateKey: string): IWalletInfo; + createNewWallet(BIP44Path?: TBIP44Path): IWalletInfo; + getWalletByMnemonic(mnemonic: TMnemonic, BIP44Path: TBIP44Path): IWalletInfo; + getWalletByPrivateKey(privateKey: TPrivateKey): IWalletInfo; signTransaction(rawTxn: ITransaction, keyPair: ec.KeyPair): TSignTransaction; sign(hexString: string, keyPair: ec.KeyPair): Buffer; } -export declare class Wallet implements IWallet{ +export declare class Wallet implements IWallet { ellipticEc: ec; hdkey: HDNode; bip39: typeof Bip39; @@ -43,9 +46,9 @@ export declare class Wallet implements IWallet{ AESDescrypt(input: string, password: string): string; getSignature(bytesToBeSign: string, keyPair: ec.KeyPair): Buffer; getAddressFromPubKey(pubKey: curve.base.BasePoint): string; - createNewWallet(BIP44Path?: string): IWalletInfo; - getWalletByMnemonic(mnemonic: string, BIP44Path: string): IWalletInfo; - getWalletByPrivateKey(privateKey: string): IWalletInfo; + createNewWallet(BIP44Path?: TBIP44Path): IWalletInfo; + getWalletByMnemonic(mnemonic: TMnemonic, BIP44Path: TBIP44Path): IWalletInfo; + getWalletByPrivateKey(privateKey: TPrivateKey): IWalletInfo; signTransaction(rawTxn: ITransaction, keyPair: ec.KeyPair): TSignTransaction; sign(hexString: string, keyPair: ec.KeyPair): Buffer; }