Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,19 @@ members = [
"packages/rs-platform-wallet",
"packages/rs-platform-wallet-ffi",
"packages/rs-platform-encryption",
"packages/wasm-sdk",
"packages/wasm-sdk",
"packages/rs-unified-sdk-ffi",
"packages/rs-scripts",
]

[workspace.dependencies]
dashcore = { git = "https://github.com/dashpay/rust-dashcore", rev = "6638745c27119778d4c78959003955f00bad373c" }
dash-spv = { git = "https://github.com/dashpay/rust-dashcore", rev = "6638745c27119778d4c78959003955f00bad373c" }
dash-spv-ffi = { git = "https://github.com/dashpay/rust-dashcore", rev = "6638745c27119778d4c78959003955f00bad373c" }
key-wallet = { git = "https://github.com/dashpay/rust-dashcore", rev = "6638745c27119778d4c78959003955f00bad373c" }
key-wallet-ffi = { git = "https://github.com/dashpay/rust-dashcore", rev = "6638745c27119778d4c78959003955f00bad373c" }
key-wallet-manager = { git = "https://github.com/dashpay/rust-dashcore", rev = "6638745c27119778d4c78959003955f00bad373c" }
dashcore-rpc = { git = "https://github.com/dashpay/rust-dashcore", rev = "6638745c27119778d4c78959003955f00bad373c" }
dashcore = { git = "https://github.com/dashpay/rust-dashcore", rev = "dda1db7a7367bb7a6a48de7f4ed79da708266460" }
dash-spv = { git = "https://github.com/dashpay/rust-dashcore", rev = "dda1db7a7367bb7a6a48de7f4ed79da708266460" }
dash-spv-ffi = { git = "https://github.com/dashpay/rust-dashcore", rev = "dda1db7a7367bb7a6a48de7f4ed79da708266460" }
key-wallet = { git = "https://github.com/dashpay/rust-dashcore", rev = "dda1db7a7367bb7a6a48de7f4ed79da708266460" }
key-wallet-ffi = { git = "https://github.com/dashpay/rust-dashcore", rev = "dda1db7a7367bb7a6a48de7f4ed79da708266460" }
key-wallet-manager = { git = "https://github.com/dashpay/rust-dashcore", rev = "dda1db7a7367bb7a6a48de7f4ed79da708266460" }
dashcore-rpc = { git = "https://github.com/dashpay/rust-dashcore", rev = "dda1db7a7367bb7a6a48de7f4ed79da708266460" }

# Optimize heavy crypto crates even in dev/test builds so that
# Halo 2 proof generation and verification run at near-release speed.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::platform_wallet_info::PlatformWalletInfo;
use crate::IdentityManager;
use dashcore::{Address as DashAddress, Network, Transaction, Txid};
use dashcore::{Address as DashAddress, InstantLock, Network, Transaction, Txid};
use dpp::prelude::CoreBlockHeight;
use key_wallet::account::{ManagedAccountCollection, TransactionRecord};
use key_wallet::wallet::managed_wallet_info::wallet_info_interface::WalletInfoInterface;
Expand Down Expand Up @@ -112,8 +112,8 @@ impl WalletInfoInterface for PlatformWalletInfo {
self.wallet_info.update_synced_height(current_height)
}

fn mark_instant_send_utxos(&mut self, txid: &Txid) -> bool {
self.wallet_info.mark_instant_send_utxos(txid)
fn mark_instant_send_utxos(&mut self, txid: &Txid, is_lock: &InstantLock) -> bool {
self.wallet_info.mark_instant_send_utxos(txid, is_lock)
}

fn monitor_revision(&self) -> u64 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ class SPVClient: @unchecked Sendable {
dash_spv_ffi_config_set_mempool_tracking(configPtr, true)
dash_spv_ffi_config_set_mempool_strategy(configPtr, FFIMempoolStrategy(rawValue: 0)) // FetchAll
_ = dash_spv_ffi_config_set_fetch_mempool_transactions(configPtr, true)
_ = dash_spv_ffi_config_set_persist_mempool(configPtr, true)

// Set user agent to include SwiftDashSDK version from the framework bundle
do {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,9 +471,7 @@ protocol SPVWalletEventsHandler: AnyObject {
func onTransactionReceived(
_ walletId: String,
_ accountIndex: UInt32,
_ txid: Data,
_ amount: Int64,
_ addresses: [String]
_ record: NotOwnedTransactionRecord
)

func onBalanceUpdated(
Expand All @@ -500,11 +498,8 @@ extension SPVWalletEventsHandler {

private func onSpvTransactionReceivedCallbackC(
walletIdPtr: UnsafePointer<CChar>?,
status: FFITransactionContext,
accountIndex: UInt32,
txidPtr: UnsafePointer<Byte32>?,
amount: Int64,
addressesPtr: UnsafePointer<CChar>?,
recordPtr: UnsafePointer<FFITransactionRecord>?,
userData: UnsafeMutableRawPointer?
) {
let handler = rawPtrIntoSpvWalletEventsHandler(userData)
Expand All @@ -514,16 +509,18 @@ private func onSpvTransactionReceivedCallbackC(
return
}

guard let recordPtr else {
assertionFailure("TransactionReceived record pointer is nil")
return
}

let walletId = String(cString: walletIdPtr)
let txid = bytePtrIntoData(txidPtr, 32)
let addresses = addressesPtrIntoString(addressesPtr)
let record = NotOwnedTransactionRecord(handle: recordPtr)

handler.onTransactionReceived(
walletId,
accountIndex,
txid,
amount,
addresses
record
)
}

Expand Down Expand Up @@ -570,9 +567,7 @@ private final class DummySPVWalletEventsHandler: SPVWalletEventsHandler {
func onTransactionReceived(
_: String,
_: UInt32,
_: Data,
_: Int64,
_: [String]
_: NotOwnedTransactionRecord,
) {}

func onBalanceUpdated(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,9 +372,7 @@ public class WalletService: ObservableObject {
func onTransactionReceived(
_ walletId: String,
_ accountIndex: UInt32,
_ txid: Data,
_ amount: Int64,
_ addresses: [String]
_ record: NotOwnedTransactionRecord
) {}

func onBalanceUpdated(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,16 @@ public class CoreWalletManager: ObservableObject {
/// - Parameters:
/// - wallet: The wallet to fund from.
/// - accountIndex: BIP44 account index (typically 0).
/// - fundingType: The type of asset lock funding account for key derivation.
/// - identityIndex: Identity index for key derivation (0 for new).
/// - fundingTypes: Array of funding account types for key derivation, one per credit output.
/// - identityIndices: Array of identity indices for key derivation, one per credit output.
/// - creditOutputs: Array of (scriptPubKey, amount) pairs for platform credit outputs.
/// - feePerKb: Fee rate in duffs per kilobyte (0 for default).
/// - Returns: `AssetLockTransactionResult` with tx bytes, output index, private key, and fee.
public func buildAssetLockTransaction(
for wallet: HDWallet,
accountIndex: UInt32 = 0,
fundingType: AssetLockFundingType = .assetLockAddressTopUp,
identityIndex: UInt32 = 0,
fundingTypes: [AssetLockFundingType] = [.assetLockAddressTopUp],
identityIndices: [UInt32] = [0],
creditOutputs: [(scriptPubKey: Data, amount: UInt64)],
feePerKb: UInt64 = 1000
) throws -> AssetLockTransactionResult {
Expand All @@ -170,11 +170,16 @@ public class CoreWalletManager: ObservableObject {
guard count > 0 else {
throw WalletError.walletError("At least one credit output required")
}
guard fundingTypes.count == count, identityIndices.count == count else {
throw WalletError.walletError("fundingTypes and identityIndices must have the same length as creditOutputs")
}

// Concatenate all scripts into a single contiguous buffer
// and build an array of pointers into it
var scriptLens: [Int] = creditOutputs.map { $0.scriptPubKey.count }
var amounts: [UInt64] = creditOutputs.map { $0.amount }
var fundingTypesRaw: [FFIAssetLockFundingType] = fundingTypes.map { FFIAssetLockFundingType(rawValue: $0.rawValue) }
var identityIndicesRaw: [UInt32] = identityIndices
var concatenatedScripts = Data()
for output in creditOutputs {
concatenatedScripts.append(output.scriptPubKey)
Expand All @@ -183,7 +188,7 @@ public class CoreWalletManager: ObservableObject {
var feeOut: UInt64 = 0
var txBytesOut: UnsafeMutablePointer<UInt8>? = nil
var txLenOut: Int = 0
var outputIndexOut: UInt32 = 0
let outputIndexOut: UInt32 = 0
Comment thread
ZocoLini marked this conversation as resolved.
var privateKeyOut: (UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
Expand All @@ -207,28 +212,31 @@ public class CoreWalletManager: ObservableObject {
return scriptPtrs.withUnsafeMutableBufferPointer { scriptPtrsBuffer in
scriptLens.withUnsafeMutableBufferPointer { scriptLensBuffer in
amounts.withUnsafeMutableBufferPointer { amountsBuffer in
wallet_build_and_sign_asset_lock_transaction(
sdkWalletManager.handle,
sdkWallet.handle,
accountIndex,
fundingType.rawValue,
identityIndex,
scriptPtrsBuffer.baseAddress,
scriptLensBuffer.baseAddress,
amountsBuffer.baseAddress,
count,
feePerKb,
&feeOut,
&txBytesOut,
&txLenOut,
&outputIndexOut,
&privateKeyOut,
&ffiError
)
fundingTypesRaw.withUnsafeMutableBufferPointer { fundingTypesBuffer in
identityIndicesRaw.withUnsafeMutableBufferPointer { identityIndicesBuffer in
wallet_build_and_sign_asset_lock_transaction(
sdkWalletManager.handle,
sdkWallet.handle,
accountIndex,
fundingTypesBuffer.baseAddress,
identityIndicesBuffer.baseAddress,
scriptPtrsBuffer.baseAddress,
scriptLensBuffer.baseAddress,
amountsBuffer.baseAddress,
count,
feePerKb,
&feeOut,
&txBytesOut,
&txLenOut,
&privateKeyOut,
&ffiError
)
}
}
}
}
}
}
}

guard success else {
let msg = ffiError.message != nil ? String(cString: ffiError.message!) : "Unknown error"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,23 +75,6 @@ public enum AddressPoolType: UInt32 {
}
}

// MARK: - Transaction Context

/// Transaction context for checking
public enum TransactionContext: UInt32 {
case mempool = 0
case inBlock = 1
case inChainLockedBlock = 2

var ffiValue: FFITransactionContext {
FFITransactionContext(rawValue: self.rawValue)
}

init(ffiContext: FFITransactionContext) {
self = TransactionContext(rawValue: ffiContext.rawValue) ?? .mempool
}
}

// MARK: - Mnemonic Language

/// Language for mnemonic generation
Expand Down Expand Up @@ -254,29 +237,6 @@ public struct TransactionCheckResult {
}
}

/// Transaction context details
public struct TransactionContextDetails {
public let context: TransactionContext
public let height: UInt32
public let blockHash: Data?
public let timestamp: UInt32

func toFFI() -> FFITransactionContextDetails {
var details = FFITransactionContextDetails()
details.context_type = context.ffiValue
details.height = height
details.timestamp = timestamp

if let hash = blockHash {
hash.withUnsafeBytes { bytes in
details.block_hash = bytes.bindMemory(to: UInt8.self).baseAddress
}
}

return details
}
}

/// UTXO information
public struct UTXO: Identifiable, Equatable, Sendable {
public let txid: Data
Expand Down
Loading
Loading