-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from MKuijpers/add_new_page
Add our page to the app
- Loading branch information
Showing
11 changed files
with
271 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
demo-android/src/main/java/nl/tudelft/ipv8/android/demo/CoinCommunity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package nl.tudelft.ipv8.android.demo | ||
import nl.tudelft.ipv8.Address | ||
import nl.tudelft.ipv8.Community | ||
import nl.tudelft.ipv8.IPv8 | ||
import nl.tudelft.ipv8.android.IPv8Android | ||
import nl.tudelft.ipv8.attestation.trustchain.* | ||
import nl.tudelft.ipv8.attestation.trustchain.store.TrustChainStore | ||
import nl.tudelft.ipv8.keyvault.Key | ||
import java.util.* | ||
|
||
class CoinCommunity: Community() { | ||
override val serviceId = "0000bitcoin0000community0000" | ||
|
||
public val discoveredAddressesContacted: MutableMap<Address, Date> = mutableMapOf() | ||
|
||
protected val trustchain: TrustChainHelper by lazy { | ||
TrustChainHelper(getTrustChainCommunity()) | ||
} | ||
|
||
override fun walkTo(address: Address) { | ||
super.walkTo(address) | ||
discoveredAddressesContacted[address] = Date() | ||
} | ||
|
||
protected fun getTrustChainCommunity(): TrustChainCommunity { | ||
return getIpv8().getOverlay() ?: throw IllegalStateException("TrustChainCommunity is not configured") | ||
} | ||
|
||
protected fun getIpv8(): IPv8 { | ||
return IPv8Android.getInstance() | ||
} | ||
|
||
public fun sendCurrency(amount: Double, toPublicKey: ByteArray = myPeer.publicKey.keyToBin()) { | ||
val message = "Transaction amount: $amount bitcoins" | ||
trustchain.createProposalBlock(message, toPublicKey, BLOCK_TYPE) | ||
} | ||
|
||
companion object { | ||
private const val BLOCK_TYPE = "coin_block" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
demo-android/src/main/java/nl/tudelft/ipv8/android/demo/ui/bitcoin/BitcoinFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package nl.tudelft.ipv8.android.demo.ui.bitcoin | ||
|
||
import android.os.Bundle | ||
import androidx.fragment.app.Fragment | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import kotlinx.android.synthetic.main.fragment_bitcoin.* | ||
import nl.tudelft.ipv8.android.demo.R | ||
import nl.tudelft.ipv8.android.demo.ui.BaseFragment | ||
import nl.tudelft.ipv8.util.hexToBytes | ||
|
||
/** | ||
* A simple [Fragment] subclass. | ||
* Use the [BitcoinFragment.newInstance] factory method to | ||
* create an instance of this fragment. | ||
*/ | ||
class BitcoinFragment : BaseFragment(R.layout.fragment_bitcoin) { | ||
private var publicKeyReceiver: String = "" | ||
private var bitcoinPrivateKey: String = "" | ||
private var transactionAmount: Double = 0.0 | ||
|
||
override fun onActivityCreated(savedInstanceState: Bundle?) { | ||
super.onActivityCreated(savedInstanceState) | ||
|
||
button3.setOnClickListener { | ||
publicKeyReceiver = pk_receiver.text.toString() | ||
transactionAmount = tx_amount.text.toString().toDouble() | ||
outputTextView.text = "PK Receiver: $publicKeyReceiver, Amount: $transactionAmount" | ||
|
||
getCoinCommunity().sendCurrency(transactionAmount, publicKeyReceiver.hexToBytes()) | ||
} | ||
} | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View? { | ||
// Inflate the layout for this fragment | ||
return inflater.inflate(R.layout.fragment_bitcoin, container, false) | ||
} | ||
|
||
companion object { | ||
/** | ||
* Use this factory method to create a new instance of | ||
* this fragment using the provided parameters. | ||
* | ||
* @return A new instance of fragment bitcoinFragment. | ||
*/ | ||
@JvmStatic | ||
fun newInstance() = BitcoinFragment() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context=".ui.bitcoin.BitcoinFragment"> | ||
|
||
<!-- TODO: Update blank fragment layout --> | ||
|
||
<LinearLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:orientation="vertical" | ||
android:padding="20px"> | ||
|
||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="@string/sending_bitcoins" | ||
android:textAppearance="@style/TextAppearance.AppCompat.Large" /> | ||
|
||
<LinearLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:orientation="horizontal"> | ||
|
||
<TextView | ||
android:id="@+id/textView" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_weight="1" | ||
android:text="PK of Receiver:" /> | ||
|
||
<EditText | ||
android:id="@+id/pk_receiver" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:ems="10" | ||
android:inputType="textPersonName" /> | ||
</LinearLayout> | ||
|
||
<LinearLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:orientation="horizontal"> | ||
|
||
<TextView | ||
android:id="@+id/textView3" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_weight="1" | ||
android:text="Bitcoin amount:" /> | ||
|
||
<EditText | ||
android:id="@+id/tx_amount" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_weight="1" | ||
android:ems="10" | ||
android:inputType="numberDecimal" /> | ||
</LinearLayout> | ||
|
||
<Button | ||
android:id="@+id/button3" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="@string/send_bitcoin" /> | ||
<TextView | ||
android:id="@+id/outputTextView" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:text="" /> | ||
|
||
<LinearLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:baselineAligned="false" | ||
android:gravity="bottom" | ||
android:orientation="vertical"> | ||
|
||
<LinearLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:orientation="vertical"> | ||
|
||
<LinearLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:orientation="horizontal"> | ||
|
||
<TextView | ||
android:id="@+id/textView7" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="Balance:" /> | ||
|
||
<TextView | ||
android:id="@+id/textView6" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_weight="1" | ||
android:text="10.3 BtC" | ||
android:textAlignment="center" /> | ||
</LinearLayout> | ||
|
||
<LinearLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:orientation="horizontal"> | ||
|
||
<TextView | ||
android:id="@+id/textView5" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="Public Key:" /> | ||
|
||
<TextView | ||
android:id="@+id/textView4" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_weight="1" | ||
android:text="1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2" | ||
android:textAlignment="center" /> | ||
</LinearLayout> | ||
|
||
</LinearLayout> | ||
|
||
</LinearLayout> | ||
|
||
</LinearLayout> | ||
|
||
</FrameLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters