react-native-rgb 0.2.1 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/src/main/java/com/rgb/RgbModule.kt +109 -18
- package/ios/AppConstants.swift +36 -50
- package/ios/Rgb.mm +246 -261
- package/ios/Rgb.swift +144 -37
- package/lib/module/Interfaces.js.map +1 -1
- package/lib/module/NativeRgb.js.map +1 -1
- package/lib/module/Wallet.js.map +1 -1
- package/lib/typescript/docs/docusaurus.config.d.ts +4 -0
- package/lib/typescript/docs/docusaurus.config.d.ts.map +1 -0
- package/lib/typescript/docs/sidebars.d.ts +14 -0
- package/lib/typescript/docs/sidebars.d.ts.map +1 -0
- package/lib/typescript/docs/src/components/HomepageFeatures/index.d.ts +3 -0
- package/lib/typescript/docs/src/components/HomepageFeatures/index.d.ts.map +1 -0
- package/lib/typescript/docs/src/pages/index.d.ts +2 -0
- package/lib/typescript/docs/src/pages/index.d.ts.map +1 -0
- package/lib/typescript/src/Interfaces.d.ts +51 -19
- package/lib/typescript/src/Interfaces.d.ts.map +1 -1
- package/lib/typescript/src/NativeRgb.d.ts +34 -173
- package/lib/typescript/src/NativeRgb.d.ts.map +1 -1
- package/package.json +3 -2
- package/src/Interfaces.ts +55 -19
- package/src/NativeRgb.ts +42 -192
- package/src/Wallet.ts +2 -2
|
@@ -340,6 +340,37 @@ class RgbModule(reactContext: ReactApplicationContext) :
|
|
|
340
340
|
return Recipient(recipientId, witnessData, assignment, transportEndpoints)
|
|
341
341
|
}
|
|
342
342
|
|
|
343
|
+
private fun assignmentToMap(assignment: Assignment): WritableMap {
|
|
344
|
+
val map = Arguments.createMap()
|
|
345
|
+
when (assignment) {
|
|
346
|
+
is Assignment.Fungible -> {
|
|
347
|
+
map.putString("type", "FUNGIBLE")
|
|
348
|
+
map.putDouble("amount", assignment.amount.toDouble())
|
|
349
|
+
}
|
|
350
|
+
is Assignment.NonFungible -> {
|
|
351
|
+
map.putString("type", "NON_FUNGIBLE")
|
|
352
|
+
}
|
|
353
|
+
is Assignment.InflationRight -> {
|
|
354
|
+
map.putString("type", "INFLATION_RIGHT")
|
|
355
|
+
map.putDouble("amount", assignment.amount.toDouble())
|
|
356
|
+
}
|
|
357
|
+
is Assignment.ReplaceRight -> {
|
|
358
|
+
map.putString("type", "REPLACE_RIGHT")
|
|
359
|
+
}
|
|
360
|
+
is Assignment.Any -> {
|
|
361
|
+
map.putString("type", "ANY")
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
return map
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
private fun outpointToMap(outpoint: org.rgbtools.Outpoint): WritableMap {
|
|
368
|
+
val map = Arguments.createMap()
|
|
369
|
+
map.putString("txid", outpoint.txid)
|
|
370
|
+
map.putDouble("vout", outpoint.vout.toDouble())
|
|
371
|
+
return map
|
|
372
|
+
}
|
|
373
|
+
|
|
343
374
|
private fun balanceToMap(balance: org.rgbtools.Balance): WritableMap {
|
|
344
375
|
val map = Arguments.createMap()
|
|
345
376
|
map.putDouble("settled", balance.settled.toDouble())
|
|
@@ -397,6 +428,7 @@ class RgbModule(reactContext: ReactApplicationContext) :
|
|
|
397
428
|
map.putString("assetId", asset.assetId)
|
|
398
429
|
map.putString("ticker", asset.ticker)
|
|
399
430
|
map.putString("name", asset.name)
|
|
431
|
+
asset.details?.let { map.putString("details", it) }
|
|
400
432
|
map.putInt("precision", asset.precision.toInt())
|
|
401
433
|
map.putDouble("issuedSupply", asset.issuedSupply.toDouble())
|
|
402
434
|
map.putDouble("timestamp", asset.timestamp.toDouble())
|
|
@@ -1458,7 +1490,7 @@ class RgbModule(reactContext: ReactApplicationContext) :
|
|
|
1458
1490
|
|
|
1459
1491
|
transfers.forEach { transfer ->
|
|
1460
1492
|
val transferMap = Arguments.createMap()
|
|
1461
|
-
transferMap.putInt("
|
|
1493
|
+
transferMap.putInt("idx", transfer.idx)
|
|
1462
1494
|
transferMap.putInt("batchTransferIdx", transfer.batchTransferIdx)
|
|
1463
1495
|
transferMap.putDouble("createdAt", transfer.createdAt.toDouble())
|
|
1464
1496
|
transferMap.putDouble("updatedAt", transfer.updatedAt.toDouble())
|
|
@@ -1482,24 +1514,39 @@ class RgbModule(reactContext: ReactApplicationContext) :
|
|
|
1482
1514
|
|
|
1483
1515
|
transfer.txid?.let { transferMap.putString("txid", it) }
|
|
1484
1516
|
transfer.recipientId?.let { transferMap.putString("recipientId", it) }
|
|
1517
|
+
transfer.expiration?.let { transferMap.putDouble("expiration", it.toDouble()) }
|
|
1518
|
+
|
|
1519
|
+
transfer.requestedAssignment?.let {
|
|
1520
|
+
transferMap.putMap("requestedAssignment", assignmentToMap(it))
|
|
1521
|
+
}
|
|
1522
|
+
|
|
1523
|
+
val assignmentsArray = Arguments.createArray()
|
|
1524
|
+
transfer.assignments.forEach { assignment ->
|
|
1525
|
+
assignmentsArray.pushMap(assignmentToMap(assignment))
|
|
1526
|
+
}
|
|
1527
|
+
transferMap.putArray("assignments", assignmentsArray)
|
|
1528
|
+
|
|
1485
1529
|
transfer.receiveUtxo?.let {
|
|
1486
|
-
transferMap.
|
|
1487
|
-
transferMap.putDouble("receiveUtxoVout", it.vout.toDouble())
|
|
1530
|
+
transferMap.putMap("receiveUtxo", outpointToMap(it))
|
|
1488
1531
|
}
|
|
1532
|
+
|
|
1489
1533
|
transfer.changeUtxo?.let {
|
|
1490
|
-
transferMap.
|
|
1491
|
-
transferMap.putDouble("changeUtxoVout", it.vout.toDouble())
|
|
1534
|
+
transferMap.putMap("changeUtxo", outpointToMap(it))
|
|
1492
1535
|
}
|
|
1493
|
-
transfer.expiration?.let { transferMap.putDouble("expiration", it.toDouble()) }
|
|
1494
1536
|
|
|
1495
|
-
val
|
|
1496
|
-
|
|
1537
|
+
val transportEndpointsMap = Arguments.createArray()
|
|
1538
|
+
transfer.transportEndpoints.forEach {
|
|
1539
|
+
val endpoint = Arguments.createMap()
|
|
1540
|
+
endpoint.putString("endpoint", it.endpoint)
|
|
1541
|
+
endpoint.putBoolean("used", it.used)
|
|
1542
|
+
endpoint.putString("transportType", it.transportType.toString())
|
|
1543
|
+
transportEndpointsMap.pushMap(endpoint)
|
|
1544
|
+
}
|
|
1545
|
+
transferMap.putArray("transportEndpoints", transportEndpointsMap)
|
|
1497
1546
|
|
|
1498
1547
|
transfer.invoiceString?.let { transferMap.putString("invoiceString", it) }
|
|
1499
1548
|
transfer.consignmentPath?.let { transferMap.putString("consignmentPath", it) }
|
|
1500
1549
|
|
|
1501
|
-
transferMap.putInt("assignmentsCount", transfer.assignments.size)
|
|
1502
|
-
|
|
1503
1550
|
transfersArray.pushMap(transferMap)
|
|
1504
1551
|
}
|
|
1505
1552
|
|
|
@@ -1534,14 +1581,26 @@ class RgbModule(reactContext: ReactApplicationContext) :
|
|
|
1534
1581
|
unspents.forEach { unspent ->
|
|
1535
1582
|
val unspentMap = Arguments.createMap()
|
|
1536
1583
|
val utxoMap = Arguments.createMap()
|
|
1537
|
-
|
|
1538
|
-
|
|
1584
|
+
val outpointMap = Arguments.createMap()
|
|
1585
|
+
outpointMap.putString("txid", unspent.utxo.outpoint.txid)
|
|
1586
|
+
outpointMap.putDouble("vout", unspent.utxo.outpoint.vout.toDouble())
|
|
1587
|
+
utxoMap.putMap("outpoint", outpointMap)
|
|
1539
1588
|
utxoMap.putDouble("btcAmount", unspent.utxo.btcAmount.toDouble())
|
|
1540
1589
|
utxoMap.putBoolean("colorable", unspent.utxo.colorable)
|
|
1541
1590
|
utxoMap.putBoolean("exists", unspent.utxo.exists)
|
|
1542
1591
|
unspentMap.putMap("utxo", utxoMap)
|
|
1543
1592
|
unspentMap.putDouble("pendingBlinded", unspent.pendingBlinded.toDouble())
|
|
1544
|
-
|
|
1593
|
+
|
|
1594
|
+
val rgbAllocationsArray = Arguments.createArray()
|
|
1595
|
+
unspent.rgbAllocations.forEach { allocation ->
|
|
1596
|
+
val allocationMap = Arguments.createMap()
|
|
1597
|
+
allocation.assetId?.let { allocationMap.putString("assetId", it) }
|
|
1598
|
+
allocationMap.putMap("assignment", assignmentToMap(allocation.assignment))
|
|
1599
|
+
allocationMap.putBoolean("settled", allocation.settled)
|
|
1600
|
+
rgbAllocationsArray.pushMap(allocationMap)
|
|
1601
|
+
}
|
|
1602
|
+
unspentMap.putArray("rgbAllocations", rgbAllocationsArray)
|
|
1603
|
+
|
|
1545
1604
|
unspentsArray.pushMap(unspentMap)
|
|
1546
1605
|
}
|
|
1547
1606
|
|
|
@@ -1870,7 +1929,28 @@ class RgbModule(reactContext: ReactApplicationContext) :
|
|
|
1870
1929
|
?: throw IllegalStateException("Wallet is not online")
|
|
1871
1930
|
|
|
1872
1931
|
session.wallet.sync(online)
|
|
1873
|
-
|
|
1932
|
+
val refresh = session.wallet.refresh(online, null, emptyList(), false)
|
|
1933
|
+
val failed = session.wallet.failTransfers(online, null, false, false)
|
|
1934
|
+
val delete = session.wallet.deleteTransfers(null, false)
|
|
1935
|
+
val assets = session.wallet.listAssets(listOf())
|
|
1936
|
+
val rgb25Assets = assets.cfa
|
|
1937
|
+
val rgb20Assets = assets.nia
|
|
1938
|
+
val udaAssets = assets.uda
|
|
1939
|
+
if (rgb20Assets != null) {
|
|
1940
|
+
for (rgb20Asset in rgb20Assets) {
|
|
1941
|
+
val assetRefresh = session.wallet.refresh(online, rgb20Asset.assetId, listOf(), false)
|
|
1942
|
+
}
|
|
1943
|
+
}
|
|
1944
|
+
if (rgb25Assets != null) {
|
|
1945
|
+
for (rgb25Asset in rgb25Assets) {
|
|
1946
|
+
val assetRefresh = session.wallet.refresh(online, rgb25Asset.assetId, listOf(), false)
|
|
1947
|
+
}
|
|
1948
|
+
}
|
|
1949
|
+
if (udaAssets != null) {
|
|
1950
|
+
for (udaAsset in udaAssets) {
|
|
1951
|
+
val assetRefresh = session.wallet.refresh(online, udaAsset.assetId, listOf(), false)
|
|
1952
|
+
}
|
|
1953
|
+
}
|
|
1874
1954
|
withContext(Dispatchers.Main) {
|
|
1875
1955
|
promise.resolve(null)
|
|
1876
1956
|
}
|
|
@@ -1930,13 +2010,24 @@ class RgbModule(reactContext: ReactApplicationContext) :
|
|
|
1930
2010
|
val map = Arguments.createMap()
|
|
1931
2011
|
map.putString("invoice", invoice)
|
|
1932
2012
|
map.putString("recipientId", invoiceData.recipientId)
|
|
1933
|
-
|
|
2013
|
+
invoiceData.assetSchema?.let { schema ->
|
|
2014
|
+
val assetSchemaString = when (schema) {
|
|
2015
|
+
AssetSchema.NIA -> "NIA"
|
|
2016
|
+
AssetSchema.UDA -> "UDA"
|
|
2017
|
+
AssetSchema.CFA -> "CFA"
|
|
2018
|
+
AssetSchema.IFA -> "IFA"
|
|
2019
|
+
}
|
|
2020
|
+
map.putString("assetSchema", assetSchemaString)
|
|
2021
|
+
}
|
|
1934
2022
|
map.putString("assetId", invoiceData.assetId)
|
|
1935
|
-
map.
|
|
2023
|
+
map.putMap("assignment", assignmentToMap(invoiceData.assignment))
|
|
1936
2024
|
map.putString("assignmentName", invoiceData.assignmentName)
|
|
1937
2025
|
map.putString("network", invoiceData.network.toString())
|
|
1938
|
-
val
|
|
1939
|
-
|
|
2026
|
+
val transportEndpointsArray = Arguments.createArray()
|
|
2027
|
+
invoiceData.transportEndpoints.forEach {
|
|
2028
|
+
transportEndpointsArray.pushString(it)
|
|
2029
|
+
}
|
|
2030
|
+
map.putArray("transportEndpoints", transportEndpointsArray)
|
|
1940
2031
|
|
|
1941
2032
|
invoiceData.expirationTimestamp?.let {
|
|
1942
2033
|
map.putDouble("expirationTimestamp", it.toDouble())
|
package/ios/AppConstants.swift
CHANGED
|
@@ -5,67 +5,53 @@ import Foundation
|
|
|
5
5
|
public class AppConstants: NSObject {
|
|
6
6
|
@objc public static let shared = AppConstants()
|
|
7
7
|
|
|
8
|
-
let rgbDirName = ""
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
"ssl://electrum.iriswallet.com:50003",
|
|
25
|
-
"https://blockstream.info/api"
|
|
26
|
-
]
|
|
27
|
-
private var callCount = 0
|
|
8
|
+
private let rgbDirName = ""
|
|
9
|
+
private var _rgbDir: URL? = nil
|
|
10
|
+
private let queue = DispatchQueue(label: "com.rgb.appconstants")
|
|
11
|
+
|
|
12
|
+
var rgbDir: URL? {
|
|
13
|
+
get {
|
|
14
|
+
return queue.sync {
|
|
15
|
+
return _rgbDir
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
set {
|
|
19
|
+
queue.sync {
|
|
20
|
+
self._rgbDir = newValue
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
28
24
|
|
|
29
25
|
private override init() {
|
|
30
26
|
super.init()
|
|
31
27
|
}
|
|
32
28
|
|
|
33
29
|
@objc public func initContext() {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
30
|
+
queue.sync {
|
|
31
|
+
let fileManager = FileManager.default
|
|
32
|
+
let documentsPath = fileManager.urls(for: .documentDirectory, in: .userDomainMask)[0]
|
|
33
|
+
_rgbDir = documentsPath.appendingPathComponent(rgbDirName)
|
|
34
|
+
|
|
35
|
+
// Create directory if it doesn't exist
|
|
36
|
+
if let rgbDir = _rgbDir {
|
|
37
|
+
try? fileManager.createDirectory(at: rgbDir, withIntermediateDirectories: true, attributes: nil)
|
|
38
|
+
}
|
|
41
39
|
}
|
|
42
40
|
}
|
|
43
41
|
|
|
44
42
|
@objc public func ensureInitialized() {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
case "REGTEST":
|
|
57
|
-
return regtestElectrumURL
|
|
58
|
-
case "MAINNET":
|
|
59
|
-
return getNextMainnetUrl()
|
|
60
|
-
default:
|
|
61
|
-
return testnetElectrumURL
|
|
43
|
+
queue.sync {
|
|
44
|
+
if _rgbDir == nil {
|
|
45
|
+
let fileManager = FileManager.default
|
|
46
|
+
let documentsPath = fileManager.urls(for: .documentDirectory, in: .userDomainMask)[0]
|
|
47
|
+
_rgbDir = documentsPath.appendingPathComponent(rgbDirName)
|
|
48
|
+
|
|
49
|
+
// Create directory if it doesn't exist
|
|
50
|
+
if let rgbDir = _rgbDir {
|
|
51
|
+
try? fileManager.createDirectory(at: rgbDir, withIntermediateDirectories: true, attributes: nil)
|
|
52
|
+
}
|
|
53
|
+
}
|
|
62
54
|
}
|
|
63
55
|
}
|
|
64
|
-
|
|
65
|
-
private func getNextMainnetUrl() -> String {
|
|
66
|
-
let url = mainnetUrls[callCount % mainnetUrls.count]
|
|
67
|
-
callCount += 1
|
|
68
|
-
return url
|
|
69
|
-
}
|
|
70
56
|
}
|
|
71
57
|
|