首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >错误验证生成的事务。BlockCypher

错误验证生成的事务。BlockCypher
EN

Stack Overflow用户
提问于 2018-09-18 14:44:59
回答 1查看 941关注 0票数 0

我正在使用来自这里的块密码api,https://github.com/blockcypher/java-client

并在尝试发送事务时获得一个异常:

代码语言:javascript
复制
    IntermediaryTransaction transaction = context.getTransactionService().
            newTransaction(
                    new ArrayList<>(Arrays.asList("mntg5ArRYYm9PirCaJYNxvHoMKbe2B4Q1b")),
                    new ArrayList<>(Arrays.asList("mzF8NP6rHYG9ehVPYSJBFygu6LSYVqZLZg")), 30000);

    String privateKey = "9acdde15b65eae424f06fd5b5e20572b20c38a25c7daf5b3244508940887dc68";
    SignUtils.signWithHexKeyWithPubKey(transaction, privateKey);

    context.getTransactionService().sendTransaction(transaction);

这是日志:

代码语言:javascript
复制
    3425   [           main] DEBUG ls.rest.jersey.JerseyRestUtils  - 
Posting to https://api.blockcypher.com/v1/btc/test3/txs/new?token=mytoken: {"double_spend":false,"inputs":[{"addresses":["mntg5ArRYYm9PirCaJYNxvHoMKbe2B4Q1b"]}],"outputs":[{"value":30000,"addresses":["mzF8NP6rHYG9ehVPYSJBFygu6LSYVqZLZg"]}]}
    5339   [           main] INFO  ockcypher.utils.sign.SignUtils  - Pushing Pub key for input
    5382   [           main] DEBUG ls.rest.jersey.JerseyRestUtils  - Posting to https://api.blockcypher.com/v1/btc/test3/txs/send?token=mytoken: {"tx":{"hash":"b37e8f5dfa909876fe636c07db13a65ea6671ea723847f2e58815e6357200dcb","block_height":-1,"addresses":["mzF8NP6rHYG9ehVPYSJBFygu6LSYVqZLZg","mntg5ArRYYm9PirCaJYNxvHoMKbe2B4Q1b"],"total":4219700,"fees":10300,"relayed_by":"78.128.153.1","received":"2018-09-18T14:37:52.357270154Z","ver":1,"vin_sz":1,"vout_sz":2,"confirmations":0,"preference":"high","double_spend":false,"inputs":[{"prev_hash":"68553b72dad64595bd2052547fcbe84a17e3966a01386b4caefb4518324cf2f9","output_index":0,"output_value":4230000,"addresses":["mntg5ArRYYm9PirCaJYNxvHoMKbe2B4Q1b"],"script_type":"pay-to-pubkey-hash"}],"outputs":[{"value":30000,"script":"76a914cd6c24f57b38917f2066b342147a3802d0a2f6f788ac","addresses":["mzF8NP6rHYG9ehVPYSJBFygu6LSYVqZLZg"],"script_type":"pay-to-pubkey-hash"},{"value":4189700,"script":"76a91450e47d76f6f5dfe1de7de1f19e40afaefbfc008c88ac","addresses":["mntg5ArRYYm9PirCaJYNxvHoMKbe2B4Q1b"],"script_type":"pay-to-pubkey-hash"}]},"tosign":["936678acb668bbe3055d98daf2bf43f7fd8c45e4948c9db01eca16759cbafc26"],"signatures":["3045022100c93d97a73c19c96a521c88d05ec1e11405611dd82407461a5a27dabf2d3d92540220574d453f707f3c40c862e8a1fd8a43c08a68e970fceaee21406aae75172ff137"],"pubkeys":["04a1cfb3e4c4088a4b8a30e09cd2e2ad0503948edab552dbe6550979fb77d3808fea0add24063d1249f2e54ec4dd01308961426f43b83393d367ac529fa8bbed9d"]}
    Exception in thread "main" BlockCypherException{message=Bad Request, status=400, blockCypherError=[Error{error='Error validating generated transaction: Error running script for input 0 referencing 68553b72dad64595bd2052547fcbe84a17e3966a01386b4caefb4518324cf2f9 at 0: Script was NOT verified successfully.'}], exception=null}
    at com.blockcypher.utils.rest.jersey.JerseyRestUtils.getBlockCypherException(JerseyRestUtils.java:90)
    at com.blockcypher.utils.rest.jersey.JerseyRestUtils.post(JerseyRestUtils.java:33)
    at com.blockcypher.utils.rest.jersey.JerseyRestUtils.post(JerseyRestUtils.java:50)
    at com.blockcypher.utils.rest.RestUtils.post(RestUtils.java:20)
    at com.blockcypher.service.TransactionService.postTransaction(TransactionService.java:59)
    at com.blockcypher.service.TransactionService.sendTransaction(TransactionService.java:133)
    at _test.sendBtc(_test.java:46)
    at _test.main(_test.java:27)

我正在使用比特币测试网。

EN

回答 1

Stack Overflow用户

发布于 2018-09-19 14:38:36

我找到了解决办法。您必须向IntermediaryTransaction添加一个公钥,并使用专用方法signWithHexKeyNoPubKey (wtf?)使用HEX格式的privateKey。其他变体不起作用。我不知道它为什么会起作用,但它起作用。以下是正确的工作代码:

代码语言:javascript
复制
private static Transaction sendBtc(String addrFrom, String addrTo, String privateKey, String pubKey, long value) throws BlockCypherException {
    IntermediaryTransaction unsignedTX = context.getTransactionService().
            newTransaction(
                    new ArrayList<>(Arrays.asList(addrFrom)),
                    new ArrayList<>(Arrays.asList(addrTo)), value);

    unsignedTX.addPubKeys(pubKey);

    SignUtils.signWithHexKeyNoPubKey(unsignedTX, privateKey);

    return context.getTransactionService().sendTransaction(unsignedTX);
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52389191

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档