Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add JvmField on PSBT fields #97

Merged
merged 1 commit into from
Aug 8, 2023
Merged
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
25 changes: 16 additions & 9 deletions src/commonMain/kotlin/fr/acinq/bitcoin/psbt/Psbt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ package fr.acinq.bitcoin.psbt

import fr.acinq.bitcoin.*
import fr.acinq.bitcoin.crypto.Pack
import fr.acinq.bitcoin.io.*
import fr.acinq.bitcoin.io.ByteArrayInput
import fr.acinq.bitcoin.io.ByteArrayOutput
import fr.acinq.bitcoin.io.readNBytes
import fr.acinq.bitcoin.utils.Either
import fr.acinq.bitcoin.utils.getOrElse
import kotlin.jvm.JvmField
import kotlin.jvm.JvmStatic

/**
Expand All @@ -30,7 +33,7 @@ import kotlin.jvm.JvmStatic
* @param inputs signing data for each input of the transaction to be signed (order matches the unsigned tx).
* @param outputs signing data for each output of the transaction to be signed (order matches the unsigned tx).
*/
public data class Psbt(val global: Global, val inputs: List<Input>, val outputs: List<Output>) {
public data class Psbt(@JvmField val global: Global, @JvmField val inputs: List<Input>, @JvmField val outputs: List<Output>) {

init {
require(global.tx.txIn.size == inputs.size) { "there must be one partially signed input per input of the unsigned tx" }
Expand Down Expand Up @@ -537,7 +540,6 @@ public data class Psbt(val global: Global, val inputs: List<Input>, val outputs:
/** Only version 0 is supported for now. */
public const val Version: Long = 0


/**
* Implements the PSBT combiner role: combines multiple psbts for the same unsigned transaction.
*
Expand Down Expand Up @@ -588,8 +590,8 @@ public data class Psbt(val global: Global, val inputs: List<Input>, val outputs:
)

private fun combineOutput(outputs: List<Output>): Output = createOutput(
outputs.mapNotNull { it.redeemScript }.firstOrNull(),
outputs.mapNotNull { it.witnessScript }.firstOrNull(),
outputs.firstNotNullOfOrNull { it.redeemScript },
outputs.firstNotNullOfOrNull { it.witnessScript },
outputs.flatMap { it.derivationPaths.toList() }.toMap(),
combineUnknown(outputs.map { it.unknown })
)
Expand Down Expand Up @@ -1066,15 +1068,15 @@ public data class Psbt(val global: Global, val inputs: List<Input>, val outputs:
* @param masterKeyFingerprint fingerprint of the master key.
* @param extendedPublicKey BIP32 extended public key.
*/
public data class ExtendedPublicKeyWithMaster(val prefix: Long, val masterKeyFingerprint: Long, val extendedPublicKey: DeterministicWallet.ExtendedPublicKey)
public data class ExtendedPublicKeyWithMaster(@JvmField val prefix: Long, @JvmField val masterKeyFingerprint: Long, @JvmField val extendedPublicKey: DeterministicWallet.ExtendedPublicKey)

/**
* @param masterKeyFingerprint fingerprint of the master key.
* @param keyPath bip 32 derivation path.
*/
public data class KeyPathWithMaster(val masterKeyFingerprint: Long, val keyPath: KeyPath)
public data class KeyPathWithMaster(@JvmField val masterKeyFingerprint: Long, @JvmField val keyPath: KeyPath)

public data class DataEntry(val key: ByteVector, val value: ByteVector)
public data class DataEntry(@JvmField val key: ByteVector, @JvmField val value: ByteVector)

/**
* Global data for the PSBT.
Expand All @@ -1084,7 +1086,12 @@ public data class DataEntry(val key: ByteVector, val value: ByteVector)
* @param extendedPublicKeys (optional) extended public keys used when signing inputs and producing outputs.
* @param unknown (optional) unknown global entries.
*/
public data class Global(val version: Long, val tx: Transaction, val extendedPublicKeys: List<ExtendedPublicKeyWithMaster>, val unknown: List<DataEntry>)
public data class Global(
@JvmField val version: Long,
@JvmField val tx: Transaction,
@JvmField val extendedPublicKeys: List<ExtendedPublicKeyWithMaster>,
@JvmField val unknown: List<DataEntry>
)

/** A PSBT input. A valid PSBT must contain one such input per input of the [[Global.tx]]. */
public sealed class Input {
Expand Down