aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/util/order.ts
diff options
context:
space:
mode:
authorAmir Bandeali <abandeali1@gmail.com>2017-11-30 14:26:51 +0800
committerAmir Bandeali <abandeali1@gmail.com>2017-11-30 23:10:18 +0800
commite85a69655c29a04b7f1a3506c5ecb55433425f7f (patch)
treed085c0f6fd46980c85f92f60adf95a6b8f272c49 /packages/contracts/util/order.ts
parent4b3e0383235ca4ca0127f24c2e05543bb45a56bb (diff)
downloaddexon-sol-tools-e85a69655c29a04b7f1a3506c5ecb55433425f7f.tar
dexon-sol-tools-e85a69655c29a04b7f1a3506c5ecb55433425f7f.tar.gz
dexon-sol-tools-e85a69655c29a04b7f1a3506c5ecb55433425f7f.tar.bz2
dexon-sol-tools-e85a69655c29a04b7f1a3506c5ecb55433425f7f.tar.lz
dexon-sol-tools-e85a69655c29a04b7f1a3506c5ecb55433425f7f.tar.xz
dexon-sol-tools-e85a69655c29a04b7f1a3506c5ecb55433425f7f.tar.zst
dexon-sol-tools-e85a69655c29a04b7f1a3506c5ecb55433425f7f.zip
Fix indentations
Diffstat (limited to 'packages/contracts/util/order.ts')
-rw-r--r--packages/contracts/util/order.ts184
1 files changed, 92 insertions, 92 deletions
diff --git a/packages/contracts/util/order.ts b/packages/contracts/util/order.ts
index 635999348..8e3822188 100644
--- a/packages/contracts/util/order.ts
+++ b/packages/contracts/util/order.ts
@@ -12,98 +12,98 @@ import {OrderParams} from './types';
const web3: Web3 = (global as any).web3;
export class Order {
- public params: OrderParams;
- constructor(params: OrderParams) {
- this.params = params;
- }
- public isValidSignature() {
- const {v, r, s} = this.params;
- if (_.isUndefined(v) || _.isUndefined(r) || _.isUndefined(s)) {
- throw new Error('Cannot call isValidSignature on unsigned order');
+ public params: OrderParams;
+ constructor(params: OrderParams) {
+ this.params = params;
}
- const orderHash = this.getOrderHash();
- const msgHash = ethUtil.hashPersonalMessage(ethUtil.toBuffer(orderHash));
- try {
- const pubKey = ethUtil.ecrecover(msgHash, v, ethUtil.toBuffer(r), ethUtil.toBuffer(s));
- const recoveredAddress = ethUtil.bufferToHex(ethUtil.pubToAddress(pubKey));
- return recoveredAddress === this.params.maker;
- } catch (err) {
- return false;
+ public isValidSignature() {
+ const {v, r, s} = this.params;
+ if (_.isUndefined(v) || _.isUndefined(r) || _.isUndefined(s)) {
+ throw new Error('Cannot call isValidSignature on unsigned order');
+ }
+ const orderHash = this.getOrderHash();
+ const msgHash = ethUtil.hashPersonalMessage(ethUtil.toBuffer(orderHash));
+ try {
+ const pubKey = ethUtil.ecrecover(msgHash, v, ethUtil.toBuffer(r), ethUtil.toBuffer(s));
+ const recoveredAddress = ethUtil.bufferToHex(ethUtil.pubToAddress(pubKey));
+ return recoveredAddress === this.params.maker;
+ } catch (err) {
+ return false;
+ }
+ }
+ public async signAsync() {
+ const orderHash = this.getOrderHash();
+ const signature = await promisify(web3.eth.sign)(this.params.maker, orderHash);
+ const {v, r, s} = ethUtil.fromRpcSig(signature);
+ this.params = _.assign(this.params, {
+ orderHashHex: orderHash,
+ v,
+ r: ethUtil.bufferToHex(r),
+ s: ethUtil.bufferToHex(s),
+ });
+ }
+ public createFill(shouldThrowOnInsufficientBalanceOrAllowance?: boolean, fillTakerTokenAmount?: BigNumber) {
+ const fill = {
+ orderAddresses: [
+ this.params.maker,
+ this.params.taker,
+ this.params.makerToken,
+ this.params.takerToken,
+ this.params.feeRecipient,
+ ],
+ orderValues: [
+ this.params.makerTokenAmount,
+ this.params.takerTokenAmount,
+ this.params.makerFee,
+ this.params.takerFee,
+ this.params.expirationTimestampInSec,
+ this.params.salt,
+ ],
+ fillTakerTokenAmount: fillTakerTokenAmount || this.params.takerTokenAmount,
+ shouldThrowOnInsufficientBalanceOrAllowance: !!shouldThrowOnInsufficientBalanceOrAllowance,
+ v: this.params.v,
+ r: this.params.r,
+ s: this.params.s,
+ };
+ return fill;
+ }
+ public createCancel(cancelTakerTokenAmount?: BigNumber) {
+ const cancel = {
+ orderAddresses: [
+ this.params.maker,
+ this.params.taker,
+ this.params.makerToken,
+ this.params.takerToken,
+ this.params.feeRecipient,
+ ],
+ orderValues: [
+ this.params.makerTokenAmount,
+ this.params.takerTokenAmount,
+ this.params.makerFee,
+ this.params.takerFee,
+ this.params.expirationTimestampInSec,
+ this.params.salt,
+ ],
+ cancelTakerTokenAmount: cancelTakerTokenAmount || this.params.takerTokenAmount,
+ };
+ return cancel;
+ }
+ private getOrderHash(): string {
+ const orderHash = crypto.solSHA3([
+ this.params.exchangeContractAddress,
+ this.params.maker,
+ this.params.taker,
+ this.params.makerToken,
+ this.params.takerToken,
+ this.params.feeRecipient,
+ this.params.makerTokenAmount,
+ this.params.takerTokenAmount,
+ this.params.makerFee,
+ this.params.takerFee,
+ this.params.expirationTimestampInSec,
+ this.params.salt,
+ ]);
+ const orderHashHex = ethUtil.bufferToHex(orderHash);
+ return orderHashHex;
}
- }
- public async signAsync() {
- const orderHash = this.getOrderHash();
- const signature = await promisify(web3.eth.sign)(this.params.maker, orderHash);
- const {v, r, s} = ethUtil.fromRpcSig(signature);
- this.params = _.assign(this.params, {
- orderHashHex: orderHash,
- v,
- r: ethUtil.bufferToHex(r),
- s: ethUtil.bufferToHex(s),
- });
- }
- public createFill(shouldThrowOnInsufficientBalanceOrAllowance?: boolean, fillTakerTokenAmount?: BigNumber) {
- const fill = {
- orderAddresses: [
- this.params.maker,
- this.params.taker,
- this.params.makerToken,
- this.params.takerToken,
- this.params.feeRecipient,
- ],
- orderValues: [
- this.params.makerTokenAmount,
- this.params.takerTokenAmount,
- this.params.makerFee,
- this.params.takerFee,
- this.params.expirationTimestampInSec,
- this.params.salt,
- ],
- fillTakerTokenAmount: fillTakerTokenAmount || this.params.takerTokenAmount,
- shouldThrowOnInsufficientBalanceOrAllowance: !!shouldThrowOnInsufficientBalanceOrAllowance,
- v: this.params.v,
- r: this.params.r,
- s: this.params.s,
- };
- return fill;
- }
- public createCancel(cancelTakerTokenAmount?: BigNumber) {
- const cancel = {
- orderAddresses: [
- this.params.maker,
- this.params.taker,
- this.params.makerToken,
- this.params.takerToken,
- this.params.feeRecipient,
- ],
- orderValues: [
- this.params.makerTokenAmount,
- this.params.takerTokenAmount,
- this.params.makerFee,
- this.params.takerFee,
- this.params.expirationTimestampInSec,
- this.params.salt,
- ],
- cancelTakerTokenAmount: cancelTakerTokenAmount || this.params.takerTokenAmount,
- };
- return cancel;
- }
- private getOrderHash(): string {
- const orderHash = crypto.solSHA3([
- this.params.exchangeContractAddress,
- this.params.maker,
- this.params.taker,
- this.params.makerToken,
- this.params.takerToken,
- this.params.feeRecipient,
- this.params.makerTokenAmount,
- this.params.takerTokenAmount,
- this.params.makerFee,
- this.params.takerFee,
- this.params.expirationTimestampInSec,
- this.params.salt,
- ]);
- const orderHashHex = ethUtil.bufferToHex(orderHash);
- return orderHashHex;
- }
}