当前位置: 首页>>代码示例>>Java>>正文


Java TransactionSignature.dummy方法代码示例

本文整理汇总了Java中org.bitcoinj.crypto.TransactionSignature.dummy方法的典型用法代码示例。如果您正苦于以下问题:Java TransactionSignature.dummy方法的具体用法?Java TransactionSignature.dummy怎么用?Java TransactionSignature.dummy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.bitcoinj.crypto.TransactionSignature的用法示例。


在下文中一共展示了TransactionSignature.dummy方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createAndUpdateEmptyInputScript

import org.bitcoinj.crypto.TransactionSignature; //导入方法依赖的package包/类
@Test
public void createAndUpdateEmptyInputScript() throws Exception {
    TransactionSignature dummySig = TransactionSignature.dummy();
    ECKey key = new ECKey();

    // pay-to-pubkey
    Script inputScript = ScriptBuilder.createInputScript(dummySig);
    assertThat(inputScript.getChunks().get(0).data, equalTo(dummySig.encodeToBitcoin()));
    inputScript = ScriptBuilder.createInputScript(null);
    assertThat(inputScript.getChunks().get(0).opcode, equalTo(OP_0));

    // pay-to-address
    inputScript = ScriptBuilder.createInputScript(dummySig, key);
    assertThat(inputScript.getChunks().get(0).data, equalTo(dummySig.encodeToBitcoin()));
    inputScript = ScriptBuilder.createInputScript(null, key);
    assertThat(inputScript.getChunks().get(0).opcode, equalTo(OP_0));
    assertThat(inputScript.getChunks().get(1).data, equalTo(key.getPubKey()));

    // pay-to-script-hash
    ECKey key2 = new ECKey();
    Script multisigScript = ScriptBuilder.createMultiSigOutputScript(2, Arrays.asList(key, key2));
    inputScript = ScriptBuilder.createP2SHMultiSigInputScript(Arrays.asList(dummySig, dummySig), multisigScript);
    assertThat(inputScript.getChunks().get(0).opcode, equalTo(OP_0));
    assertThat(inputScript.getChunks().get(1).data, equalTo(dummySig.encodeToBitcoin()));
    assertThat(inputScript.getChunks().get(2).data, equalTo(dummySig.encodeToBitcoin()));
    assertThat(inputScript.getChunks().get(3).data, equalTo(multisigScript.getProgram()));

    inputScript = ScriptBuilder.createP2SHMultiSigInputScript(null, multisigScript);
    assertThat(inputScript.getChunks().get(0).opcode, equalTo(OP_0));
    assertThat(inputScript.getChunks().get(1).opcode, equalTo(OP_0));
    assertThat(inputScript.getChunks().get(2).opcode, equalTo(OP_0));
    assertThat(inputScript.getChunks().get(3).data, equalTo(multisigScript.getProgram()));

    inputScript = ScriptBuilder.updateScriptWithSignature(inputScript, dummySig.encodeToBitcoin(), 0, 1, 1);
    assertThat(inputScript.getChunks().get(0).opcode, equalTo(OP_0));
    assertThat(inputScript.getChunks().get(1).data, equalTo(dummySig.encodeToBitcoin()));
    assertThat(inputScript.getChunks().get(2).opcode, equalTo(OP_0));
    assertThat(inputScript.getChunks().get(3).data, equalTo(multisigScript.getProgram()));

    inputScript = ScriptBuilder.updateScriptWithSignature(inputScript, dummySig.encodeToBitcoin(), 1, 1, 1);
    assertThat(inputScript.getChunks().get(0).opcode, equalTo(OP_0));
    assertThat(inputScript.getChunks().get(1).data, equalTo(dummySig.encodeToBitcoin()));
    assertThat(inputScript.getChunks().get(2).data, equalTo(dummySig.encodeToBitcoin()));
    assertThat(inputScript.getChunks().get(3).data, equalTo(multisigScript.getProgram()));

    // updating scriptSig with no missing signatures
    try {
        ScriptBuilder.updateScriptWithSignature(inputScript, dummySig.encodeToBitcoin(), 1, 1, 1);
        fail("Exception expected");
    } catch (Exception e) {
        assertEquals(IllegalArgumentException.class, e.getClass());
    }
}
 
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:54,代码来源:ScriptTest.java


注:本文中的org.bitcoinj.crypto.TransactionSignature.dummy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。