Skip to content

How do I use Redeem Script Hex for create PSBT to unlock P2SH? #125

@rushmi0

Description

@rushmi0
val xpub = DeterministicWallet.ExtendedPublicKey.decode(
            "xpub6CEAyB6zF8bLzi1tNqg4zEfWSBBXtieA4hm3EstWsgSJCgMQS1UrfAFAZHYH1o7tfgFuNWzJhsDHg1EhoF4G5gzXUpQNkt1RzSTyFeAUv4S"
        ).second
        println(xpub)

        // สร้างธุรกรรม
        val unsignedTx = Transaction(
            version = 2,
            txIn = listOf(
                TxIn(
                    OutPoint(
                        TxId("c95039b1ce6152a20ecab1759e924c15e25f4d980673bd64c07a43d2fb501acb"),
                        0
                    ),
                    signatureScript = listOf(),
                    sequence = 0xfdffffff
                )
            ),
            txOut = listOf(
                TxOut(
                    12_000.toSatoshi(),
                    ByteVector("0014d85c2b71d0060b09c9886aeb815e50991dda124d")
                )
            ),
            lockTime = 1423787
        )
        val psbt = Psbt(unsignedTx)

        // ดึงข้อมูล public key, fingerprint, และ key path จาก xpub
        val publicKey = xpub.publicKey
        val fingerprint = xpub.parent
        val keyPath = xpub.path

        // สร้าง mapping ของ public key และ key path
        val pubkeyData = mapOf(
            publicKey to KeyPathWithMaster(fingerprint, keyPath)
        )

        // ระบุ redeem script
        val redeemScript = listOf(

        )

        // อัปเดต PSBT : https://github.com/ACINQ/bitcoin-kmp/blob/master/src%2FcommonMain%2Fkotlin%2Ffr%2Facinq%2Fbitcoin%2Fpsbt%2FPsbt.kt#L172-L172
        val firstPSBT = psbt.updateNonWitnessInput(
            inputTx = unsignedTx,
            outputIndex = 0,
            redeemScript = redeemScript,
            sighashType = 1,
            derivationPaths = pubkeyData
        )

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions