diff --git a/currencyii/src/main/java/nl/tudelft/trustchain/currencyii/CoinCommunity.kt b/currencyii/src/main/java/nl/tudelft/trustchain/currencyii/CoinCommunity.kt index de52e5917..433e30408 100644 --- a/currencyii/src/main/java/nl/tudelft/trustchain/currencyii/CoinCommunity.kt +++ b/currencyii/src/main/java/nl/tudelft/trustchain/currencyii/CoinCommunity.kt @@ -4,6 +4,7 @@ import android.app.Activity import android.content.Context import android.util.Log import android.widget.Toast +import androidx.fragment.app.Fragment import nl.tudelft.ipv8.Community import nl.tudelft.ipv8.Overlay import nl.tudelft.ipv8.Peer @@ -252,6 +253,12 @@ open class CoinCommunity constructor( payload: ByteArray ) { Log.i("CoinCommunitySending", "Sending payload to ${peer.address}") + Toast.makeText( + this.context, + "Sending payload to ${peer.address}", + Toast.LENGTH_SHORT + ).show() + send( peer, payload @@ -293,6 +300,11 @@ open class CoinCommunity constructor( private fun onDaoJoinDataPacket(packet: Packet) { Log.d("LEADER", "Received data from Peer wanting to join") + Toast.makeText( + this.context, + "Received data from Peer wanting to join", + Toast.LENGTH_SHORT + ).show() val (peer, payload) = packet.getAuthPayload( @@ -300,6 +312,12 @@ open class CoinCommunity constructor( ) try { Log.d("LEADER", "Peer wanting to join: ${peer.publicKey}") + Toast.makeText( + this.context, + "Peer wanting to join: ${peer.publicKey}", + Toast.LENGTH_SHORT + ).show() + joinBitcoinWallet( payload.mostRecentSWBlock.transaction, payload.proposeBlockData, @@ -309,8 +327,19 @@ open class CoinCommunity constructor( // Add new nonceKey after joining a DAO WalletManagerAndroid.getInstance() .addNewNonceKey(payload.proposeBlockData.SW_UNIQUE_ID, this.context) + + Toast.makeText( + this.context, + "Peer: ${peer.publicKey}, joined successfully", + Toast.LENGTH_SHORT + ).show() } catch (t: Throwable) { Log.e("LEADER", "Joining failed. ${t.message ?: "No further information"}.") + Toast.makeText( + this.context, + "Peer: ${peer.publicKey}, failed to join", + Toast.LENGTH_SHORT + ).show() } } @@ -354,6 +383,12 @@ open class CoinCommunity constructor( payload: ElectedPayload ) { Log.d("LEADER", "Elected: " + peer.publicKey) + Toast.makeText( + this.context, + "Elected: ${peer.publicKey} as leader", + Toast.LENGTH_SHORT + ).show() + getCurrentLeader()[payload.DAOid.decodeToString()] = peer } @@ -363,6 +398,12 @@ open class CoinCommunity constructor( ElectionPayload.Deserializer ) Log.d("Leader", "Election packet received.") + + Toast.makeText( + this.context, + "Election packed received", + Toast.LENGTH_SHORT + ).show() getCandidates()[payload.DAOid.decodeToString()] = ArrayList() onElectionRequest(peer, payload) } @@ -390,6 +431,11 @@ open class CoinCommunity constructor( this.sendPayload(peer, aliveResponse) Log.d("Leader", "Election started.") + Toast.makeText( + this.context, + "Leader election started", + Toast.LENGTH_SHORT + ).show() getCurrentLeader()[payload.DAOid.decodeToString()] = null @@ -403,6 +449,11 @@ open class CoinCommunity constructor( if (higherPeers.isEmpty()) { Log.d("Leader", "Elected: " + this.myPeer.publicKey) + Toast.makeText( + this.context, + "Elected ${this.myPeer.publicKey} as leader", + Toast.LENGTH_SHORT + ).show() val electedPayload = this.createElectedResponse(payload.DAOid) this.sendPayload(peer, electedPayload) @@ -450,6 +501,12 @@ open class CoinCommunity constructor( ) { Log.d("LEADER", "Leader doesn't exists.") Log.d("LEADER", "Requesting election...") + Toast.makeText( + this.context, + "Requesting election...", + Toast.LENGTH_SHORT + ).show() + val peers = this.getPeers() val peerPK = getPeersPKInDao(publicKeyBlock) for (peer in peers) { @@ -466,6 +523,12 @@ open class CoinCommunity constructor( val currentLeader = getCurrentLeader()[publicKeyBlock.decodeToString()]!! Log.d("LEADER", "sending dao join transaction data to leader ${currentLeader.publicKey}") + Toast.makeText( + this.context, + "sending dao join transaction data to leader ${currentLeader.publicKey}", + Toast.LENGTH_SHORT + ).show() + val payload = SignPayload( getServiceIdNew().toByteArray(),