Skip to content

Commit

Permalink
Further code cleanup / requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
brian2509 committed Feb 21, 2023
1 parent faac618 commit ed05929
Show file tree
Hide file tree
Showing 14 changed files with 26 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class DAOJoinHelper {
* 2.1 Send a proposal on the trust chain to join a shared wallet and to collect signatures.
* The proposal is a serialized bitcoin join transaction.
* **NOTE** the latest walletBlockData should be given, otherwise the serialized transaction is invalid.
* @param mostRecentWalletBlock - the latest (that you know of) sharedwallet block.
* @param mostRecentWalletBlock - the latest (that you know of) shared wallet block.
*/
fun proposeJoinWallet(
myPeer: Peer,
Expand Down Expand Up @@ -91,7 +91,7 @@ class DAOJoinHelper {
* Create a bitcoin transaction that creates a new shared wallet. This takes some time to complete.
*
* NOTE:
* - the latest walletBlockData should be given, otherwise the serialized transaction is invalid.
* - the latest walletBlockData should be given, otherwise the serialized transaction is invalid.
* - It takes some time before the shared wallet is accepted on the bitcoin blockchain.
* @param sharedWalletData data of the shared wallet that you want to join.
*/
Expand Down
Binary file removed musicdao-datafeeder/libs/jlibtorrent-1.2.15.2.jar
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package nl.tudelft.trustchain.musicdao.core.ipv8

import nl.tudelft.trustchain.musicdao.core.ipv8.blocks.releasePublish.ReleasePublishBlock
import nl.tudelft.trustchain.musicdao.core.ipv8.blocks.release_publish.ReleasePublishBlockValidator
import nl.tudelft.trustchain.musicdao.core.ipv8.blocks.releasePublish.ReleasePublishBlockValidator
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.isActive
Expand All @@ -11,7 +11,7 @@ import javax.inject.Inject

class ReleaseBlockGossiper @Inject constructor(
private val musicCommunity: MusicCommunity,
private val releasePublishBlockSigner: ReleasePublishBlockValidator,
private val releasePublishBlockSigner: ReleasePublishBlockValidator
) {

fun startGossip(coroutineScope: CoroutineScope) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package nl.tudelft.trustchain.musicdao.core.ipv8

import nl.tudelft.trustchain.musicdao.core.ipv8.blocks.release_publish.ReleasePublishBlockSigner
import nl.tudelft.trustchain.musicdao.core.ipv8.blocks.release_publish.ReleasePublishBlockValidator
import nl.tudelft.trustchain.musicdao.core.ipv8.blocks.releasePublish.ReleasePublishBlockSigner
import nl.tudelft.trustchain.musicdao.core.ipv8.blocks.releasePublish.ReleasePublishBlockValidator
import javax.inject.Inject

class SetupMusicCommunity @Inject constructor(
private val musicCommunity: MusicCommunity,
private val releasePublishBlockSigner: ReleasePublishBlockSigner,
private val releasePublishBlockValidator: ReleasePublishBlockValidator,
private val releasePublishBlockValidator: ReleasePublishBlockValidator
) {

fun registerListeners() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package nl.tudelft.trustchain.musicdao.core.ipv8.blocks.release_publish
package nl.tudelft.trustchain.musicdao.core.ipv8.blocks.releasePublish

import nl.tudelft.trustchain.musicdao.core.ipv8.MusicCommunity
import nl.tudelft.trustchain.musicdao.core.ipv8.blocks.Constants
import nl.tudelft.ipv8.android.IPv8Android
import nl.tudelft.ipv8.attestation.trustchain.TrustChainBlock
import nl.tudelft.ipv8.util.toHex
import nl.tudelft.trustchain.musicdao.core.ipv8.blocks.releasePublish.ReleasePublishBlock
import javax.inject.Inject

class ReleasePublishBlockRepository @Inject constructor(
private val musicCommunity: MusicCommunity,
private val releasePublishBlockValidator: ReleasePublishBlockValidator,
private val releasePublishBlockValidator: ReleasePublishBlockValidator
) {

fun getValidBlocks(): List<ReleasePublishBlock> {
Expand All @@ -24,7 +23,7 @@ class ReleasePublishBlockRepository @Inject constructor(
magnet: String,
title: String,
artist: String,
releaseDate: String,
releaseDate: String
): TrustChainBlock? {
val myPeer = IPv8Android.getInstance().myPeer
val transaction = mutableMapOf(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package nl.tudelft.trustchain.musicdao.core.ipv8.blocks.release_publish
package nl.tudelft.trustchain.musicdao.core.ipv8.blocks.releasePublish

import nl.tudelft.trustchain.musicdao.core.ipv8.MusicCommunity
import nl.tudelft.ipv8.attestation.trustchain.BlockSigner
import nl.tudelft.ipv8.attestation.trustchain.TrustChainBlock
import nl.tudelft.trustchain.musicdao.core.ipv8.blocks.releasePublish.ReleasePublishBlock
import javax.inject.Inject

class ReleasePublishBlockSigner @Inject constructor(val musicCommunity: MusicCommunity) :
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package nl.tudelft.trustchain.musicdao.core.ipv8.blocks.release_publish
package nl.tudelft.trustchain.musicdao.core.ipv8.blocks.releasePublish

import nl.tudelft.trustchain.musicdao.core.ipv8.MusicCommunity
import nl.tudelft.trustchain.musicdao.core.ipv8.blocks.Constants
Expand All @@ -7,7 +7,6 @@ import nl.tudelft.ipv8.attestation.trustchain.TrustChainTransaction
import nl.tudelft.ipv8.attestation.trustchain.store.TrustChainStore
import nl.tudelft.ipv8.attestation.trustchain.validation.TransactionValidator
import nl.tudelft.ipv8.attestation.trustchain.validation.ValidationResult
import nl.tudelft.trustchain.musicdao.core.ipv8.blocks.releasePublish.ReleasePublishBlock
import javax.inject.Inject

class ReleasePublishBlockValidator @Inject constructor(val musicCommunity: MusicCommunity) :
Expand All @@ -34,8 +33,6 @@ class ReleasePublishBlockValidator @Inject constructor(val musicCommunity: Music
val releaseDate = transaction["releaseDate"]
val protocolVersion = transaction["protocolVersion"]

// Log.d("MusicDao", "Validating: $protocolVersion === ${Constants.PROTOCOL_VERSION} = ${protocolVersion == Constants.PROTOCOL_VERSION}")

return (
releaseId is String && releaseId.isNotEmpty() && transaction.containsKey("releaseId") &&
magnet is String && magnet.isNotEmpty() && transaction.containsKey("magnet") &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import androidx.lifecycle.map
import nl.tudelft.trustchain.musicdao.core.cache.CacheDatabase
import nl.tudelft.trustchain.musicdao.core.cache.entities.AlbumEntity
import nl.tudelft.trustchain.musicdao.core.ipv8.blocks.releasePublish.ReleasePublishBlock
import nl.tudelft.trustchain.musicdao.core.ipv8.blocks.release_publish.ReleasePublishBlockRepository
import nl.tudelft.trustchain.musicdao.core.ipv8.blocks.releasePublish.ReleasePublishBlockRepository
import nl.tudelft.trustchain.musicdao.core.repositories.model.Album
import nl.tudelft.trustchain.musicdao.core.torrent.TorrentEngine
import javax.inject.Inject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import androidx.compose.material.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.PlayArrow
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
Expand Down Expand Up @@ -42,11 +40,6 @@ fun MusicDAOApp() {

val context = LocalContext.current

val openCreateReleaseDialog = remember { mutableStateOf(false) }
val closeDialog = {
openCreateReleaseDialog.value = false
}

val playerViewModel: PlayerViewModel =
viewModel(factory = PlayerViewModel.provideFactory(context = context))
val ownProfileViewScreenModel: MyProfileScreenViewModel = hiltViewModel()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.runtime.Composable
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.navigation.NavHostController
import androidx.navigation.NavType
Expand All @@ -25,7 +24,6 @@ import nl.tudelft.trustchain.musicdao.ui.screens.artists.DiscoverArtistsScreen
import nl.tudelft.trustchain.musicdao.ui.screens.debug.Debug
import nl.tudelft.trustchain.musicdao.ui.screens.donate.DonateScreen
import nl.tudelft.trustchain.musicdao.ui.screens.home.HomeScreen
import nl.tudelft.trustchain.musicdao.ui.screens.home.HomeScreenViewModel
import nl.tudelft.trustchain.musicdao.ui.screens.release.create.CreateReleaseDialog
import nl.tudelft.trustchain.musicdao.ui.screens.release.ReleaseScreen
import nl.tudelft.trustchain.musicdao.ui.screens.search.SearchScreen
Expand Down Expand Up @@ -67,11 +65,9 @@ fun AppNavigation(
startDestination = Screen.Home.route,
builder = {
composable(Screen.Home.route) {
val homeScreenViewModel: HomeScreenViewModel = hiltViewModel()
val searchScreenViewModel: SearchScreenViewModel = hiltViewModel()
HomeScreen(
navController = navController,
homeScreenViewModel = homeScreenViewModel,
screenViewModel = searchScreenViewModel
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import nl.tudelft.ipv8.attestation.trustchain.TrustChainCommunity
import nl.tudelft.ipv8.util.hexToBytes
import nl.tudelft.ipv8.util.toHex
import nl.tudelft.trustchain.currencyii.CoinCommunity
import nl.tudelft.trustchain.currencyii.CoinCommunity.Companion.SIGNATURE_AGREEMENT_BLOCK
import nl.tudelft.trustchain.currencyii.TrustChainHelper
import nl.tudelft.trustchain.currencyii.coin.WalletManager
import nl.tudelft.trustchain.currencyii.coin.WalletManagerAndroid
Expand Down Expand Up @@ -74,23 +73,6 @@ class DaoViewModel @Inject constructor(val artistRepository: ArtistRepository) :
}
}

/**
* Fetch all DAO blocks that contain a signature. These blocks are the response of a signature request.
* Signatures are fetched from [SIGNATURE_AGREEMENT_BLOCK] type blocks.
*/
fun fetchProposalResponses(
walletId: String,
proposalId: String
): List<SWResponseSignatureBlockTD> {
return getTrustChainCommunity().database.getBlocksWithType(SIGNATURE_AGREEMENT_BLOCK)
.filter {
val blockData = SWResponseSignatureTransactionData(it.transaction)
blockData.matchesProposal(walletId, proposalId)
}.map {
SWResponseSignatureTransactionData(it.transaction).getData()
}
}

/**
* Refresh the state of the DAOs/proposals
*/
Expand Down Expand Up @@ -268,7 +250,7 @@ class DaoViewModel @Inject constructor(val artistRepository: ArtistRepository) :
// TODO: Commented this line out, it causes the app to crash
// withTimeout(SW_CRAWLING_TIMEOUT_MILLI) {
trustchain.crawlChain(peer)
val crawlResult = trustchain
trustchain
.getChainByUser(peer.publicKey.keyToBin())
} catch (t: Throwable) {
val message = t.message ?: "No further information"
Expand Down Expand Up @@ -306,9 +288,9 @@ class DaoViewModel @Inject constructor(val artistRepository: ArtistRepository) :
var signatures: List<SWResponseSignatureBlockTD>? = null
while (signatures == null) {
Thread.sleep(1000)
val oldSignatureCounbt = signatures?.size ?: 0
val oldSignatureCount = signatures?.size ?: 0
signatures = collectJoinWalletResponses(proposeBlockData)
if (signatures != null && signatures.size != oldSignatureCounbt) {
if (signatures != null && signatures.size != oldSignatureCount) {
SnackbarHandler.displaySnackbar(
"Received a new signature: ${signatures.size}/${
requiredSignatures(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import com.google.accompanist.swiperefresh.rememberSwipeRefreshState
@Composable
fun HomeScreen(
navController: NavHostController,
homeScreenViewModel: HomeScreenViewModel,
screenViewModel: SearchScreenViewModel
) {
val isRefreshing by screenViewModel.isRefreshing.observeAsState(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import androidx.compose.material.Text
import androidx.compose.material.TextField
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
Expand All @@ -22,16 +21,13 @@ import kotlinx.coroutines.launch
@RequiresApi(Build.VERSION_CODES.O)
@Composable
fun EditProfileScreen(navController: NavController) {

val ownProfileViewScreenModel: MyProfileScreenViewModel = hiltViewModel()
val profile = ownProfileViewScreenModel.profile.collectAsState()

val name = remember { mutableStateOf(profile.value?.name) }
val bitcoinPublicKey = remember { mutableStateOf(profile.value?.bitcoinAddress) }
val biography = remember { mutableStateOf(profile.value?.biography) }
val socials = remember { mutableStateOf(profile.value?.socials) }

val context = LocalContext.current
val coroutine = rememberCoroutineScope()

fun save() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ fun ReleaseScreen(
playerViewModel: PlayerViewModel,
navController: NavController
) {

var state by remember { mutableStateOf(0) }
val titles = listOf("RELEASE", "TORRENT")

Expand All @@ -65,7 +64,7 @@ fun ReleaseScreen(
)

val torrentStatus by viewModel.torrentState.collectAsState()
val album by viewModel.saturatedReleaseState.observeAsState()
val albumState by viewModel.saturatedReleaseState.observeAsState()

val playingTrack = playerViewModel.playingTrack.collectAsState()

Expand All @@ -81,15 +80,16 @@ fun ReleaseScreen(
Song(
file = track.file,
artist = track.artist,
title = track.title,
title = track.title
),
context, cover
context,
cover
)
}

val scrollState = rememberScrollState()

album?.let { album ->
albumState?.let { album ->
LaunchedEffect(
key1 = playerViewModel,
block = {
Expand Down Expand Up @@ -144,7 +144,6 @@ fun ReleaseScreen(
if (album.songs != null && album.songs.isNotEmpty()) {
val files = album.songs
files.map {

val isPlayingModifier = playingTrack.value?.let { current ->
if (it.title == current.title) {
MaterialTheme.colors.primary
Expand Down Expand Up @@ -263,7 +262,7 @@ fun Header(album: Album, navController: NavController) {
IconButton(onClick = { /*TODO*/ }) {
Icon(
imageVector = Icons.Outlined.Favorite,
contentDescription = null,
contentDescription = null
)
}
IconButton(
Expand All @@ -275,7 +274,7 @@ fun Header(album: Album, navController: NavController) {
) {
Icon(
imageVector = Icons.Outlined.Person,
contentDescription = null,
contentDescription = null
)
}
IconButton(
Expand All @@ -287,7 +286,7 @@ fun Header(album: Album, navController: NavController) {
) {
Icon(
imageVector = Icons.Default.ShoppingCart,
contentDescription = null,
contentDescription = null
)
}

Expand All @@ -296,7 +295,7 @@ fun Header(album: Album, navController: NavController) {
IconButton(onClick = { expanded = true }) {
Icon(
imageVector = Icons.Outlined.MoreVert,
contentDescription = null,
contentDescription = null
)
}
DropdownMenu(
Expand Down Expand Up @@ -330,15 +329,9 @@ fun Header(album: Album, navController: NavController) {
IconButton(onClick = { /*TODO*/ }) {
Icon(
imageVector = Icons.Outlined.PlayArrow,
contentDescription = null,

contentDescription = null
)
}
// OutlinedButton(onClick = { navController.navigate(Screen.Donate.route) }) {
// Row {
// Icon(imageVector = Icons.Default.Send, contentDescription = null)
// }
// }
}
}
}

0 comments on commit ed05929

Please sign in to comment.