Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move wallet in MusicDAO to separate file #180

Merged
merged 1 commit into from
Feb 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Move wallet in MusicDAO to separate file
InvictusRMC committed Feb 21, 2024
commit 37e22bac8b347013425b6f312a30dd7ca86ca148
Original file line number Diff line number Diff line change
@@ -66,19 +66,19 @@ class DashboardActivity : AppCompatActivity() {
}

private fun hasBluetoothPermissions(): Boolean {
return checkSelfPermission(Companion.BLUETOOTH_PERMISSIONS_ADVERTISE) == PackageManager.PERMISSION_GRANTED &&
checkSelfPermission(Companion.BLUETOOTH_PERMISSIONS_CONNECT) == PackageManager.PERMISSION_GRANTED &&
checkSelfPermission(Companion.BLUETOOTH_PERMISSIONS_SCAN) == PackageManager.PERMISSION_GRANTED
return checkSelfPermission(BLUETOOTH_PERMISSIONS_ADVERTISE) == PackageManager.PERMISSION_GRANTED &&
checkSelfPermission(BLUETOOTH_PERMISSIONS_CONNECT) == PackageManager.PERMISSION_GRANTED &&
checkSelfPermission(BLUETOOTH_PERMISSIONS_SCAN) == PackageManager.PERMISSION_GRANTED
}

private fun requestBluetoothPermissions() {
requestPermissions(
arrayOf(
Companion.BLUETOOTH_PERMISSIONS_ADVERTISE,
Companion.BLUETOOTH_PERMISSIONS_CONNECT,
Companion.BLUETOOTH_PERMISSIONS_SCAN
BLUETOOTH_PERMISSIONS_ADVERTISE,
BLUETOOTH_PERMISSIONS_CONNECT,
BLUETOOTH_PERMISSIONS_SCAN
),
Companion.BLUETOOTH_PERMISSIONS_REQUEST_CODE
BLUETOOTH_PERMISSIONS_REQUEST_CODE
)
}

@@ -88,7 +88,7 @@ class DashboardActivity : AppCompatActivity() {
grantResults: IntArray
) {
when (requestCode) {
Companion.BLUETOOTH_PERMISSIONS_REQUEST_CODE -> {
BLUETOOTH_PERMISSIONS_REQUEST_CODE -> {
if (hasBluetoothPermissions()) {
(application as TrustChainApplication).initIPv8()
} else {
@@ -106,7 +106,7 @@ class DashboardActivity : AppCompatActivity() {
data: Intent?
) {
when (requestCode) {
Companion.SETTINGS_INTENT_CODE -> {
SETTINGS_INTENT_CODE -> {
if (hasBluetoothPermissions()) {
(application as TrustChainApplication).initIPv8()
} else {
@@ -132,8 +132,7 @@ class DashboardActivity : AppCompatActivity() {
Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
val uri: Uri = Uri.fromParts("package", packageName, null)
intent.data = uri
@Suppress("DEPRECATION") // TODO: Fix deprecation issue.
startActivityForResult(intent, Companion.SETTINGS_INTENT_CODE)
startActivityForResult(intent, SETTINGS_INTENT_CODE)
}
}.create()
}
Original file line number Diff line number Diff line change
@@ -59,7 +59,6 @@ var minBlockchainPeers = MIN_BLOCKCHAIN_PEERS_TEST_NET
* In these location you can find all information to run the regtest and python server.
* Make sure to also change the IP's (and URLs) in the kotlin code when swapping to a different server.
*/
@Suppress("DEPRECATION", "NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS")
class WalletManager(
walletManagerConfiguration: WalletManagerConfiguration,
walletDir: File,
@@ -91,6 +90,8 @@ class WalletManager(
BitcoinNetworkOptions.REG_TEST -> RegTestParams.get()
}

val customPrefix = MUSIC_DAO_PREFIX

val filePrefix =
when (walletManagerConfiguration.network) {
BitcoinNetworkOptions.TEST_NET -> TEST_NET_WALLET_NAME
@@ -99,7 +100,7 @@ class WalletManager(
}

kit =
object : WalletAppKit(params, walletDir, filePrefix) {
object : WalletAppKit(params, walletDir, customPrefix + filePrefix) {
override fun onSetupCompleted() {
// Make a fresh new key if no keys in stored wallet.
if (wallet().keyChainGroupSize < 1) {
@@ -731,6 +732,8 @@ class WalletManager(
val creationTime = seed.creationTimeSeconds
return SerializedDeterministicKey(words, creationTime)
}

const val MUSIC_DAO_PREFIX = "musicdao-"
}

fun toSeed(): SerializedDeterministicKey {
Original file line number Diff line number Diff line change
@@ -7,7 +7,6 @@ import android.content.Context
*/
object WalletManagerAndroid { // TODO: Clean up Thread usage.
private var walletManager: WalletManager? = null
private var context: Context? = null
var isRunning: Boolean = false

fun getInstance(): WalletManager {
@@ -31,8 +30,6 @@ object WalletManagerAndroid { // TODO: Clean up Thread usage.
configuration
?: throw IllegalStateException("Configuration is not set")

WalletManagerAndroid.context = context

val walletManager =
WalletManager(
configuration,