gpt4 book ai didi

bitcoinj 将 P2SH 输入交易连接到输出交易

转载 作者:行者123 更新时间:2023-12-02 03:26:55 35 4
gpt4 key购买 nike

我已经创建了 P2SH 地址并将硬币发送到该地址
https://www.blocktrail.com/tBTC/address/2N8Xu6rNAwssXtP2XPjSTuT2ViWQoPeHr3r

接下来我想从 2N8Xu6rNAwssXtP2XPjSTuT2ViWQoPeHr3r 地址发送硬币。

如何准备 P2SH 交易并将其连接到输出脚本?

public static void sendFromP2SH(WalletAppKit kit, Address destAdd, Coin coin) throws AddressFormatException, InsufficientMoneyException, ExecutionException, InterruptedException {
Transaction tx = new Transaction(TestNet3Params.get());
tx.addOutput(coin, destAdd); //prepare destination output


Wallet.SendRequest req = Wallet.SendRequest.forTx(tx);

//TODO prepare P2SH input for output //https://www.blocktrail.com/tBTC/address/2N8Xu6rNAwssXtP2XPjSTuT2ViWQoPeHr3r
Script script = P2SHScript(kit); //2N8Xu6rNAwssXtP2XPjSTuT2ViWQoPeHr3r
TransactionOutput t = null;//... HOW TO CONNECT P2SH input transaction to the output ?
tx.addInput(t);

kit.wallet().completeTx(req);
kit.wallet().commitTx(req.tx);
kit.peerGroup().broadcastTransaction(req.tx).get();
}

prepare script for the P2SH address 2N8Xu6rNAwssXtP2XPjSTuT2ViWQoPeHr3r
public static Script P2SHScript(WalletAppKit kit) {
ECKey pubClientKey = kit.wallet().getImportedKeys().get(0);
ECKey pubServerKey = kit.wallet().getImportedKeys().get(1);
return ScriptBuilder.createP2SHOutputScript(1, ImmutableList.of(pubClientKey, pubServerKey));
}

谢谢你。

最佳答案

下面的构造函数呢?

public TransactionOutput(NetworkParameters params, Transaction parent, BigInteger value, Address to)

在代码内部,它推测“to”地址以检查它是否是多重签名并适本地创建输出脚本。

关于bitcoinj 将 P2SH 输入交易连接到输出交易,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29804845/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com