本文整理匯總了TypeScript中@0xproject/utils.promisify函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript promisify函數的具體用法?TypeScript promisify怎麽用?TypeScript promisify使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了promisify函數的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: it
it('clears the cache on a Nonce Too Low Error', async () => {
provider = new Web3ProviderEngine();
const nonceTrackerSubprovider = new NonceTrackerSubprovider();
provider.addProvider(nonceTrackerSubprovider);
provider.addProvider(createFixtureSubprovider());
provider.addProvider(
new FixtureSubprovider({
eth_sendRawTransaction: (data: any, next: any, end: any) => {
end(new Error('Transaction nonce is too low'));
},
}),
);
provider.start();
const noncePayload = {
...getTransactionCountPayload,
params: ['0x1f36f546477cda21bf2296c50976f2740247906f', 'pending'],
};
const transaction = new EthereumTx(txParams);
const txPayload = {
...sendTransactionPayload,
params: [transaction.serialize()],
};
const response = await promisify<any>(provider.sendAsync, provider)(noncePayload);
expect(response.result).to.be.eq('0x00');
const secondResponse = await promisify<any>(provider.sendAsync, provider)(noncePayload);
expect(secondResponse.result).to.be.eq('0x00');
try {
await promisify(provider.sendAsync, provider)(txPayload);
} catch (err) {
const thirdResponse = await promisify<any>(provider.sendAsync, provider)(noncePayload);
expect(thirdResponse.result).to.be.eq('0x99');
}
});
示例2: promisify
_.forEach(functionsAbi, (functionAbi: MethodAbi) => {
if (functionAbi.constant) {
const cbStyleCallFunction = this._contract[functionAbi.name].call;
this[functionAbi.name] = promisify(cbStyleCallFunction, this._contract);
this[functionAbi.name].call = promisify(cbStyleCallFunction, this._contract);
} else {
const cbStyleFunction = this._contract[functionAbi.name];
const cbStyleCallFunction = this._contract[functionAbi.name].call;
const cbStyleEstimateGasFunction = this._contract[functionAbi.name].estimateGas;
this[functionAbi.name] = this._promisifyWithDefaultParams(cbStyleFunction);
this[functionAbi.name].estimateGasAsync = promisify(cbStyleEstimateGasFunction);
this[functionAbi.name].sendTransactionAsync = this._promisifyWithDefaultParams(cbStyleFunction);
this[functionAbi.name].call = promisify(cbStyleCallFunction, this._contract);
}
});
示例3: async
return async () => {
logUtils.log(`Processing ETH ${recipientAddress}`);
const userBalance = await promisify<BigNumber>(web3.eth.getBalance)(recipientAddress);
const maxAmountInWei = new BigNumber(web3.toWei(DISPENSE_MAX_AMOUNT_ETHER, 'ether'));
if (userBalance.greaterThanOrEqualTo(maxAmountInWei)) {
logUtils.log(
`User exceeded ETH balance maximum (${maxAmountInWei}) ${recipientAddress} ${userBalance} `,
);
return;
}
const sendTransactionAsync = promisify(web3.eth.sendTransaction);
const txHash = await sendTransactionAsync({
from: configs.DISPENSER_ADDRESS,
to: recipientAddress,
value: web3.toWei(DISPENSE_AMOUNT_ETHER, 'ether'),
});
logUtils.log(`Sent ${DISPENSE_AMOUNT_ETHER} ETH to ${recipientAddress} tx: ${txHash}`);
};
示例4: _onPageLoadInitFireAndForgetAsync
private async _onPageLoadInitFireAndForgetAsync() {
await utils.onPageLoadAsync(); // wait for page to load
// Hack: We need to know the networkId the injectedWeb3 is connected to (if it is defined) in
// order to properly instantiate the web3Wrapper. Since we must use the async call, we cannot
// retrieve it from within the web3Wrapper constructor. This is and should remain the only
// call to a web3 instance outside of web3Wrapper in the entire dapp.
// In addition, if the user has an injectedWeb3 instance that is disconnected from a backing
// Ethereum node, this call will throw. We need to handle this case gracefully
const injectedWeb3 = (window as any).web3;
let networkIdIfExists: number;
if (!_.isUndefined(injectedWeb3)) {
try {
networkIdIfExists = _.parseInt(await promisify<string>(injectedWeb3.version.getNetwork)());
} catch (err) {
// Ignore error and proceed with networkId undefined
}
}
const provider = await Blockchain._getProviderAsync(injectedWeb3, networkIdIfExists);
this.networkId = !_.isUndefined(networkIdIfExists)
? networkIdIfExists
: configs.IS_MAINNET_ENABLED ? constants.NETWORK_ID_MAINNET : constants.NETWORK_ID_KOVAN;
this._dispatcher.updateNetworkId(this.networkId);
const zeroExConfigs = {
networkId: this.networkId,
};
this._zeroEx = new ZeroEx(provider, zeroExConfigs);
this._updateProviderName(injectedWeb3);
const shouldPollUserAddress = true;
this._web3Wrapper = new Web3Wrapper(provider);
this._blockchainWatcher = new BlockchainWatcher(
this._dispatcher,
this._web3Wrapper,
this.networkId,
shouldPollUserAddress,
);
const userAddresses = await this._web3Wrapper.getAvailableAddressesAsync();
this._userAddressIfExists = userAddresses[0];
this._dispatcher.updateUserAddress(this._userAddressIfExists);
await this.fetchTokenInformationAsync();
this._blockchainWatcher.startEmittingNetworkConnectionAndUserBalanceState();
await this._rehydrateStoreWithContractEvents();
}
示例5: _firstSuccessAsync
private static async _firstSuccessAsync(
rpcs: RpcSubprovider[],
payload: JSONRPCRequestPayload,
next: Callback,
): Promise<any> {
let lastErr: Error | undefined;
for (const rpc of rpcs) {
try {
const data = await promisify(rpc.handleRequest.bind(rpc))(payload, next);
return data;
} catch (err) {
lastErr = err;
continue;
}
}
if (!_.isUndefined(lastErr)) {
throw lastErr;
}
}
示例6:
import { promisify } from '@0xproject/utils';
import * as fs from 'fs';
export const fsWrapper = {
readdirAsync: promisify<string[]>(fs.readdir),
readFileAsync: promisify<string>(fs.readFile),
writeFileAsync: promisify<undefined>(fs.writeFile),
mkdirAsync: promisify<undefined>(fs.mkdir),
doesPathExistSync: fs.existsSync,
rmdirSync: fs.rmdirSync,
removeFileAsync: promisify<undefined>(fs.unlink),
};
示例7:
import { promisify } from '@0xproject/utils';
import { NewmanRunSummary, run as newmanRun } from 'newman';
export const utils = {
newmanRunAsync: promisify<NewmanRunSummary>(newmanRun),
};