Add OrThrow suffix to getContractAddressesForNetwork

This commit is contained in:
Alex Browne 2018-10-15 14:22:48 -07:00
parent e3af06ab10
commit 38b146c395
4 changed files with 8 additions and 7 deletions

View File

@ -12,13 +12,14 @@ yarn add @0xproject/contract-addresses
**Import** **Import**
```typescript ```typescript
import { getContractAddressesForNetwork } from '@0xproject/contract-addresses'; import { getContractAddressesForNetworkOrThrow } from '@0xproject/contract-addresses';
``` ```
or or
```javascript ```javascript
var getContractAddressesForNetwork = require('@0xproject/contract-addresses').getContractAddressesForNetwork; var getContractAddressesForNetworkOrThrow = require('@0xproject/contract-addresses')
.getContractAddressesForNetworkOrThrow;
``` ```
## Contributing ## Contributing

View File

@ -52,12 +52,13 @@ const networkToAddresses: { [networkId: number]: ContractAddresses } = {
/** /**
* Used to get addresses of contracts that have been deployed to either the * Used to get addresses of contracts that have been deployed to either the
* Ethereum mainnet or a supported testnet. * Ethereum mainnet or a supported testnet. Throws if there are no known
* contracts deployed on the corresponding network.
* @param networkId The desired networkId. * @param networkId The desired networkId.
* @returns The set of addresses for contracts which have been deployed on the * @returns The set of addresses for contracts which have been deployed on the
* given networkId. * given networkId.
*/ */
export function getContractAddressesForNetwork(networkId: NetworkId): ContractAddresses { export function getContractAddressesForNetworkOrThrow(networkId: NetworkId): ContractAddresses {
if (_.isUndefined(networkToAddresses[networkId])) { if (_.isUndefined(networkToAddresses[networkId])) {
throw new Error(`Unknown network id (${networkId}). No known 0x contracts have been deployed on this network.`); throw new Error(`Unknown network id (${networkId}). No known 0x contracts have been deployed on this network.`);
} }

View File

@ -1,4 +1,3 @@
import { ContractAddresses, getContractAddressesForNetwork, NetworkId } from '@0xproject/contract-addresses';
import { AbiDecoder, intervalUtils, logUtils } from '@0xproject/utils'; import { AbiDecoder, intervalUtils, logUtils } from '@0xproject/utils';
import { marshaller, Web3Wrapper } from '@0xproject/web3-wrapper'; import { marshaller, Web3Wrapper } from '@0xproject/web3-wrapper';
import { import {

View File

@ -1,4 +1,4 @@
import { ContractAddresses, getContractAddressesForNetwork, NetworkId } from '@0xproject/contract-addresses'; import { ContractAddresses, getContractAddressesForNetworkOrThrow, NetworkId } from '@0xproject/contract-addresses';
import * as _ from 'lodash'; import * as _ from 'lodash';
/** /**
@ -11,5 +11,5 @@ export function _getDefaultContractAddresses(networkId: number): ContractAddress
`No default contract addresses found for the given network id (${networkId}). If you want to use ContractWrappers on this network, you must manually pass in the contract address(es) to the constructor.`, `No default contract addresses found for the given network id (${networkId}). If you want to use ContractWrappers on this network, you must manually pass in the contract address(es) to the constructor.`,
); );
} }
return getContractAddressesForNetwork(networkId); return getContractAddressesForNetworkOrThrow(networkId);
} }