Skip to content

Commit 2f4db3a

Browse files
committed
fixes and improvements
* rgb121 issuance * consignment endpoints * fee rate * updated rgb-lib, java, cmake and other deps * many other fixes/improvements
1 parent c16e3b4 commit 2f4db3a

47 files changed

Lines changed: 1417 additions & 376 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
# Sets the minimum version of CMake required to build the native library.
55

6-
cmake_minimum_required(VERSION 3.4.1)
6+
cmake_minimum_required(VERSION 3.10)
7+
8+
project(iriswallet)
79

810
# Creates and names a library, sets it as either STATIC
911
# or SHARED, and provides the relative paths to its source code.

app/build.gradle

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,12 @@ android {
8484
}
8585

8686
compileOptions {
87-
sourceCompatibility JavaVersion.VERSION_1_8
88-
targetCompatibility JavaVersion.VERSION_1_8
87+
sourceCompatibility JavaVersion.VERSION_11
88+
targetCompatibility JavaVersion.VERSION_11
8989
}
9090

9191
kotlinOptions {
92-
jvmTarget = '1.8'
92+
jvmTarget = '11'
9393
}
9494

9595
buildFeatures {
@@ -123,7 +123,7 @@ ksp {
123123

124124
dependencies {
125125
// AndroidX
126-
implementation 'androidx.appcompat:appcompat:1.5.1'
126+
implementation 'androidx.appcompat:appcompat:1.6.0'
127127

128128
implementation 'androidx.biometric:biometric-ktx:1.2.0-alpha05'
129129

@@ -157,24 +157,26 @@ dependencies {
157157

158158
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
159159

160+
implementation 'androidx.work:work-runtime-ktx:2.7.1'
161+
160162
// Bitcoindevkit
161163
implementation 'org.bitcoindevkit:bdk-android:0.11.0'
162164

163165
// Github
164166
implementation 'com.github.lelloman:android-identicons:v11'
165167

166168
// Google
167-
implementation 'com.google.android.gms:play-services-auth:20.4.0'
169+
implementation 'com.google.android.gms:play-services-auth:20.4.1'
168170

169-
implementation 'com.google.android.material:material:1.7.0'
171+
implementation 'com.google.android.material:material:1.8.0'
170172

171173
implementation 'com.google.code.gson:gson:2.9.0'
172174

173175
// Journeyapps
174176
implementation 'com.journeyapps:zxing-android-embedded:4.3.0'
175177

176178
// RGB-Tools
177-
implementation 'org.rgbtools:rgb-lib-android:0.1.6'
179+
implementation 'org.rgbtools:rgb-lib-android:0.1.7'
178180

179181
// Squareup
180182
implementation 'com.squareup.okhttp3:logging-interceptor:4.10.0'

app/src/main/java/com/iriswallet/IrisWallet.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,12 @@ class IrisWallet : Application() {
2828
PreferenceManager.getDefaultSharedPreferences(this)
2929
)
3030
AppContainer.storedMnemonic = SharedPreferencesManager.mnemonic
31+
32+
if (SharedPreferencesManager.proxyConsignmentEndpoint.isBlank()) {
33+
SharedPreferencesManager.proxyConsignmentEndpoint =
34+
AppContainer.proxyConsignmentEndpointDefault
35+
SharedPreferencesManager.electrumURL = AppContainer.electrumURLDefault
36+
SharedPreferencesManager.removeOldKeys()
37+
}
3138
}
3239
}

app/src/main/java/com/iriswallet/data/AppRepository.kt

Lines changed: 66 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@ import com.iriswallet.data.db.HiddenAsset
77
import com.iriswallet.data.db.RgbPendingAsset
88
import com.iriswallet.data.retrofit.RgbAsset
99
import com.iriswallet.utils.*
10+
import java.io.File
11+
import java.io.InputStream
1012
import java.util.concurrent.TimeUnit
1113
import org.rgbtools.RgbLibException
1214

1315
object AppRepository {
1416

1517
internal var isCacheDirty: Boolean = false
1618

17-
lateinit var appAssets: MutableList<AppAsset>
19+
val appAssets: MutableList<AppAsset> = mutableListOf()
1820

1921
private var rgbPendingAssetIDs: MutableList<String> = mutableListOf()
2022

@@ -51,9 +53,7 @@ object AppRepository {
5153

5254
val transfers = BdkRepository.listTransfers().toMutableList()
5355
val autoTXs = AppContainer.db.automaticTransactionDao().getAutomaticTransactions()
54-
transfers
55-
.filter { it.txid in autoTXs.map { tx -> tx.txid } }
56-
.forEach { it.automatic = true }
56+
transfers.filter { it.txid in autoTXs.map { tx -> tx.txid } }.forEach { it.internal = true }
5757
bitcoinAsset.transfers = transfers
5858

5959
val balance = BdkRepository.getBalance()
@@ -129,8 +129,8 @@ object AppRepository {
129129
if (firstAppRefresh) {
130130
val changed = RgbRepository.refresh()
131131
if (!changed) return
132-
val rgbAssets = RgbRepository.listAssets()
133-
for (rgbAsset in rgbAssets) {
132+
val updatedRgbAssets = RgbRepository.listAssets()
133+
for (rgbAsset in updatedRgbAssets) {
134134
var assetToUpdate = getCachedAsset(rgbAsset.id)
135135
if (assetToUpdate == null) {
136136
assetToUpdate = rgbAsset
@@ -169,7 +169,11 @@ object AppRepository {
169169
Log.d(TAG, "Sending funds to RGB wallet...")
170170
try {
171171
val txid =
172-
BdkRepository.sendToAddress(RgbRepository.getAddress(), AppConstants.satsForRgb)
172+
BdkRepository.sendToAddress(
173+
RgbRepository.getAddress(),
174+
AppConstants.satsForRgb,
175+
SharedPreferencesManager.feeRate.toFloat()
176+
)
173177
AppContainer.db
174178
.automaticTransactionDao()
175179
.insertAutomaticTransactions(AutomaticTransaction(txid))
@@ -235,9 +239,15 @@ object AppRepository {
235239
return Receiver(blindedData.invoice, AppConstants.rgbBlindDuration, false)
236240
}
237241

238-
private fun initiateRgbTransfer(asset: AppAsset, blindedUTXO: String, amount: ULong): String {
242+
private fun initiateRgbTransfer(
243+
asset: AppAsset,
244+
blindedUTXO: String,
245+
amount: ULong,
246+
consignmentEndpoints: List<String>,
247+
feeRate: Float,
248+
): String {
239249
Log.d(TAG, "Initiating transfer for blinded UTXO: $blindedUTXO")
240-
val txid = RgbRepository.send(asset, blindedUTXO, amount)
250+
val txid = RgbRepository.send(asset, blindedUTXO, amount, consignmentEndpoints, feeRate)
241251
runCatching {
242252
updateRGBAssets(
243253
refresh = false,
@@ -249,7 +259,7 @@ object AppRepository {
249259
return txid
250260
}
251261

252-
fun issueRGBAsset(ticker: String, name: String, amounts: List<ULong>): AppAsset {
262+
fun issueRgb20Asset(ticker: String, name: String, amounts: List<ULong>): AppAsset {
253263
checkMaxAssets()
254264
val contract = handleMissingFunds { RgbRepository.issueAssetRgb20(ticker, name, amounts) }
255265
val asset =
@@ -264,6 +274,40 @@ object AppRepository {
264274
return asset
265275
}
266276

277+
fun issueRgb121Asset(
278+
name: String,
279+
amounts: List<ULong>,
280+
description: String?,
281+
fileStream: InputStream?
282+
): AppAsset {
283+
checkMaxAssets()
284+
val contract = handleMissingFunds {
285+
var filePath: String? = null
286+
var file: File? = null
287+
288+
if (fileStream != null) {
289+
file = File.createTempFile("tmp", null, AppContainer.appContext.cacheDir)
290+
file.writeBytes(fileStream.readBytes())
291+
fileStream.close()
292+
filePath = file.absolutePath
293+
}
294+
295+
val contract = RgbRepository.issueAssetRgb121(name, amounts, description, filePath)
296+
file?.delete()
297+
contract
298+
}
299+
val asset =
300+
AppAsset(
301+
AppAssetType.RGB121,
302+
contract.assetId,
303+
name,
304+
)
305+
if (contract.dataPaths.isNotEmpty()) asset.media = AppMedia(contract.dataPaths[0])
306+
appAssets.add(asset)
307+
updateRGBAsset(asset)
308+
return asset
309+
}
310+
267311
fun deleteRGBTransfer(asset: AppAsset, transfer: AppTransfer): AppAsset {
268312
Log.d(TAG, "Removing transfer '$transfer'")
269313
RgbRepository.deleteTransfer(transfer)
@@ -299,13 +343,21 @@ object AppRepository {
299343
else handleMissingFunds { startRGBReceiving(asset) }
300344
}
301345

302-
fun sendAsset(asset: AppAsset, recipient: String, amount: ULong): String {
303-
return if (asset.bitcoin()) BdkRepository.sendToAddress(recipient, amount)
304-
else handleMissingFunds { initiateRgbTransfer(asset, recipient, amount) }
346+
fun sendAsset(
347+
asset: AppAsset,
348+
recipient: String,
349+
amount: ULong,
350+
consignmentEndpoints: List<String>,
351+
feeRate: Float,
352+
): String {
353+
return if (asset.bitcoin()) BdkRepository.sendToAddress(recipient, amount, feeRate)
354+
else
355+
handleMissingFunds {
356+
initiateRgbTransfer(asset, recipient, amount, consignmentEndpoints, feeRate)
357+
}
305358
}
306359

307360
fun getAssets(): List<AppAsset> {
308-
appAssets = mutableListOf()
309361
updateBitcoinAsset(refresh = false)
310362
updateRGBAssets(refresh = false)
311363

app/src/main/java/com/iriswallet/data/BdkRepository.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,12 @@ object BdkRepository {
7878
return vanillaWallet.listUnspent().map { UTXO(it) }
7979
}
8080

81-
fun sendToAddress(address: String, amount: ULong): String {
81+
fun sendToAddress(address: String, amount: ULong, feeRate: Float): String {
8282
try {
8383
val psbt =
8484
TxBuilder()
8585
.addRecipient(Address(address).scriptPubkey(), amount)
86+
.feeRate(feeRate)
8687
.finish(vanillaWallet)
8788
.psbt
8889
vanillaWallet.sign(psbt)

app/src/main/java/com/iriswallet/data/RgbRepository.kt

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,16 @@ object RgbRepository {
1919
)
2020
}
2121

22-
private val online: Online by lazy {
23-
coloredWallet.goOnline(true, AppContainer.electrumURL, AppContainer.proxyURL)
24-
}
22+
private val online: Online by lazy { coloredWallet.goOnline(true, AppContainer.electrumURL) }
2523

2624
fun createUTXOs(): UByte {
27-
return coloredWallet.createUtxos(online, false, null, null)
25+
return coloredWallet.createUtxos(
26+
online,
27+
false,
28+
null,
29+
null,
30+
SharedPreferencesManager.feeRate.toFloat()
31+
)
2832
}
2933

3034
fun deleteTransfer(transfer: AppTransfer) {
@@ -49,7 +53,12 @@ object RgbRepository {
4953
}
5054

5155
fun getBlindedUTXO(assetID: String? = null, expirationSeconds: UInt): BlindData {
52-
return coloredWallet.blind(assetID, null, expirationSeconds)
56+
return coloredWallet.blind(
57+
assetID,
58+
null,
59+
expirationSeconds,
60+
listOf(AppContainer.proxyConsignmentEndpoint)
61+
)
5362
}
5463

5564
fun getMetadata(assetID: String): Metadata {
@@ -66,6 +75,23 @@ object RgbRepository {
6675
)
6776
}
6877

78+
fun issueAssetRgb121(
79+
name: String,
80+
amounts: List<ULong>,
81+
description: String?,
82+
filePath: String?
83+
): AssetRgb121 {
84+
return coloredWallet.issueAssetRgb121(
85+
online,
86+
name,
87+
description,
88+
AppConstants.rgbDefaultPrecision,
89+
amounts,
90+
null,
91+
filePath
92+
)
93+
}
94+
6995
fun listAssets(): List<AppAsset> {
7096
val assets = coloredWallet.listAssets(listOf())
7197
val assetsRgb20 = assets.rgb20!!.toList()
@@ -88,15 +114,29 @@ object RgbRepository {
88114
}
89115
}
90116

91-
fun refresh(asset: AppAsset? = null): Boolean {
92-
return coloredWallet.refresh(online, asset?.id, listOf())
117+
fun refresh(asset: AppAsset? = null, light: Boolean = false): Boolean {
118+
val filter =
119+
if (light)
120+
listOf(
121+
RefreshFilter(RefreshTransferStatus.WAITING_COUNTERPARTY, true),
122+
RefreshFilter(RefreshTransferStatus.WAITING_COUNTERPARTY, false)
123+
)
124+
else listOf()
125+
return coloredWallet.refresh(online, asset?.id, filter)
93126
}
94127

95-
fun send(asset: AppAsset, blindedUTXO: String, amount: ULong): String {
128+
fun send(
129+
asset: AppAsset,
130+
blindedUTXO: String,
131+
amount: ULong,
132+
consignmentEndpoints: List<String>,
133+
feeRate: Float,
134+
): String {
96135
return coloredWallet.send(
97136
online,
98-
mapOf(asset.id to listOf(Recipient(blindedUTXO, amount))),
99-
false
137+
mapOf(asset.id to listOf(Recipient(blindedUTXO, amount, consignmentEndpoints))),
138+
false,
139+
feeRate,
100140
)
101141
}
102142
}

0 commit comments

Comments
 (0)