Skip to content

Commit

Permalink
TestRpc accounts are now loaded according to the value of PRIVATE_TES…
Browse files Browse the repository at this point in the history
…T_NET
  • Loading branch information
fmrsabino committed Aug 18, 2017
1 parent eb6c91a commit 75c32da
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
9 changes: 5 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ android {
defaultConfig {
buildConfigField "String", "BLOCKCHAIN_NET_URL", '"https://mainnet.infura.io"'
buildConfigField "String", "INFURA_API_KEY", getKey("INFURA_API_KEY")
buildConfigField "boolean", "PRIVATE_TEST_NET", "false"
}

buildTypes {
otherChain {
chainTest {
signingConfig signingConfigs.debug
minifyEnabled false
buildConfigField "String", "BLOCKCHAIN_NET_URL", getKey("BLOCKCHAIN_NET_URL")
buildConfigField "boolean", "PRIVATE_TEST_NET", getKey("PRIVATE_TEST_NET", "false")
}

debug {
Expand All @@ -41,7 +43,6 @@ android {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
buildConfigField "String", "INFURA_API_KEY", getKey("INFURA_API_KEY")
}
}

Expand All @@ -55,11 +56,11 @@ android {
}
}

static def getKey(String property) {
static def getKey(String property, String defaultValue = "") {
Properties properties = new Properties()
properties.load(new FileInputStream("project_keys"))
String value = properties.getProperty(property)
return value != null ? value : ""
return value != null ? value : defaultValue
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class GethAccountManager @Inject constructor(private val preferencesManager: Pre
private val keyStore: KeyStore) {
init {
if (keyStore.accounts.size() == 0L) {
if (BuildConfig.DEBUG) {
@Suppress("ConstantConditionIf")
if (BuildConfig.PRIVATE_TEST_NET) {
TestRPC.accounts.iterator().forEach({
val privateKey = it.value.first
val passphrase = it.value.second
Expand All @@ -33,7 +34,7 @@ class GethAccountManager @Inject constructor(private val preferencesManager: Pre

fun getAccounts(): List<Account> {
val accounts = ArrayList<Account>()
for (i in 0..keyStore.accounts.size() - 1) {
for (i in 0 until keyStore.accounts.size()) {
accounts += keyStore.accounts[i]
}
return accounts
Expand All @@ -52,8 +53,9 @@ class GethAccountManager @Inject constructor(private val preferencesManager: Pre


fun getAccountPassphrase(): String {
if (BuildConfig.DEBUG) {
return TestRPC.accounts[getActiveAccount().address.hex]?.second!!
@Suppress("ConstantConditionIf")
(return if (BuildConfig.PRIVATE_TEST_NET) {
TestRPC.accounts[getActiveAccount().address.hex]?.second!!
} else {
var passphrase = preferencesManager.prefs.getString(PreferencesManager.PASSPHRASE_KEY, "")
if (passphrase.isEmpty()) {
Expand All @@ -62,7 +64,7 @@ class GethAccountManager @Inject constructor(private val preferencesManager: Pre
putString(PreferencesManager.PASSPHRASE_KEY, passphrase)
}
}
return passphrase
}
passphrase
})
}
}

0 comments on commit 75c32da

Please sign in to comment.