Skip to content

Commit

Permalink
WA-206: Integrate service for transaction execution (#199)
Browse files Browse the repository at this point in the history
  • Loading branch information
rmeissner authored Jul 5, 2018
1 parent 1ae8f44 commit 1c0d24c
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 287 deletions.
3 changes: 0 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,6 @@ dependencies {
}
implementation "com.github.gnosis.svalinn-kotlin:utils-ethereum:$versions.svalinn"
implementation "com.github.gnosis.svalinn-kotlin:mnemonic-android:$versions.svalinn"
implementation ("com.github.gnosis.svalinn-kotlin:ticker:$versions.svalinn") {
exclude group: "com.squareup.retrofit2", module: "converter-moshi"
}
implementation "com.github.gnosis.svalinn-kotlin:security:$versions.svalinn"
implementation "com.github.gnosis.svalinn-kotlin:utils:$versions.svalinn"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ interface RelayServiceApi {
const val BASE_URL = "https://safe-relay.dev.gnosisdev.com/api/"
}

@POST("v1/transactions/")
fun execute(@Body params: ExecuteParams): Single<RelayExecution>
@POST("v1/safes/{address}/transactions/")
fun execute(@Path("address") address: String, @Body params: ExecuteParams): Single<RelayExecution>

@POST("v1/transactions/estimate/")
fun estimate(@Body params: EstimateParams): Single<RelayEstimate>
@POST("v1/safes/{address}/transactions/estimate/")
fun estimate(@Path("address") address: String, @Body params: EstimateParams): Single<RelayEstimate>

@POST("v1/safes/")
fun safeCreation(@Body params: RelaySafeCreationParams): Single<RelaySafeCreation>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@ import java.math.BigInteger

@JsonClass(generateAdapter = true)
data class ExecuteParams(
@Json(name = "safe")
val safe: String,
@Json(name = "to")
val to: String,
@Json(name = "value")
val value: String,
@Json(name = "data")
val data: String,
val data: String?,
@Json(name = "operation")
val operation: Int,
@Json(name = "signatures")
Expand All @@ -27,7 +25,9 @@ data class ExecuteParams(
@Json(name = "dataGas")
val dataGas: String,
@Json(name = "gasPrice")
val gasPrice: String
val gasPrice: String,
@Json(name = "nonce")
val nonce: Long
)

@JsonClass(generateAdapter = true)
Expand All @@ -38,8 +38,6 @@ data class RelayExecution(

@JsonClass(generateAdapter = true)
data class EstimateParams(
@Json(name = "safe")
val safe: String,
@Json(name = "to")
val to: String,
@Json(name = "value")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ class DefaultTransactionExecutionRepository @Inject constructor(
val initial = StringBuilder().append(ERC191_BYTE).append(ERC191_VERSION).append(safeAddress.asEthereumAddressString().removeHexPrefix())
return Sha3Utils.keccak(
parts.fold(
initial,
{ acc, part -> acc.append(part) }).toString().hexToByteArray()
initial
) { acc, part -> acc.append(part) }.toString().hexToByteArray()
)
}

Expand Down Expand Up @@ -126,9 +126,9 @@ class DefaultTransactionExecutionRepository @Inject constructor(
loadSafeState(safeAddress)
.flatMap { info ->
relayServiceApi.estimate(
safeAddress.asEthereumAddressChecksumString(),
EstimateParams(
safeAddress.asEthereumAddressString(),
transaction.wrapped.address.asEthereumAddressString(),
transaction.wrapped.address.asEthereumAddressChecksumString(),
transaction.wrapped.value?.value?.asDecimalString() ?: "0",
transaction.wrapped.data ?: "0x",
transaction.operation.toInt(),
Expand Down Expand Up @@ -233,8 +233,8 @@ class DefaultTransactionExecutionRepository @Inject constructor(
gasPrice: BigInteger
): Single<String> =
loadExecutionParams(safeAddress, transaction, signatures, senderIsOwner, txGas, dataGas, gasPrice)
.flatMap(relayServiceApi::execute)
.flatMap { handleSubmittedTransaction(safeAddress, transaction, it.transactionHash, txGas, dataGas, gasPrice) }
.flatMap { relayServiceApi.execute(safeAddress.asEthereumAddressChecksumString(), it) }
.flatMap { handleSubmittedTransaction(safeAddress, transaction, it.transactionHash.addHexPrefix(), txGas, dataGas, gasPrice) }

private fun loadExecutionParams(
safeAddress: Solidity.Address,
Expand Down Expand Up @@ -265,15 +265,15 @@ class DefaultTransactionExecutionRepository @Inject constructor(

val tx = innerTransaction.wrapped
ExecuteParams(
safeAddress.asEthereumAddressChecksumString(),
tx.address.asEthereumAddressChecksumString(),
tx.value?.value?.asDecimalString() ?: "0",
tx.data ?: "0x",
tx.data,
innerTransaction.operation.toInt(),
serviceSignatures,
txGas.asDecimalString(),
dataGas.asDecimalString(),
gasPrice.asDecimalString()
gasPrice.asDecimalString(),
tx.nonce?.toLong() ?: 0
)
}

Expand Down Expand Up @@ -314,7 +314,7 @@ class DefaultTransactionExecutionRepository @Inject constructor(
.switchMap { status ->
status.success?.let {
Observable.just(it to (status.timestamp ?: 0))
} ?: ethereumRepository.getTransactionReceipt(status.transactionId)
} ?: ethereumRepository.getTransactionReceipt(status.transactionId.addHexPrefix())
.flatMap { receipt ->
ethereumRepository.getBlockByHash(receipt.blockHash)
.map { receipt to (it.timestamp.toLong() * 1000) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import pm.gnosis.heimdall.ui.base.BaseActivity
import pm.gnosis.svalinn.accounts.base.repositories.AccountsRepository
import pm.gnosis.svalinn.common.utils.QrCodeGenerator
import pm.gnosis.svalinn.security.EncryptionManager
import pm.gnosis.ticker.data.repositories.TickerRepository
import javax.inject.Singleton

@Singleton
Expand All @@ -48,7 +47,6 @@ interface ApplicationComponent {
fun accountsRepository(): AccountsRepository
fun addressBookRepository(): AddressBookRepository
fun safeRepository(): GnosisSafeRepository
fun tickerRepository(): TickerRepository
fun tokenRepository(): TokenRepository
fun transactionInfoRepository(): TransactionInfoRepository

Expand Down
Loading

0 comments on commit 1c0d24c

Please sign in to comment.