Skip to content

Commit

Permalink
Merge pull request #123 from brian2509/musicdao_mvp
Browse files Browse the repository at this point in the history
Music DAO MVP
  • Loading branch information
InvictusRMC authored Feb 21, 2023
2 parents b348ac5 + ed05929 commit 8330148
Show file tree
Hide file tree
Showing 205 changed files with 8,661 additions and 3,990 deletions.
17 changes: 16 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ apply plugin: 'org.jlleitschuh.gradle.ktlint'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'
apply plugin: 'kotlinx-serialization'
apply plugin: "dagger.hilt.android.plugin"
apply plugin: "kotlin-kapt"

buildscript {
repositories {
Expand All @@ -15,6 +17,8 @@ buildscript {

dependencies {
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.2'
classpath("com.google.dagger:hilt-android-gradle-plugin:$hilt_ver")

}
}

Expand Down Expand Up @@ -103,7 +107,6 @@ allprojects {
repositories {
mavenCentral()
jcenter()

}
}

Expand Down Expand Up @@ -181,6 +184,18 @@ dependencies {
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

// Hilt
implementation("com.google.dagger:hilt-android:$hilt_ver")
implementation("androidx.hilt:hilt-navigation-fragment:1.0.0")
implementation("androidx.hilt:hilt-navigation-compose:1.1.0-alpha01")
kapt("com.google.dagger:hilt-android-compiler:$hilt_ver")

// Room
implementation "androidx.room:room-runtime:$room_version"
implementation("androidx.room:room-ktx:$room_version")
annotationProcessor "androidx.room:room-compiler:$room_version"
kapt("androidx.room:room-compiler:$room_version")
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#0fff" />
<stroke
android:width="1dp"
android:color="#000" />
<solid android:color="@color/android_green" />
</shape>

15 changes: 5 additions & 10 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,12 @@
android:windowSoftInputMode="stateAlwaysHidden" />

<activity
android:name="com.example.musicdao.MusicService"
android:name="nl.tudelft.trustchain.musicdao.MusicActivity"
android:label="Music App"
android:exported="true"
android:label="Music app"
android:parentActivityName=".ui.dashboard.DashboardActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="@xml/searchable" />
android:screenOrientation="portrait"
android:theme="@style/Theme.MusicDaoTheme">
</activity>

<activity
Expand All @@ -183,7 +178,7 @@
android:exported="false" />

<service
android:name="com.example.musicdao.MusicGossipingService"
android:name="nl.tudelft.trustchain.musicdao.core.repositories.MusicGossipingService"
android:enabled="true"
android:exported="false" />

Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/nl/tudelft/trustchain/app/AppDefinition.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package nl.tudelft.trustchain.app
import android.app.Activity
import androidx.annotation.ColorRes
import androidx.annotation.DrawableRes
import com.example.musicdao.MusicService
import nl.tudelft.trustchain.musicdao.MusicActivity
import nl.tudelft.trustchain.FOC.MainActivityFOC
import nl.tudelft.trustchain.atomicswap.AtomicSwapActivity
import nl.tudelft.trustchain.common.R
Expand Down Expand Up @@ -101,7 +101,7 @@ enum class AppDefinition(
android.R.drawable.ic_media_play,
"MusicDAO",
R.color.black,
MusicService::class.java
MusicActivity::class.java
),
EUROTOKEN(
R.drawable.ic_baseline_euro_symbol_24,
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/nl/tudelft/trustchain/app/AppLoader.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package nl.tudelft.trustchain.app

import android.annotation.SuppressLint
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.edit
Expand Down Expand Up @@ -58,6 +59,7 @@ class AppLoader(
}
}

@SuppressLint("NewApi")
private suspend fun setPreferredAppList(newPreferences: Set<String>) {
dataStore.edit { settings ->
settings[PREFERRED_APPS] = newPreferences
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@ import androidx.datastore.preferences.core.booleanPreferencesKey
import androidx.datastore.preferences.core.edit
import androidx.datastore.preferences.preferencesDataStore
import androidx.preference.PreferenceManager
import com.example.musicdao.ipv8.MusicCommunity
import nl.tudelft.trustchain.musicdao.core.ipv8.MusicCommunity
import nl.tudelft.trustchain.musicdao.core.dao.DaoCommunity
import com.squareup.sqldelight.android.AndroidSqliteDriver
import com.squareup.sqldelight.db.SqlDriver
import dagger.hilt.android.HiltAndroidApp
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.first
Expand Down Expand Up @@ -71,7 +76,9 @@ import nl.tudelft.gossipML.sqldelight.Database as MLDatabase

val Context.dataStore: DataStore<Preferences> by preferencesDataStore(name = "settings")

@OptIn(DelicateCoroutinesApi::class)
@ExperimentalUnsignedTypes
@HiltAndroidApp
class TrustChainApplication : Application() {

var isFirstRun: Boolean = false
Expand Down Expand Up @@ -104,6 +111,7 @@ class TrustChainApplication : Application() {
createAtomicSwapCommunity(),
createMarketCommunity(),
createCoinCommunity(),
createDaoCommunity(),
createVotingCommunity(),
createMusicCommunity(),
createLiteratureCommunity(),
Expand Down Expand Up @@ -358,6 +366,16 @@ class TrustChainApplication : Application() {
)
}

private fun createDaoCommunity(): OverlayConfiguration<DaoCommunity> {
val randomWalk = RandomWalk.Factory()
val nsd = NetworkServiceDiscovery.Factory(getSystemService()!!)

return OverlayConfiguration(
Overlay.Factory(DaoCommunity::class.java),
listOf(randomWalk, nsd)
)
}

private fun createCoinCommunity(): OverlayConfiguration<CoinCommunity> {
val randomWalk = RandomWalk.Factory()
val nsd = NetworkServiceDiscovery.Factory(getSystemService()!!)
Expand All @@ -381,7 +399,8 @@ class TrustChainApplication : Application() {

private fun createMusicCommunity(): OverlayConfiguration<MusicCommunity> {
val settings = TrustChainSettings()
val driver = AndroidSqliteDriver(Database.Schema, this, "music.db")
// TODO: Re-concile this community with Reccomender Community
val driver = AndroidSqliteDriver(Database.Schema, this, "music-private.db")
val store = TrustChainSQLiteStore(Database(driver))
val randomWalk = RandomWalk.Factory()
return OverlayConfiguration(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ class DashboardActivity : AppCompatActivity() {
}
}

@Suppress("DEPRECATION")
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
when (requestCode) {
SETTINGS_INTENT_CODE -> {
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/xml/network_security_config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@
<domain includeSubdomains="true">131.180.27.224</domain>
<!-- IP address of the host machine when ran from the Android emulator -->
<!-- <domain includeSubdomains="true">10.0.2.2</domain>-->

<!-- This is for RegTest faucet, to claim some starter money -->
<domain includeSubdomains="true">95.179.182.243</domain>
</domain-config>
</network-security-config>
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ import org.junit.Test
class ExampleUnitTest {
@Test
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
assertEquals(4, (2 + 2))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ enum class Currency(val currencyCodeStringResourceId: Int) {

companion object {
fun fromString(coin: String): Currency {
@Suppress("DEPRECATION")
return when (coin.toLowerCase()) {
"btc" -> BTC
"eth" -> ETH
Expand Down
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ buildscript {
ext.lifecycle_version = "2.5.1"
ext.jlibtorrent_version = '1.2.17.0'
ext.dokka_version = "0.10.1"
ext.hilt_ver = '2.44.2'
ext.room_version = '2.4.0'
repositories {
google()
jcenter()
Expand Down
2 changes: 1 addition & 1 deletion common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ dependencies {
testImplementation 'org.json:json:20190722'
testImplementation "com.squareup.sqldelight:sqlite-driver:$sqldelight_version"
testImplementation "com.goterl:lazysodium-java:5.1.4"
annotationProcessor 'androidx.room:room-compiler:2.2.5'
annotationProcessor "androidx.room:room-compiler:$room_version"
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import nl.tudelft.trustchain.currencyii.util.DAOJoinHelper
import nl.tudelft.trustchain.currencyii.util.DAOTransferFundsHelper

@Suppress("UNCHECKED_CAST")
class CoinCommunity : Community() {
override val serviceId = "02313685c1912a141279f8248fc8db5899c5df5b"
class CoinCommunity constructor(serviceId: String = "02313685c1912a141279f8248fc8db5899c5df5b") : Community() {
override val serviceId = serviceId

private fun getTrustChainCommunity(): TrustChainCommunity {
return IPv8Android.getInstance().getOverlay()
Expand Down Expand Up @@ -73,16 +73,14 @@ class CoinCommunity : Community() {
walletBlockData: TrustChainTransaction,
blockData: SWSignatureAskBlockTD,
responses: List<SWResponseSignatureBlockTD>,
context: Context,
activity: Activity
context: Context
) {
daoJoinHelper.joinBitcoinWallet(
myPeer,
walletBlockData,
blockData,
responses,
context,
activity
context
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import nl.tudelft.ipv8.util.toHex
import nl.tudelft.trustchain.currencyii.CoinCommunity.Companion.DEFAULT_BITCOIN_MAX_TIMEOUT
import nl.tudelft.trustchain.currencyii.util.taproot.*
import org.bitcoinj.core.*
import org.bitcoinj.core.DumpedPrivateKey
import org.bitcoinj.core.LegacyAddress
import org.bitcoinj.core.listeners.DownloadProgressTracker
import org.bitcoinj.crypto.DeterministicKey
import org.bitcoinj.kits.WalletAppKit
Expand Down Expand Up @@ -68,6 +66,12 @@ class WalletManager(
var progress: Int = 0
val key = addressPrivateKeyPair

val onSetupCompletedListeners = mutableListOf<() -> Unit>()

fun addOnSetupCompletedListener(listener: () -> Unit) {
onSetupCompletedListeners.add(listener)
}

/**
* Initializes WalletManager.
*/
Expand Down Expand Up @@ -95,6 +99,10 @@ class WalletManager(
}
wallet().allowSpendingUnconfirmedTransactions()
Log.i("Coin", "Coin: WalletManager started successfully.")
onSetupCompletedListeners.forEach {
Log.i("Coin", "Coin: calling listener $it")
it()
}
}
}

Expand Down Expand Up @@ -246,7 +254,8 @@ class WalletManager(
val transaction = Transaction(params)

transaction.addOutput(
entranceFee, Address.fromString(params, addressMuSig)
entranceFee,
Address.fromString(params, addressMuSig)
)

// no fees since we are in a test network and this is a proof of concept still
Expand All @@ -259,7 +268,10 @@ class WalletManager(
kit.wallet().completeTx(req)

Log.i("Coin", "SafeCreationAndSendGensisWallet - txid: " + req.tx.txId.toString())
Log.i("Coin", "SafeCreationAndSendGensisWallet - serialized tx: " + req.tx.bitcoinSerialize().toHex())
Log.i(
"Coin",
"SafeCreationAndSendGensisWallet - serialized tx: " + req.tx.bitcoinSerialize().toHex()
)

val serializedTransaction = req.tx.bitcoinSerialize()

Expand Down Expand Up @@ -326,7 +338,11 @@ class WalletManager(
kit.wallet().signTransaction(req)

Log.i("Coin", "Joining DAO - newtxid: " + newTransaction.txId.toString())
Log.i("Coin", "Joining DAO - serialized new tx without signatures: " + newTransaction.bitcoinSerialize().toHex())
Log.i(
"Coin",
"Joining DAO - serialized new tx without signatures: " + newTransaction.bitcoinSerialize()
.toHex()
)

// TODO there is probably a bug if multiple vins are required by our own wallet (for example, multiple small txin's combined to 1 big vout)
return req.tx.bitcoinSerialize().toHex()
Expand Down Expand Up @@ -376,7 +392,10 @@ class WalletManager(
sighashMuSig
)

Log.i("NONCE_KEY", "nonce_key priv: " + getNonceKey(walletId, context).first.privKey.toString())
Log.i(
"NONCE_KEY",
"nonce_key priv: " + getNonceKey(walletId, context).first.privKey.toString()
)

return signature
}
Expand Down Expand Up @@ -415,7 +434,10 @@ class WalletManager(

newTransaction.wit = cTxWitness

Log.i("Coin", "Joining DAO - serialized new tx with signatures: " + newTransaction.serialize().toHex())
Log.i(
"Coin",
"Joining DAO - serialized new tx with signatures: " + newTransaction.serialize().toHex()
)

return Pair(sendTaprootTransaction(newTransaction), newTransaction.serialize().toHex())
}
Expand Down Expand Up @@ -456,7 +478,11 @@ class WalletManager(
receiverAddress
)

Log.i("Coin", "Transfer funds DAO - serialized new tx without signature: " + newTransaction.serialize().toHex())
Log.i(
"Coin",
"Transfer funds DAO - serialized new tx without signature: " + newTransaction.serialize()
.toHex()
)

val privChallenge =
detKey.privKey.multiply(BigInteger(1, cMap[key.decompress()])).mod(Schnorr.n)
Expand Down Expand Up @@ -517,7 +543,11 @@ class WalletManager(

newTransaction.wit = cTxWitness

Log.i("Coin", "Transfer funds DAO - final serialized new tx with signature: " + newTransaction.serialize().toHex())
Log.i(
"Coin",
"Transfer funds DAO - final serialized new tx with signature: " + newTransaction.serialize()
.toHex()
)

return Pair(sendTaprootTransaction(newTransaction), newTransaction.serialize().toHex())
}
Expand Down
Loading

0 comments on commit 8330148

Please sign in to comment.