国产xxxx99真实实拍_久久不雅视频_高清韩国a级特黄毛片_嗯老师别我我受不了了小说

資訊專欄INFORMATION COLUMN

Bytom交易說明(賬戶管理模式)

AlphaWatch / 2484人閱讀

摘要:簽名失敗只需將簽名的交易數(shù)據(jù)用正確的密碼重新簽名即可,無需再次構(gòu)建交易提交交易接口,代碼提交交易的輸入請求格式如下對應(yīng)源代碼的請求對象如下結(jié)構(gòu)字段說明如下簽名完成之后的交易信息。

該部分主要針對用戶使用bytom自帶的賬戶模式發(fā)送交易

1、構(gòu)建交易

API接口 build-transaction,代碼api/transact.go#L120

以標準的非BTM資產(chǎn)轉(zhuǎn)賬交易為例,資產(chǎn)ID為全F表示BTM資產(chǎn),在該示例中BTM資產(chǎn)僅作為手續(xù)費,該交易表示花費99個特定的資產(chǎn)到指定地址中。其中構(gòu)建交易的輸入請求json格式如下:

{
  "base_transaction": null,
  "actions": [
    {
      "account_id": "0ER7MEFGG0A02",
      "amount": 20000000,
      "asset_id": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
      "type": "spend_account"
    },
    {
      "account_id": "0ER7MEFGG0A02",
      "amount": 99,
      "asset_id": "42275aacbeda1522cd41580f875c3c452daf5174b17ba062bf0ab71a568c123f",
      "type": "spend_account"
    },
    {
      "amount": 99,
      "asset_id": "42275aacbeda1522cd41580f875c3c452daf5174b17ba062bf0ab71a568c123f",
      "address": "sm1qxe4jwhkekgnxkezu7xutu5gqnnpmyc8ppq98me",
      "type": "control_address"
    }
  ],
  "ttl": 0,
  "time_range": 0
}

對應(yīng)源代碼的請求對象如下:

// BuildRequest is main struct when building transactions
type BuildRequest struct {
    Tx        *types.TxData            `json:"base_transaction"`
    Actions   []map[string]interface{} `json:"actions"`
    TTL       json.Duration            `json:"ttl"`
    TimeRange uint64                   `json:"time_range"`
}

結(jié)構(gòu)字段說明如下:

Tx 交易的TxData部分,該字段為預(yù)留字段,為空即可

TTL 構(gòu)建交易的生存時間(單位為毫秒),意味著在該時間范圍內(nèi),已經(jīng)緩存的utxo不能用于再一次build交易,除非剩余的utxo足以構(gòu)建一筆新的交易,否則會報錯。當ttl為0時會被默認設(shè)置為600s,即5分鐘

TimeRange 時間戳,意味著該交易將在該時間戳(區(qū)塊高度)之后不會被提交上鏈,為了防止交易在網(wǎng)絡(luò)中傳輸延遲而等待太久時間,如果交易沒有在特定的時間范圍內(nèi)被打包,該交易便會自動失效

Actions 交易的actions結(jié)構(gòu),所有的交易都是由action構(gòu)成的,map類型的interface{}保證了action類型的可擴展性。其中action中必須包含type字段,用于區(qū)分不同的action類型,action主要包含inputoutput兩種類型,其詳細介紹如下:

input action 類型:

issue 發(fā)行資產(chǎn)

spend_account 以賬戶的模式花費utxo

spend_account_unspent_output 直接花費指定的utxo

output action 類型:

control_address 接收方式為地址模式

control_program 接收方式為(program)合約模式

retire 銷毀資產(chǎn)

注意事項

一個交易必須至少包含一個input和output(coinbase交易除外,因為coinbase交易是由系統(tǒng)產(chǎn)生,故不在此加以描述),否則交易將會報錯。

除了BTM資產(chǎn)(所有交易都是以BTM資產(chǎn)作為手續(xù)費)之外,其他資產(chǎn)在構(gòu)建input和output時,所有輸入和輸出的資產(chǎn)總和必須相等,否則交易會報出輸入輸出不平衡的錯誤信息。

交易的手續(xù)費: 所有inputs的BTM資產(chǎn)數(shù)量 - 所有outputs的BTM資產(chǎn)數(shù)量

交易中的資產(chǎn)amount都是neu為單位的,BTM的單位換算如下:1 BTM = 1000 mBTM = 100000000 neu


action簡介

下面對構(gòu)建交易時用到的各種action類型進行詳細說明:

issue

issueAction結(jié)構(gòu)體源代碼如下:

type issueAction struct {
    assets *Registry
    bc.AssetAmount
}

type AssetAmount struct {
    AssetId *AssetID `protobuf:"bytes,1,opt,name=asset_id,json=assetId" json:"asset_id,omitempty"`
    Amount  uint64   `protobuf:"varint,2,opt,name=amount" json:"amount,omitempty"`
}

結(jié)構(gòu)字段說明如下:

assets 主要用于資產(chǎn)的管理,無需用戶設(shè)置參數(shù)

AssetAmount 表示用戶需要發(fā)行的資產(chǎn)ID和對應(yīng)的資產(chǎn)數(shù)目,這里的AssetID需要通過create-asset創(chuàng)建,并且這里不能使用BTM的資產(chǎn)ID

issueActionjson格式為:

{
  "amount": 100000000,
  "asset_id": "3152a15da72be51b330e1c0f8e1c0db669269809da4f16443ff266e07cc43680",
  "type": "issue"
}

例如發(fā)行一筆資產(chǎn)的交易示例如下:
(該交易表示發(fā)行數(shù)量為900000000assetID42275aacbeda1522cd41580f875c3c452daf5174b17ba062bf0ab71a568c123f的資產(chǎn)到接收地址sm1qxe4jwhkekgnxkezu7xutu5gqnnpmyc8ppq98me中, 其中手續(xù)費為20000000neu的BTM資產(chǎn))

{
  "base_transaction": null,
  "actions": [
    {
      "account_id": "0ER7MEFGG0A02",
      "amount": 20000000,
      "asset_id": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
      "type": "spend_account"
    },
    {
      "amount": 900000000,
      "asset_id": "42275aacbeda1522cd41580f875c3c452daf5174b17ba062bf0ab71a568c123f",
      "type": "issue"
    },
    {
      "amount": 900000000,
      "asset_id": "42275aacbeda1522cd41580f875c3c452daf5174b17ba062bf0ab71a568c123f",
      "address": "sm1qxe4jwhkekgnxkezu7xutu5gqnnpmyc8ppq98me",
      "type": "control_address"
    }
  ],
  "ttl": 0,
  "time_range": 0
}

spend_account

spendAction結(jié)構(gòu)體源代碼如下:

type spendAction struct {
    accounts *Manager
    bc.AssetAmount
    AccountID   string  `json:"account_id"`
    ClientToken *string `json:"client_token"`
}

type AssetAmount struct {
    AssetId *AssetID `protobuf:"bytes,1,opt,name=asset_id,json=assetId" json:"asset_id,omitempty"`
    Amount  uint64   `protobuf:"varint,2,opt,name=amount" json:"amount,omitempty"`
}

結(jié)構(gòu)字段說明如下:

accounts 主要用于賬戶的管理,無需用戶設(shè)置參數(shù)

AccountID 表示需要花費資產(chǎn)的賬戶ID

AssetAmount 表示花費的資產(chǎn)ID和對應(yīng)的資產(chǎn)數(shù)目

ClientToken 表示Reserve用戶UTXO的限制條件,目前不填或為空即可

spendActionjson格式為:

{
  "account_id": "0BF63M2U00A04",
  "amount": 2000000000,
  "asset_id": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
  "type": "spend_account"
}

例如轉(zhuǎn)賬一筆資產(chǎn)的交易示例如下:
(該交易表示通過賬戶的方式轉(zhuǎn)賬100000000neu的BTM資產(chǎn)到地址sm1qxe4jwhkekgnxkezu7xutu5gqnnpmyc8ppq98me中, 其中手續(xù)費20000000neu = 輸入BTM資產(chǎn)數(shù)量 - 輸出BTM資產(chǎn)數(shù)量)

{
  "base_transaction": null,
  "actions": [
    {
      "account_id": "0ER7MEFGG0A02",
      "amount": 120000000,
      "asset_id": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
      "type": "spend_account"
    },
    {
      "amount": 100000000,
      "asset_id": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
      "address": "sm1qxe4jwhkekgnxkezu7xutu5gqnnpmyc8ppq98me",
      "type": "control_address"
    }
  ],
  "ttl": 0,
  "time_range": 0
}

spend_account_unspent_output

spendUTXOAction結(jié)構(gòu)體源代碼如下:

type spendUTXOAction struct {
    accounts *Manager
    OutputID *bc.Hash `json:"output_id"`
    ClientToken *string `json:"client_token"`
}

結(jié)構(gòu)字段說明如下:

accounts 主要用于賬戶的管理,無需用戶設(shè)置參數(shù)

OutputID 表示需要花費的UTXO的ID,可以根據(jù)list-unspent-outputs查詢可用的UTXO,其中OutputID對應(yīng)該API返回結(jié)果的id字段

ClientToken 表示Reserve用戶UTXO的限制條件,目前不填或為空即可

spendUTXOActionjson格式為:

{
  "type": "spend_account_unspent_output",
  "output_id": "58f29f0f85f7bd2a91088bcbe536dee41cd0642dfb1480d3a88589bdbfd642d9"
}

例如通過花費UTXO的方式轉(zhuǎn)賬一筆資產(chǎn)的交易示例如下:
(該交易表示通過直接花費UTXO的方式轉(zhuǎn)賬100000000neu的BTM資產(chǎn)到地址sm1qxe4jwhkekgnxkezu7xutu5gqnnpmyc8ppq98me中, 其中手續(xù)費 = 輸入BTM資產(chǎn)的UTXO值 - 輸出BTM資產(chǎn)數(shù)量)

{
  "base_transaction": null,
  "actions": [
    {
      "output_id": "58f29f0f85f7bd2a91088bcbe536dee41cd0642dfb1480d3a88589bdbfd642d9",
      "type": "spend_account_unspent_output"
    },
    {
      "amount": 100000000,
      "asset_id": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
      "address": "sm1qxe4jwhkekgnxkezu7xutu5gqnnpmyc8ppq98me",
      "type": "control_address"
    }
  ],
  "ttl": 0,
  "time_range": 0
}

control_address

controlAddressAction結(jié)構(gòu)體源代碼如下:

type controlAddressAction struct {
    bc.AssetAmount
    Address string `json:"address"`
}

type AssetAmount struct {
    AssetId *AssetID `protobuf:"bytes,1,opt,name=asset_id,json=assetId" json:"asset_id,omitempty"`
    Amount  uint64   `protobuf:"varint,2,opt,name=amount" json:"amount,omitempty"`
}

結(jié)構(gòu)字段說明如下:

Address 表示接收資產(chǎn)的地址,可以根據(jù) create-account-receiver API接口創(chuàng)建地址

AssetAmount 表示接收的資產(chǎn)ID和對應(yīng)的資產(chǎn)數(shù)目

controlAddressActionjson格式為:

{
  "amount": 100000000,
  "asset_id": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
  "address": "bm1q50u3z8empm5ke0g3ngl2t3sqtr6sd7cepd3z68",
  "type": "control_address"
}

例如轉(zhuǎn)賬一筆資產(chǎn)的交易示例如下:
(該交易表示通過賬戶的方式轉(zhuǎn)賬100000000neu的BTM資產(chǎn)到地址sm1qxe4jwhkekgnxkezu7xutu5gqnnpmyc8ppq98me中, 其中control_address類型表示以地址作為接收方式)

{
  "base_transaction": null,
  "actions": [
    {
      "account_id": "0ER7MEFGG0A02",
      "amount": 120000000,
      "asset_id": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
      "type": "spend_account"
    },
    {
      "amount": 100000000,
      "asset_id": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
      "address": "sm1qxe4jwhkekgnxkezu7xutu5gqnnpmyc8ppq98me",
      "type": "control_address"
    }
  ],
  "ttl": 0,
  "time_range": 0
}

control_program

controlProgramAction結(jié)構(gòu)體源代碼如下:

type controlProgramAction struct {
    bc.AssetAmount
    Program json.HexBytes `json:"control_program"`
}

type AssetAmount struct {
    AssetId *AssetID `protobuf:"bytes,1,opt,name=asset_id,json=assetId" json:"asset_id,omitempty"`
    Amount  uint64   `protobuf:"varint,2,opt,name=amount" json:"amount,omitempty"`
}

結(jié)構(gòu)字段說明如下:

Program 表示接收資產(chǎn)的合約腳本,可以根據(jù) create-account-receiver API接口創(chuàng)建接收program(返回結(jié)果的 programaddress 是一一對應(yīng)的)

AssetAmount 表示接收的資產(chǎn)ID和對應(yīng)的資產(chǎn)數(shù)目

controlProgramActionjson格式為:

{
  "amount": 100000000,
  "asset_id": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
  "control_program":"0014a3f9111f3b0ee96cbd119a3ea5c60058f506fb19",
  "type": "control_program"
}

例如轉(zhuǎn)賬一筆資產(chǎn)的交易示例如下:
(該交易表示通過賬戶的方式轉(zhuǎn)賬100000000neu的BTM資產(chǎn)到接收program(跟address是一一對應(yīng)的)0014a3f9111f3b0ee96cbd119a3ea5c60058f506fb19中, 其中control_program類型表示以program作為接收方式)

{
  "base_transaction": null,
  "actions": [
    {
      "account_id": "0ER7MEFGG0A02",
      "amount": 120000000,
      "asset_id": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
      "type": "spend_account"
    },
    {
      "amount": 100000000,
      "asset_id": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
      "control_program": "0014a3f9111f3b0ee96cbd119a3ea5c60058f506fb19",
      "type": "control_program"
    }
  ],
  "ttl": 0,
  "time_range": 0
}

retire

retireAction結(jié)構(gòu)體源代碼如下:

type retireAction struct {
    bc.AssetAmount
}

type AssetAmount struct {
    AssetId *AssetID `protobuf:"bytes,1,opt,name=asset_id,json=assetId" json:"asset_id,omitempty"`
    Amount  uint64   `protobuf:"varint,2,opt,name=amount" json:"amount,omitempty"`
}

結(jié)構(gòu)字段說明如下:

AssetAmount 表示銷毀的資產(chǎn)ID和對應(yīng)的資產(chǎn)數(shù)目

retireActionjson格式為:

{
  "amount": 900000000,
  "asset_id": "3152a15da72be51b330e1c0f8e1c0db669269809da4f16443ff266e07cc43680",
  "type": "retire"
}

例如銷毀一筆資產(chǎn)的交易示例如下:
(該交易表示通過賬戶的方式將100000000neu的BTM資產(chǎn)銷毀, retire表示銷毀指定數(shù)量的資產(chǎn))

{
  "base_transaction": null,
  "actions": [
    {
      "account_id": "0ER7MEFGG0A02",
      "amount": 120000000,
      "asset_id": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
      "type": "spend_account"
    },
    {
      "amount": 100000000,
      "asset_id": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
      "type": "retire"
    }
  ],
  "ttl": 0,
  "time_range": 0
}

build-transaction的輸入構(gòu)造完成之后,便可以通過http的調(diào)用方式進行發(fā)送交易,構(gòu)建交易請求成功之后返回的json結(jié)果如下:

{
  "allow_additional_actions": false,
  "raw_transaction": "070100020161015f1190c60818b4aff485c865113c802942f29ce09088cae1b117fc4c8db2292212ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8099c4d599010001160014a86c83ee12e6d790fb388345cc2e2b87056a077301000161015fb018097c4040c8dd86d95611a13c24f90d4c9d9d06b25f5c9ed0556ac8abd73442275aacbeda1522cd41580f875c3c452daf5174b17ba062bf0ab71a568c123f80a094a58d1d0101160014068840e56af74038571f223b1c99f1b60caaf456010003013effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff80bfffcb9901011600140b946646626c55a52a325c8bb48de792284d9b7200013e42275aacbeda1522cd41580f875c3c452daf5174b17ba062bf0ab71a568c123f9d9f94a58d1d01160014c8b4391bab4923a83b955170d24ee4ca5b6ec3fb00013942275aacbeda1522cd41580f875c3c452daf5174b17ba062bf0ab71a568c123f6301160014366b275ed9b2266b645cf1b8be51009cc3b260e100",
  "signing_instructions": [
    {
      "position": 0,
      "witness_components": [
        {
          "keys": [
            {
              "derivation_path": [
                "010100000000000000",
                "0100000000000000"
              ],
              "xpub": "de0db655c091b2838ccb6cddb675779b0a9a4204b122e61699b339867dd10eb0dbdc926882ff6dd75c099c181c60d63eab0033a4b0a4d0a8c78079e39d7ad1d8"
            }
          ],
          "quorum": 1,
          "signatures": null,
          "type": "raw_tx_signature"
        },
        {
          "type": "data",
          "value": "d174db6506e35f2decb5be148c2984bfd0f6c67f043365bf642d1af387c04fd5"
        }
      ]
    },
    {
      "position": 1,
      "witness_components": [
        {
          "keys": [
            {
              "derivation_path": [
                "010100000000000000",
                "0800000000000000"
              ],
              "xpub": "de0db655c091b2838ccb6cddb675779b0a9a4204b122e61699b339867dd10eb0dbdc926882ff6dd75c099c181c60d63eab0033a4b0a4d0a8c78079e39d7ad1d8"
            }
          ],
          "quorum": 1,
          "signatures": null,
          "type": "raw_tx_signature"
        },
        {
          "type": "data",
          "value": "05cdbcc705f07ad87521835bbba226ad7b430cc24e5e3f008edbe61540535419"
        }
      ]
    }
  ]
}

對應(yīng)響應(yīng)對象的源代碼如下:

// Template represents a partially- or fully-signed transaction.
type Template struct {
    Transaction         *types.Tx             `json:"raw_transaction"`
    SigningInstructions []*SigningInstruction `json:"signing_instructions"`

    // AllowAdditional affects whether Sign commits to the tx sighash or
    // to individual details of the tx so far. When true, signatures
    // commit to tx details, and new details may be added but existing
    // ones cannot be changed. When false, signatures commit to the tx
    // as a whole, and any change to the tx invalidates the signature.
    AllowAdditional bool `json:"allow_additional_actions"`
}

結(jié)構(gòu)字段說明如下:

Transaction 交易相關(guān)信息,該字段包含TxDatabc.Tx兩個部分:

TxData 表示給用戶展示的交易數(shù)據(jù)部分,該部分對用戶可見

Version 交易版本

SerializedSize 交易序列化之后的size

TimeRange 交易提交上鏈的最大時間戳(區(qū)塊高度)(主鏈區(qū)塊高度到達該時間戳(區(qū)塊高度)之后,如果交易沒有被提交上鏈,該交易便會失效)

Inputs 交易輸入

Outputs 交易輸出

bc.Tx 表示系統(tǒng)中處理交易用到的轉(zhuǎn)換結(jié)構(gòu),該部分對用戶不可見,故不做詳細描述

SigningInstructions 交易的簽名信息

Positioninput action簽名的位置

WitnessComponentsinput action簽名需要的數(shù)據(jù)信息,其中build交易的signaturesnull,表示沒有簽名; 如果交易簽名成功,則該字段會存在簽名信息。該字段是一個interface接口,主要包含3種不同的類型:

SignatureWitness 對交易模板Template中交易input action位置的合約program進行哈希,然后對hash值進行簽名

signatures (數(shù)組類型)交易的簽名,sign-transaction執(zhí)行完成之后才會有值存在

keys (數(shù)組類型)包含主公鑰xpub和派生路徑derivation_path,通過它們可以在簽名階段找到對應(yīng)的派生私鑰child_xprv,然后使用派生私鑰進行簽名

quorum 賬戶key 的個數(shù),必須和上面的keys的長度相等。如果quorum 等于1,則表示單簽賬戶,否則為多簽賬戶

program 簽名的數(shù)據(jù)部分,program的hash值作為簽名數(shù)據(jù)。如果program為空,則會根據(jù)當前交易ID和對應(yīng)action位置的InputID兩部分生成一個hash,然后把它們作為指令數(shù)據(jù)自動構(gòu)造一個program

RawTxSigWitness 對交易模板Template的交易ID和對應(yīng)input action位置的InputID(該字段位于bc.Tx中)進行哈希,然后對hash值進行簽名

signatures (數(shù)組類型)交易的簽名,sign-transaction執(zhí)行完成之后才會有值存在

keys (數(shù)組類型)包含主公鑰xpub和派生路徑derivation_path,通過它們可以在簽名階段找到對應(yīng)的派生私鑰child_xprv,然后使用派生私鑰進行簽名

quorum 賬戶key的個數(shù),必須和上面的keys 的長度相等。如果quorum 等于1,則表示單簽賬戶,否則為多簽賬戶

DataWitness 該類型無需簽名,驗證合約program的附加數(shù)據(jù)

AllowAdditional 是否允許交易的附加數(shù)據(jù),如果為true,則交易的附加數(shù)據(jù)會添加到交易中,但是不會影響交易的執(zhí)行的program腳本,對簽名結(jié)果不會造成影響; 如果為false,則整個交易作為一個整體進行簽名,任何數(shù)據(jù)的改變將影響整個交易的簽名


估算手續(xù)費

估算手續(xù)費接口estimate-transaction-gas是對build-transaction的結(jié)果進行手續(xù)費的預(yù)估,估算的結(jié)果需要重新加到build-transaction的結(jié)果中,然后對交易進行簽名和提交。其主要流程如下:

  build - estimate - build - sign - submit

估算手續(xù)費的輸入請求json格式如下:

{
  "transaction_template": {
    "allow_additional_actions": false,
    "raw_transaction": "070100020161015f1190c60818b4aff485c865113c802942f29ce09088cae1b117fc4c8db2292212ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8099c4d599010001160014a86c83ee12e6d790fb388345cc2e2b87056a077301000161015fb018097c4040c8dd86d95611a13c24f90d4c9d9d06b25f5c9ed0556ac8abd73442275aacbeda1522cd41580f875c3c452daf5174b17ba062bf0ab71a568c123f80a094a58d1d0101160014068840e56af74038571f223b1c99f1b60caaf456010003013effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff80bfffcb9901011600140b946646626c55a52a325c8bb48de792284d9b7200013e42275aacbeda1522cd41580f875c3c452daf5174b17ba062bf0ab71a568c123f9d9f94a58d1d01160014c8b4391bab4923a83b955170d24ee4ca5b6ec3fb00013942275aacbeda1522cd41580f875c3c452daf5174b17ba062bf0ab71a568c123f6301160014366b275ed9b2266b645cf1b8be51009cc3b260e100",
    "signing_instructions": [
      {
        "position": 0,
        "witness_components": [
          {
            "keys": [
              {
                "derivation_path": [
                  "010100000000000000",
                  "0100000000000000"
                ],
                "xpub": "de0db655c091b2838ccb6cddb675779b0a9a4204b122e61699b339867dd10eb0dbdc926882ff6dd75c099c181c60d63eab0033a4b0a4d0a8c78079e39d7ad1d8"
              }
            ],
            "quorum": 1,
            "signatures": null,
            "type": "raw_tx_signature"
          },
          {
            "type": "data",
            "value": "d174db6506e35f2decb5be148c2984bfd0f6c67f043365bf642d1af387c04fd5"
          }
        ]
      },
      {
        "position": 1,
        "witness_components": [
          {
            "keys": [
              {
                "derivation_path": [
                  "010100000000000000",
                  "0800000000000000"
                ],
                "xpub": "de0db655c091b2838ccb6cddb675779b0a9a4204b122e61699b339867dd10eb0dbdc926882ff6dd75c099c181c60d63eab0033a4b0a4d0a8c78079e39d7ad1d8"
              }
            ],
            "quorum": 1,
            "signatures": null,
            "type": "raw_tx_signature"
          },
          {
            "type": "data",
            "value": "05cdbcc705f07ad87521835bbba226ad7b430cc24e5e3f008edbe61540535419"
          }
        ]
      }
    ]
  }
}

對應(yīng)響應(yīng)對象的源代碼如下:

type request struct{
    TxTemplate txbuilder.Template `json:"transaction_template"`
}

// Template represents a partially- or fully-signed transaction.
type Template struct {
    Transaction         *types.Tx             `json:"raw_transaction"`
    SigningInstructions []*SigningInstruction `json:"signing_instructions"`

    // AllowAdditional affects whether Sign commits to the tx sighash or
    // to individual details of the tx so far. When true, signatures
    // commit to tx details, and new details may be added but existing
    // ones cannot be changed. When false, signatures commit to the tx
    // as a whole, and any change to the tx invalidates the signature.
    AllowAdditional bool `json:"allow_additional_actions"`
}

其中TxTemplate相關(guān)字段的說明見build-transaction的結(jié)果描述

調(diào)用estimate-transaction-gas接口成功之后返回的json結(jié)果如下:

{
  "total_neu": 5000000,
  "storage_neu": 3840000,
  "vm_neu": 1419000
}

對應(yīng)響應(yīng)對象的源代碼如下:

// EstimateTxGasResp estimate transaction consumed gas
type EstimateTxGasResp struct {
    TotalNeu   int64 `json:"total_neu"`
    StorageNeu int64 `json:"storage_neu"`
    VMNeu      int64 `json:"vm_neu"`
}

結(jié)構(gòu)字段說明如下:

TotalNeu 預(yù)估的總手續(xù)費(單位為neu),該值直接加到build-transaction的BTM資產(chǎn)輸入action中即可

StorageNeu 存儲交易的手續(xù)費

VMNeu 運行虛擬機的手續(xù)費


2、簽名交易

API接口 sign-transaction,代碼api/hsm.go#L53

簽名交易的輸入請求json格式如下:

{
  "password": "123456",
  "transaction": {
    "allow_additional_actions": false,
    "raw_transaction": "070100020161015f1190c60818b4aff485c865113c802942f29ce09088cae1b117fc4c8db2292212ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8099c4d599010001160014a86c83ee12e6d790fb388345cc2e2b87056a077301000161015fb018097c4040c8dd86d95611a13c24f90d4c9d9d06b25f5c9ed0556ac8abd73442275aacbeda1522cd41580f875c3c452daf5174b17ba062bf0ab71a568c123f80a094a58d1d0101160014068840e56af74038571f223b1c99f1b60caaf456010003013effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff80bfffcb9901011600140b946646626c55a52a325c8bb48de792284d9b7200013e42275aacbeda1522cd41580f875c3c452daf5174b17ba062bf0ab71a568c123f9d9f94a58d1d01160014c8b4391bab4923a83b955170d24ee4ca5b6ec3fb00013942275aacbeda1522cd41580f875c3c452daf5174b17ba062bf0ab71a568c123f6301160014366b275ed9b2266b645cf1b8be51009cc3b260e100",
    "signing_instructions": [
      {
        "position": 0,
        "witness_components": [
          {
            "keys": [
              {
                "derivation_path": [
                  "010100000000000000",
                  "0100000000000000"
                ],
                "xpub": "de0db655c091b2838ccb6cddb675779b0a9a4204b122e61699b339867dd10eb0dbdc926882ff6dd75c099c181c60d63eab0033a4b0a4d0a8c78079e39d7ad1d8"
              }
            ],
            "quorum": 1,
            "signatures": null,
            "type": "raw_tx_signature"
          },
          {
            "type": "data",
            "value": "d174db6506e35f2decb5be148c2984bfd0f6c67f043365bf642d1af387c04fd5"
          }
        ]
      },
      {
        "position": 1,
        "witness_components": [
          {
            "keys": [
              {
                "derivation_path": [
                  "010100000000000000",
                  "0800000000000000"
                ],
                "xpub": "de0db655c091b2838ccb6cddb675779b0a9a4204b122e61699b339867dd10eb0dbdc926882ff6dd75c099c181c60d63eab0033a4b0a4d0a8c78079e39d7ad1d8"
              }
            ],
            "quorum": 1,
            "signatures": null,
            "type": "raw_tx_signature"
          },
          {
            "type": "data",
            "value": "05cdbcc705f07ad87521835bbba226ad7b430cc24e5e3f008edbe61540535419"
          }
        ]
      }
    ]
  }
}

對應(yīng)請求對象的源代碼如下:

type SignRequest struct {    //function pseudohsmSignTemplates request
    Password string             `json:"password"`
    Txs      txbuilder.Template `json:"transaction"`
}

結(jié)構(gòu)字段說明如下:

Password 簽名的密碼,根據(jù)密碼可以從節(jié)點服務(wù)器上解析出用戶的私鑰,然后用私鑰對交易進行簽名

Txs 交易模板,build-transaction的返回結(jié)果,結(jié)構(gòu)類型為 txbuilder.Template,相關(guān)字段的說明見build-transaction的結(jié)果描述

簽名交易sign-transaction請求成功之后返回的json結(jié)果如下:

{
  "sign_complete": true,
  "transaction": {
    "allow_additional_actions": false,
    "raw_transaction": "070100020161015f1190c60818b4aff485c865113c802942f29ce09088cae1b117fc4c8db2292212ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8099c4d599010001160014a86c83ee12e6d790fb388345cc2e2b87056a0773630240273d5fc4fb06909fbc2968ea91c411fd20f690c88e74284ce2732052400129948538562fe432afd6cf17e590e8645b80edf80b9d9581d0a980d5f9f859e3880620d174db6506e35f2decb5be148c2984bfd0f6c67f043365bf642d1af387c04fd50161015fb018097c4040c8dd86d95611a13c24f90d4c9d9d06b25f5c9ed0556ac8abd73442275aacbeda1522cd41580f875c3c452daf5174b17ba062bf0ab71a568c123f80a094a58d1d0101160014068840e56af74038571f223b1c99f1b60caaf4566302400cf0beefceaf9fbf1efadedeff7aee5b38ee7a25a20d78b630b01613bc2f8c9230555a6e09aaa11a82ba68c0fc9e98a47c852dfe3de851d93f9b2b7ce256f90d2005cdbcc705f07ad87521835bbba226ad7b430cc24e5e3f008edbe6154053541903013effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff80bfffcb9901011600140b946646626c55a52a325c8bb48de792284d9b7200013e42275aacbeda1522cd41580f875c3c452daf5174b17ba062bf0ab71a568c123f9d9f94a58d1d01160014c8b4391bab4923a83b955170d24ee4ca5b6ec3fb00013942275aacbeda1522cd41580f875c3c452daf5174b17ba062bf0ab71a568c123f6301160014366b275ed9b2266b645cf1b8be51009cc3b260e100",
    "signing_instructions": [
      {
        "position": 0,
        "witness_components": [
          {
            "keys": [
              {
                "derivation_path": [
                  "010100000000000000",
                  "0100000000000000"
                ],
                "xpub": "de0db655c091b2838ccb6cddb675779b0a9a4204b122e61699b339867dd10eb0dbdc926882ff6dd75c099c181c60d63eab0033a4b0a4d0a8c78079e39d7ad1d8"
              }
            ],
            "quorum": 1,
            "signatures": [
              "273d5fc4fb06909fbc2968ea91c411fd20f690c88e74284ce2732052400129948538562fe432afd6cf17e590e8645b80edf80b9d9581d0a980d5f9f859e38806"
            ],
            "type": "raw_tx_signature"
          },
          {
            "type": "data",
            "value": "d174db6506e35f2decb5be148c2984bfd0f6c67f043365bf642d1af387c04fd5"
          }
        ]
      },
      {
        "position": 1,
        "witness_components": [
          {
            "keys": [
              {
                "derivation_path": [
                  "010100000000000000",
                  "0800000000000000"
                ],
                "xpub": "de0db655c091b2838ccb6cddb675779b0a9a4204b122e61699b339867dd10eb0dbdc926882ff6dd75c099c181c60d63eab0033a4b0a4d0a8c78079e39d7ad1d8"
              }
            ],
            "quorum": 1,
            "signatures": [
              "0cf0beefceaf9fbf1efadedeff7aee5b38ee7a25a20d78b630b01613bc2f8c9230555a6e09aaa11a82ba68c0fc9e98a47c852dfe3de851d93f9b2b7ce256f90d"
            ],
            "type": "raw_tx_signature"
          },
          {
            "type": "data",
            "value": "05cdbcc705f07ad87521835bbba226ad7b430cc24e5e3f008edbe61540535419"
          }
        ]
      }
    ]
  }
}

對應(yīng)響應(yīng)對象的源代碼如下:

type signResp struct {
    Tx           *txbuilder.Template `json:"transaction"`
    SignComplete bool                `json:"sign_complete"`
}

結(jié)構(gòu)字段說明如下:

Tx 簽名之后的交易模板txbuilder.Template,如果簽名成功則signatures會由null變成簽名的值,而raw_transaction的長度會變長,是因為bc.Tx部分添加了驗證簽名的參數(shù)信息

SignComplete 簽名是否完成標志,如果為true表示簽名完成,否則為false表示簽名未完成,單簽的話一般可能為簽名密碼錯誤; 而多簽的話一般為還需要其他簽名。簽名失敗只需將簽名的交易數(shù)據(jù)用正確的密碼重新簽名即可,無需再次build-transaction構(gòu)建交易


3、提交交易

API接口 submit-transaction,代碼api/transact.go#L135

提交交易的輸入請求json格式如下:

{
  "raw_transaction": "070100020161015f1190c60818b4aff485c865113c802942f29ce09088cae1b117fc4c8db2292212ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8099c4d599010001160014a86c83ee12e6d790fb388345cc2e2b87056a0773630240273d5fc4fb06909fbc2968ea91c411fd20f690c88e74284ce2732052400129948538562fe432afd6cf17e590e8645b80edf80b9d9581d0a980d5f9f859e3880620d174db6506e35f2decb5be148c2984bfd0f6c67f043365bf642d1af387c04fd50161015fb018097c4040c8dd86d95611a13c24f90d4c9d9d06b25f5c9ed0556ac8abd73442275aacbeda1522cd41580f875c3c452daf5174b17ba062bf0ab71a568c123f80a094a58d1d0101160014068840e56af74038571f223b1c99f1b60caaf4566302400cf0beefceaf9fbf1efadedeff7aee5b38ee7a25a20d78b630b01613bc2f8c9230555a6e09aaa11a82ba68c0fc9e98a47c852dfe3de851d93f9b2b7ce256f90d2005cdbcc705f07ad87521835bbba226ad7b430cc24e5e3f008edbe6154053541903013effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff80bfffcb9901011600140b946646626c55a52a325c8bb48de792284d9b7200013e42275aacbeda1522cd41580f875c3c452daf5174b17ba062bf0ab71a568c123f9d9f94a58d1d01160014c8b4391bab4923a83b955170d24ee4ca5b6ec3fb00013942275aacbeda1522cd41580f875c3c452daf5174b17ba062bf0ab71a568c123f6301160014366b275ed9b2266b645cf1b8be51009cc3b260e100"
}

對應(yīng)源代碼的請求對象如下:

type SubmitRequest struct {    //function submit request
    Tx types.Tx `json:"raw_transaction"`
}

結(jié)構(gòu)字段說明如下:

Tx 簽名完成之后的交易信息。這里需要注意該字段中的raw_transaction不是簽名交易sign-transaction的全部返回結(jié)果,而是簽名交易返回結(jié)果中transaction中的raw_transaction字段。

submit-transaction請求成功之后返回的json結(jié)果如下:

{
  "tx_id": "2c0624a7d251c29d4d1ad14297c69919214e78d995affd57e73fbf84ece361cd"
}

對應(yīng)源代碼的響應(yīng)對象如下:

type submitTxResp struct {
    TxID *bc.Hash `json:"tx_id"`
}

結(jié)構(gòu)字段說明如下:

TxID 交易ID,當交易被提交到交易池之后會顯示該信息,否則表示交易失敗

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

轉(zhuǎn)載請注明本文地址:http://specialneedsforspecialkids.com/yun/24219.html

相關(guān)文章

  • Bytom設(shè)計結(jié)構(gòu)解讀

    摘要:一引文設(shè)計數(shù)據(jù)結(jié)構(gòu),組合了許多技術(shù)點,如,,,,,,等。采用樹,其中的數(shù)據(jù)可快速證明,可以快速證明每一份狀態(tài)機是否一致。四是在狀態(tài)機的轉(zhuǎn)化過程被啟動運行,也就是這一步驟。是指發(fā)布該資產(chǎn)時需要執(zhí)行的程序。的邏輯結(jié)構(gòu)則是用二叉樹來管理。 一、引文 設(shè)計Bytom 數(shù)據(jù)結(jié)構(gòu),組合了許多技術(shù)點,如 patricia tree,utxo, bvm, account model,protobuf,...

    xuexiangjys 評論0 收藏0
  • 調(diào)用Bytom Chrome插件錢包開發(fā)Dapp

    摘要:流程總結(jié)就是下載安裝插件錢包,如果自己的不需要跳過這一步。然后將編譯后的合約參數(shù)配置在的配置文件,如下圖全紅部分是測試網(wǎng)合約配置參數(shù)調(diào)用插件錢包。開發(fā)出優(yōu)秀的應(yīng)用。 安裝使用插件錢包 1. 打開Google瀏覽器的應(yīng)用商店,搜索Bystore showImg(https://segmentfault.com/img/bVbq0Ol?w=2554&h=1312); 下載鏈接:http:/...

    Mike617 評論0 收藏0
  • Bytom交易說明(UTXO用戶自己管理模式

    摘要:比原項目倉庫地址地址該部分主要針對用戶自己管理私鑰和地址,并通過來構(gòu)建和發(fā)送交易。其中創(chuàng)建單簽地址參考代碼進行相應(yīng)改造為創(chuàng)建多簽地址參考代碼進行相應(yīng)改造為找到可花費的找到可花費的,其實就是找到接收地址或接收是你自己的。 比原項目倉庫: Github地址:https://github.com/Bytom/bytom Gitee地址:https://gitee.com/BytomBlock...

    RyanQ 評論0 收藏0
  • Bytom猜謎合約使用指南

    摘要:結(jié)語當前猜謎合約提供了體驗版本,有興趣的朋友可以做一個口令紅包,簡化一下用戶操作和體驗。 準備工作: 1、安裝全節(jié)點錢包V1.0.5以上并同步完成; 2、已經(jīng)發(fā)行一種資產(chǎn),發(fā)行資產(chǎn)的方法具體見文章《如何在Bytom上發(fā)布資產(chǎn)?》 3、準備好一些BTM作為手續(xù)費; 設(shè)置謎語(鎖定資產(chǎn)): 1、打開錢包,點擊Equity合約按鈕; showImg(https://segmentfault....

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

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

    cocopeak 評論0 收藏0

發(fā)表評論

0條評論

最新活動
閱讀需要支付1元查看
<