Skip to content

Commit

Permalink
Fix some minor issues such as magic strings
Browse files Browse the repository at this point in the history
Some magic strings got extracted to a constant in the gradle build
config.
  • Loading branch information
Chris Lemaire committed May 23, 2021
1 parent 5da60e5 commit c8cd547
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 50 deletions.
8 changes: 8 additions & 0 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ android {

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'consumer-rules.pro'

buildConfigField "String", "DEFAULT_GATEWAY_IP", "\"gateway.euro-token.nl\""
buildConfigField "Integer", "DEFAULT_GATEWAY_PORT", "8090"
buildConfigField "String", "DEFAULT_GATEWAY_PK", "\"4c69624e61434c504b3a035fd325276e03b9d0d106a91353cdd00f7a21aa861be79226224809cfedf80cbcc0e210c2ddc2f91a1fbc3e1e3cd0622e32027a27a8be7f5d28a73b42c0369f\""
buildConfigField "String", "DEFAULT_GATEWAY_NAME", "\"Demo Gateway\""

buildConfigField "String", "BITCOIN_FAUCET", "\"http://134.122.59.107:3000\""
buildConfigField "String", "BITCOIN_DEFAULT_PEER", "\"134.122.59.107\""
}

buildTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package nl.tudelft.trustchain.common.bitcoin
import android.util.Log
import com.google.common.util.concurrent.Service
import nl.tudelft.ipv8.keyvault.PublicKey
import nl.tudelft.trustchain.common.BuildConfig
import nl.tudelft.trustchain.common.eurotoken.TransactionRepository
import org.bitcoinj.core.ECKey
import org.bitcoinj.core.PeerAddress
Expand All @@ -16,7 +17,6 @@ class WalletService {

companion object {
private lateinit var globalWallet: WalletAppKit
private val bitcoinFaucetEndpoint = "http://134.122.59.107:3000"
private val walletStore: MutableMap<String, WalletAppKit> = mutableMapOf()
val params: RegTestParams = RegTestParams.get()
private lateinit var lastDir: File
Expand Down Expand Up @@ -72,12 +72,18 @@ class WalletService {

if (wallet().balance.isZero) {
val address = wallet().issuedReceiveAddresses.first().toString()
URL("$bitcoinFaucetEndpoint?id=$address").readBytes()
URL("${BuildConfig.BITCOIN_FAUCET}?id=$address").readBytes()
}
}
}

app.setPeerNodes(PeerAddress(params, InetAddress.getByName("134.122.59.107"), params.port))
app.setPeerNodes(
PeerAddress(
params,
InetAddress.getByName(BuildConfig.BITCOIN_DEFAULT_PEER),
params.port
)
)

app.setAutoSave(true)
app.setBlockingStartup(false)
Expand All @@ -103,7 +109,11 @@ class WalletService {
"amount" to tx.getValueSentToMe(wallet).toFriendlyString()
)
Log.d("bitcoin_received", "Bitcoins received making a note on my chain")
transactionRepository.trustChainCommunity.createProposalBlock("bitcoin_transfer", transaction, publicKey.keyToBin())
transactionRepository.trustChainCommunity.createProposalBlock(
"bitcoin_transfer",
transaction,
publicKey.keyToBin()
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ package nl.tudelft.trustchain.eurotoken.ui.settings

import nl.tudelft.ipv8.keyvault.defaultCryptoProvider
import nl.tudelft.ipv8.util.hexToBytes
import nl.tudelft.trustchain.common.BuildConfig
import nl.tudelft.trustchain.common.eurotoken.GatewayStore

object DefaultGateway {
val ip = "188.166.94.39" // "gateway.euro-token.nl"
val port = 8090
val publicKey =
"4c69624e61434c504b3aa57e128a49ca6f2779668b39e3d57e56ea624b57255432cfa4c693092351bb4c110d379ca5822a4e43d5863909a1bccaea18c1735027a78ae876dc9f11ca01e4"
// "4c69624e61434c504b3a035fd325276e03b9d0d106a91353cdd00f7a21aa861be79226224809cfedf80cbcc0e210c2ddc2f91a1fbc3e1e3cd0622e32027a27a8be7f5d28a73b42c0369f"
val name = "Demo gateway"


fun addGateway(store: GatewayStore) {
val key = defaultCryptoProvider.keyFromPublicBin(publicKey.hexToBytes())
store.addGateway(key, name, ip, port.toLong(), true)
val key =
defaultCryptoProvider.keyFromPublicBin(BuildConfig.DEFAULT_GATEWAY_PK.hexToBytes())
store.addGateway(
key,
BuildConfig.DEFAULT_GATEWAY_NAME,
BuildConfig.DEFAULT_GATEWAY_IP,
BuildConfig.DEFAULT_GATEWAY_PORT.toLong(),
true
)
}
}
1 change: 1 addition & 0 deletions liquidity-pool/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/build
**/.DS_store
12 changes: 10 additions & 2 deletions liquidity-pool/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ android {

consumerProguardFiles "consumer-rules.pro"

// The address of the MultiSig wallet deployed on the goerli test network.
buildConfigField "String", "ETH_TEST_MULTISIG_ADDR", "\"0x2DfEecF7d2f5363149cC73cAb96C00575c732170\""

// The default bitcoin/eurotoken wallet address that is filled in for the pool at startup. This address
// is mostly used for testing and should be replaced with a real address as soon as a real pool
// is up and running.
buildConfigField "String", "DEFAULT_EURO_POOL_ADDR", "\"4c69624e61434c504b3a85f8c38cec5caa72c2e23da91d0288d7f49615ee400ca82e97e925e1a2f7ae33460843aea94611d04eb535f463a9857f592a7cb072eb7e0b52f080ef078c7c5f\""
buildConfigField "String", "DEFAULT_BTC_POOL_ADDR", "\"mv7x4cqQMM8ptFgiHwJZTMTQTcTFV5rteU\""
}

buildTypes {
Expand Down Expand Up @@ -99,10 +107,10 @@ dependencies {

// Wallet libraries
implementation group: 'org.bitcoinj', name: 'bitcoinj-core', version: '0.15.10'
implementation (group: 'org.web3j', name: 'core', version: '4.6.0-android') {
implementation(group: 'org.web3j', name: 'core', version: '4.6.0-android') {
exclude group: 'org.bouncycastle'
}
implementation group: 'org.ethereum', name:'geth-android-all-1.10.1-c2d2f4ed', ext:'aar'
implementation group: 'org.ethereum', name: 'geth-android-all-1.10.1-c2d2f4ed', ext: 'aar'

// Testing
testImplementation "junit:junit:4.12"
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package nl.tudelft.trustchain.liquidity.data

import kotlinx.coroutines.delay
import nl.tudelft.trustchain.liquidity.BuildConfig
import nl.tudelft.trustchain.liquidity.data.ethereum.contracts.geth.MultiSigWallet
import org.ethereum.geth.*

Expand All @@ -13,24 +14,13 @@ class EthereumGethMultiSigWallet(gethWallet: EthereumGethWallet) {
init {
singleGethWallet = gethWallet
gethNode = gethWallet.node
// val transactOpts = TransactOpts()
// transactOpts.setContext(wallet.context)
// transactOpts.from = wallet.account.address
// transactOpts.gasLimit = 8000000
// transactOpts.gasPrice = BigInt(2)
// transactOpts.setSigner(MySigner(wallet.account, wallet.keyStore, wallet.password, BigInt(wallet.nodeConfig.ethereumNetworkID)))
// transactOpts.nonce = wallet.node.ethereumClient.getPendingNonceAt(wallet.context, wallet.account.address)

// val ownersAddresses = Addresses()
// ownersAddresses.append(wallet.account.address)
// instance = MultiSigWallet.deploy(transactOpts, wallet.node.ethereumClient, ownersAddresses, BigInt(1))
}

private suspend fun bindContract() {
// if contract already bound, don't do anything
if (contractBound) return
// else, let's bind!
val contractAddressHex = "0x2DfEecF7d2f5363149cC73cAb96C00575c732170"
val contractAddressHex = BuildConfig.ETH_TEST_MULTISIG_ADDR
val contractAddress = Geth.newAddressFromHex(contractAddressHex)
// wait until Geth node has at least 1 peer
while (!nodeConnected()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import nl.tudelft.trustchain.common.bitcoin.WalletService
import nl.tudelft.trustchain.common.eurotoken.GatewayStore
import nl.tudelft.trustchain.common.eurotoken.TransactionRepository
import nl.tudelft.trustchain.common.ui.BaseFragment
import nl.tudelft.trustchain.liquidity.BuildConfig
import nl.tudelft.trustchain.liquidity.R
import nl.tudelft.trustchain.liquidity.data.EuroTokenWallet
import org.bitcoinj.core.*
Expand Down Expand Up @@ -96,8 +97,8 @@ class PoolFragment : BaseFragment(R.layout.fragment_pool) {
}

lifecycleScope.launchWhenStarted {
poolBitcoinAddress = sharedPreference.getString("poolBitcoinAddress", "mv7x4cqQMM8ptFgiHwJZTMTQTcTFV5rteU").toString()
poolEuroAddress = sharedPreference.getString("poolEuroAddress", "4c69624e61434c504b3a85f8c38cec5caa72c2e23da91d0288d7f49615ee400ca82e97e925e1a2f7ae33460843aea94611d04eb535f463a9857f592a7cb072eb7e0b52f080ef078c7c5f").toString()
poolBitcoinAddress = sharedPreference.getString("poolBitcoinAddress", BuildConfig.DEFAULT_BTC_POOL_ADDR).toString()
poolEuroAddress = sharedPreference.getString("poolEuroAddress", BuildConfig.DEFAULT_EURO_POOL_ADDR).toString()
val btcTransferTXID = sharedPreference.getString("btcTransferTXID", null)
if (btcTransferTXID != null) {
btcTransaction = btcWallet.getTransaction(Sha256Hash.wrap(btcTransferTXID))
Expand All @@ -113,19 +114,8 @@ class PoolFragment : BaseFragment(R.layout.fragment_pool) {
// tradeTransaction is the last trade that has occurred
tradeTransaction = transactionRepository.getTransactionWithHash(tradeTXID.hexToBytes())
}
/**
* if transaction is pending from before, disable button
* TODO: Uncomment line below when not testing
*/
// if (getTransactionStatus() == "Pending" || status["btc"] == Status.PENDING || status["eur"] == Status.PENDING) {
// convert_tokens.isEnabled = false
// convert_tokens.setBackgroundColor(Color.parseColor("#808080"))
// }

convert_tokens.setOnClickListener {
// TODO grey out button when disabled
// convert_tokens.isEnabled = false
// convert_tokens.setBackgroundColor(Color.parseColor("#808080"));
if (selectedSupplyToken == "BTC") {
btcTransaction(suppliedAmount)
}
Expand Down Expand Up @@ -172,15 +162,6 @@ class PoolFragment : BaseFragment(R.layout.fragment_pool) {
completeTransaction()
}

// TODO: do we have to check other states? Unknown for example?
// if (getTransactionStatus() == "Pending") {
// convert_tokens.isEnabled = false
// convert_tokens.setBackgroundColor(Color.parseColor("#808080"))
// } else {
// convert_tokens.isEnabled = true
// convert_tokens.setBackgroundColor(Color.parseColor("#2962FF"))
// }

bitcoin_status.text = "BTC Status: " + getStatusString("btc")
euro_status.text = "EUR Status: " + getStatusString("euro")
transaction_status.text = "Transaction Status: " + getTransactionStatus()
Expand Down

0 comments on commit c8cd547

Please sign in to comment.