Skip to content

Commit

Permalink
wip-vote
Browse files Browse the repository at this point in the history
  • Loading branch information
dkoukoul committed Feb 27, 2024
1 parent 2899424 commit 8e6a7ce
Show file tree
Hide file tree
Showing 27 changed files with 203 additions and 99 deletions.
3 changes: 2 additions & 1 deletion app/src/main/java/co/anode/anodium/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ class MainActivity : AppCompatActivity() {
initTimber()
AnodeUtil.initializeApp()
AnodeUtil.launchCJDNS()
AnodeUtil.launchPld()
//PLD will be launched after creating a wallet
// AnodeUtil.launchPld()
AnodeUtil.serviceThreads()

val prefs = getSharedPreferences(BuildConfig.APPLICATION_ID, MODE_PRIVATE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,26 @@ 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> {
runCatching {
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)
}
return Result.failure(Exception("Wallet creation failed"))
}

override fun launchPLD() {
AnodeUtil.launchPld("")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ class WalletRepositoryImpl @Inject constructor() : WalletRepository {

override suspend fun unlockWallet(passphrase: String): Result<Boolean> {
Timber.d("unlockWallet")
val request = UnlockWalletRequest(passphrase, "$activeWallet.db")
val request = UnlockWalletRequest(passphrase)
val response = walletAPI.unlockWalletAPI(request)
return Result.success(response)
}
Expand Down Expand Up @@ -249,9 +249,12 @@ class WalletRepositoryImpl @Inject constructor() : WalletRepository {
}
}

override suspend fun renameWallet(name: String): Result<String?> {
override suspend fun renameWallet(name: String, srcName: String): Result<String?> {
Timber.d("renameWallet: $name")
checkWalletName(name).onSuccess {
if (srcName.isNotEmpty()) {
activeWallet = srcName
}
val walletFile = File("${AnodeUtil.filesDirectory}/pkt/$activeWallet.db")
walletFile.renameTo(File("${AnodeUtil.filesDirectory}/pkt/$name.db"))
//update stored PIN
Expand Down Expand Up @@ -354,8 +357,8 @@ class WalletRepositoryImpl @Inject constructor() : WalletRepository {
}
}

override suspend fun sendVote(fromAddresses: List<String>, voteFor: String, isCandidate: Boolean): Result<SendVoteResponse> {
val request = SendVoteRequest(voteFor, fromAddresses, isCandidate)
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}")
Expand Down
Loading

0 comments on commit 8e6a7ce

Please sign in to comment.