submitting tx to history service wip
This commit is contained in:
parent
b240c08783
commit
cf4a58f7a3
|
@ -3,4 +3,4 @@ export * from './gas'
|
||||||
export * from './send'
|
export * from './send'
|
||||||
export * from './safeBlockchainOperations'
|
export * from './safeBlockchainOperations'
|
||||||
export * from './safeTxSignerEIP712'
|
export * from './safeTxSignerEIP712'
|
||||||
export * from './saveTxViaService'
|
export * from './txHistory'
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// @flow
|
// @flow
|
||||||
import { List } from 'immutable'
|
import { List } from 'immutable'
|
||||||
import { calculateGasOf, checkReceiptStatus, calculateGasPrice } from '~/logic/wallets/ethTransactions'
|
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 { getGnosisSafeInstanceAt } from '~/logic/contracts/safeContracts'
|
||||||
import { buildSignaturesFrom } from '~/logic/safe/safeTxSigner'
|
import { buildSignaturesFrom } from '~/logic/safe/safeTxSigner'
|
||||||
import { generateMetamaskSignature, generateTxGasEstimateFrom, estimateDataGas } from '~/logic/safe/transactions'
|
import { generateMetamaskSignature, generateTxGasEstimateFrom, estimateDataGas } from '~/logic/safe/transactions'
|
||||||
|
@ -49,7 +49,7 @@ export const approveTransaction = async (
|
||||||
const txHash = txReceipt.tx
|
const txHash = txReceipt.tx
|
||||||
await checkReceiptStatus(txHash)
|
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
|
return txHash
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,10 +5,11 @@ import { EMPTY_DATA } from '~/logic/wallets/ethTransactions'
|
||||||
import { isEther } from '~/logic/tokens/utils/tokenHelpers'
|
import { isEther } from '~/logic/tokens/utils/tokenHelpers'
|
||||||
import { type Token } from '~/logic/tokens/store/model/token'
|
import { type Token } from '~/logic/tokens/store/model/token'
|
||||||
import { getGnosisSafeInstanceAt } from '~/logic/contracts/safeContracts'
|
import { getGnosisSafeInstanceAt } from '~/logic/contracts/safeContracts'
|
||||||
import { saveTxViaService } from '~/logic/safe/transactions'
|
import { saveTxToHistory } from '~/logic/safe/transactions'
|
||||||
|
|
||||||
export const CALL = 0
|
export const CALL = 0
|
||||||
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'
|
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'
|
||||||
|
export const EXECUTION_TX_TYPE = 'execution'
|
||||||
|
|
||||||
export const executeTransaction = async (
|
export const executeTransaction = async (
|
||||||
safeInstance: any,
|
safeInstance: any,
|
||||||
|
@ -39,17 +40,18 @@ export const executeTransaction = async (
|
||||||
sigs,
|
sigs,
|
||||||
{ from: sender },
|
{ from: sender },
|
||||||
)
|
)
|
||||||
await saveTxViaService(
|
|
||||||
|
await saveTxToHistory(
|
||||||
safeInstance.address,
|
safeInstance.address,
|
||||||
to,
|
to,
|
||||||
valueInWei,
|
valueInWei,
|
||||||
data,
|
data,
|
||||||
|
CALL,
|
||||||
nonce,
|
nonce,
|
||||||
0,
|
|
||||||
tx.tx, // tx hash,
|
tx.tx, // tx hash,
|
||||||
sender,
|
sender,
|
||||||
|
EXECUTION_TX_TYPE,
|
||||||
)
|
)
|
||||||
console.log(tx.tx)
|
|
||||||
|
|
||||||
return tx
|
return tx
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
@ -3,6 +3,7 @@ import axios from 'axios'
|
||||||
import { getWeb3 } from '~/logic/wallets/getWeb3'
|
import { getWeb3 } from '~/logic/wallets/getWeb3'
|
||||||
import { getTxServiceUriFrom, getTxServiceHost } from '~/config'
|
import { getTxServiceUriFrom, getTxServiceHost } from '~/config'
|
||||||
import { getGnosisSafeInstanceAt } from '~/logic/contracts/safeContracts'
|
import { getGnosisSafeInstanceAt } from '~/logic/contracts/safeContracts'
|
||||||
|
import { ZERO_ADDRESS } from '~/logic/wallets/ethAddresses'
|
||||||
|
|
||||||
export type TxServiceType = 'confirmation' | 'execution' | 'initialised'
|
export type TxServiceType = 'confirmation' | 'execution' | 'initialised'
|
||||||
export type Operation = 0 | 1 | 2
|
export type Operation = 0 | 1 | 2
|
||||||
|
@ -13,7 +14,7 @@ const calculateBodyFrom = async (
|
||||||
valueInWei: number,
|
valueInWei: number,
|
||||||
data: string,
|
data: string,
|
||||||
operation: Operation,
|
operation: Operation,
|
||||||
nonce: number,
|
nonce: string | number,
|
||||||
transactionHash: string,
|
transactionHash: string,
|
||||||
sender: string,
|
sender: string,
|
||||||
type: TxServiceType,
|
type: TxServiceType,
|
||||||
|
@ -27,13 +28,13 @@ const calculateBodyFrom = async (
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
0,
|
ZERO_ADDRESS,
|
||||||
0,
|
ZERO_ADDRESS,
|
||||||
nonce,
|
nonce,
|
||||||
)
|
)
|
||||||
|
|
||||||
return JSON.stringify({
|
return {
|
||||||
to: getWeb3().toChecksumAddress(to),
|
to: getWeb3().utils.toChecksumAddress(to),
|
||||||
value: valueInWei,
|
value: valueInWei,
|
||||||
data,
|
data,
|
||||||
operation,
|
operation,
|
||||||
|
@ -41,37 +42,36 @@ const calculateBodyFrom = async (
|
||||||
safeTxGas: 0,
|
safeTxGas: 0,
|
||||||
dataGas: 0,
|
dataGas: 0,
|
||||||
gasPrice: 0,
|
gasPrice: 0,
|
||||||
gasToken: null,
|
gasToken: ZERO_ADDRESS,
|
||||||
refundReceiver: null,
|
refundReceiver: ZERO_ADDRESS,
|
||||||
contractTransactionHash,
|
contractTransactionHash,
|
||||||
transactionHash,
|
transactionHash,
|
||||||
sender: getWeb3().toChecksumAddress(sender),
|
sender: getWeb3().utils.toChecksumAddress(sender),
|
||||||
type,
|
type,
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const buildTxServiceUrl = (safeAddress: string) => {
|
export const buildTxServiceUrl = (safeAddress: string) => {
|
||||||
const host = getTxServiceHost()
|
const host = getTxServiceHost()
|
||||||
const address = getWeb3().toChecksumAddress(safeAddress)
|
const address = getWeb3().utils.toChecksumAddress(safeAddress)
|
||||||
const base = getTxServiceUriFrom(address)
|
const base = getTxServiceUriFrom(address)
|
||||||
return `${host}${base}`
|
return `${host}${base}`
|
||||||
}
|
}
|
||||||
|
|
||||||
export const submitOperation = async (
|
export const saveTxToHistory = async (
|
||||||
safeAddress: string,
|
safeAddress: string,
|
||||||
to: string,
|
to: string,
|
||||||
valueInWei: number,
|
valueInWei: number,
|
||||||
data: string,
|
data: string,
|
||||||
operation: Operation,
|
operation: Operation,
|
||||||
nonce: number,
|
nonce: number | string,
|
||||||
txHash: string,
|
txHash: string,
|
||||||
sender: string,
|
sender: string,
|
||||||
type: TxServiceType,
|
type: TxServiceType,
|
||||||
) => {
|
) => {
|
||||||
const url = buildTxServiceUrl(safeAddress)
|
const url = buildTxServiceUrl(safeAddress)
|
||||||
const body = await calculateBodyFrom(safeAddress, to, valueInWei, data, operation, nonce, txHash, sender, type)
|
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) {
|
if (response.status !== 202) {
|
||||||
return Promise.reject(new Error('Error submitting the transaction'))
|
return Promise.reject(new Error('Error submitting the transaction'))
|
||||||
|
|
Loading…
Reference in New Issue