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
}
}

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
}

Important:

  • UTXOs are LOCKED during selection (state = PENDING)

  • If transaction fails, call utxoManager.unlockUtxos() to release

  • Change output only created if change 0

  • Signatures added during the signing phase

Constructors

Link copied to clipboard
constructor(utxoManager: UtxoManager)

Types

Link copied to clipboard
sealed class BuildResult

Result of transaction building.

Link copied to clipboard
object Companion

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.