Returning Promise.reject(new Error(....)) when checking receipt status and gas calculation

This commit is contained in:
apanizo 2018-08-29 09:21:11 +02:00
parent 8ecf518022
commit 3003805763
1 changed files with 11 additions and 5 deletions

View File

@ -9,7 +9,7 @@ export const EMPTY_DATA = '0x'
export const checkReceiptStatus = async (hash: string) => { export const checkReceiptStatus = async (hash: string) => {
if (!hash) { if (!hash) {
throw new Error('No valid Tx hash to get receipt from') return Promise.reject(new Error('No valid Tx hash to get receipt from'))
} }
const web3 = getWeb3() const web3 = getWeb3()
@ -17,13 +17,15 @@ export const checkReceiptStatus = async (hash: string) => {
const { status } = txReceipt const { status } = txReceipt
if (!status) { if (!status) {
throw new Error('No status found on this transaction receipt') return Promise.reject(new Error('No status found on this transaction receipt'))
} }
const hasError = status === '0x0' const hasError = status === '0x0'
if (hasError) { if (hasError) {
throw new Error('Obtained a transaction failure in the receipt') return Promise.reject(new Error('Obtained a transaction failure in the receipt'))
} }
return Promise.resolve()
} }
export const calculateGasPrice = async () => { export const calculateGasPrice = async () => {
@ -50,7 +52,11 @@ export const calculateGasPrice = async () => {
export const calculateGasOf = async (data: Object, from: string, to: string) => { export const calculateGasOf = async (data: Object, from: string, to: string) => {
const web3 = getWeb3() const web3 = getWeb3()
try {
const gas = await promisify(cb => web3.eth.estimateGas({ data, from, to }, cb)) const gas = await promisify(cb => web3.eth.estimateGas({ data, from, to }, cb))
return gas * 2 return gas * 2
} catch (err) {
return Promise.reject(new Error(err))
}
} }