[NOD-165] In getBlockVerboseResult and getBlockHeaderVerboseResult, renamed merkleRoot to HashMerkleRoot and added idMerkleRoot and acceptedIdMerkleRoot. (#294)

This commit is contained in:
stasatdaglabs 2019-05-12 15:05:33 +03:00 committed by Ori Newman
parent 08d94c7a47
commit dfd12cdaac
3 changed files with 91 additions and 79 deletions

View File

@ -10,39 +10,43 @@ import "encoding/json"
// the verbose flag is set. When the verbose flag is not set, getblockheader
// returns a hex-encoded string.
type GetBlockHeaderVerboseResult struct {
Hash string `json:"hash"`
Confirmations uint64 `json:"confirmations"`
Height uint64 `json:"height"`
Version int32 `json:"version"`
VersionHex string `json:"versionHex"`
MerkleRoot string `json:"merkleRoot"`
Time int64 `json:"time"`
Nonce uint64 `json:"nonce"`
Bits string `json:"bits"`
Difficulty float64 `json:"difficulty"`
ParentHashes []string `json:"parentHashes,omitempty"`
NextHashes []string `json:"nextHashes,omitempty"`
Hash string `json:"hash"`
Confirmations uint64 `json:"confirmations"`
Height uint64 `json:"height"`
Version int32 `json:"version"`
VersionHex string `json:"versionHex"`
HashMerkleRoot string `json:"hashMerkleRoot"`
IDMerkleRoot string `json:"idMerkleRoot"`
AcceptedIDMerkleRoot string `json:"acceptedIdMerkleRoot"`
Time int64 `json:"time"`
Nonce uint64 `json:"nonce"`
Bits string `json:"bits"`
Difficulty float64 `json:"difficulty"`
ParentHashes []string `json:"parentHashes,omitempty"`
NextHashes []string `json:"nextHashes,omitempty"`
}
// GetBlockVerboseResult models the data from the getblock command when the
// verbose flag is set. When the verbose flag is not set, getblock returns a
// hex-encoded string.
type GetBlockVerboseResult struct {
Hash string `json:"hash"`
Confirmations uint64 `json:"confirmations"`
Size int32 `json:"size"`
Height uint64 `json:"height"`
Version int32 `json:"version"`
VersionHex string `json:"versionHex"`
MerkleRoot string `json:"merkleRoot"`
Tx []string `json:"tx,omitempty"`
RawTx []TxRawResult `json:"rawRx,omitempty"`
Time int64 `json:"time"`
Nonce uint64 `json:"nonce"`
Bits string `json:"bits"`
Difficulty float64 `json:"difficulty"`
ParentHashes []string `json:"parentHashes"`
NextHashes []string `json:"nextHashes,omitempty"`
Hash string `json:"hash"`
Confirmations uint64 `json:"confirmations"`
Size int32 `json:"size"`
Height uint64 `json:"height"`
Version int32 `json:"version"`
VersionHex string `json:"versionHex"`
HashMerkleRoot string `json:"hashMerkleRoot"`
IDMerkleRoot string `json:"idMerkleRoot"`
AcceptedIDMerkleRoot string `json:"acceptedIdMerkleRoot"`
Tx []string `json:"tx,omitempty"`
RawTx []TxRawResult `json:"rawRx,omitempty"`
Time int64 `json:"time"`
Nonce uint64 `json:"nonce"`
Bits string `json:"bits"`
Difficulty float64 `json:"difficulty"`
ParentHashes []string `json:"parentHashes"`
NextHashes []string `json:"nextHashes,omitempty"`
}
// CreateMultiSigResult models the data returned from the createmultisig

View File

@ -1194,19 +1194,21 @@ func handleGetBlock(s *Server, cmd interface{}, closeChan <-chan struct{}) (inte
params := s.cfg.DAGParams
blockHeader := &blk.MsgBlock().Header
blockReply := btcjson.GetBlockVerboseResult{
Hash: c.Hash,
Version: blockHeader.Version,
VersionHex: fmt.Sprintf("%08x", blockHeader.Version),
MerkleRoot: blockHeader.HashMerkleRoot.String(),
ParentHashes: daghash.Strings(blockHeader.ParentHashes),
Nonce: blockHeader.Nonce,
Time: blockHeader.Timestamp.Unix(),
Confirmations: uint64(1 + s.cfg.DAG.Height() - blockHeight), //TODO: (Ori) This is probably wrong. Done only for compilation
Height: blockHeight,
Size: int32(len(blkBytes)),
Bits: strconv.FormatInt(int64(blockHeader.Bits), 16),
Difficulty: getDifficultyRatio(blockHeader.Bits, params),
NextHashes: nextHashStrings,
Hash: c.Hash,
Version: blockHeader.Version,
VersionHex: fmt.Sprintf("%08x", blockHeader.Version),
HashMerkleRoot: blockHeader.HashMerkleRoot.String(),
IDMerkleRoot: blockHeader.IDMerkleRoot.String(),
AcceptedIDMerkleRoot: blockHeader.AcceptedIDMerkleRoot.String(),
ParentHashes: daghash.Strings(blockHeader.ParentHashes),
Nonce: blockHeader.Nonce,
Time: blockHeader.Timestamp.Unix(),
Confirmations: uint64(1 + s.cfg.DAG.Height() - blockHeight), //TODO: (Ori) This is probably wrong. Done only for compilation
Height: blockHeight,
Size: int32(len(blkBytes)),
Bits: strconv.FormatInt(int64(blockHeader.Bits), 16),
Difficulty: getDifficultyRatio(blockHeader.Bits, params),
NextHashes: nextHashStrings,
}
if c.VerboseTx == nil || !*c.VerboseTx {
@ -1393,18 +1395,20 @@ func handleGetBlockHeader(s *Server, cmd interface{}, closeChan <-chan struct{})
params := s.cfg.DAGParams
blockHeaderReply := btcjson.GetBlockHeaderVerboseResult{
Hash: c.Hash,
Confirmations: uint64(1 + s.cfg.DAG.Height() - blockHeight), //TODO: (Ori) This is probably wrong. Done only for compilation
Height: blockHeight,
Version: blockHeader.Version,
VersionHex: fmt.Sprintf("%08x", blockHeader.Version),
MerkleRoot: blockHeader.HashMerkleRoot.String(),
NextHashes: nextHashStrings,
ParentHashes: daghash.Strings(blockHeader.ParentHashes),
Nonce: uint64(blockHeader.Nonce),
Time: blockHeader.Timestamp.Unix(),
Bits: strconv.FormatInt(int64(blockHeader.Bits), 16),
Difficulty: getDifficultyRatio(blockHeader.Bits, params),
Hash: c.Hash,
Confirmations: uint64(1 + s.cfg.DAG.Height() - blockHeight), //TODO: (Ori) This is probably wrong. Done only for compilation
Height: blockHeight,
Version: blockHeader.Version,
VersionHex: fmt.Sprintf("%08x", blockHeader.Version),
HashMerkleRoot: blockHeader.HashMerkleRoot.String(),
IDMerkleRoot: blockHeader.IDMerkleRoot.String(),
AcceptedIDMerkleRoot: blockHeader.AcceptedIDMerkleRoot.String(),
NextHashes: nextHashStrings,
ParentHashes: daghash.Strings(blockHeader.ParentHashes),
Nonce: uint64(blockHeader.Nonce),
Time: blockHeader.Timestamp.Unix(),
Bits: strconv.FormatInt(int64(blockHeader.Bits), 16),
Difficulty: getDifficultyRatio(blockHeader.Bits, params),
}
return blockHeaderReply, nil
}

View File

@ -235,21 +235,23 @@ var helpDescsEnUS = map[string]string{
"searchRawTransactionsResult-size": "The size of the transaction in bytes",
// GetBlockVerboseResult help.
"getBlockVerboseResult-hash": "The hash of the block (same as provided)",
"getBlockVerboseResult-confirmations": "The number of confirmations",
"getBlockVerboseResult-size": "The size of the block",
"getBlockVerboseResult-height": "The height of the block in the block chain",
"getBlockVerboseResult-version": "The block version",
"getBlockVerboseResult-versionHex": "The block version in hexadecimal",
"getBlockVerboseResult-merkleRoot": "Root hash of the merkle tree",
"getBlockVerboseResult-tx": "The transaction hashes (only when verbosetx=false)",
"getBlockVerboseResult-rawRx": "The transactions as JSON objects (only when verbosetx=true)",
"getBlockVerboseResult-time": "The block time in seconds since 1 Jan 1970 GMT",
"getBlockVerboseResult-nonce": "The block nonce",
"getBlockVerboseResult-bits": "The bits which represent the block difficulty",
"getBlockVerboseResult-difficulty": "The proof-of-work difficulty as a multiple of the minimum difficulty",
"getBlockVerboseResult-parentHashes": "The hashes of the parent blocks",
"getBlockVerboseResult-nextHashes": "The hashes of the next blocks (only if there are any)",
"getBlockVerboseResult-hash": "The hash of the block (same as provided)",
"getBlockVerboseResult-confirmations": "The number of confirmations",
"getBlockVerboseResult-size": "The size of the block",
"getBlockVerboseResult-height": "The height of the block in the block chain",
"getBlockVerboseResult-version": "The block version",
"getBlockVerboseResult-versionHex": "The block version in hexadecimal",
"getBlockVerboseResult-hashMerkleRoot": "Merkle tree reference to hash of all transactions for the block",
"getBlockVerboseResult-idMerkleRoot": "Merkle tree reference to hash of all transactions' IDs for the block",
"getBlockVerboseResult-acceptedIdMerkleRoot": "Merkle tree reference to hash all transactions accepted form the block blues",
"getBlockVerboseResult-tx": "The transaction hashes (only when verbosetx=false)",
"getBlockVerboseResult-rawRx": "The transactions as JSON objects (only when verbosetx=true)",
"getBlockVerboseResult-time": "The block time in seconds since 1 Jan 1970 GMT",
"getBlockVerboseResult-nonce": "The block nonce",
"getBlockVerboseResult-bits": "The bits which represent the block difficulty",
"getBlockVerboseResult-difficulty": "The proof-of-work difficulty as a multiple of the minimum difficulty",
"getBlockVerboseResult-parentHashes": "The hashes of the parent blocks",
"getBlockVerboseResult-nextHashes": "The hashes of the next blocks (only if there are any)",
// GetBlockCountCmd help.
"getBlockCount--synopsis": "Returns the number of blocks in the longest block chain.",
@ -269,18 +271,20 @@ var helpDescsEnUS = map[string]string{
"getBlockHeader--result0": "The block header hash",
// GetBlockHeaderVerboseResult help.
"getBlockHeaderVerboseResult-hash": "The hash of the block (same as provided)",
"getBlockHeaderVerboseResult-confirmations": "The number of confirmations",
"getBlockHeaderVerboseResult-height": "The height of the block in the block chain",
"getBlockHeaderVerboseResult-version": "The block version",
"getBlockHeaderVerboseResult-versionHex": "The block version in hexadecimal",
"getBlockHeaderVerboseResult-merkleRoot": "Root hash of the merkle tree",
"getBlockHeaderVerboseResult-time": "The block time in seconds since 1 Jan 1970 GMT",
"getBlockHeaderVerboseResult-nonce": "The block nonce",
"getBlockHeaderVerboseResult-bits": "The bits which represent the block difficulty",
"getBlockHeaderVerboseResult-difficulty": "The proof-of-work difficulty as a multiple of the minimum difficulty",
"getBlockHeaderVerboseResult-parentHashes": "The hashes of the parent blocks",
"getBlockHeaderVerboseResult-nextHashes": "The hashes of the next blocks (only if there are any)",
"getBlockHeaderVerboseResult-hash": "The hash of the block (same as provided)",
"getBlockHeaderVerboseResult-confirmations": "The number of confirmations",
"getBlockHeaderVerboseResult-height": "The height of the block in the block chain",
"getBlockHeaderVerboseResult-version": "The block version",
"getBlockHeaderVerboseResult-versionHex": "The block version in hexadecimal",
"getBlockHeaderVerboseResult-hashMerkleRoot": "Merkle tree reference to hash of all transactions for the block",
"getBlockHeaderVerboseResult-idMerkleRoot": "Merkle tree reference to hash of all transactions' IDs for the block",
"getBlockHeaderVerboseResult-acceptedIdMerkleRoot": "Merkle tree reference to hash all transactions accepted form the block blues",
"getBlockHeaderVerboseResult-time": "The block time in seconds since 1 Jan 1970 GMT",
"getBlockHeaderVerboseResult-nonce": "The block nonce",
"getBlockHeaderVerboseResult-bits": "The bits which represent the block difficulty",
"getBlockHeaderVerboseResult-difficulty": "The proof-of-work difficulty as a multiple of the minimum difficulty",
"getBlockHeaderVerboseResult-parentHashes": "The hashes of the parent blocks",
"getBlockHeaderVerboseResult-nextHashes": "The hashes of the next blocks (only if there are any)",
// TemplateRequest help.
"templateRequest-mode": "This is 'template', 'proposal', or omitted",