UnshieldedTransactionBuilder
Builds unshielded transactions for Midnight blockchain.
Purpose:
Construct balanced transactions from user inputs
Select appropriate UTXOs using coin selection
Create Intent with guaranteed offer
Calculate change and create change outputs
Usage:
val builder = UnshieldedTransactionBuilder(utxoManager)
val result = builder.buildTransfer(
from = "mn_addr_sender...",
to = "mn_addr_recipient...",
amount = BigInteger("100000000"), // 100.0 NIGHT
tokenType = UtxoOutput.NATIVE_TOKEN_TYPE
)
when (result) {
is BuildResult.Success -> {
val intent = result.intent
// Proceed to sign the intent
}
is BuildResult.InsufficientFunds -> {
// Show error to user
}
}Content copied to clipboard
Transaction Structure:
Intent {
guaranteedUnshieldedOffer: {
inputs: [UtxoSpend, ...] // Selected UTXOs
outputs: [
UtxoOutput(recipient), // Payment output
UtxoOutput(sender)? // Change output (if any)
]
signatures: [] // Empty (added during signing)
}
ttl: currentTime + 30 minutes
}Content copied to clipboard
Important:
UTXOs are LOCKED during selection (state = PENDING)
If transaction fails, call
utxoManager.unlockUtxos()to releaseChange output only created if change 0
Signatures added during the signing phase
Functions
Link copied to clipboard
suspend fun buildTransfer(from: String, to: String, amount: BigInteger, tokenType: String, senderPublicKey: String, ttlMinutes: Int = DEFAULT_TTL_MINUTES): UnshieldedTransactionBuilder.BuildResult
Build an unshielded transfer transaction.