feat: expose commit method on wallet type

This commit is contained in:
thunderbiscuit 2024-05-08 11:33:35 -04:00
parent 72b5bfd4c9
commit e9a76287c8
No known key found for this signature in database
GPG Key ID: 88253696EB836462
10 changed files with 36 additions and 21 deletions

View File

@ -29,6 +29,7 @@ class LiveTxBuilderTest {
val fullScanRequest: FullScanRequest = wallet.startFullScan()
val update = esploraClient.fullScan(fullScanRequest, 10uL, 1uL)
wallet.applyUpdate(update)
wallet.commit()
println("Balance: ${wallet.getBalance().total}")
assert(wallet.getBalance().total > 0uL)
@ -52,6 +53,7 @@ class LiveTxBuilderTest {
val fullScanRequest: FullScanRequest = wallet.startFullScan()
val update = esploraClient.fullScan(fullScanRequest, 10uL, 1uL)
wallet.applyUpdate(update)
wallet.commit()
println("Balance: ${wallet.getBalance().total}")
assert(wallet.getBalance().total > 0uL)

View File

@ -29,6 +29,7 @@ class LiveWalletTest {
val fullScanRequest: FullScanRequest = wallet.startFullScan()
val update = esploraClient.fullScan(fullScanRequest, 10uL, 1uL)
wallet.applyUpdate(update)
wallet.commit()
println("Balance: ${wallet.getBalance().total}")
val balance: Balance = wallet.getBalance()
println("Balance: $balance")
@ -52,8 +53,8 @@ class LiveWalletTest {
val esploraClient = EsploraClient("https://esplora.testnet.kuutamo.cloud/")
val fullScanRequest: FullScanRequest = wallet.startFullScan()
val update = esploraClient.fullScan(fullScanRequest, 10uL, 1uL)
wallet.applyUpdate(update)
wallet.commit()
println("Balance: ${wallet.getBalance().total}")
println("New address: ${wallet.revealNextAddress(KeychainKind.EXTERNAL).address}")

View File

@ -267,6 +267,9 @@ interface Wallet {
[Throws=CannotConnectError]
void apply_update(Update update);
[Throws=PersistenceError]
boolean commit();
boolean is_mine([ByRef] Script script);
[Throws=SignerError]

View File

@ -69,18 +69,13 @@ impl Wallet {
.map_err(CannotConnectError::from)
}
// TODO: This is the fallible version of get_internal_address; should I rename it to get_internal_address?
// It's a slight change of the API, the other option is to rename the get_address to try_get_address
// pub fn try_get_internal_address(
// &self,
// address_index: AddressIndex,
// ) -> Result<AddressInfo, PersistenceError> {
// let address_info = self
// .get_wallet()
// .try_get_internal_address(address_index.into())?
// .into();
// Ok(address_info)
// }
pub fn commit(&self) -> Result<bool, PersistenceError> {
self.get_wallet()
.commit()
.map_err(|e| PersistenceError::Write {
error_message: e.to_string(),
})
}
pub fn network(&self) -> Network {
self.get_wallet().network()

View File

@ -22,16 +22,18 @@ class LiveTxBuilderTest {
@Test
fun testTxBuilder() {
val descriptor = Descriptor("wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/0/*)", Network.TESTNET)
val wallet = Wallet(descriptor, null, persistenceFilePath, Network.TESTNET)
val esploraClient = EsploraClient("https://esplora.testnet.kuutamo.cloud/")
val wallet = Wallet(descriptor, null, persistenceFilePath, Network.SIGNET)
// val esploraClient = EsploraClient("https://esplora.testnet.kuutamo.cloud/")
val esploraClient = EsploraClient("http://signet.bitcoindevkit.net")
val fullScanRequest: FullScanRequest = wallet.startFullScan()
val update = esploraClient.fullScan(fullScanRequest, 10uL, 1uL)
wallet.applyUpdate(update)
wallet.commit()
println("Balance: ${wallet.getBalance().total}")
assert(wallet.getBalance().total > 0uL)
val recipient: Address = Address("tb1qrnfslnrve9uncz9pzpvf83k3ukz22ljgees989", Network.TESTNET)
val recipient: Address = Address("tb1qrnfslnrve9uncz9pzpvf83k3ukz22ljgees989", Network.SIGNET)
val psbt: Psbt = TxBuilder()
.addRecipient(recipient.scriptPubkey(), 4200uL)
.feeRate(FeeRate.fromSatPerVb(2uL))
@ -46,17 +48,19 @@ class LiveTxBuilderTest {
fun complexTxBuilder() {
val externalDescriptor = Descriptor("wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/0/*)", Network.TESTNET)
val changeDescriptor = Descriptor("wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/1/*)", Network.TESTNET)
val wallet = Wallet(externalDescriptor, changeDescriptor, persistenceFilePath, Network.TESTNET)
val esploraClient = EsploraClient("https://esplora.testnet.kuutamo.cloud/")
val wallet = Wallet(externalDescriptor, changeDescriptor, persistenceFilePath, Network.SIGNET)
// val esploraClient = EsploraClient("https://esplora.testnet.kuutamo.cloud/")
val esploraClient = EsploraClient("http://signet.bitcoindevkit.net")
val fullScanRequest: FullScanRequest = wallet.startFullScan()
val update = esploraClient.fullScan(fullScanRequest, 10uL, 1uL)
wallet.applyUpdate(update)
wallet.commit()
println("Balance: ${wallet.getBalance().total}")
assert(wallet.getBalance().total > 0uL)
val recipient1: Address = Address("tb1qrnfslnrve9uncz9pzpvf83k3ukz22ljgees989", Network.TESTNET)
val recipient2: Address = Address("tb1qw2c3lxufxqe2x9s4rdzh65tpf4d7fssjgh8nv6", Network.TESTNET)
val recipient1: Address = Address("tb1qrnfslnrve9uncz9pzpvf83k3ukz22ljgees989", Network.SIGNET)
val recipient2: Address = Address("tb1qw2c3lxufxqe2x9s4rdzh65tpf4d7fssjgh8nv6", Network.SIGNET)
val allRecipients: List<ScriptAmount> = listOf(
ScriptAmount(recipient1.scriptPubkey(), 4200uL),
ScriptAmount(recipient2.scriptPubkey(), 4200uL),

View File

@ -29,6 +29,7 @@ class LiveWalletTest {
val fullScanRequest: FullScanRequest = wallet.startFullScan()
val update = esploraClient.fullScan(fullScanRequest, 10uL, 1uL)
wallet.applyUpdate(update)
wallet.commit()
println("Balance: ${wallet.getBalance().total}")
assert(wallet.getBalance().total > 0uL)
@ -51,6 +52,7 @@ class LiveWalletTest {
val fullScanRequest: FullScanRequest = wallet.startFullScan()
val update = esploraClient.fullScan(fullScanRequest, 10uL, 1uL)
wallet.applyUpdate(update)
wallet.commit()
println("Balance: ${wallet.getBalance().total}")
println("New address: ${wallet.revealNextAddress(KeychainKind.EXTERNAL).address.asString()}")

View File

@ -27,6 +27,7 @@ class LiveTxBuilderTest(unittest.TestCase):
parallel_requests=1
)
wallet.apply_update(update)
wallet.commit()
self.assertGreater(wallet.get_balance().total, 0)
@ -62,6 +63,7 @@ class LiveTxBuilderTest(unittest.TestCase):
parallel_requests=1
)
wallet.apply_update(update)
wallet.commit()
self.assertGreater(wallet.get_balance().total, 0)

View File

@ -27,6 +27,7 @@ class LiveWalletTest(unittest.TestCase):
parallel_requests=1
)
wallet.apply_update(update)
wallet.commit()
self.assertGreater(wallet.get_balance().total, 0)
@ -58,6 +59,7 @@ class LiveWalletTest(unittest.TestCase):
parallel_requests=1
)
wallet.apply_update(update)
wallet.commit()
self.assertGreater(wallet.get_balance().total, 0)

View File

@ -42,6 +42,7 @@ final class LiveTxBuilderTests: XCTestCase {
parallelRequests: 1
)
try wallet.applyUpdate(update: update)
try wallet.commit()
XCTAssertGreaterThan(wallet.getBalance().total, UInt64(0), "Wallet must have positive balance, please add funds")
@ -78,7 +79,8 @@ final class LiveTxBuilderTests: XCTestCase {
parallelRequests: 1
)
try wallet.applyUpdate(update: update)
try wallet.commit()
XCTAssertGreaterThan(wallet.getBalance().total, UInt64(0), "Wallet must have positive balance, please add funds")
let recipient1: Address = try Address(address: "tb1qrnfslnrve9uncz9pzpvf83k3ukz22ljgees989", network: .testnet)

View File

@ -42,6 +42,7 @@ final class LiveWalletTests: XCTestCase {
parallelRequests: 1
)
try wallet.applyUpdate(update: update)
try wallet.commit()
XCTAssertGreaterThan(wallet.getBalance().total, UInt64(0))
@ -74,6 +75,7 @@ final class LiveWalletTests: XCTestCase {
parallelRequests: 1
)
try wallet.applyUpdate(update: update)
try wallet.commit()
XCTAssertGreaterThan(wallet.getBalance().total, UInt64(0), "Wallet must have positive balance, please add funds")