-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 4665d31
Showing
96 changed files
with
6,522 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
*.iml | ||
.gradle | ||
.idea/ | ||
/local.properties | ||
/build |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2019 bitcoin portal | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,211 @@ | ||
# SLPWallet Android SDK | ||
|
||
![Platform](https://img.shields.io/badge/platform-android-lightgrey.svg) | ||
![License](https://img.shields.io/badge/License-MIT-black.svg) | ||
|
||
## Supported Android Versions | ||
5.0+ | ||
|
||
### Warning | ||
On Android versions prior to Android 6.0 Marshmallow, disabling the secure lock screen (reconfiguring it to None, Swipe, or another mode which does not authenicate the user) will have the following conquences: | ||
- Loss of the BCH and tokens held at the wallet address. | ||
- Loss of access to the private key that controls the BCH and tokens held at the wallet address. | ||
|
||
|
||
Tokens and any extra BCH at the wallet address can only be recovered if the mnemonic has been previously backed up. | ||
|
||
|
||
## Installation | ||
|
||
### Gradle | ||
Add JitPack to the list of repositories in your top level `build.gradle` file for the project: | ||
```groovy | ||
allprojects { | ||
repositories { | ||
google() | ||
jcenter() | ||
maven { url 'https://jitpack.io' } // Add this repository | ||
} | ||
} | ||
``` | ||
|
||
In the module 'build.gradle' file, add the dependency: | ||
```groovy | ||
dependencies { | ||
// ... | ||
implementation 'com.github.Bitcoin-com:slp-wallet-sdk-android:0.4' | ||
implementation 'com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava' | ||
} | ||
``` | ||
Excluding guava is required to avoid conflicts. | ||
|
||
#### Binary compatibility | ||
In the current version of the SDK, some items need to be removed for binary compatibility. | ||
|
||
Add these packaging options to your module `build.gradle`. | ||
```groovy | ||
android { | ||
// ... | ||
packagingOptions { | ||
exclude 'lib/x86_64/darwin/libscrypt.dylib' | ||
exclude 'lib/x86_64/freebsd/libscrypt.so' | ||
exclude 'lib/x86_64/linux/libscrypt.so' | ||
} | ||
} | ||
``` | ||
|
||
|
||
## Get Started | ||
|
||
```kotlin | ||
import com.bitcoin.slpwallet.SLPWallet | ||
|
||
// Create a new wallet on mainnet, or load one previously created. | ||
val slpWallet: SLPWallet = SLPWallet.loadOrCreate(context, Network.MAIN) | ||
|
||
val slpWalletFromPhrase: SLPWallet = SLPWallet.fromMnemonic( | ||
context, | ||
Network.MAIN | ||
"rare genre crumble sport burger laugh lecture reject exhaust hello express pass" | ||
) | ||
|
||
// A wallet is created on mainnet if one does not exist already. | ||
val slpWallet: SLPWallet = SLPWallet.getInstance(context) | ||
``` | ||
|
||
|
||
## Addresses + Mnemonic | ||
The wallet resuses two addresses that shares mnemonic. | ||
|
||
* The SLP address on m/44'/245'/0'/0/0. | ||
* The BCH address on m/44'/145'/0'/0/0. | ||
|
||
All BCH change will be sent to the BCH address while all token change is sent to the SLP address, separating the two if they were not already. This helps protect against accidental spending of BCH that contains SLP, by wallets are not aware of SLP, which would result in loss of coins. | ||
|
||
```kotlin | ||
slpWallet.mnemonic // "rare", "genre", "crumble", "sport", "burger", "laugh", "lecture", "reject", "exhaust", "hello", "express", "pass" | ||
slpWallet.slpAddress // simpleledger:qr6wa5eemn0fl3vghvk5cr480s3fqtgnevkaxny9x7 | ||
slpWallet.bchAddress // bitcoincash:qr6wa5eemn0fl3vghvk5cr480s3fqtgnev6xdg39cq | ||
|
||
``` | ||
|
||
### Token and BCH Balances | ||
The balances, including both tokens and BCH, are available as LiveData. | ||
```kotlin | ||
slpWallet.balance.observe(this, Observer { balanceList: List<BalanceInfo> -> | ||
var balances = "" | ||
for (balance in balanceList) { | ||
val nf = getTokenNumberFormat(balance.decimals, balance.ticker) | ||
balances += "${nf.format(balance.amount)}\n" | ||
} | ||
balancesText.text = balances | ||
}) | ||
``` | ||
The BCH balance item has an emtpy `tokenId` of `""`. | ||
|
||
```kotlin | ||
interface BalanceInfo { | ||
var tokenId: String | ||
var amount: BigDecimal | ||
var ticker: String? | ||
var name: String? | ||
var decimals: Int? | ||
} | ||
``` | ||
|
||
To refresh the current balance: | ||
|
||
```kotlin | ||
slpWallet.refreshBalance() | ||
``` | ||
|
||
## Send Token | ||
|
||
```kotlin | ||
private val compositeDisposable = CompositeDisposable() | ||
|
||
// ... | ||
|
||
val tokenId = "73bf34eb6cd6879fc75b0e91ad82ef61a6bf2f10adb38a067a25b30f9a644cea" | ||
val amount = BigDecimal(1) | ||
val toAddress = "simpleledger:qpfp0tfafxfq52mdpperlyschmmh6scfgse80v7a4p" | ||
|
||
slpWallet.sendToken(tokenId, amount, toAddress) | ||
.subscribeOn(Schedulers.io()) | ||
.subscribe( | ||
{ txid: String -> | ||
Timber.d("sendToken() was successful, with txid: $txid") | ||
}, | ||
{ e: Throwable -> | ||
Timber.e("Error when sending. $e") | ||
} | ||
).addTo(compositeDisposable) | ||
``` | ||
The example above uses Rx, but the status of the send task is also available as LiveData: | ||
```kotlin | ||
slpWallet.sendStatus.observe(this, Observer { task: ProgressTask<String?> -> | ||
var sendStatus = "" | ||
when (task.status) { | ||
TaskStatus.IDLE -> { | ||
sendStatus = "" | ||
} | ||
TaskStatus.UNDERWAY -> { | ||
sendStatus = "Sending..." | ||
} | ||
TaskStatus.SUCCESS -> { | ||
sendStatus = "Sent tx ${task.result}" | ||
} | ||
TaskStatus.ERROR -> { | ||
sendStatus = "Error. ${task.message}" | ||
} | ||
} | ||
sendStatusText.text = sendStatus | ||
}) | ||
``` | ||
|
||
Once a send has been completed, you can reset the status to `IDLE`: | ||
```kotlin | ||
slpWallet.clearSendStatus() | ||
``` | ||
|
||
## UI | ||
Some convenience methods are included to make it easier to display tokens in your UI. | ||
|
||
### Formatting Amounts | ||
This will display the amount to the full number of decimal places permitted by the coin, preceded by the ticker. | ||
```kotlin | ||
import com.bitcoin.slpwallet.getTokenNumberFormat | ||
|
||
val nf: NumberFormat = getTokenNumberFormat(decimals, ticker) | ||
val text: String = nf.format(amount) // "AAR 123.45" | ||
``` | ||
|
||
## Logging | ||
This library uses [Timber](https://github.com/JakeWharton/timber) for logging, but does not plant it's own tree. Plant a tree like this when your application starts to see the logs: | ||
|
||
```kotlin | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
if (BuildConfig.DEBUG) { | ||
Timber.plant(Timber.DebugTree()) | ||
} | ||
|
||
// ... | ||
} | ||
``` | ||
|
||
## Authors & Maintainers | ||
- [akibabu](https://github.com/akibabu) | ||
- [brendoncoin](https://github.com/brendoncoin) | ||
|
||
|
||
## References | ||
- [Simple Ledger Protocol (SLP)](https://github.com/simpleledger/slp-specifications/blob/master/slp-token-type-1.md) | ||
|
||
## License | ||
|
||
SLPWallet Android SDK is available under the MIT license. See the LICENSE file for more info. |
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,31 @@ | ||
buildscript { | ||
ext.kotlin_version = '1.3.21' | ||
ext.lifecycle_version = "2.0.0" | ||
ext.room_version = "1.1.1" | ||
ext.retrofit_version = "2.5.0" | ||
|
||
repositories { | ||
google() | ||
jcenter() | ||
mavenCentral() | ||
} | ||
dependencies { | ||
classpath 'com.android.tools.build:gradle:3.3.2' | ||
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' | ||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" | ||
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.0.0" | ||
} | ||
} | ||
|
||
allprojects { | ||
repositories { | ||
google() | ||
jcenter() | ||
mavenCentral() | ||
maven { url 'https://jitpack.io' } | ||
} | ||
} | ||
|
||
task clean(type: Delete) { | ||
delete rootProject.buildDir | ||
} |
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,21 @@ | ||
# Project-wide Gradle settings. | ||
# IDE (e.g. Android Studio) users: | ||
# Gradle settings configured through the IDE *will override* | ||
# any settings specified in this file. | ||
# For more details on how to configure your build environment visit | ||
# http://www.gradle.org/docs/current/userguide/build_environment.html | ||
# Specifies the JVM arguments used for the daemon process. | ||
# The setting is particularly useful for tweaking memory settings. | ||
org.gradle.jvmargs=-Xmx1536m | ||
# When configured, Gradle will run in incubating parallel mode. | ||
# This option should only be used with decoupled projects. More details, visit | ||
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects | ||
# org.gradle.parallel=true | ||
# AndroidX package structure to make it clearer which packages are bundled with the | ||
# Android operating system, and which are packaged with your app's APK | ||
# https://developer.android.com/topic/libraries/support-library/androidx-rn | ||
android.useAndroidX=true | ||
# Automatically convert third-party libraries to use AndroidX | ||
android.enableJetifier=true | ||
# Kotlin code style for this project: "official" or "obsolete": | ||
kotlin.code.style=official |
Binary file not shown.
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,6 @@ | ||
#Thu Mar 28 22:17:42 JST 2019 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip |
Oops, something went wrong.