Merge branch 'development' into feature/web3-wrapper

This commit is contained in:
Leonid
2017-12-08 14:46:51 +03:00
committed by GitHub
8 changed files with 22 additions and 23 deletions

View File

@@ -1,6 +1,6 @@
# ABI Gen
This package allows you to generate contract wrappers in any language from ABI files.
This package allows you to generate TypeScript contract wrappers from ABI files.
It's heavily inspired by [Geth abigen](https://github.com/ethereum/go-ethereum/wiki/Native-DApps:-Go-bindings-to-Ethereum-contracts) but takes a different approach.
You can write your custom handlebars templates which will allow you to seamlessly integrate the generated code into your existing codebase with existing conventions.
@@ -18,10 +18,9 @@ Options:
--abiGlob Glob pattern to search for ABI JSON files [string] [required]
--templates Folder where to search for templates [string] [required]
--output Folder where to put the output files [string] [required]
--fileExtension The extension of the output file [string] [required]
```
## ABI files
You're required to pass a [glob](https://en.wikipedia.org/wiki/Glob_(programming) template where your abi files are located.
You're required to pass a [glob](https://en.wikipedia.org/wiki/Glob_(programming)) template where your abi files are located.
TL;DR - here is the example from 0x.js.
`--abiGlob 'src/artifacts/@(Exchange|Token|TokenTransferProxy|EtherToken|TokenRegistry).json`
@@ -34,7 +33,7 @@ The best way to get started is to copy [0x.js templates](https://github.com/0xPr
We use [handlebars](handlebarsjs.com) template engine under the hood.
You need to have a master template called `contract.mustache`. it will be used to generate each contract wrapper. Although - you don't need and probably shouldn't write all your logic in a single template file. You can write [partial templates](http://handlebarsjs.com/partials.html) and as long as they are within a partials folder - they will be registered and available.
## Which data/context do I get in my templates?
For now you don't get much on top of methods abi and a contract name because it was enough for our use-case, but if you need something else - create a PR.
For now you don't get much on top of methods abi, some usefull helpers and a contract name because it was enough for our use-case, but if you need something else - create a PR.
[Type definition](https://github.com/0xProject/0x.js/tree/development/packages/abi-gen/src/types.ts) of what we pass to a render method.
## Output files
Output files will be generated within an output folder with names converted to camel case and taken from abi file names. If you already have some files in that folder they will be overwritten.

View File

@@ -33,16 +33,11 @@ const args = yargs
type: 'string',
demand: true,
})
.option('fileExtension', {
describe: 'The extension of the output file',
type: 'string',
demand: true,
})
.argv;
function writeOutputFile(name: string, renderedTsCode: string): void {
const fileName = toSnakeCase(name);
const filePath = `${args.output}/${fileName}.${args.fileExtension}`;
const filePath = `${args.output}/${fileName}.ts`;
fs.writeFileSync(filePath, renderedTsCode);
utils.log(`Created: ${chalk.bold(filePath)}`);
}

View File

@@ -3,6 +3,7 @@
vx.x.x
------------------------
* Expose WebSocketOrderbookChannel and associated types to public interface (#251)
* Remove tokenA and tokenB fields from OrdersRequest (#256)
v0.2.0 - _November 29, 2017_
------------------------

View File

@@ -63,7 +63,7 @@ export interface OrderbookChannelHandler {
order: SignedOrder) => void;
onError: (channel: OrderbookChannel, subscriptionOpts: OrderbookChannelSubscriptionOpts,
err: Error) => void;
onClose: (channel: OrderbookChannel) => void;
onClose: (channel: OrderbookChannel, subscriptionOpts: OrderbookChannelSubscriptionOpts) => void;
}
export type OrderbookChannelMessage =
@@ -128,8 +128,6 @@ export interface OrdersRequest {
tokenAddress?: string;
makerTokenAddress?: string;
takerTokenAddress?: string;
tokenA?: string;
tokenB?: string;
maker?: string;
taker?: string;
trader?: string;

View File

@@ -62,7 +62,7 @@ export class WebSocketOrderbookChannel implements OrderbookChannel {
handler.onError(this, subscriptionOpts, wsError);
});
connection.on(WebsocketConnectionEventType.Close, () => {
handler.onClose(this);
handler.onClose(this, subscriptionOpts);
});
connection.on(WebsocketConnectionEventType.Message, message => {
this._handleWebSocketMessage(subscribeMessage.requestId, subscriptionOpts, message, handler);

View File

@@ -61,12 +61,12 @@ describe('HttpClient', () => {
const orders = await relayerClient.getOrdersAsync();
expect(orders).to.be.deep.equal(ordersResponse);
});
it('gets specfic orders for request', async () => {
it('gets specific orders for request', async () => {
const tokenAddress = '0x323b5d4c32345ced77393b3530b1eed0f346429d';
const ordersRequest = {
tokenA: tokenAddress,
tokenAddress,
};
const urlWithQuery = `${url}?tokenA=${tokenAddress}`;
const urlWithQuery = `${url}?tokenAddress=${tokenAddress}`;
fetchMock.get(urlWithQuery, ordersResponseJSON);
const orders = await relayerClient.getOrdersAsync(ordersRequest);
expect(orders).to.be.deep.equal(ordersResponse);

View File

@@ -621,19 +621,24 @@ export class Blockchain {
// 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 networkId: number;
let networkIdIfExists: number;
if (!_.isUndefined(injectedWeb3)) {
try {
networkId = _.parseInt(await promisify<string>(injectedWeb3.version.getNetwork)());
networkIdIfExists = _.parseInt(await promisify<string>(injectedWeb3.version.getNetwork)());
} catch (err) {
// Ignore error and proceed with networkId undefined
}
}
const provider = await Blockchain.getProviderAsync(injectedWeb3, networkId);
this.zeroEx = new ZeroEx(provider, {
const provider = await Blockchain.getProviderAsync(injectedWeb3, networkIdIfExists);
const networkId = !_.isUndefined(networkIdIfExists) ? networkIdIfExists :
configs.isMainnetEnabled ?
constants.MAINNET_NETWORK_ID :
constants.TESTNET_NETWORK_ID;
const zeroExConfigs = {
networkId,
});
};
this.zeroEx = new ZeroEx(provider, zeroExConfigs);
this.updateProviderName(injectedWeb3);
const shouldPollUserAddress = true;
this.web3Wrapper = new Web3Wrapper(this.dispatcher, provider, networkId, shouldPollUserAddress);

View File

@@ -1,4 +1,5 @@
import {Order, ZeroEx} from '0x.js';
import * as _ from 'lodash';
import * as React from 'react';
import ReactTooltip = require('react-tooltip');
import {Blockchain} from 'ts/blockchain';
@@ -49,7 +50,7 @@ export class HashInput extends React.Component<HashInputProps, HashInputState> {
exchangeContractAddress,
expirationUnixTimestampSec: hashData.orderExpiryTimestamp,
feeRecipient: hashData.feeRecipientAddress,
maker: hashData.orderMakerAddress,
maker: _.isEmpty(hashData.orderMakerAddress) ? constants.NULL_ADDRESS : hashData.orderMakerAddress,
makerFee: hashData.makerFee,
makerTokenAddress: hashData.depositTokenContractAddr,
makerTokenAmount: hashData.depositAmount,