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:
Tx
TxData
of transaction,reserved fields,nullTTL
lifetime(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.Whenttl
is 0,its default is 600s(5minutes)TimeRange
Timestamp 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.Actions
actions
structure of transaction,all transactions are made up of action,map
type ofinterface{}
ensure the scalability of action type.Action has to contain type fields to distinguish between different action types.action
mainly containsinput
andoutput
,its detailed introduction :input action
type:- issue issue asset
- spend_account spend utxo in account mode
- spend_account_unspent_output spend specified utxo directly
output action
type:- 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
action
types when you build transaction:
issue
issueAction
Structural 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:
assets
asset management,users dont need to set parametersAssetAmount
ssetID and corresponding asset amount,need to createAssetID
bycreate-asset
,cant use the assetID ofBTM
json
format of issueAction
:
{
"amount": 100000000,
"asset_id": "3152a15da72be51b330e1c0f8e1c0db669269809da4f16443ff266e07cc43680",
"type": "issue"
}
an example of issue asset: (issue900000000
whichassetID
is42275aacbeda1522cd41580f875c3c452daf5174b17ba062bf0ab71a568c123f
tosm1qxe4jwhkekgnxkezu7xutu5gqnnpmyc8ppq98me
, gas is20000000
neu 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
spendAction
Structural 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:
accounts
account management.users dont need to set parametersAccountID
spend_accountAssetAmount
AssetID and corresponding asset amountClientToken
Reserved limits of users' UTXO,null
spendAction``json
format of spendAction
:
{
"account_id": "0BF63M2U00A04",
"amount": 2000000000,
"asset_id": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
"type": "spend_account"
}
transaction example is as following下: (transfer100000000
neu Bytom asset to sm1qxe4jwhkekgnxkezu7xutu5gqnnpmyc8ppq98me
, gas is20000000
neu =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
spendUTXOAction
Structural source code:
type spendUTXOAction struct {
accounts *Manager
OutputID *bc.Hash `json:"output_id"`
ClientToken *string `json:"client_token"`
}
structure fields:
accounts
account management.users dont need to set parametersOutputID
ID of UTXO,query available UTXO bylist-unspent-outputs
,OutputID
corresponding toid
fields of API return resultsClientToken
reserved limit of UTXO,null
json
format of spendUTXOAction
:
{
"type": "spend_account_unspent_output",
"output_id": "58f29f0f85f7bd2a91088bcbe536dee41cd0642dfb1480d3a88589bdbfd642d9"
}
transaction example by spendUTXO: (transfer100000000
neu BTM asset to sm1qxe4jwhkekgnxkezu7xutu5gqnnpmyc8ppq98me
by 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
controlAddressAction
Structural 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:
Address
receive address,can create address bycreate-account-receiver
APIinterfaceAssetAmount
asset ID to receive and corresponding asset amount
json
format of controlAddressAction
:
{
"amount": 100000000,
"asset_id": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
"address": "bm1q50u3z8empm5ke0g3ngl2t3sqtr6sd7cepd3z68",
"type": "control_address"
}
Transaction example: (transfer100000000
neuBTM address to sm1qxe4jwhkekgnxkezu7xutu5gqnnpmyc8ppq98me
in account mode,control_address
type 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
controlProgramAction
Structural 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:
Program
contract script to receive asset,throughcreate-account-receiver
APIinterface build and receiveprogram
(The return results ofprogram
andaddress
are one to one correspondence)AssetAmount
AssetID to receive and corresponding asset amount
json
format of controlProgramAction
:
{
"amount": 100000000,
"asset_id": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
"control_program":"0014a3f9111f3b0ee96cbd119a3ea5c60058f506fb19",
"type": "control_program"
}
Transaction example: (transfer100000000
neu BTM asset to program
(one to one correspondence withaddress
)0014a3f9111f3b0ee96cbd119a3ea5c60058f506fb19
, control_program
type usesprogram
to 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
retireAction
structural 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:
AssetAmount
asset ID to receive and corresponding asset amount
json
format of retireAction
:
{
"amount": 900000000,
"asset_id": "3152a15da72be51b330e1c0f8e1c0db669269809da4f16443ff266e07cc43680",
"type": "retire"
}
Transaction example: (transfer100000000
neu BTM retired asset in account mode, retire
retire 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:
Transaction
about transaction informations includingTxData
andbc.Tx
:TxData
Represents the transaction data portion shown to the user, which is visible to the userVersion
transaction versionSerializedSize
Size after transaction serializationTimeRange
maximum timestamp(blockheight) of submitting transaction on chain(If the transaction havent been on chain when the blockheight reach the blockheight,the transaction will empire)Inputs
transaction inputsOutputs
transaction outputsbc.Tx
Represents the transformation structure used to process transactions in the system. This part is not visible to users, so it is not described in detailSigningInstructions
signature information of transactionPosition
toinput action
Location of signature- Data informations of
WitnessComponents
toinput action
signature,signatures
of 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: SignatureWitness
hash the contract program ofinput action
in the transactionTemplate
,then sign for hash valuesignatures
transaction signature(arraytype),Aftersign-transaction
performed,there will be a valuekeys
(arraytype)Including main publickeyxpub
and derived pathderivation_path
,they can find corresponding derived privatekeychild_xprv
in signature period,then use derived key to signkey
amount ofquorum
account ,the length has to be equal to thekeys
above。Ifquorum
is equal to 1,it's single signature account,or it's multi-signature accountprogram
Data of signature,hash value ofprogram
is as signature data 。Ifprogram
is 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 aprogram
automaticallyRawTxSigWitness
hash InoutID(this field is in bc.Tx) ofinput action
with transaction ID ofTemplate
signatures
transaction signature(arraytype),Aftersign-transaction
performed,there will be a valuekeys
(arraytype) includingxpub
and derived pathderivation_path
,you can find derived private key in their signature periodchild_xprv
,then use derived private key to signkey
amount ofquorum
account,the length has to be equal tokeys
above。Ifquorum
is equal to 1,it represents single signature account,or its multi-signature accountDataWitness
this type doesnt need signature,verify the additional data of contract programAllowAdditional
Whether to allow trading of additional data, if fortrue
, then additional data will be added to the transaction, but will not affect the transaction executionprogram
script, 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:
TotalNeu
Estimated gas(neu),you can add the value to BTM asset of build-transaction by inputting actionStorageNeu
Gas for storing transactionVMNeu
Gas 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:
Password
password of signature,analysis users' private key from node server according to password,then use private key to sign for transactionTxs
transaction template,return result of build-transaction,its structure type istxbuilder.Template
,you can see related fields in the description of build-transaction
sign-transaction
The 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. Template
afterTx
signature , if the signature's successfulsignatures
will change from null to the value of the signature andraw_transaction
length will be longer, becauseBC. Tx
part added to verify the parameters of the signature information To complete - SignComplete
mark 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-transaction
again
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:
Tx
transaction information after signature。raw_transaction
in this field is not the who;e returen results ofsign-transaction
,it'sraw_transaction
field in thetransaction
of sign transaction's reture results
submit-transaction
The 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:
TxID
Transaction ID, which displays the information when the transaction is submitted to the transaction pool, otherwise indicates that the transaction failed