diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3bb5085..a45394f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,21 @@
+## [0.31.0]
+
+#### APIs Changed:
+
+- `BumpFeeTxBuilder.allowShrinking()` now takes a `Script` as its argument.
+- The `Address` constructor now takes a `Network` argument.
+- The `Payload::PubkeyHash` and `Payload::ScriptHash` now have string arguments instead of byte arrays.
+
+#### APIs Added:
+
+- The `Address` type now has the `isValidForNetwork()` method.
+
+## [0.30.0]
+
+#### APIs added
+
+- Added `BIP-86` descriptor templates
+
## [0.29.0]
#### APIs added
diff --git a/README.md b/README.md
index 8ac598f..e4a430f 100644
--- a/README.md
+++ b/README.md
@@ -55,7 +55,7 @@ cd ios && pod install
```ts
import { DescriptorSecretKey, Mnemonic, Blockchain, Wallet, DatabaseConfig, Descriptor } from 'bdk-rn';
-import { WordCount, Network } from 'bdk-rn/lib/lib/enums';
+import { WordCount, Network, KeychainKind } from 'bdk-rn/lib/lib/enums';
// ....
@@ -69,7 +69,7 @@ const config: BlockchainElectrumConfig = {
sock5: null,
retry: 5,
timeout: 5,
- stopGap: 100,
+ stopGap: 500,
validateDomain: false,
};
@@ -111,8 +111,10 @@ const dbConfig = await new DatabaseConfig().sqlite(`${RNFS.DocumentDirectoryPath
```
### References:
+
- Setting up a local Esplora instance for testing:
-https://bitcoin.stackexchange.com/questions/116937/how-do-i-setup-an-esplora-instance-for-local-testing/116938#116938
+ https://bitcoin.stackexchange.com/questions/116937/how-do-i-setup-an-esplora-instance-for-local-testing/116938#116938
+
---
_Note: Caution this is an Alpha at this stage
diff --git a/__tests__/classes/Address.spec.ts b/__tests__/classes/Address.spec.ts
index a96e613..56cf1dd 100644
--- a/__tests__/classes/Address.spec.ts
+++ b/__tests__/classes/Address.spec.ts
@@ -15,7 +15,7 @@ describe('Address', () => {
const addressString = 'tb1qccmtnhczmv3a6k4mtq8twm7ltj3e32qsntmamv';
beforeAll(async () => {
- address = await new Address().create('address');
+ address = await new Address().create('address', Network.Testnet);
});
afterEach(() => {
jest.clearAllMocks();
@@ -69,4 +69,11 @@ describe('Address', () => {
expect(res).toBe(addressString);
expect(mockBdkRnModule.addressAsString).toHaveBeenCalledWith(address.id);
});
+
+ it('verify addressIsValidForNetwork()', async () => {
+ mockBdkRnModule.addressIsValidForNetwork.mockResolvedValueOnce(true);
+ let res = await address.isValidForNetwork(Network.Testnet);
+ expect(res).toBe(true);
+ expect(mockBdkRnModule.addressIsValidForNetwork).toHaveBeenCalledWith(address.id, Network.Testnet);
+ });
});
diff --git a/__tests__/classes/BumpFeeTxBuilder.spec.ts b/__tests__/classes/BumpFeeTxBuilder.spec.ts
index 3bae428..3da1d86 100644
--- a/__tests__/classes/BumpFeeTxBuilder.spec.ts
+++ b/__tests__/classes/BumpFeeTxBuilder.spec.ts
@@ -1,6 +1,6 @@
import { BumpFeeTxBuilder, DatabaseConfig, Descriptor, PartiallySignedTransaction, Wallet } from '../../src';
import { Network } from '../../src/lib/enums';
-import { mockWallet } from '../mockData';
+import { mockScript, mockWallet } from '../mockData';
import { mockBdkRnModule } from '../setup';
const id = 'instanceId';
@@ -27,9 +27,8 @@ describe('BumpFeeTxBuilder', () => {
expect(bumpFeeTxBuilder).toBeInstanceOf(BumpFeeTxBuilder);
});
it('should allow shrinking', async () => {
- const address = 'address';
- await bumpFeeTxBuilder.allowShrinking(address);
- expect(mockBdkRnModule.bumpFeeTxBuilderAllowShrinking).toHaveBeenCalledWith(id, address);
+ await bumpFeeTxBuilder.allowShrinking(mockScript);
+ expect(mockBdkRnModule.bumpFeeTxBuilderAllowShrinking).toHaveBeenCalledWith(id, mockScript.id);
});
it('should enable rbf', async () => {
await bumpFeeTxBuilder.enableRbf();
diff --git a/__tests__/setup.ts b/__tests__/setup.ts
index 13d05b4..f4714e3 100644
--- a/__tests__/setup.ts
+++ b/__tests__/setup.ts
@@ -48,6 +48,7 @@ export const mockBdkRnModule = {
addressNetwork: jest.fn(),
addressToQrUri: jest.fn(),
addressAsString: jest.fn(),
+ addressIsValidForNetwork: jest.fn(),
addRecipient: jest.fn(),
finish: jest.fn(),
diff --git a/android/.classpath b/android/.classpath
new file mode 100644
index 0000000..44b427a
--- /dev/null
+++ b/android/.classpath
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/android/.project b/android/.project
new file mode 100644
index 0000000..d2aa961
--- /dev/null
+++ b/android/.project
@@ -0,0 +1,34 @@
+
+
+ bdk-rn
+ Project bdk-rn created by Buildship.
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+ org.eclipse.buildship.core.gradleprojectbuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+ org.eclipse.buildship.core.gradleprojectnature
+
+
+
+ 1706000397923
+
+ 30
+
+ org.eclipse.core.resources.regexFilterMatcher
+ node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__
+
+
+
+
diff --git a/android/.settings/org.eclipse.buildship.core.prefs b/android/.settings/org.eclipse.buildship.core.prefs
new file mode 100644
index 0000000..7e4e543
--- /dev/null
+++ b/android/.settings/org.eclipse.buildship.core.prefs
@@ -0,0 +1,13 @@
+arguments=--init-script /var/folders/77/pwdxzmrn7p53dyts2cw8s2ch0000gn/T/d146c9752a26f79b52047fb6dc6ed385d064e120494f96f08ca63a317c41f94c.gradle --init-script /var/folders/77/pwdxzmrn7p53dyts2cw8s2ch0000gn/T/52cde0cfcf3e28b8b7510e992210d9614505e0911af0c190bd590d7158574963.gradle
+auto.sync=false
+build.scans.enabled=false
+connection.gradle.distribution=GRADLE_DISTRIBUTION(VERSION(8.1.1))
+connection.project.dir=
+eclipse.preferences.version=1
+gradle.user.home=
+java.home=/Library/Java/JavaVirtualMachines/jdk-18.0.2.jdk/Contents/Home
+jvm.arguments=
+offline.mode=false
+override.workspace.settings=true
+show.console.view=true
+show.executions.view=true
diff --git a/android/.settings/org.eclipse.jdt.core.prefs b/android/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..65de196
--- /dev/null
+++ b/android/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,4 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=16
+org.eclipse.jdt.core.compiler.compliance=16
+org.eclipse.jdt.core.compiler.source=16
diff --git a/android/build.gradle b/android/build.gradle
index 67d41c0..fa1ff87 100644
--- a/android/build.gradle
+++ b/android/build.gradle
@@ -41,5 +41,5 @@ dependencies {
implementation 'com.facebook.react:react-native:+'
// bitcoindevkit
- implementation 'org.bitcoindevkit:bdk-android:0.29.0'
+ implementation 'org.bitcoindevkit:bdk-android:0.31.0'
}
diff --git a/android/src/main/java/io/ltbl/bdkrn/BdkRnModule.kt b/android/src/main/java/io/ltbl/bdkrn/BdkRnModule.kt
index ab8954e..2d9b988 100644
--- a/android/src/main/java/io/ltbl/bdkrn/BdkRnModule.kt
+++ b/android/src/main/java/io/ltbl/bdkrn/BdkRnModule.kt
@@ -1,8 +1,6 @@
package io.ltbl.bdkrn
import com.facebook.react.bridge.*
-import com.facebook.react.bridge.ReadableType
-import com.facebook.react.bridge.Dynamic
import com.facebook.react.bridge.UiThreadUtil.runOnUiThread
import org.bitcoindevkit.*
import org.bitcoindevkit.Descriptor.Companion.newBip44
@@ -11,6 +9,8 @@ import org.bitcoindevkit.Descriptor.Companion.newBip49
import org.bitcoindevkit.Descriptor.Companion.newBip49Public
import org.bitcoindevkit.Descriptor.Companion.newBip84
import org.bitcoindevkit.Descriptor.Companion.newBip84Public
+import org.bitcoindevkit.Descriptor.Companion.newBip86
+import org.bitcoindevkit.Descriptor.Companion.newBip86Public
class BdkRnModule(reactContext: ReactApplicationContext) :
ReactContextBaseJavaModule(reactContext) {
@@ -38,41 +38,49 @@ class BdkRnModule(reactContext: ReactApplicationContext) :
/** Mnemonic methods starts */
@ReactMethod
fun generateSeedFromWordCount(wordCount: Int, result: Promise) {
- val response = Mnemonic(setWordCount(wordCount))
- result.resolve(response.asString())
+ Thread {
+ val response = Mnemonic(setWordCount(wordCount))
+ result.resolve(response.asString())
+ }.start()
}
@ReactMethod
fun generateSeedFromString(mnemonic: String, result: Promise) {
- try {
- val response = Mnemonic.fromString(mnemonic)
- result.resolve(response.asString())
- } catch (error: Throwable) {
- return result.reject("Generate seed error", error.localizedMessage, error)
- }
+ Thread {
+ try {
+ val response = Mnemonic.fromString(mnemonic)
+ result.resolve(response.asString())
+ } catch (error: Throwable) {
+ result.reject("Generate seed error", error.localizedMessage, error)
+ }
+ }.start()
}
@ReactMethod
fun generateSeedFromEntropy(entropy: ReadableArray, result: Promise) {
- try {
- val response = Mnemonic.fromEntropy(getEntropy(entropy))
- result.resolve(response.asString())
- } catch (error: Throwable) {
- return result.reject("Generate seed error", error.localizedMessage, error)
- }
+ Thread {
+ try {
+ val response = Mnemonic.fromEntropy(getEntropy(entropy))
+ result.resolve(response.asString())
+ } catch (error: Throwable) {
+ result.reject("Generate seed error", error.localizedMessage, error)
+ }
+ }.start()
}
/** Mnemonic methods ends */
/** Derviation path methods starts */
@ReactMethod
fun createDerivationPath(path: String, result: Promise) {
- try {
- val id = randomId()
- _derivationPaths[id] = DerivationPath(path)
- result.resolve(id)
- } catch (error: Throwable) {
- return result.reject("Create Derivation path error", error.localizedMessage, error)
- }
+ Thread {
+ try {
+ val id = randomId()
+ _derivationPaths[id] = DerivationPath(path)
+ result.resolve(id)
+ } catch (error: Throwable) {
+ result.reject("Create Derivation path error", error.localizedMessage, error)
+ }
+ }.start()
}
/** Derviation path methods ends */
@@ -81,94 +89,118 @@ class BdkRnModule(reactContext: ReactApplicationContext) :
fun createDescriptorSecret(
network: String, mnemonic: String, password: String? = null, result: Promise
) {
- try {
- val id = randomId()
- _descriptorSecretKeys[id] =
- DescriptorSecretKey(setNetwork(network), Mnemonic.fromString(mnemonic), password)
- result.resolve(id)
- } catch (error: Throwable) {
- return result.reject("DescriptorSecret create error", error.localizedMessage, error)
- }
+ Thread {
+ try {
+ val id = randomId()
+ _descriptorSecretKeys[id] =
+ DescriptorSecretKey(
+ setNetwork(network),
+ Mnemonic.fromString(mnemonic),
+ password
+ )
+ result.resolve(id)
+ } catch (error: Throwable) {
+ result.reject("DescriptorSecret create error", error.localizedMessage, error)
+ }
+ }.start()
}
@ReactMethod
fun descriptorSecretDerive(secretKeyId: String, derivationPathId: String, result: Promise) {
- try {
- val keyInfo =
- _descriptorSecretKeys[secretKeyId]!!.derive(_derivationPaths[derivationPathId]!!)
- result.resolve(keyInfo.asString())
- } catch (error: Throwable) {
- return result.reject("DescriptorSecret derive error", error.localizedMessage, error)
- }
+ Thread {
+ try {
+ val keyInfo =
+ _descriptorSecretKeys[secretKeyId]!!.derive(_derivationPaths[derivationPathId]!!)
+ result.resolve(keyInfo.asString())
+ } catch (error: Throwable) {
+ result.reject("DescriptorSecret derive error", error.localizedMessage, error)
+ }
+ }.start()
}
@ReactMethod
fun descriptorSecretExtend(secretKeyId: String, derivationPathId: String, result: Promise) {
- try {
- val keyInfo =
- _descriptorSecretKeys[secretKeyId]!!.extend(_derivationPaths[derivationPathId]!!)
- result.resolve(keyInfo.asString())
- } catch (error: Throwable) {
- return result.reject("DescriptorSecret extend error", error.localizedMessage, error)
- }
+ Thread {
+ try {
+ val keyInfo =
+ _descriptorSecretKeys[secretKeyId]!!.extend(_derivationPaths[derivationPathId]!!)
+ result.resolve(keyInfo.asString())
+ } catch (error: Throwable) {
+ result.reject("DescriptorSecret extend error", error.localizedMessage, error)
+ }
+ }.start()
}
@ReactMethod
fun descriptorSecretAsPublic(secretKeyId: String, result: Promise) {
- val id = randomId()
- _descriptorPublicKeys[id] = _descriptorSecretKeys[secretKeyId]!!.asPublic()
- result.resolve(id)
+ Thread {
+ val id = randomId()
+ _descriptorPublicKeys[id] = _descriptorSecretKeys[secretKeyId]!!.asPublic()
+ result.resolve(id)
+ }.start()
}
@ReactMethod
fun descriptorSecretAsString(secretKeyId: String, result: Promise) {
- result.resolve(_descriptorSecretKeys[secretKeyId]!!.asString())
+ Thread {
+ result.resolve(_descriptorSecretKeys[secretKeyId]!!.asString())
+ }.start()
}
@ReactMethod
fun descriptorSecretAsSecretBytes(secretKeyId: String, result: Promise) {
- val scretBytes = _descriptorSecretKeys[secretKeyId]!!.secretBytes()
- result.resolve(makeNativeArray(scretBytes))
+ Thread {
+ val secretBytes = _descriptorSecretKeys[secretKeyId]!!.secretBytes()
+ result.resolve(makeNativeArray(secretBytes))
+ }.start()
}
/** Descriptor secret key methods ends */
/** Descriptor public key methods starts */
@ReactMethod
fun createDescriptorPublic(publicKey: String, result: Promise) {
- try {
- val id = randomId()
- _descriptorPublicKeys[id] = DescriptorPublicKey.fromString(publicKey)
- result.resolve(id)
- } catch (error: Throwable) {
- return result.reject("DescriptorPublic create error", error.localizedMessage, error)
- }
+ Thread {
+ try {
+ val id = randomId()
+ _descriptorPublicKeys[id] = DescriptorPublicKey.fromString(publicKey)
+ result.resolve(id)
+ } catch (error: Throwable) {
+ result.reject("DescriptorPublic create error", error.localizedMessage, error)
+ }
+ }.start()
}
@ReactMethod
fun descriptorPublicDerive(publicKeyId: String, derivationPathId: String, result: Promise) {
- try {
- val keyInfo =
- _descriptorPublicKeys[publicKeyId]!!.derive(_derivationPaths[derivationPathId]!!)
- result.resolve(keyInfo.asString())
- } catch (error: Throwable) {
- return result.reject("DescriptorPublic derive error", error.localizedMessage, error)
- }
+ Thread {
+ try {
+ val keyInfo =
+ _descriptorPublicKeys[publicKeyId]!!.derive(_derivationPaths[derivationPathId]!!)
+ result.resolve(keyInfo.asString())
+ } catch (error: Throwable) {
+ result.reject("DescriptorPublic derive error", error.localizedMessage, error)
+ }
+ }.start()
}
@ReactMethod
fun descriptorPublicExtend(publicKeyId: String, derivationPathId: String, result: Promise) {
- try {
- val keyInfo =
- _descriptorPublicKeys[publicKeyId]!!.extend(_derivationPaths[derivationPathId]!!)
- result.resolve(keyInfo.asString())
- } catch (error: Throwable) {
- return result.reject("DescriptorPublic extend error", error.localizedMessage, error)
- }
+ Thread {
+ try {
+ val keyInfo =
+ _descriptorPublicKeys[publicKeyId]!!.extend(_derivationPaths[derivationPathId]!!)
+ result.resolve(keyInfo.asString())
+ } catch (error: Throwable) {
+ result.reject("DescriptorPublic extend error", error.localizedMessage, error)
+ }
+ }.start()
}
@ReactMethod
fun descriptorPublicAsString(publicKeyId: String, result: Promise) {
- result.resolve(_descriptorPublicKeys[publicKeyId]!!.asString())
+ Thread {
+ result.resolve(_descriptorPublicKeys[publicKeyId]!!.asString())
+ }.start()
}
/** Descriptor public key methods ends */
@@ -188,23 +220,25 @@ class BdkRnModule(reactContext: ReactApplicationContext) :
validateDomain: Boolean,
result: Promise
) {
- try {
- val _blockchainConfig = BlockchainConfig.Electrum(
- ElectrumConfig(
- url,
- sock5 ?: null,
- retry.toUByte(),
- timeout.toUByte(),
- stopGap.toULong(),
- validateDomain
+ Thread {
+ try {
+ val _blockchainConfig = BlockchainConfig.Electrum(
+ ElectrumConfig(
+ url,
+ sock5 ?: null,
+ retry.toUByte(),
+ timeout.toUByte(),
+ stopGap.toULong(),
+ validateDomain
+ )
)
- )
- val blockChainId = randomId()
- _blockChains[blockChainId] = Blockchain(_blockchainConfig)
- result.resolve(blockChainId)
- } catch (error: Throwable) {
- return result.reject("BlockchainElectrum init error", error.localizedMessage, error)
- }
+ val blockChainId = randomId()
+ _blockChains[blockChainId] = Blockchain(_blockchainConfig)
+ result.resolve(blockChainId)
+ } catch (error: Throwable) {
+ result.reject("BlockchainElectrum init error", error.localizedMessage, error)
+ }
+ }.start()
}
@@ -217,103 +251,119 @@ class BdkRnModule(reactContext: ReactApplicationContext) :
timeout: Int,
result: Promise
) {
- try {
- val _blockchainConfig = BlockchainConfig.Esplora(
- EsploraConfig(
- baseUrl,
- proxy ?: null,
- concurrency.toUByte(),
- stopGap.toULong(),
- timeout.toULong(),
+ Thread {
+ try {
+ val _blockchainConfig = BlockchainConfig.Esplora(
+ EsploraConfig(
+ baseUrl,
+ proxy ?: null,
+ concurrency.toUByte(),
+ stopGap.toULong(),
+ timeout.toULong(),
+ )
)
- )
- val blockChainId = randomId()
- _blockChains[blockChainId] = Blockchain(_blockchainConfig)
- result.resolve(blockChainId)
- } catch (error: Throwable) {
- return result.reject("BlockchainEsplora init error", error.localizedMessage, error)
- }
+ val blockChainId = randomId()
+ _blockChains[blockChainId] = Blockchain(_blockchainConfig)
+ result.resolve(blockChainId)
+ } catch (error: Throwable) {
+ result.reject("BlockchainEsplora init error", error.localizedMessage, error)
+ }
+ }.start()
}
@ReactMethod
fun initRpcBlockchain(config: ReadableMap, result: Promise) {
- try {
- var authType: Auth = Auth.None
- if (config.getString("authCookie") != null) {
- authType = Auth.Cookie(config.getString("authCookie")!!)
- }
+ Thread {
+ try {
+ var authType: Auth = Auth.None
+ if (config.getString("authCookie") != null) {
+ authType = Auth.Cookie(config.getString("authCookie")!!)
+ }
- if (config.getMap("authUserPass") != null) {
- val userPass = config.getMap("authUserPass") as ReadableMap
- authType = Auth.UserPass(
- userPass.getString("username")!!,
- userPass.getString("password")!!
- )
- }
- var syncParams: RpcSyncParams? = null
- if (config.getMap("syncParams") != null) {
- val syncParamsConfig = config.getMap("syncParams") as ReadableMap
- syncParams = RpcSyncParams(
- syncParamsConfig.getInt("startScriptCount").toULong()!!,
- syncParamsConfig.getInt("startTime").toULong()!!,
- syncParamsConfig.getBoolean("forceStartTime"),
- syncParamsConfig.getInt("pollRateSec").toULong()!!,
- )
- }
+ if (config.getMap("authUserPass") != null) {
+ val userPass = config.getMap("authUserPass") as ReadableMap
+ authType = Auth.UserPass(
+ userPass.getString("username")!!,
+ userPass.getString("password")!!
+ )
+ }
+ var syncParams: RpcSyncParams? = null
+ if (config.getMap("syncParams") != null) {
+ val syncParamsConfig = config.getMap("syncParams") as ReadableMap
+ syncParams = RpcSyncParams(
+ syncParamsConfig.getInt("startScriptCount").toULong()!!,
+ syncParamsConfig.getInt("startTime").toULong()!!,
+ syncParamsConfig.getBoolean("forceStartTime"),
+ syncParamsConfig.getInt("pollRateSec").toULong()!!,
+ )
+ }
- val _blockchainConfig = BlockchainConfig.Rpc(
- RpcConfig(
- config.getString("url")!!,
- authType,
- setNetwork(config.getString("network")!!),
- config.getString("walletName")!!,
- syncParams
+ val _blockchainConfig = BlockchainConfig.Rpc(
+ RpcConfig(
+ config.getString("url")!!,
+ authType,
+ setNetwork(config.getString("network")!!),
+ config.getString("walletName")!!,
+ syncParams
+ )
)
- )
- val blockChainId = randomId()
- _blockChains[blockChainId] = Blockchain(_blockchainConfig)
- result.resolve(blockChainId)
- } catch (error: Throwable) {
- return result.reject("BlockchainRpc init error", error.localizedMessage, error)
- }
+ val blockChainId = randomId()
+ _blockChains[blockChainId] = Blockchain(_blockchainConfig)
+ result.resolve(blockChainId)
+ } catch (error: Throwable) {
+ result.reject("BlockchainRpc init error", error.localizedMessage, error)
+ }
+ }.start()
}
@ReactMethod
fun getBlockchainHeight(id: String, result: Promise) {
- try {
- result.resolve(getBlockchainById(id).getHeight().toInt())
- } catch (error: Throwable) {
- return result.reject("Blockchain get height error", error.localizedMessage, error)
- }
+ Thread {
+ try {
+ result.resolve(getBlockchainById(id).getHeight().toInt())
+ } catch (error: Throwable) {
+ result.reject("Blockchain get height error", error.localizedMessage, error)
+ }
+ }.start()
}
@ReactMethod
fun getBlockchainHash(id: String, height: Int, result: Promise) {
- try {
- result.resolve(getBlockchainById(id).getBlockHash(height.toUInt()))
- } catch (error: Throwable) {
- return result.reject("Blockchain get block hash error", error.localizedMessage, error)
- }
+ Thread {
+ try {
+ result.resolve(getBlockchainById(id).getBlockHash(height.toUInt()))
+ } catch (error: Throwable) {
+ result.reject(
+ "Blockchain get block hash error",
+ error.localizedMessage,
+ error
+ )
+ }
+ }.start()
}
@ReactMethod
fun broadcast(id: String, txId: String, result: Promise) {
- try {
- getBlockchainById(id).broadcast(_transactions[txId]!!)
- result.resolve(true)
- } catch (error: Throwable) {
- return result.reject("Broadcast transaction error", error.localizedMessage, error)
- }
+ Thread {
+ try {
+ getBlockchainById(id).broadcast(_transactions[txId]!!)
+ result.resolve(true)
+ } catch (error: Throwable) {
+ result.reject("Broadcast transaction error", error.localizedMessage, error)
+ }
+ }.start()
}
@ReactMethod
fun estimateFee(id: String, target: Int, result: Promise) {
- try {
- val fee = getBlockchainById(id).estimateFee(target.toULong())
- result.resolve(fee.asSatPerVb())
- } catch (error: Throwable) {
- return result.reject("Estimate Fee error", error.localizedMessage, error)
- }
+ Thread {
+ try {
+ val fee = getBlockchainById(id).estimateFee(target.toULong())
+ result.resolve(fee.asSatPerVb())
+ } catch (error: Throwable) {
+ result.reject("Estimate Fee error", error.localizedMessage, error)
+ }
+ }.start()
}
/** Blockchain methods ends */
@@ -321,23 +371,29 @@ class BdkRnModule(reactContext: ReactApplicationContext) :
/** DB configuration methods starts*/
@ReactMethod
fun memoryDBInit(result: Promise) {
- val id = randomId()
- _databaseConfigs[id] = DatabaseConfig.Memory
- result.resolve(id)
+ Thread {
+ val id = randomId()
+ _databaseConfigs[id] = DatabaseConfig.Memory
+ result.resolve(id)
+ }.start()
}
@ReactMethod
fun sledDBInit(path: String, treeName: String, result: Promise) {
- val id = randomId()
- _databaseConfigs[id] = DatabaseConfig.Sled(SledDbConfiguration(path, treeName))
- result.resolve(id)
+ Thread {
+ val id = randomId()
+ _databaseConfigs[id] = DatabaseConfig.Sled(SledDbConfiguration(path, treeName))
+ result.resolve(id)
+ }.start()
}
@ReactMethod
fun sqliteDBInit(path: String, result: Promise) {
- val id = randomId()
- _databaseConfigs[id] = DatabaseConfig.Sqlite(SqliteDbConfiguration(path))
- result.resolve(id)
+ Thread {
+ val id = randomId()
+ _databaseConfigs[id] = DatabaseConfig.Sqlite(SqliteDbConfiguration(path))
+ result.resolve(id)
+ }.start()
}
/** DB configuration methods ends*/
@@ -357,13 +413,17 @@ class BdkRnModule(reactContext: ReactApplicationContext) :
) {
try {
val id = randomId()
- _wallets[id] = Wallet(
- _descriptors[descriptor]!!,
- if (changeDescriptor != null) _descriptors[changeDescriptor]!! else null,
- setNetwork(network),
- _databaseConfigs[dbConfigID]!!
- )
- result.resolve(id)
+ val nativeDescriptor = _descriptors[descriptor]!!
+ val nativeChangeDescriptor = if (changeDescriptor != null) _descriptors[changeDescriptor]!! else null
+ Thread {
+ _wallets[id] = Wallet(
+ nativeDescriptor,
+ nativeChangeDescriptor,
+ setNetwork(network),
+ _databaseConfigs[dbConfigID]!!
+ )
+ result.resolve(id)
+ }.start()
} catch (error: Throwable) {
result.reject("Init wallet error", error.localizedMessage, error)
}
@@ -386,18 +446,22 @@ class BdkRnModule(reactContext: ReactApplicationContext) :
Thread {
try {
val randomId = randomId()
+
var resolvedIndex: Any = "new"
when (val type = addressIndex.getType()) {
ReadableType.String -> {
resolvedIndex = (addressIndex as Dynamic).asString() ?: "new"
}
+
ReadableType.Number -> {
resolvedIndex = (addressIndex as Dynamic).asDouble() ?: "new"
}
+
else -> {
resolvedIndex = setAddressIndex("new")
}
}
+
val addressInfo = getWalletById(id).getAddress(setAddressIndex(resolvedIndex))
_addresses[randomId] = addressInfo.address
val responseObject = mutableMapOf()
@@ -421,13 +485,16 @@ class BdkRnModule(reactContext: ReactApplicationContext) :
ReadableType.String -> {
resolvedIndex = (addressIndex as Dynamic).asString() ?: "new"
}
+
ReadableType.Number -> {
resolvedIndex = (addressIndex as Dynamic).asDouble() ?: "new"
}
+
else -> {
resolvedIndex = setAddressIndex("new")
}
}
+
val addressInfo = getWalletById(id).getInternalAddress(setAddressIndex(resolvedIndex))
_addresses[randomId] = addressInfo.address
val responseObject = mutableMapOf()
@@ -443,11 +510,13 @@ class BdkRnModule(reactContext: ReactApplicationContext) :
@ReactMethod
fun isMine(id: String, scriptId: String, result: Promise) {
- try {
- result.resolve(getWalletById(id).isMine(_scripts[scriptId]!!))
- } catch (error: Throwable) {
- result.reject("Get isMine error", error.localizedMessage, error)
- }
+ Thread {
+ try {
+ result.resolve(getWalletById(id).isMine(_scripts[scriptId]!!))
+ } catch (error: Throwable) {
+ result.reject("Get isMine error", error.localizedMessage, error)
+ }
+ }.start()
}
@ReactMethod
@@ -456,11 +525,11 @@ class BdkRnModule(reactContext: ReactApplicationContext) :
try {
val balance = getWalletById(id).getBalance()
val responseObject = mutableMapOf()
- responseObject["trustedPending"] = balance.trustedPending.toInt()
- responseObject["untrustedPending"] = balance.untrustedPending.toInt()
- responseObject["confirmed"] = balance.confirmed.toInt()
- responseObject["spendable"] = balance.spendable.toInt()
- responseObject["total"] = balance.total.toInt()
+ responseObject["trustedPending"] = balance.trustedPending.toDouble()
+ responseObject["untrustedPending"] = balance.untrustedPending.toDouble()
+ responseObject["confirmed"] = balance.confirmed.toDouble()
+ responseObject["spendable"] = balance.spendable.toDouble()
+ responseObject["total"] = balance.total.toDouble()
result.resolve(Arguments.makeNativeMap(responseObject))
} catch (error: Throwable) {
result.reject("Get wallet balance error", error.localizedMessage, error)
@@ -470,8 +539,10 @@ class BdkRnModule(reactContext: ReactApplicationContext) :
@ReactMethod
fun getNetwork(id: String, result: Promise) {
- val network = getWalletById(id).network()
- result.resolve(getNetworkString(network))
+ Thread {
+ val network = getWalletById(id).network()
+ result.resolve(getNetworkString(network))
+ }.start()
}
@ReactMethod
@@ -497,95 +568,120 @@ class BdkRnModule(reactContext: ReactApplicationContext) :
@ReactMethod
fun listTransactions(id: String, includeRaw: Boolean, result: Promise) {
- try {
- val list = getWalletById(id).listTransactions(includeRaw)
- val transactions: MutableList