Bytom Transaction Introduction
Bytom project:
Github:https://github.com/Bytom/bytom
Gitee:https://gitee.com/BytomBlockchain/bytom
This part is for users who send transactions in Bytom own account mode.
1、Build transaction
API interface build-transaction,codesapi/transact.go#L120
Take transactions of standard non-BTM asset for example,BTM asset which ID are consisted of F is only as gas in this transaction.This transaction means that spends 99 specified asset to specified address,its input request’s json of built transaction are as following:
{
"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
}The source code of the corresponding response object is as follows:
// 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"`
}structure fields:
TxTxDataof transaction,reserved fields,nullTTLlifetime(ms) of constructed transaction,it means utxo which is already cached cannot be used for another build transaction within that timeframe,unless the left utxo are enough to build a new transaction or it will prompt error.Whenttlis 0,its default is 600s(5minutes)TimeRangeTimestamp means the transaction wont be on chain after this blockheight(timestamp).To avoid waiting too long when you transfer transaction due to transport delay , transaction will expire if it's not packaged in specified TimeRange.Actionsactionsstructure of transaction,all transactions are made up of action,maptype ofinterface{}ensure the scalability of action type.Action has to contain type fields to distinguish between different action types.actionmainly containsinputandoutput,its detailed introduction :input actiontype:- issue issue asset
- spend_account spend utxo in account mode
- spend_account_unspent_output spend specified utxo directly
output actiontype:- control_address receive in address mode
- control_program receive in (program) contract mode
- retire retire asset
Pay attention:
- One transaction must contain an input and a output or tThe asset sum of input a has to be equal with output when building input and output,otherwise transaction will show error message as the imbalance of input and output.
- Gas:BTM asset of all inputs reduce to asset of all outputs
- The asset amount in the transaction is all in units of neu, 1 BTM = 1000 mBTM = 100,000,000neu
action introduction
actiontypes when you build transaction:
issue
issueActionStructural source code:
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"`
}
construction fields:
assetsasset management,users dont need to set parametersAssetAmountssetID and corresponding asset amount,need to createAssetIDbycreate-asset,cant use the assetID ofBTM
jsonformat of issueAction:
{
"amount": 100000000,
"asset_id": "3152a15da72be51b330e1c0f8e1c0db669269809da4f16443ff266e07cc43680",
"type": "issue"
}an example of issue asset: (issue900000000whichassetIDis42275aacbeda1522cd41580f875c3c452daf5174b17ba062bf0ab71a568c123ftosm1qxe4jwhkekgnxkezu7xutu5gqnnpmyc8ppq98me, gas is20000000neu of BTM asset)
{
"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
spendActionStructural source code:
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"`
}
structure fields:
accountsaccount management.users dont need to set parametersAccountIDspend_accountAssetAmountAssetID and corresponding asset amountClientTokenReserved limits of users' UTXO,null
spendAction``jsonformat of spendAction:
{
"account_id": "0BF63M2U00A04",
"amount": 2000000000,
"asset_id": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
"type": "spend_account"
}transaction example is as following下: (transfer100000000neu Bytom asset to sm1qxe4jwhkekgnxkezu7xutu5gqnnpmyc8ppq98me, gas is20000000neu =input BTM asset - output BTM asset)
{
"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
spendUTXOActionStructural source code:
type spendUTXOAction struct {
accounts *Manager
OutputID *bc.Hash `json:"output_id"`
ClientToken *string `json:"client_token"`
}structure fields:
accountsaccount management.users dont need to set parametersOutputIDID of UTXO,query available UTXO bylist-unspent-outputs,OutputIDcorresponding toidfields of API return resultsClientTokenreserved limit of UTXO,null
jsonformat of spendUTXOAction:
{
"type": "spend_account_unspent_output",
"output_id": "58f29f0f85f7bd2a91088bcbe536dee41cd0642dfb1480d3a88589bdbfd642d9"
}transaction example by spendUTXO: (transfer100000000neu BTM asset to sm1qxe4jwhkekgnxkezu7xutu5gqnnpmyc8ppq98meby UTXO, gas = input UTXO of BTM asset - output BTM asset)
{
"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
controlAddressActionStructural source code:
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"`
}
Structure field:
Addressreceive address,can create address bycreate-account-receiverAPIinterfaceAssetAmountasset ID to receive and corresponding asset amount
jsonformat of controlAddressAction:
{
"amount": 100000000,
"asset_id": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
"address": "bm1q50u3z8empm5ke0g3ngl2t3sqtr6sd7cepd3z68",
"type": "control_address"
}Transaction example: (transfer100000000neuBTM address to sm1qxe4jwhkekgnxkezu7xutu5gqnnpmyc8ppq98mein account mode,control_addresstype use address to receive)
{
"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
controlProgramActionStructural source code:
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"`
}
Structure fields:
Programcontract script to receive asset,throughcreate-account-receiverAPIinterface build and receiveprogram(The return results ofprogramandaddressare one to one correspondence)AssetAmountAssetID to receive and corresponding asset amount
jsonformat of controlProgramAction:
{
"amount": 100000000,
"asset_id": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
"control_program":"0014a3f9111f3b0ee96cbd119a3ea5c60058f506fb19",
"type": "control_program"
}Transaction example: (transfer100000000neu BTM asset to program(one to one correspondence withaddress)0014a3f9111f3b0ee96cbd119a3ea5c60058f506fb19, control_programtype usesprogramto receive)
{
"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
retireActionstructural source code is as follow:
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"`
}
Structure field:
AssetAmountasset ID to receive and corresponding asset amount
jsonformat of retireAction:
{
"amount": 900000000,
"asset_id": "3152a15da72be51b330e1c0f8e1c0db669269809da4f16443ff266e07cc43680",
"type": "retire"
}Transaction example: (transfer100000000neu BTM retired asset in account mode, retireretire specified amount of asset)
{
"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
}Implement the input construction ofbuild-transaction,you can sent transaction by http calling,json result after the implement of constructing 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"
}
]
}
]
}The source code of the corresponding response object is as follows:
// 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"`
}
structure fields:
Transactionabout transaction informations includingTxDataandbc.Tx:TxDataRepresents the transaction data portion shown to the user, which is visible to the userVersiontransaction versionSerializedSizeSize after transaction serializationTimeRangemaximum timestamp(blockheight) of submitting transaction on chain(If the transaction havent been on chain when the blockheight reach the blockheight,the transaction will empire)Inputstransaction inputsOutputstransaction outputsbc.TxRepresents the transformation structure used to process transactions in the system. This part is not visible to users, so it is not described in detailSigningInstructionssignature information of transactionPositiontoinput actionLocation of signature- Data informations of
WitnessComponentstoinput actionsignature,signaturesof building transaction arenull,no signature; If transaction signed successfully,this field will exist signature information。This field is an interface,mainly include three different types: SignatureWitnesshash the contract program ofinput actionin the transactionTemplate,then sign for hash valuesignaturestransaction signature(arraytype),Aftersign-transactionperformed,there will be a valuekeys(arraytype)Including main publickeyxpuband derived pathderivation_path,they can find corresponding derived privatekeychild_xprvin signature period,then use derived key to signkeyamount ofquorumaccount ,the length has to be equal to thekeysabove。Ifquorumis equal to 1,it's single signature account,or it's multi-signature accountprogramData of signature,hash value ofprogramis as signature data 。Ifprogramis empty,, then a hash is generated based on the current transaction ID and the corresponding action location of InputID,then use them as command data to construct aprogramautomaticallyRawTxSigWitnesshash InoutID(this field is in bc.Tx) ofinput actionwith transaction ID ofTemplatesignaturestransaction signature(arraytype),Aftersign-transactionperformed,there will be a valuekeys(arraytype) includingxpuband derived pathderivation_path,you can find derived private key in their signature periodchild_xprv,then use derived private key to signkeyamount ofquorumaccount,the length has to be equal tokeysabove。Ifquorumis equal to 1,it represents single signature account,or its multi-signature accountDataWitnessthis type doesnt need signature,verify the additional data of contract programAllowAdditionalWhether to allow trading of additional data, if fortrue, then additional data will be added to the transaction, but will not affect the transaction executionprogramscript, will not affect the result of the signature; If forfalse, the entire transaction as a whole to sign, any data changes will affect the signatures of the transaction
Estimate gas
Estimated fees interface estimate ws-transaction - gas is for build -transaction fee estimate, the results of estimation results need to be added to the build -transaction results, and then to sign and submit for the deal. The main process is as follows:
build - estimate - build - sign - submit估算手续费的输入请求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"
}
]
}
]
}
}The source code for the corresponding response object is as follows:
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"`
}
you can see related fields including TxTemplate in the result description of build-transaction
Call estimate ws-transaction - gas interface after successful return json results are as follows:
{
"total_neu": 5000000,
"storage_neu": 3840000,
"vm_neu": 1419000
}The source code for the corresponding response object is as follows:
// EstimateTxGasResp estimate transaction consumed gas
type EstimateTxGasResp struct {
TotalNeu int64 `json:"total_neu"`
StorageNeu int64 `json:"storage_neu"`
VMNeu int64 `json:"vm_neu"`
}The structure field is explained as follows:
TotalNeuEstimated gas(neu),you can add the value to BTM asset of build-transaction by inputting actionStorageNeuGas for storing transactionVMNeuGas for BVM operation
2、signature transaction
APIinterface sign-transaction,codesapi/hsm.go#L53
The input request for the sign transaction is in json format below:
{
"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"
}
]
}
]
}
}The source code for the corresponding request object is as follows::
type SignRequest struct { //function pseudohsmSignTemplates request
Password string `json:"password"`
Txs txbuilder.Template `json:"transaction"`
}The structure field is explained as follows:
Passwordpassword of signature,analysis users' private key from node server according to password,then use private key to sign for transactionTxstransaction template,return result of build-transaction,its structure type istxbuilder.Template,you can see related fields in the description of build-transaction
sign-transactionThe json result returned after the successful request is as follows:
{
"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"
}
]
}
]
}
}The source code for the corresponding response object is as follows:
type signResp struct {
Tx *txbuilder.Template `json:"transaction"`
SignComplete bool `json:"sign_complete"`
}The structure field is explained below:
- Transaction Template
txbuilder. TemplateafterTxsignature , if the signature's successfulsignatureswill change from null to the value of the signature andraw_transactionlength will be longer, becauseBC. Txpart added to verify the parameters of the signature information To complete - SignCompletemark whether the signature is completed,if fortrue,signature completes,or it forfalse,for single signature,it's usual wrong password of signature while you need other signature for multi-signature.Use correct password to sign again when you fail to sign,no need tobuild-transactionagain
3、Submit transaction
APIinterface submit-transaction,codesapi/transact.go#L135
The input request to submit the transaction is in json format as follows:
{
"raw_transaction": "070100020161015f1190c60818b4aff485c865113c802942f29ce09088cae1b117fc4c8db2292212ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8099c4d599010001160014a86c83ee12e6d790fb388345cc2e2b87056a0773630240273d5fc4fb06909fbc2968ea91c411fd20f690c88e74284ce2732052400129948538562fe432afd6cf17e590e8645b80edf80b9d9581d0a980d5f9f859e3880620d174db6506e35f2decb5be148c2984bfd0f6c67f043365bf642d1af387c04fd50161015fb018097c4040c8dd86d95611a13c24f90d4c9d9d06b25f5c9ed0556ac8abd73442275aacbeda1522cd41580f875c3c452daf5174b17ba062bf0ab71a568c123f80a094a58d1d0101160014068840e56af74038571f223b1c99f1b60caaf4566302400cf0beefceaf9fbf1efadedeff7aee5b38ee7a25a20d78b630b01613bc2f8c9230555a6e09aaa11a82ba68c0fc9e98a47c852dfe3de851d93f9b2b7ce256f90d2005cdbcc705f07ad87521835bbba226ad7b430cc24e5e3f008edbe6154053541903013effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff80bfffcb9901011600140b946646626c55a52a325c8bb48de792284d9b7200013e42275aacbeda1522cd41580f875c3c452daf5174b17ba062bf0ab71a568c123f9d9f94a58d1d01160014c8b4391bab4923a83b955170d24ee4ca5b6ec3fb00013942275aacbeda1522cd41580f875c3c452daf5174b17ba062bf0ab71a568c123f6301160014366b275ed9b2266b645cf1b8be51009cc3b260e100"
}The request object for the source code is shown below:
type SubmitRequest struct { //function submit request
Tx types.Tx `json:"raw_transaction"`
}The structure field is explained below:
Txtransaction information after signature。raw_transactionin this field is not the who;e returen results ofsign-transaction,it'sraw_transactionfield in thetransactionof sign transaction's reture results
submit-transactionThe json result returned after the successful request is as follows:
{
"tx_id": "2c0624a7d251c29d4d1ad14297c69919214e78d995affd57e73fbf84ece361cd"
}The response object corresponding to the source code is as follows:
type submitTxResp struct {
TxID *bc.Hash `json:"tx_id"`
}The structure field is explained below:
TxIDTransaction ID, which displays the information when the transaction is submitted to the transaction pool, otherwise indicates that the transaction failed
