From fa1046f9ff39f732762e5589f640a8ae5cbcd973 Mon Sep 17 00:00:00 2001 From: lyd Date: Wed, 5 Sep 2018 16:48:16 +0800 Subject: [PATCH] update according to h5dex --- src/common/utils.js | 6 +++++- src/relay/rpc/account.js | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/common/utils.js b/src/common/utils.js index fcc769e..8971433 100644 --- a/src/common/utils.js +++ b/src/common/utils.js @@ -1,4 +1,4 @@ -import {keccak} from 'ethereumjs-util'; +import {keccak, hashPersonalMessage} from 'ethereumjs-util'; import {toHex, toBig} from './formatter'; /** @@ -28,3 +28,7 @@ export function calculateGas (gasPrice, gasLimit) { return toBig(gasPrice).times(gasLimit).div(1e9); } + +export default { + hashPersonalMessage +}; diff --git a/src/relay/rpc/account.js b/src/relay/rpc/account.js index 7e28726..76c6946 100644 --- a/src/relay/rpc/account.js +++ b/src/relay/rpc/account.js @@ -62,6 +62,10 @@ export default class Account { return getNonce(this.host, owner); } + getAllEstimatedAllocatedAmount (params) + { + return getAllEstimatedAllocatedAmount(this.host, params); + } } /** @@ -208,7 +212,7 @@ export function getTransactions (host, filter) */ export function getEstimatedAllocatedAllowance (host, filter) { - const {owner, token, delegateAddress} = filter; + const {owner} = filter; try { validator.validate({value: owner, type: 'ETH_ADDRESS'}); @@ -376,3 +380,31 @@ export async function getNonce (host, owner) body }); } +/** + * + * @param host + * @param owner + * @param delegateAddress + * @return {Promise.<*>} + */ +export async function getAllEstimatedAllocatedAmount (host, {owner, delegateAddress}) +{ + try + { + validator.validate({value: owner, type: 'ETH_ADDRESS'}); + validator.validate({value: delegateAddress, type: 'ETH_ADDRESS'}); + } + catch (e) + { + return Promise.resolve(new Response(code.PARAM_INVALID.code, code.PARAM_INVALID.msg)); + } + let body = {}; + body.method = 'loopring_getAllEstimatedAllocatedAmount'; + body.params = [{owner, delegateAddress}]; + body.id = id(); + body.jsonrpc = '2.0'; + return request(host, { + method: 'post', + body + }); +}