WA-234 Wait until transactions are mined

This commit is contained in:
apanizo 2018-06-15 08:40:45 +02:00
parent 9d27d7a7a7
commit 704d6cc083
4 changed files with 30 additions and 38 deletions

View File

@ -8,7 +8,7 @@ import { getGnosisSafeContract } from '~/wallets/safeContracts'
import { getWeb3 } from '~/wallets/getWeb3' import { getWeb3 } from '~/wallets/getWeb3'
import { type Safe } from '~/routes/safe/store/model/safe' import { type Safe } from '~/routes/safe/store/model/safe'
import { sameAddress } from '~/wallets/ethAddresses' import { sameAddress } from '~/wallets/ethAddresses'
import executeTransaction, { checkReceiptStatus } from '~/wallets/ethTransactions' import { checkReceiptStatus, calculateGasOf, calculateGasPrice } from '~/wallets/ethTransactions'
export const TX_NAME_PARAM = 'txName' export const TX_NAME_PARAM = 'txName'
export const TX_DESTINATION_PARAM = 'txDestination' export const TX_DESTINATION_PARAM = 'txDestination'
@ -100,22 +100,25 @@ export const createTransaction = async (
const gnosisSafe = await getSafeEthereumInstance(safeAddress) const gnosisSafe = await getSafeEthereumInstance(safeAddress)
const valueInWei = web3.toWei(txValue, 'ether') const valueInWei = web3.toWei(txValue, 'ether')
const CALL = 0 const CALL = 0
const gasPrice = await calculateGasPrice()
const thresholdIsOne = safe.get('threshold') === 1 const thresholdIsOne = safe.get('threshold') === 1
if (hasOneOwner(safe) || thresholdIsOne) { if (hasOneOwner(safe) || thresholdIsOne) {
const txConfirmationData = const txConfirmationData =
gnosisSafe.contract.execTransactionIfApproved.getData(txDest, valueInWei, data, CALL, nonce) gnosisSafe.contract.execTransactionIfApproved.getData(txDest, valueInWei, data, CALL, nonce)
const txHash = await executeTransaction(txConfirmationData, user, safeAddress) const gas = await calculateGasOf(txConfirmationData, user, safeAddress)
checkReceiptStatus(txHash) const txHash =
await gnosisSafe.execTransactionIfApproved(txDest, valueInWei, data, CALL, nonce, { from: user, gas, gasPrice })
await checkReceiptStatus(txHash.tx)
const executedConfirmations: List<Confirmation> = buildExecutedConfirmationFrom(safe.get('owners'), user) const executedConfirmations: List<Confirmation> = buildExecutedConfirmationFrom(safe.get('owners'), user)
return storeTransaction(txName, nonce, txDest, txValue, user, executedConfirmations, txHash, safeAddress, safe.get('threshold'), data) return storeTransaction(txName, nonce, txDest, txValue, user, executedConfirmations, txHash, safeAddress, safe.get('threshold'), data)
} }
const txConfirmationData = const txData = gnosisSafe.contract.approveTransactionWithParameters.getData(txDest, valueInWei, data, CALL, nonce)
gnosisSafe.contract.approveTransactionWithParameters.getData(txDest, valueInWei, data, CALL, nonce) const gas = await calculateGasOf(txData, user, safeAddress)
const txConfirmationHash = await executeTransaction(txConfirmationData, user, safeAddress) const txConfirmationHash = await gnosisSafe
checkReceiptStatus(txConfirmationHash) .approveTransactionWithParameters(txDest, valueInWei, txData, CALL, nonce, { from: user, gas, gasPrice })
await checkReceiptStatus(txConfirmationHash)
const confirmations: List<Confirmation> = buildConfirmationsFrom(safe.get('owners'), user, txConfirmationHash) const confirmations: List<Confirmation> = buildConfirmationsFrom(safe.get('owners'), user, txConfirmationHash)

View File

@ -8,7 +8,7 @@ import { getGnosisSafeContract } from '~/wallets/safeContracts'
import { getWeb3 } from '~/wallets/getWeb3' import { getWeb3 } from '~/wallets/getWeb3'
import { sameAddress } from '~/wallets/ethAddresses' import { sameAddress } from '~/wallets/ethAddresses'
import { EXECUTED_CONFIRMATION_HASH } from '~/routes/safe/component/AddTransaction/createTransactions' import { EXECUTED_CONFIRMATION_HASH } from '~/routes/safe/component/AddTransaction/createTransactions'
import executeTransaction, { checkReceiptStatus } from '~/wallets/ethTransactions' import { checkReceiptStatus, calculateGasOf, calculateGasPrice } from '~/wallets/ethTransactions'
export const updateTransaction = ( export const updateTransaction = (
name: string, name: string,
@ -51,8 +51,11 @@ const execTransaction = async (
const web3 = getWeb3() const web3 = getWeb3()
const valueInWei = web3.toWei(txValue, 'ether') const valueInWei = web3.toWei(txValue, 'ether')
const txData = await gnosisSafe.contract.execTransactionIfApproved.getData(destination, valueInWei, data, CALL, nonce) const txData = await gnosisSafe.contract.execTransactionIfApproved.getData(destination, valueInWei, data, CALL, nonce)
const gas = await calculateGasOf(txData, executor, gnosisSafe.address)
const gasPrice = await calculateGasPrice()
return executeTransaction(txData, executor, gnosisSafe.address) return gnosisSafe
.execTransactionIfApproved(destination, valueInWei, txData, CALL, nonce, { from: executor, gas, gasPrice })
} }
const execConfirmation = async ( const execConfirmation = async (
@ -66,10 +69,13 @@ const execConfirmation = async (
const CALL = getOperation() const CALL = getOperation()
const web3 = getWeb3() const web3 = getWeb3()
const valueInWei = web3.toWei(txValue, 'ether') const valueInWei = web3.toWei(txValue, 'ether')
const txConfirmationData = const txData = await gnosisSafe.contract
await gnosisSafe.contract.approveTransactionWithParameters.getData(txDestination, valueInWei, data, CALL, nonce) .approveTransactionWithParameters.getData(txDestination, valueInWei, data, CALL, nonce)
const gas = await calculateGasOf(txData, executor, gnosisSafe.address)
const gasPrice = await calculateGasPrice()
return executeTransaction(txConfirmationData, executor, gnosisSafe.address) return gnosisSafe
.approveTransactionWithParameters(txDestination, valueInWei, data, CALL, nonce, { from: executor, gas, gasPrice })
} }
const updateConfirmations = (confirmations: List<Confirmation>, userAddress: string, txHash: string) => const updateConfirmations = (confirmations: List<Confirmation>, userAddress: string, txHash: string) =>
@ -116,9 +122,9 @@ export const processTransaction = async (
? await execTransaction(gnosisSafe, txDestination, txValue, nonce, userAddress, data) ? await execTransaction(gnosisSafe, txDestination, txValue, nonce, userAddress, data)
: await execConfirmation(gnosisSafe, txDestination, txValue, nonce, userAddress, data) : await execConfirmation(gnosisSafe, txDestination, txValue, nonce, userAddress, data)
checkReceiptStatus(txHash) checkReceiptStatus(txHash.tx)
const confirmationHash = thresholdReached ? EXECUTED_CONFIRMATION_HASH : txHash const confirmationHash = thresholdReached ? EXECUTED_CONFIRMATION_HASH : txHash.tx
const executedConfirmations: List<Confirmation> = updateConfirmations(tx.get('confirmations'), userAddress, confirmationHash) const executedConfirmations: List<Confirmation> = updateConfirmations(tx.get('confirmations'), userAddress, confirmationHash)
return updateTransaction( return updateTransaction(
@ -128,7 +134,7 @@ export const processTransaction = async (
txValue, txValue,
userAddress, userAddress,
executedConfirmations, executedConfirmations,
thresholdReached ? txHash : '', thresholdReached ? txHash.tx : '',
safeAddress, safeAddress,
threshold, threshold,
data, data,

View File

@ -2,7 +2,7 @@
import { getWeb3 } from '~/wallets/getWeb3' import { getWeb3 } from '~/wallets/getWeb3'
import { getGnosisSafeContract, getCreateDailyLimitExtensionContract } from '~/wallets/safeContracts' import { getGnosisSafeContract, getCreateDailyLimitExtensionContract } from '~/wallets/safeContracts'
import { type DailyLimitProps } from '~/routes/safe/store/model/dailyLimit' import { type DailyLimitProps } from '~/routes/safe/store/model/dailyLimit'
import executeTransaction, { checkReceiptStatus } from '~/wallets/ethTransactions' import { checkReceiptStatus, calculateGasOf, calculateGasPrice } from '~/wallets/ethTransactions'
export const LIMIT_POSITION = 0 export const LIMIT_POSITION = 0
export const SPENT_TODAY_POS = 1 export const SPENT_TODAY_POS = 1
@ -44,9 +44,11 @@ const withdrawn = async (values: Object, safeAddress: string, userAccount: strin
const value = web3.toWei(values[VALUE_PARAM], 'ether') const value = web3.toWei(values[VALUE_PARAM], 'ether')
const dailyLimitData = dailyLimitModule.contract.executeDailyLimit.getData(0, destination, value) const dailyLimitData = dailyLimitModule.contract.executeDailyLimit.getData(0, destination, value)
const gas = await calculateGasOf(dailyLimitData, userAccount, dailyLimitModule.address)
const gasPrice = await calculateGasPrice()
const txHash = await executeTransaction(dailyLimitData, userAccount, dailyLimitModule.address) const txHash = await dailyLimitModule.executeDailyLimit(0, destination, value, { from: userAccount, gas, gasPrice })
checkReceiptStatus(txHash) checkReceiptStatus(txHash.tx)
} }
export default withdrawn export default withdrawn

View File

@ -51,22 +51,3 @@ export const calculateGasOf = async (data: Object, from: string, to: string) =>
return gas * 2 return gas * 2
} }
const executeTransaction = async (data: Object, from: string, to: string) => {
const web3 = getWeb3()
const gas = await calculateGasOf(data, from, to)
let gasPrice
try {
gasPrice = await calculateGasPrice()
} catch (err) {
gasPrice = await promisify(cb => web3.eth.getGasPrice(cb))
}
return promisify(cb => web3.eth.sendTransaction({
from, to, data, gas, gasPrice,
}, cb))
}
export default executeTransaction