Skip to content

Commit

Permalink
[CORDA-2341]: Fixing ABI compatibility for TransactionBuilder vs Cord…
Browse files Browse the repository at this point in the history
…a 3.3. (corda#4429)
  • Loading branch information
sollecitom authored Dec 18, 2018
1 parent 43f241c commit 5a601de
Showing 1 changed file with 29 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,37 @@ open class TransactionBuilder @JvmOverloads constructor(
protected val outputs: MutableList<TransactionState<ContractState>> = arrayListOf(),
protected val commands: MutableList<Command<*>> = arrayListOf(),
protected var window: TimeWindow? = null,
protected var privacySalt: PrivacySalt = PrivacySalt(),
protected val references: MutableList<StateRef> = arrayListOf(),
protected val serviceHub: ServiceHub? = (Strand.currentStrand() as? FlowStateMachine<*>)?.serviceHub
protected var privacySalt: PrivacySalt = PrivacySalt()
) {

private companion object {
private val log = contextLogger()

private fun defaultReferencesList(): MutableList<StateRef> = arrayListOf()

private fun defaultServiceHub(): ServiceHub? = (Strand.currentStrand() as? FlowStateMachine<*>)?.serviceHub
}

constructor(
notary: Party? = null,
lockId: UUID = (Strand.currentStrand() as? FlowStateMachine<*>)?.id?.uuid ?: UUID.randomUUID(),
inputs: MutableList<StateRef> = arrayListOf(),
attachments: MutableList<SecureHash> = arrayListOf(),
outputs: MutableList<TransactionState<ContractState>> = arrayListOf(),
commands: MutableList<Command<*>> = arrayListOf(),
window: TimeWindow? = null,
privacySalt: PrivacySalt = PrivacySalt(),
references: MutableList<StateRef> = defaultReferencesList(),
serviceHub: ServiceHub? = defaultServiceHub()
) : this(notary, lockId, inputs, attachments, outputs, commands, window, privacySalt) {
this.references = references
this.serviceHub = serviceHub
}

protected var references: MutableList<StateRef> = defaultReferencesList()
private set
protected var serviceHub: ServiceHub? = defaultServiceHub()
private set

private val inputsWithTransactionState = arrayListOf<StateAndRef<ContractState>>()
private val referencesWithTransactionState = arrayListOf<TransactionState<ContractState>>()

Expand Down Expand Up @@ -469,8 +491,9 @@ open class TransactionBuilder @JvmOverloads constructor(
// Recursively resolve all pointers.
while (statePointerQueue.isNotEmpty()) {
val nextStatePointer = statePointerQueue.pop()
if (serviceHub != null) {
val resolvedStateAndRef = nextStatePointer.resolve(serviceHub)
val hub = serviceHub
if (hub != null) {
val resolvedStateAndRef = nextStatePointer.resolve(hub)
// Don't add dupe reference states because CoreTransaction doesn't allow it.
if (resolvedStateAndRef.ref !in referenceStates()) {
addReferenceState(resolvedStateAndRef.referenced())
Expand Down

0 comments on commit 5a601de

Please sign in to comment.