How to use the 0x.js.ZeroEx.getOrderHashHex function in 0x

To help you get started, we’ve selected a few 0x examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github 0xchange / 0xchange / src / store / actions.js View on Github external
submitOrder ({commit, state, dispatch}, order) {
    // console.log('hier?')
    console.log(order)

    if (typeof order === 'string') order = JSON.parse(order)
    // {
    //   try {
    //     ZeroEx.isValidSignature(order)
    //   } catch (error) {
    //     console.error(error)
    //     dispatch('addNotification', {type: 'error', 'text': 'Order failed, check log for details'})
    //   }
    // }
    try {
      var orderHash = ZeroEx.getOrderHashHex(order)
      console.log('HASH', orderHash)
      return zeroEx.signOrderHashAsync(orderHash, state.addresses[0]).then((ecSignature) => {
        const signedOrder = {
          ...order,
          ecSignature
        }
        // console.log(signedOrder)
        // commit('ADD_ORDER', signedOrder)
        return axios.post('/order/new', signedOrder).then((results) => {
          // console.log(results)
          dispatch('pageServer')
          dispatch('addNotification', {type: 'success', 'text': 'Order Added'})
        }).catch((error) => {
          dispatch('addNotification', {type: 'error', 'text': 'Order failed, check log for details'})
          console.error(error)
        })
github dekz / 0xRelay / domain / lib / order / validations / validOrder.ts View on Github external
predicate: (data, cb) => {
    let result = validator.validate(data.payload, orderSchema);
    if (!result.valid) {
      return cb('Invalid Order', result.errors);
    }

    let order: SignedOrder = data.payload;
    let orderHex = ZeroEx.getOrderHashHex(order);
    let validSignature = ZeroEx.isValidSignature(orderHex, order.ecSignature, order.maker)
    if (!validSignature) {
      return cb('Invalid Order Signature', order.ecSignature);
    }

    // TODO validateOrderFillableOrThrowAsync with an Infura/Local Provider
    cb(null, data);
  }
};
github johnrjj / conduit / src / modules / client / client.ts View on Github external
//   logger.log('debug', `Order ${orderHash} is not fillable`);
    // }
    // const isValidSig = await ZeroEx.isValidSignature(
    //   orderHash,
    //   possibleOrder.ecSignature,
    //   possibleOrder.maker
    // );
    // if (!isValidSig) {
    //   logger.log('debug', `Invalid signature for order: ${orderHash}`);
    //   const e = {
    //     code: 1005,
    //     message: 'Invalid signature',
    //   };
    // }

    const orderHash = ZeroEx.getOrderHashHex(signedOrder);
    const takerTokenRemainingAmount = await this.getRemainingTakerAmount(
      orderHash,
      signedOrder.takerTokenAmount
    );
    const addedOrder = await this.repository.addOrder(
      orderHash,
      takerTokenRemainingAmount,
      signedOrder
    );
    const {
      baseToken,
      quoteToken,
    } = await this.repository.getBaseTokenAndQuoteTokenFromMakerAndTaker(
      addedOrder.takerTokenAddress,
      addedOrder.makerTokenAddress
    );
github dekz / 0xRelay / host / order / services / createOrder.ts View on Github external
public success(data): CreateOrderSuccessResult {
    let correlationId: string = uuid.v4();
    let orderHashHex = ZeroEx.getOrderHashHex(data);
    let orderHash = orderHashHex.split('0x')[1];
    data.id = orderHash;
    let command: Command = {
      'command': 'createOrder',
      'aggregateId': orderHash,
      'id': correlationId,
      'payload': data
    }

    this._msgbus.emitCommand(command);
    return { id: correlationId };
  }
github johnrjj / conduit / src / modules / order-watcher / watcher.ts View on Github external
async watchOrder(order: SignedOrder) {
    const orderHash = ZeroEx.getOrderHashHex(order);
    console.log(orderHash);
    if (this.watchedOrders.has(orderHash)) {
      return;
    }
    this.watchedOrders.add(orderHash);
    return await this.zeroEx.orderStateWatcher.addOrder(order);
  }
github ethfinex / 0x-order-verify / src / App.js View on Github external
})
      return
    }

    try {
      JSON.parse(this.state.order)
    } catch (e) {
      this.setState({
        error: 'Order must be in JSON format i.e. {\'key\':\'value\',...}'
      })
      return
    }

    try {
      let calculatedOrderHash =
      ZeroEx.getOrderHashHex(JSON.parse(this.state.order))
      if (ZeroEx.isValidOrderHash(this.state.hash)) {
        if (calculatedOrderHash === this.state.hash) {
          this.setState({success: true})
        } else {
          this.setState({
            error: 'The hash does not match the order.'
          })
        }
      } else {
        this.setState({
          error: 'The hash should look be in the following format 0x4jdsf...'
        })
      }
    } catch (e) {
      this.setState({
        error: 'Order must conform to the 0x message format (see: https://0xproject.com/wiki#Message-Format)'
github 0xProject / 0x-monorepo / packages / sra-report / src / postman_environment_factory.ts View on Github external
async function createOrderEnvironmentValuesAsync(url: string) {
    const httpClient = new HttpClient(url);
    const orders = await httpClient.getOrdersAsync();
    const orderIfExists = _.head(orders);
    if (!_.isUndefined(orderIfExists)) {
        return [
            createEnvironmentValue('order', JSON.stringify(orderIfExists)),
            createEnvironmentValue('orderMaker', orderIfExists.maker),
            createEnvironmentValue('orderTaker', orderIfExists.taker),
            createEnvironmentValue('orderFeeRecipient', orderIfExists.feeRecipient),
            createEnvironmentValue('orderHash', ZeroEx.getOrderHashHex(orderIfExists)),
        ];
    } else {
        logUtils.log(`${chalk.red(`No orders from /orders found`)}`);
        return [
            createEnvironmentValue('order', ''),
            createEnvironmentValue('orderMaker', ''),
            createEnvironmentValue('orderTaker', ''),
            createEnvironmentValue('orderFeeRecipient', ''),
            createEnvironmentValue('orderHash', ''),
        ];
    }
}
function getContractAddresses(networkId: number) {
github johnrjj / conduit / src / modules / order-watcher / watcher.ts View on Github external
private async handleOrderAddedEvent(orderAddedEvent: OrderEvent) {
    const { type, payload } = orderAddedEvent;
    const signedOrder = deserializeSignedOrder(orderAddedEvent.payload.order as any);
    const orderHash = ZeroEx.getOrderHashHex(orderAddedEvent.payload.order);
    this.log(
      'debug',
      `OrderWatcher: New order added, adding to active watcher ${orderHash}`,
      orderAddedEvent
    );
    this.watchOrder(signedOrder);
  }