Golang implemented sidechain for Bytom
修订版 | 907f75b076ffd7bfccb7227b0cd0f493cf9f75d9 (tree) |
---|---|
时间 | 2019-06-03 17:57:59 |
作者 | Paladz <yzhu101@uott...> |
Commiter | GitHub |
Merge branch 'v0.1' into merge_bbft
@@ -53,6 +53,7 @@ type AnnotatedOutput struct { | ||
53 | 53 | AccountAlias string `json:"account_alias,omitempty"` |
54 | 54 | ControlProgram chainjson.HexBytes `json:"control_program"` |
55 | 55 | Address string `json:"address,omitempty"` |
56 | + Vote chainjson.HexBytes `json:"vote,omitempty"` | |
56 | 57 | } |
57 | 58 | |
58 | 59 | //AnnotatedAccount means an annotated account. |
@@ -56,11 +56,12 @@ func (c *consensusNodeManager) getConsensusNode(prevBlockHash *bc.Hash, pubkey s | ||
56 | 56 | } |
57 | 57 | |
58 | 58 | func (c *consensusNodeManager) isBlocker(prevBlockHash *bc.Hash, pubKey string, timeStamp uint64) (bool, error) { |
59 | - consensusNode, err := c.getConsensusNode(prevBlockHash, pubKey) | |
60 | - if err != nil && err != errNotFoundConsensusNode { | |
59 | + consensusNodeMap, err := c.getConsensusNodesByVoteResult(prevBlockHash) | |
60 | + if err != nil { | |
61 | 61 | return false, err |
62 | 62 | } |
63 | 63 | |
64 | + consensusNode := consensusNodeMap[pubKey] | |
64 | 65 | if consensusNode == nil { |
65 | 66 | return false, nil |
66 | 67 | } |
@@ -71,14 +72,14 @@ func (c *consensusNodeManager) isBlocker(prevBlockHash *bc.Hash, pubKey string, | ||
71 | 72 | } |
72 | 73 | |
73 | 74 | startTimestamp := prevVoteRoundLastBlock.Timestamp + consensus.BlockTimeInterval |
74 | - begin := getLastBlockTimeInTimeRange(startTimestamp, timeStamp, consensusNode.order) | |
75 | + begin := getLastBlockTimeInTimeRange(startTimestamp, timeStamp, consensusNode.order, len(consensusNodeMap)) | |
75 | 76 | end := begin + consensus.BlockNumEachNode*consensus.BlockTimeInterval |
76 | 77 | return timeStamp >= begin && timeStamp < end, nil |
77 | 78 | } |
78 | 79 | |
79 | -func getLastBlockTimeInTimeRange(startTimestamp, endTimestamp, order uint64) uint64 { | |
80 | +func getLastBlockTimeInTimeRange(startTimestamp, endTimestamp, order uint64, numOfConsensusNode int) uint64 { | |
80 | 81 | // One round of product block time for all consensus nodes |
81 | - roundBlockTime := uint64(consensus.BlockNumEachNode * consensus.NumOfConsensusNode * consensus.BlockTimeInterval) | |
82 | + roundBlockTime := uint64(consensus.BlockNumEachNode * numOfConsensusNode * consensus.BlockTimeInterval) | |
82 | 83 | // The start time of the last round of product block |
83 | 84 | lastRoundStartTime := startTimestamp + (endTimestamp-startTimestamp)/roundBlockTime*roundBlockTime |
84 | 85 | // The time of product block of the consensus in last round |
@@ -16,7 +16,6 @@ import ( | ||
16 | 16 | dbm "github.com/vapor/database/leveldb" |
17 | 17 | "github.com/vapor/protocol/bc" |
18 | 18 | "github.com/vapor/protocol/bc/types" |
19 | - "github.com/vapor/protocol/vm/vmutil" | |
20 | 19 | ) |
21 | 20 | |
22 | 21 | // annotateTxs adds asset data to transactions |
@@ -248,10 +247,15 @@ func (w *Wallet) BuildAnnotatedOutput(tx *types.Tx, idx int) *query.AnnotatedOut | ||
248 | 247 | Address: w.getAddressFromControlProgram(orig.ControlProgram()), |
249 | 248 | } |
250 | 249 | |
251 | - if vmutil.IsUnspendable(out.ControlProgram) { | |
252 | - out.Type = "retire" | |
253 | - } else { | |
250 | + switch e := tx.Entries[*outid].(type) { | |
251 | + case *bc.IntraChainOutput: | |
254 | 252 | out.Type = "control" |
253 | + case *bc.CrossChainOutput: | |
254 | + out.Type = "cross_Output" | |
255 | + case *bc.VoteOutput: | |
256 | + out.Type = "vote" | |
257 | + out.Vote = e.Vote | |
255 | 258 | } |
259 | + | |
256 | 260 | return out |
257 | 261 | } |