成人国产在线小视频_日韩寡妇人妻调教在线播放_色成人www永久在线观看_2018国产精品久久_亚洲欧美高清在线30p_亚洲少妇综合一区_黄色在线播放国产_亚洲另类技巧小说校园_国产主播xx日韩_a级毛片在线免费

資訊專欄INFORMATION COLUMN

Bytom Java版本離線簽名

weapon / 1071人閱讀

摘要:比原項(xiàng)目倉庫地址地址使用來構(gòu)造對(duì)象參數(shù)單簽使用來構(gòu)造對(duì)象參數(shù)多簽使用來構(gòu)造對(duì)象參數(shù)多簽多輸入

比原項(xiàng)目倉庫:

Github地址:https://github.com/Bytom/bytom

Gitee地址:https://gitee.com/BytomBlockc...

tx_signer

Java implementation of signing transaction offline to bytomd.

Pre Get the source code
$ git clone https://github.com/Bytom/bytom.git $GOPATH/src/github.com/bytom
git checkout
$ git checkout dev

Why need dev branch? Because you could call decode transaction api from dev branch and obtain tx_id and some inputs ids.

Build
$ cd $GOPATH/src/github.com/bytom
$ make bytomd    # build bytomd
$ make bytomcli  # build bytomcli

When successfully building the project, the bytom and bytomcli binary should be present in cmd/bytomd and cmd/bytomcli directory, respectively.

Initialize

First of all, initialize the node:

$ cd ./cmd/bytomd
$ ./bytomd init --chain_id solonet
launch
$ ./bytomd node --mining
Usage Build jar

first get source code

git clone https://github.com/successli/tx_signer.git

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 來構(gòu)造 Template 對(duì)象參數(shù), 單簽
public void testSignSingleKey() throws BytomException {
    Client client = Client.generateClient();

    String asset_id = "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff";
    String address = "sm1qvyus3s5d7jv782syuqe3qrh65fx23lgpzf33em";
    // 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 來構(gòu)造 Template 對(duì)象參數(shù), 多簽
public void testSignMultiKeys() throws BytomException {
    Client client = Client.generateClient();

    String asset_id = "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff";
    String address = "sm1qvyus3s5d7jv782syuqe3qrh65fx23lgpzf33em";
    // 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 來構(gòu)造 Template 對(duì)象參數(shù), 多簽, 多輸入
public void testSignMultiKeysMultiInputs() throws BytomException {
    Client client = Client.generateClient();

    String asset_id = "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff";
    String address = "sm1qvyus3s5d7jv782syuqe3qrh65fx23lgpzf33em";
    // 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
}

文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請(qǐng)注明本文地址:http://systransis.cn/yun/72071.html

相關(guān)文章

  • Bytom Java版本離線簽名

    摘要:比原項(xiàng)目倉庫地址地址使用來構(gòu)造對(duì)象參數(shù)單簽使用來構(gòu)造對(duì)象參數(shù)多簽使用來構(gòu)造對(duì)象參數(shù)多簽多輸入 比原項(xiàng)目倉庫: Github地址:https://github.com/Bytom/bytom Gitee地址:https://gitee.com/BytomBlockc... tx_signer Java implementation of signing transaction offli...

    xumenger 評(píng)論0 收藏0
  • 使用Java SDK實(shí)現(xiàn)離線簽名

    摘要:當(dāng)使用構(gòu)建完成一筆交易并簽名后,若沒有全節(jié)點(diǎn)的幫助,也需要自己實(shí)現(xiàn)網(wǎng)絡(luò)協(xié)議將交易廣播到其他節(jié)點(diǎn)。其中,第一個(gè)依賴是的封裝,可用于查詢可用的以及提交交易第二個(gè)依賴用于構(gòu)建交易以及對(duì)交易進(jìn)行離線簽名。 嚴(yán)格來說,tx-signer并不屬于SDK,它是bytomd中構(gòu)建交易、對(duì)交易簽名兩大模塊的java實(shí)現(xiàn)版。因此,若想用tx-signer對(duì)交易進(jìn)行離線簽名,需要由你在本地保管好自己的私鑰。...

    dreamGong 評(píng)論0 收藏0
  • Bytom國密網(wǎng)說明和指南

    摘要:在比原鏈主網(wǎng)中,在獲取交易和區(qū)塊頭等摘要的過程中使用的哈希算法是算法,而在國密測(cè)試網(wǎng)中,使用算法替代。啟動(dòng)的是國密測(cè)試網(wǎng)??梢哉f,比原鏈的項(xiàng)目進(jìn)展伴隨著國密測(cè)試網(wǎng)的發(fā)布更上一層樓。 比原項(xiàng)目倉庫: Github地址:https://github.com/Bytom/bytom Gitee地址:https://gitee.com/BytomBlockc... 國密算法是指國家密碼管理局制...

    王巖威 評(píng)論0 收藏0
  • 比原鏈Bytom錯(cuò)誤碼一覽

    摘要:錯(cuò)誤編號(hào)內(nèi)容注釋非比原標(biāo)準(zhǔn)錯(cuò)誤請(qǐng)求超時(shí)非法的請(qǐng)求體為網(wǎng)絡(luò)錯(cuò)誤編號(hào)內(nèi)容注釋區(qū)塊鏈網(wǎng)絡(luò)類型不匹配是簽名相關(guān)的錯(cuò)誤編號(hào)內(nèi)容注釋需要簽名的個(gè)數(shù)超過實(shí)際需求簽名的個(gè)數(shù)簽名格式錯(cuò)誤缺少主公鑰主公鑰重復(fù)為交易相關(guān)的錯(cuò)誤構(gòu)建交易錯(cuò)誤編號(hào)內(nèi)容注釋資產(chǎn)余額不 0XX API錯(cuò)誤 編號(hào) 內(nèi)容 注釋 BTM000 Bytom API Error 非比原標(biāo)準(zhǔn)錯(cuò)誤 BTM001 Request t...

    Nosee 評(píng)論0 收藏0
  • Bytom Kit開發(fā)輔助工具介紹

    摘要:是一款為了幫助開發(fā)者更簡(jiǎn)單地理解的開發(fā)輔助工具,集合了校驗(yàn)標(biāo)注解碼測(cè)試水龍頭等功能。這一功能可以創(chuàng)建新的私鑰。鏈接比原水龍頭工具接口,開發(fā)者可以使用該工具接口領(lǐng)取比原測(cè)試。 showImg(https://segmentfault.com/img/bVbrThp?w=1920&h=1280); Bytom Kit是一款為了幫助開發(fā)者更簡(jiǎn)單地理解Bytom的開發(fā)輔助工具,集合了校驗(yàn)、標(biāo)注...

    cocopeak 評(píng)論0 收藏0

發(fā)表評(píng)論

0條評(píng)論

最新活動(dòng)
閱讀需要支付1元查看
<