亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Java版本離線簽名怎么實現

發布時間:2021-12-20 16:23:22 來源:億速云 閱讀:151 作者:iii 欄目:互聯網科技

本篇內容介紹了“Java版本離線簽名怎么實現”的有關知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領大家學習一下如何處理這些情況吧!希望大家仔細閱讀,能夠學有所成!

Build jar
  1. first get source code

    git clone https://github.com/successli/tx_signer.git
  2. get jar package

    $ mvn assembly:assembly -Dmaven.test.skip=true


    You can get a jar with dependencies, and you can use it in your project.

Test cases

Need 3 Parameters:

  • Private Keys Array

  • Template Object

  • After call build transaction api return a Template json object. build transaction api

  • use bytom java sdk return a Template object.

  • Raw Transaction

  • call decode raw-transaction api from dev branch. decode raw-transaction api

Call method:

// return a Template object signed offline basically.
Template result = signatures.generateSignatures(privates, template, rawTransaction);
// use result's raw_transaction call sign transaction api to build another data but not need password or private key.

Single-key Example:

@Test
// 使用 SDK 來構造 Template 對象參數, 單簽
public void testSignSingleKey() throws BytomException {
    Client client = Client.generateClient();

    String asset_id = "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff";
    String address = "sm1qvyus3s5d7jv782syuqe3qrh75fx23lgpzf33em";
    // build transaction obtain a Template object
    Template template = new Transaction.Builder()
        .addAction(
        new Transaction.Action.SpendFromAccount()
        .setAccountId("0G0NLBNU00A02")
        .setAssetId(asset_id)
        .setAmount(40000000)
    )
        .addAction(
        new Transaction.Action.SpendFromAccount()
        .setAccountId("0G0NLBNU00A02")
        .setAssetId(asset_id)
        .setAmount(300000000)
    )
        .addAction(
        new Transaction.Action.ControlWithAddress()
        .setAddress(address)
        .setAssetId(asset_id)
        .setAmount(30000000)
    ).build(client);
    logger.info("template: " + template.toJson());
    // use Template object's raw_transaction id to decode raw_transaction obtain a RawTransaction object
    RawTransaction decodedTx = RawTransaction.decode(client, template.rawTransaction);
    logger.info("decodeTx: " + decodedTx.toJson());
    // need a private key array
    String[] privateKeys = new String[]{"10fdbc41a4d3b8e5a0f50dd3905c1660e7476d4db3dbd9454fa4347500a633531c487e8174ffc0cfa76c3be6833111a9b8cd94446e37a76ee18bb21a7d6ea66b"};
    logger.info("private key:" + privateKeys[0]);
    // call offline sign method to obtain a basic offline signed template
    Signatures signatures = new SignaturesImpl();
    Template basicSigned = signatures.generateSignatures(privateKeys, template, decodedTx);
    logger.info("basic signed raw: " + basicSigned.toJson());
    // call sign transaction api to calculate whole raw_transaction id
    // sign password is None or another random String
    Template result = new Transaction.SignerBuilder().sign(client,
                                                           basicSigned, "");
    logger.info("result raw_transaction: " + result.toJson());
    // success to submit transaction
}

Multi-keys Example:

Need an account has two or more keys.

@Test
// 使用 SDK 來構造 Template 對象參數, 多簽
public void testSignMultiKeys() throws BytomException {
    Client client = Client.generateClient();

    String asset_id = "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff";
    String address = "sm1qvyus3s5d7jv782syuqe3qrh75fx23lgpzf33em";
    // build transaction obtain a Template object
    // account 0G1RPP6OG0A06 has two keys
    Template template = new Transaction.Builder()
        .setTtl(10)
        .addAction(
        new Transaction.Action.SpendFromAccount()
        .setAccountId("0G1RPP6OG0A06")
        .setAssetId(asset_id)
        .setAmount(40000000)
    )
        .addAction(
        new Transaction.Action.SpendFromAccount()
        .setAccountId("0G1RPP6OG0A06")
        .setAssetId(asset_id)
        .setAmount(300000000)
    )
        .addAction(
        new Transaction.Action.ControlWithAddress()
        .setAddress(address)
        .setAssetId(asset_id)
        .setAmount(30000000)
    ).build(client);
    logger.info("template: " + template.toJson());
    // use Template object's raw_transaction id to decode raw_transaction obtain a RawTransaction object
    RawTransaction decodedTx = RawTransaction.decode(client, template.rawTransaction);
    logger.info("decodeTx: " + decodedTx.toJson());
    // need a private key array
    String[] privateKeys = new String[]{"08bdbd6c22856c5747c930f64d0e5d58ded17c4473910c6c0c3f94e485833a436247976253c8e29e961041ad8dfad9309744255364323163837cbef2483b4f67",
                                        "40c821f736f60805ad59b1fea158762fa6355e258601dfb49dda6f672092ae5adf072d5cab2ceaaa0d68dd3fe7fa04869d95afed8c20069f446a338576901e1b"};
    logger.info("private key 1:" + privateKeys[0]);
    logger.info("private key 2:" + privateKeys[1]);
    // call offline sign method to obtain a basic offline signed template
    Signatures signatures = new SignaturesImpl();
    Template basicSigned = signatures.generateSignatures(privateKeys, template, decodedTx);
    logger.info("basic signed raw: " + basicSigned.toJson());
    // call sign transaction api to calculate whole raw_transaction id
    // sign password is None or another random String
    Template result = new Transaction.SignerBuilder().sign(client,
                                                           basicSigned, "");
    logger.info("result raw_transaction: " + result.toJson());
    // success to submit transaction
}

Multi-keys and Multi-inputs Example:

@Test
// 使用 SDK 來構造 Template 對象參數, 多簽, 多輸入
public void testSignMultiKeysMultiInputs() throws BytomException {
    Client client = Client.generateClient();

    String asset_id = "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff";
    String address = "sm1qvyus3s5d7jv782syuqe3qrh75fx23lgpzf33em";
    // build transaction obtain a Template object
    Template template = new Transaction.Builder()
        .setTtl(10)
        // 1 input
        .addAction(
        new Transaction.Action.SpendFromAccount()
        .setAccountId("0G1RPP6OG0A06") // Multi-keys account
        .setAssetId(asset_id)
        .setAmount(40000000)
    )
        .addAction(
        new Transaction.Action.SpendFromAccount()
        .setAccountId("0G1RPP6OG0A06")
        .setAssetId(asset_id)
        .setAmount(300000000)
    )    // 2 input
        .addAction(
        new Transaction.Action.SpendFromAccount()
        .setAccountId("0G1Q6V1P00A02") // Multi-keys account
        .setAssetId(asset_id)
        .setAmount(40000000)
    )
        .addAction(
        new Transaction.Action.SpendFromAccount()
        .setAccountId("0G1Q6V1P00A02")
        .setAssetId(asset_id)
        .setAmount(300000000)
    )
        .addAction(
        new Transaction.Action.ControlWithAddress()
        .setAddress(address)
        .setAssetId(asset_id)
        .setAmount(60000000)
    ).build(client);
    logger.info("template: " + template.toJson());
    // use Template object's raw_transaction id to decode raw_transaction obtain a RawTransaction object
    RawTransaction decodedTx = RawTransaction.decode(client, template.rawTransaction);
    logger.info("decodeTx: " + decodedTx.toJson());
    // need a private key array
    String[] privateKeys = new String[]{"08bdbd6c22856c5747c930f64d0e5d58ded17c4473910c6c0c3f94e485833a436247976253c8e29e961041ad8dfad9309744255364323163837cbef2483b4f67",
                                        "40c821f736f60805ad59b1fea158762fa6355e258601dfb49dda6f672092ae5adf072d5cab2ceaaa0d68dd3fe7fa04869d95afed8c20069f446a338576901e1b",
                                        "08bdbd6c22856c5747c930f64d0e5d58ded17c4473910c6c0c3f94e485833a436247976253c8e29e961041ad8dfad9309744255364323163837cbef2483b4f67"};
    logger.info("private key 1:" + privateKeys[0]);
    logger.info("private key 2:" + privateKeys[1]);
    // call offline sign method to obtain a basic offline signed template
    Signatures signatures = new SignaturesImpl();
    Template basicSigned = signatures.generateSignatures(privateKeys, template, decodedTx);
    logger.info("basic signed raw: " + basicSigned.toJson());
    // call sign transaction api to calculate whole raw_transaction id
    // sign password is None or another random String
    Template result = new Transaction.SignerBuilder().sign(client,
                                                           basicSigned, "");
    logger.info("result raw_transaction: " + result.toJson());
    // success to submit transaction
}

“Java版本離線簽名怎么實現”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識可以關注億速云網站,小編將為大家輸出更多高質量的實用文章!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

秭归县| 和龙市| 星座| 盖州市| 九江县| 诏安县| 仙游县| 长子县| 康马县| 通榆县| 文山县| 财经| 宝兴县| 大洼县| 连江县| 仁化县| 营口市| 临湘市| 堆龙德庆县| 鹤岗市| 聊城市| 个旧市| 平江县| 浠水县| 田林县| 南靖县| 桐庐县| 嘉兴市| 长治市| 北碚区| 尤溪县| 莫力| 彭州市| 威远县| 怀安县| 垫江县| 福州市| 紫阳县| 塔河县| 株洲县| 丹凤县|