Skip to content

Commit

Permalink
Add a RemoteSwapInV2 message
Browse files Browse the repository at this point in the history
This message includes all outputs from the remote tx and not just the one that is included in the swap.
This is needed for Schnorr signatures.
  • Loading branch information
sstone committed Nov 8, 2023
1 parent 942aede commit 3282d1b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ sealed class InteractiveTxInput {
/** A remote input from a swap-in: our peer needs our signature to build a witness for that input. */
data class RemoteSwapIn(override val serialId: Long, override val outPoint: OutPoint, override val txOut: TxOut, override val sequence: UInt, val userKey: PublicKey, val serverKey: PublicKey, val refundDelay: Int) : Remote()

data class RemoteSwapInV2(override val serialId: Long, override val outPoint: OutPoint, val txOuts: List<TxOut>, override val sequence: UInt, val userKey: PublicKey, val serverKey: PublicKey, val refundDelay: Int) : Remote() {
override val txOut: TxOut get() = txOuts[outPoint.index.toInt()]
}

/** The shared input can be added by us or by our peer, depending on who initiated the protocol. */
data class Shared(override val serialId: Long, override val outPoint: OutPoint, override val sequence: UInt, val localAmount: MilliSatoshi, val remoteAmount: MilliSatoshi) : InteractiveTxInput(), Incoming, Outgoing
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,15 @@ object Deserialization {
serverKey = readPublicKey(),
refundDelay = readNumber().toInt()
)
0x03 -> InteractiveTxInput.RemoteSwapInV2(
serialId = readNumber(),
outPoint = readOutPoint(),
txOuts = readCollection { TxOut.read(readDelimitedByteArray()) }.toList(),
sequence = readNumber().toUInt(),
userKey = readPublicKey(),
serverKey = readPublicKey(),
refundDelay = readNumber().toInt()
)
else -> error("unknown discriminator $discriminator for class ${InteractiveTxInput.Remote::class}")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,16 @@ object Serialization {
writePublicKey(serverKey)
writeNumber(refundDelay)
}
is InteractiveTxInput.RemoteSwapInV2 -> i.run {
write(0x03)
writeNumber(serialId)
writeBtcObject(outPoint)
writeCollection(i.txOuts) { o -> writeBtcObject(o) }
writeNumber(sequence.toLong())
writePublicKey(userKey)
writePublicKey(serverKey)
writeNumber(refundDelay)
}
}

private fun Output.writeSharedInteractiveTxOutput(o: InteractiveTxOutput.Shared) = o.run {
Expand Down

0 comments on commit 3282d1b

Please sign in to comment.