submitting tx to history service wip

This commit is contained in:
Mikhail Mikheev 2019-06-14 16:10:03 +04:00
parent b240c08783
commit cf4a58f7a3
4 changed files with 23 additions and 21 deletions

View File

@ -3,4 +3,4 @@ export * from './gas'
export * from './send'
export * from './safeBlockchainOperations'
export * from './safeTxSignerEIP712'
export * from './saveTxViaService'
export * from './txHistory'

View File

@ -1,7 +1,7 @@
// @flow
import { List } from 'immutable'
import { calculateGasOf, checkReceiptStatus, calculateGasPrice } from '~/logic/wallets/ethTransactions'
import { type Operation, submitOperation } from '~/logic/safe/safeTxHistory'
import { type Operation, saveTxToHistory } from '~/logic/safe/transactions'
import { getGnosisSafeInstanceAt } from '~/logic/contracts/safeContracts'
import { buildSignaturesFrom } from '~/logic/safe/safeTxSigner'
import { generateMetamaskSignature, generateTxGasEstimateFrom, estimateDataGas } from '~/logic/safe/transactions'
@ -49,7 +49,7 @@ export const approveTransaction = async (
const txHash = txReceipt.tx
await checkReceiptStatus(txHash)
await submitOperation(safeAddress, to, valueInWei, data, operation, nonce, txHash, sender, 'confirmation')
await saveTxToHistory(safeAddress, to, valueInWei, data, operation, nonce, txHash, sender, 'confirmation')
return txHash
}

View File

@ -5,10 +5,11 @@ import { EMPTY_DATA } from '~/logic/wallets/ethTransactions'
import { isEther } from '~/logic/tokens/utils/tokenHelpers'
import { type Token } from '~/logic/tokens/store/model/token'
import { getGnosisSafeInstanceAt } from '~/logic/contracts/safeContracts'
import { saveTxViaService } from '~/logic/safe/transactions'
import { saveTxToHistory } from '~/logic/safe/transactions'
export const CALL = 0
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'
export const EXECUTION_TX_TYPE = 'execution'
export const executeTransaction = async (
safeInstance: any,
@ -39,17 +40,18 @@ export const executeTransaction = async (
sigs,
{ from: sender },
)
await saveTxViaService(
await saveTxToHistory(
safeInstance.address,
to,
valueInWei,
data,
CALL,
nonce,
0,
tx.tx, // tx hash,
sender,
EXECUTION_TX_TYPE,
)
console.log(tx.tx)
return tx
} catch (error) {

View File

@ -3,6 +3,7 @@ import axios from 'axios'
import { getWeb3 } from '~/logic/wallets/getWeb3'
import { getTxServiceUriFrom, getTxServiceHost } from '~/config'
import { getGnosisSafeInstanceAt } from '~/logic/contracts/safeContracts'
import { ZERO_ADDRESS } from '~/logic/wallets/ethAddresses'
export type TxServiceType = 'confirmation' | 'execution' | 'initialised'
export type Operation = 0 | 1 | 2
@ -13,7 +14,7 @@ const calculateBodyFrom = async (
valueInWei: number,
data: string,
operation: Operation,
nonce: number,
nonce: string | number,
transactionHash: string,
sender: string,
type: TxServiceType,
@ -27,13 +28,13 @@ const calculateBodyFrom = async (
0,
0,
0,
0,
0,
ZERO_ADDRESS,
ZERO_ADDRESS,
nonce,
)
return JSON.stringify({
to: getWeb3().toChecksumAddress(to),
return {
to: getWeb3().utils.toChecksumAddress(to),
value: valueInWei,
data,
operation,
@ -41,37 +42,36 @@ const calculateBodyFrom = async (
safeTxGas: 0,
dataGas: 0,
gasPrice: 0,
gasToken: null,
refundReceiver: null,
gasToken: ZERO_ADDRESS,
refundReceiver: ZERO_ADDRESS,
contractTransactionHash,
transactionHash,
sender: getWeb3().toChecksumAddress(sender),
sender: getWeb3().utils.toChecksumAddress(sender),
type,
})
}
}
export const buildTxServiceUrl = (safeAddress: string) => {
const host = getTxServiceHost()
const address = getWeb3().toChecksumAddress(safeAddress)
const address = getWeb3().utils.toChecksumAddress(safeAddress)
const base = getTxServiceUriFrom(address)
return `${host}${base}`
}
export const submitOperation = async (
export const saveTxToHistory = async (
safeAddress: string,
to: string,
valueInWei: number,
data: string,
operation: Operation,
nonce: number,
nonce: number | string,
txHash: string,
sender: string,
type: TxServiceType,
) => {
const url = buildTxServiceUrl(safeAddress)
const body = await calculateBodyFrom(safeAddress, to, valueInWei, data, operation, nonce, txHash, sender, type)
const response = await axios.post(url, { body })
const response = await axios.post(url, body)
if (response.status !== 202) {
return Promise.reject(new Error('Error submitting the transaction'))