Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
dkoukoul committed Mar 21, 2024
2 parents 87cd9d8 + a98bb3b commit 75bc7e1
Show file tree
Hide file tree
Showing 84 changed files with 1,748 additions and 273 deletions.
3 changes: 2 additions & 1 deletion .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/compiler.xml
100755 → 100644

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/migrations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 28 additions & 9 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,22 @@ android {
buildConfigField "String", "BUILD_PLATFORM", "\"playstore\""
applicationIdSuffix ".playstore"
versionNameSuffix "-playstore"
} else if (System.getenv("ANDROIDTV_BUILD") == "true") {
def tmpFilePath = System.getProperty("user.home") + "/work/_temp/keystore/"
def allFilesFromDir = new File(tmpFilePath).listFiles()

if (allFilesFromDir != null) {
def keystoreFile = allFilesFromDir.first()
keystoreFile.renameTo("keystore/your_keystore.jks")
}
println("Building ANDROID TV build")
signingConfigs.release.storeFile = file("../../../_temp/keystore/your_keystore.jks")
signingConfigs.release.storePassword = System.getenv("KEYSTORE_PASSWORD")
signingConfigs.release.keyAlias = System.getenv("KEY_ALIAS")
signingConfigs.release.keyPassword = System.getenv("KEY_PASSWORD")
buildConfigField "String", "BUILD_PLATFORM", "\"playstore\""
applicationIdSuffix ".androidtv"
versionNameSuffix "-androidtv"
} else if (System.getenv("CI") == "true") {
println("Building AutoUpdate build")
signingConfigs.release.storeFile = file("../tools/android_key")
Expand All @@ -63,13 +79,16 @@ android {
buildConfigField "String", "BUILD_PLATFORM", "\"travis\""
} else {
println("Building local release build")
buildConfigField "String", "BUILD_PLATFORM", "\"local\""
signingConfigs.release.storeFile = file("../tools/android_key")
signingConfigs.release.storePassword = System.getenv("KEYSTORE_PASSWORD")
signingConfigs.release.keyAlias = System.getenv("KEY_ALIAS")
signingConfigs.release.keyPassword = System.getenv("KEY_PASSWORD")
applicationIdSuffix ".release"
versionNameSuffix "-release"
// buildConfigField "String", "BUILD_PLATFORM", "\"local\""
// signingConfigs.release.storeFile = file("../tools/android_key")
// signingConfigs.release.storePassword = System.getenv("KEYSTORE_PASSWORD")
// signingConfigs.release.keyAlias = System.getenv("KEY_ALIAS")
// signingConfigs.release.keyPassword = System.getenv("KEY_PASSWORD")
// applicationIdSuffix ".release"
// versionNameSuffix "-release"

applicationIdSuffix ".androidtv"
versionNameSuffix "-androidtv"
}
//Disable minify,
// check this: https://developer.android.com/guide/navigation/navigation-pass-data#proguard_considerations
Expand All @@ -78,10 +97,10 @@ android {
signingConfig signingConfigs.release
}
debug {
signingConfigs.debug.storeFile = file("../tools/android_key")
/*signingConfigs.debug.storeFile = file("../tools/android_key")
signingConfigs.debug.storePassword = System.getenv("KEYSTORE_PASSWORD")
signingConfigs.debug.keyAlias = System.getenv("KEY_ALIAS")
signingConfigs.debug.keyPassword = System.getenv("KEY_PASSWORD")
signingConfigs.debug.keyPassword = System.getenv("KEY_PASSWORD")*/
println("Building local debug build")
buildConfigField "String", "BUILD_PLATFORM", "\"local\""
applicationIdSuffix ".debug"
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
android:name="android.permission.WRITE_SETTINGS"
tools:ignore="ProtectedPermissions" />

<uses-feature android:name="android.software.leanback" android:required="true" /><uses-feature android:name="android.hardware.touchscreen" android:required="false" />

<application
android:name=".volley.BackendVolley"
android:extractNativeLibs="true"
android:icon="@mipmap/ic_logo"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_logo_round"
Expand Down
8 changes: 7 additions & 1 deletion app/src/main/java/co/anode/anodium/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ class MainActivity : AppCompatActivity() {
searchForInternetSharing()
}

override fun onResume() {
super.onResume()
Timber.i("MainActivity onResume starting PktMainActivity")
startActivity(Intent(this, PktMainActivity::class.java))
}

private fun initializeApp() {
//Initialize Util before Client
AnodeUtil.init(applicationContext)
Expand All @@ -83,7 +89,7 @@ class MainActivity : AppCompatActivity() {
initTimber()
AnodeUtil.initializeApp()
AnodeUtil.launchCJDNS()
AnodeUtil.launchPld()
AnodeUtil.launchPld("")
AnodeUtil.serviceThreads()

val prefs = getSharedPreferences(BuildConfig.APPLICATION_ID, MODE_PRIVATE)
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/co/anode/anodium/PktMainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import kotlinx.coroutines.Job
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import timber.log.Timber
import java.time.Instant
import java.time.LocalDateTime
import java.time.ZoneOffset
Expand Down Expand Up @@ -41,6 +42,7 @@ class PktMainActivity : AppCompatActivity() {
checkPermissions()

startNotificationsCheck()
Timber.i("PktMainActivity onCreate")
}

private fun startNotificationsCheck() {
Expand All @@ -59,6 +61,7 @@ class PktMainActivity : AppCompatActivity() {
}
override fun onResume() {
super.onResume()
Timber.i("PktMainActivity onResume")
startNotificationsCheck()
}
override fun onPause() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,40 @@ class GeneralRepositoryImpl @Inject constructor() : GeneralRepository {
override fun getPremiumEndTime(server: String): Long {
return AnodeUtil.getPremiumEndTime(server)
}

override suspend fun createPldWallet(password: String, pin: String, wallet: String): Result<String> {
val seed = AnodeUtil.createPldWallet(password, wallet)
if (seed.isEmpty()) {
return Result.failure(Exception("Wallet creation failed"))
}
val encryptedPassword = AnodeUtil.encrypt(password, pin)
AnodeUtil.storeWalletPassword(encryptedPassword, wallet)
if (pin.isNotEmpty()) {
AnodeUtil.storeWalletPin(pin, wallet)
}

Timber.d("createWallet: success")
return Result.success(seed)
}

override suspend fun recoverPldWallet(password: String, seed: String, seedPassword:String, pin: String, wallet: String): Result<String> {
if (seed.isEmpty()) {
return Result.failure(Exception("Seed is empty"))
}
val returnedSeed = AnodeUtil.recoverPldWallet(password, wallet, seed, seedPassword)
if (returnedSeed.isEmpty()) {
return Result.failure(Exception("Wallet creation failed"))
}
val encryptedPassword = AnodeUtil.encrypt(password, pin)
AnodeUtil.storeWalletPassword(encryptedPassword, wallet)
if (pin.isNotEmpty()) {
AnodeUtil.storeWalletPin(pin, wallet)
}

Timber.d("createWallet: success")
return Result.success(seed)
}
override fun launchPLD(wallet: String) {
AnodeUtil.launchPld(wallet)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,25 @@ class WalletRepositoryImpl @Inject constructor() : WalletRepository {
private var activeWallet = AnodeUtil.DEFAULT_WALLET_NAME

override fun getAllWalletNames(): List<String> {
return AnodeUtil.getWalletFiles()
val wallets = AnodeUtil.getWalletFiles()
return wallets.map { it.removePrefix("wallet_") }
}

override fun getActiveWallet(): String {
AnodeUtil.context?.getSharedPreferences(AnodeUtil.ApplicationID, Context.MODE_PRIVATE)?.getString("activeWallet", "wallet")?.let {
activeWallet = it
}
Timber.i("getActiveWallet: $activeWallet")
//Check if wallet file exists, otherwise choose other available wallet
if (!AnodeUtil.getWalletFiles().contains(activeWallet)) {
if ((!AnodeUtil.getWalletFiles().contains(activeWallet)) && (!AnodeUtil.getWalletFiles().contains("wallet_$activeWallet"))) {
Timber.e("Active wallet file not found, choosing another wallet")
activeWallet = AnodeUtil.getWalletFiles().firstOrNull() ?: AnodeUtil.DEFAULT_WALLET_NAME
}
return activeWallet
}

override suspend fun setActiveWallet(walletName: String) {
Timber.i("setActiveWallet: $walletName")
//delete existing chain back up file when changing active wallet
if (walletName != activeWallet) {
AnodeUtil.deleteWalletChainBackupFile()
Expand Down Expand Up @@ -78,6 +82,20 @@ class WalletRepositoryImpl @Inject constructor() : WalletRepository {
return Result.success(balance)
}

override suspend fun getVote(address: String): Result<Vote?> {
val addresses = walletAPI.getWalletBalances(true)
for (addr in addresses.addrs) {
if (addr.address == address) {
return if (addr.vote != null) {
Result.success(addr.vote!!)
} else {
Result.success(null)
}
}
}
return Result.failure(Exception("Address not found"))
}

//Get wallet balance, if address is empty then return total balance of all addresses
override suspend fun getWalletBalance(address: String): Result<Long> =
runCatching {
Expand Down Expand Up @@ -139,9 +157,9 @@ class WalletRepositoryImpl @Inject constructor() : WalletRepository {
}
}
address
}.onSuccess { address ->
}.onSuccess {
Timber.d("getWalletAddress: success")
address
return Result.success(it)
}.onFailure {
Timber.e(it, "getWalletAddress: failure")
}
Expand Down Expand Up @@ -198,10 +216,25 @@ class WalletRepositoryImpl @Inject constructor() : WalletRepository {
}

override suspend fun unlockWallet(passphrase: String): Result<Boolean> {
// For new pld, we need to restart it
// AnodeUtil.stopPld()
// AnodeUtil.launchPld(activeWallet)
val request = UnlockWalletRequest(passphrase)
Timber.d("unlockWallet")
val request = UnlockWalletRequest(passphrase, "$activeWallet.db")
val response = walletAPI.unlockWalletAPI(request)
return Result.success(response)
var attempts = 0
var response: Boolean
do {
response = walletAPI.unlockWalletAPI(request)
attempts++
} while (!response && attempts < 3)

return if (response) {
Timber.d("unlockWallet: success")
Result.success(true)
} else {
Timber.e("unlockWallet: failed")
Result.failure(Exception("Failed to unlock wallet"))
}
}

override suspend fun unlockWalletWithPIN(pin: String): Result<Boolean> {
Expand Down Expand Up @@ -249,15 +282,33 @@ class WalletRepositoryImpl @Inject constructor() : WalletRepository {
}
}

override suspend fun renameWallet(name: String): Result<String?> {
Timber.d("renameWallet: $name")
checkWalletName(name).onSuccess {
val walletFile = File("${AnodeUtil.filesDirectory}/pkt/$activeWallet.db")
walletFile.renameTo(File("${AnodeUtil.filesDirectory}/pkt/$name.db"))
override suspend fun renameWallet(name: String, srcName: String): Result<String?> {
var dstName = name
if (name != AnodeUtil.DEFAULT_WALLET_NAME) {
dstName = "wallet_$name"
}
Timber.d("renameWallet: $dstName")
checkWalletName(dstName).onSuccess {
if (srcName.isNotEmpty()) {
activeWallet = srcName

}

if ((activeWallet != AnodeUtil.DEFAULT_WALLET_NAME) && (!activeWallet.startsWith("wallet_"))) {
Timber.i("renameWallet: add wallet_ prefix to activeWallet name")
val walletFile = File("${AnodeUtil.filesDirectory}/pkt/wallet_$activeWallet.db")
walletFile.renameTo(File("${AnodeUtil.filesDirectory}/pkt/$dstName.db"))
Timber.i("renameWallet: renaming wallet wallet_$activeWallet to $dstName")
} else {
Timber.i("renameWallet: renaming wallet $activeWallet to $dstName")
val walletFile = File("${AnodeUtil.filesDirectory}/pkt/$activeWallet.db")
walletFile.renameTo(File("${AnodeUtil.filesDirectory}/pkt/$dstName.db"))
}

//update stored PIN
AnodeUtil.renameEncryptedWalletPreferences(activeWallet,name)
setActiveWallet(name)
return Result.success(name)
AnodeUtil.renameEncryptedWalletPreferences(activeWallet,dstName)
setActiveWallet(dstName)
return Result.success(dstName)
}.onFailure {
Timber.e(it, "renameWallet: failed")
return Result.failure(Exception("A wallet already exists with this name"))
Expand Down Expand Up @@ -354,6 +405,21 @@ class WalletRepositoryImpl @Inject constructor() : WalletRepository {
}
}

override suspend fun sendVote(fromAddress: String, voteFor: String, isCandidate: Boolean): Result<SendVoteResponse> {
val request = SendVoteRequest(voteFor, fromAddress, isCandidate)
val response = walletAPI.sendVote(request)
if (response.message.isNotEmpty()) {
Timber.e("sendVote: Failed: ${response.message}")
return Result.failure(Exception("Failed to send vote: ${response.message}"))
} else if (response.txHash.isNotEmpty()){
Timber.d("sendVote: success")
return Result.success(response)
} else {
Timber.e("sendVote: Failed, empty response")
return Result.failure(Exception("Failed to send vote"))
}
}

override suspend fun createTransaction(fromAddresses: List<String>, amount: Double, toAddress: String): Result<CreateTransactionResponse> {
val request = CreateTransactionRequest(toAddress, amount, fromAddresses, true)
val response = walletAPI.createTransaction(request)
Expand Down Expand Up @@ -441,5 +507,4 @@ class WalletRepositoryImpl @Inject constructor() : WalletRepository {
override suspend fun decodeTransaction(binTx: String): String {
return walletAPI.decodeTransaction(binTx)
}

}
Loading

0 comments on commit 75bc7e1

Please sign in to comment.