Golang implemented sidechain for Bytom
Revision | 7667ab494e054d87261e98e9a77256715255088c (tree) |
---|---|
Time | 2020-02-24 19:29:10 |
Author | ipqhjjybj <ipqhjjybj@qq.c...> |
Commiter | ipqhjjybj |
update test
@@ -102,7 +102,7 @@ type Params struct { | ||
102 | 102 | // ProducerSubsidys defines the producer subsidy by block height |
103 | 103 | ProducerSubsidys []ProducerSubsidy |
104 | 104 | |
105 | - SoftForkPoint map[uint64]uint64 | |
105 | + SoftForkPoint map[uint64]uint64 | |
106 | 106 | MovStartHeight uint64 |
107 | 107 | } |
108 | 108 |
@@ -1,12 +1,14 @@ | ||
1 | 1 | package database |
2 | 2 | |
3 | 3 | import ( |
4 | - "github.com/golang/protobuf/proto" | |
4 | + "fmt" | |
5 | + | |
5 | 6 | dbm "github.com/bytom/vapor/database/leveldb" |
6 | 7 | "github.com/bytom/vapor/database/storage" |
7 | 8 | "github.com/bytom/vapor/errors" |
8 | 9 | "github.com/bytom/vapor/protocol/bc" |
9 | 10 | "github.com/bytom/vapor/protocol/state" |
11 | + "github.com/golang/protobuf/proto" | |
10 | 12 | ) |
11 | 13 | |
12 | 14 | const utxoPreFix = "UT:" |
@@ -16,18 +18,28 @@ func calcUtxoKey(hash *bc.Hash) []byte { | ||
16 | 18 | } |
17 | 19 | |
18 | 20 | func getTransactionsUtxo(db dbm.DB, view *state.UtxoViewpoint, txs []*bc.Tx) error { |
21 | + fmt.Println("[very important]") | |
19 | 22 | for _, tx := range txs { |
23 | + fmt.Println("[very important] getTransactionsUtxo tx.string()", tx.String()) | |
20 | 24 | for _, prevout := range tx.SpentOutputIDs { |
25 | + fmt.Println("[very important] getTransactionsUtxo prevout", prevout.String()) | |
21 | 26 | if view.HasUtxo(&prevout) { |
22 | 27 | continue |
23 | 28 | } |
24 | 29 | |
30 | + utxoEntry, err := GetUtxo(db, &prevout) | |
31 | + fmt.Println("[why really important] prevout", prevout.String()) | |
32 | + fmt.Println("[why really important] utxoEntry:", utxoEntry.String(), "err", err) | |
33 | + | |
34 | + fmt.Println("calcKey:", calcUtxoKey(&prevout)) | |
25 | 35 | data := db.Get(calcUtxoKey(&prevout)) |
26 | 36 | if data == nil { |
37 | + fmt.Println("why data is not here") | |
27 | 38 | continue |
28 | 39 | } |
29 | 40 | |
30 | 41 | var utxo storage.UtxoEntry |
42 | + fmt.Println("Unmarshal data", data) | |
31 | 43 | if err := proto.Unmarshal(data, &utxo); err != nil { |
32 | 44 | return errors.Wrap(err, "unmarshaling utxo entry") |
33 | 45 | } |
@@ -36,6 +48,7 @@ func getTransactionsUtxo(db dbm.DB, view *state.UtxoViewpoint, txs []*bc.Tx) err | ||
36 | 48 | } |
37 | 49 | |
38 | 50 | for _, prevout := range tx.MainchainOutputIDs { |
51 | + fmt.Println("MainchainOutputIDs preout", prevout.String()) | |
39 | 52 | if view.HasUtxo(&prevout) { |
40 | 53 | continue |
41 | 54 | } |
@@ -70,14 +83,22 @@ func getUtxo(db dbm.DB, hash *bc.Hash) (*storage.UtxoEntry, error) { | ||
70 | 83 | return &utxo, nil |
71 | 84 | } |
72 | 85 | |
86 | +func GetUtxo(db dbm.DB, hash *bc.Hash) (*storage.UtxoEntry, error) { | |
87 | + return getUtxo(db, hash) | |
88 | +} | |
89 | + | |
73 | 90 | func saveUtxoView(batch dbm.Batch, view *state.UtxoViewpoint) error { |
91 | + fmt.Println("[important] now go to saveUtxoView len entries:", len(view.Entries)) | |
74 | 92 | for key, entry := range view.Entries { |
93 | + fmt.Println("[important] saveUtxoView key:", key.String(), " entry:", entry.String()) | |
75 | 94 | if entry.Type == storage.CrosschainUTXOType && !entry.Spent { |
95 | + fmt.Println("[important] delete key:", calcUtxoKey(&key)) | |
76 | 96 | batch.Delete(calcUtxoKey(&key)) |
77 | 97 | continue |
78 | 98 | } |
79 | 99 | |
80 | 100 | if entry.Type == storage.NormalUTXOType && entry.Spent { |
101 | + fmt.Println("[important] delete key:", calcUtxoKey(&key)) | |
81 | 102 | batch.Delete(calcUtxoKey(&key)) |
82 | 103 | continue |
83 | 104 | } |
@@ -86,6 +107,7 @@ func saveUtxoView(batch dbm.Batch, view *state.UtxoViewpoint) error { | ||
86 | 107 | if err != nil { |
87 | 108 | return errors.Wrap(err, "marshaling utxo entry") |
88 | 109 | } |
110 | + fmt.Println("[important set] calcUtxoKey(&key)", calcUtxoKey(&key)) | |
89 | 111 | batch.Set(calcUtxoKey(&key), b) |
90 | 112 | } |
91 | 113 | return nil |
@@ -89,18 +89,20 @@ func (c *Chain) calcReorganizeChain(beginAttach *types.BlockHeader, beginDetach | ||
89 | 89 | } |
90 | 90 | |
91 | 91 | func (c *Chain) connectBlock(block *types.Block) (err error) { |
92 | + prevOut := bc.Hash{V0: 13401662211606668461, V1: 16715925272045549698, V2: 14986839123336726356, V3: 599535074188477126} | |
93 | + entry, err := c.store.GetUtxo(&prevOut) | |
94 | + fmt.Println("connectBlock entry:", entry, "err:", err) | |
95 | + | |
92 | 96 | bcBlock := types.MapBlock(block) |
93 | 97 | if bcBlock.TransactionStatus, err = c.store.GetTransactionStatus(&bcBlock.ID); err != nil { |
94 | 98 | return err |
95 | 99 | } |
96 | 100 | |
97 | - fmt.Println("connectBlock abcd") | |
98 | 101 | utxoView := state.NewUtxoViewpoint() |
99 | 102 | if err := c.store.GetTransactionsUtxo(utxoView, bcBlock.Transactions); err != nil { |
100 | 103 | return err |
101 | 104 | } |
102 | 105 | |
103 | - fmt.Println("utxoView.ApplyBlock") | |
104 | 106 | //fmt.Println("bcBlock.TransactionStatus", bcBlock.TransactionStatus) |
105 | 107 | if err := utxoView.ApplyBlock(bcBlock, bcBlock.TransactionStatus); err != nil { |
106 | 108 | return err |
@@ -388,23 +390,19 @@ func (c *Chain) saveBlock(block *types.Block) error { | ||
388 | 390 | } |
389 | 391 | |
390 | 392 | bcBlock := types.MapBlock(block) |
391 | - fmt.Println("validation.ValidateBlock") | |
392 | 393 | if err := validation.ValidateBlock(bcBlock, parent, rewards); err != nil { |
393 | 394 | return errors.Sub(ErrBadBlock, err) |
394 | 395 | } |
395 | 396 | |
396 | - fmt.Println("block.go _, p := range c.subProtocols") | |
397 | 397 | for _, p := range c.subProtocols { |
398 | 398 | if err := p.ValidateBlock(block, bcBlock.TransactionStatus.GetVerifyStatus()); err != nil { |
399 | 399 | return errors.Wrap(err, "sub protocol save block") |
400 | 400 | } |
401 | 401 | } |
402 | - fmt.Println("end validation") | |
403 | 402 | |
404 | 403 | if err := c.store.SaveBlock(block, bcBlock.TransactionStatus); err != nil { |
405 | 404 | return err |
406 | 405 | } |
407 | - fmt.Println("end save block") | |
408 | 406 | |
409 | 407 | c.orphanManage.Delete(&bcBlock.ID) |
410 | 408 | return nil |
@@ -463,6 +461,11 @@ func (c *Chain) blockProcesser() { | ||
463 | 461 | |
464 | 462 | // ProcessBlock is the entry for handle block insert |
465 | 463 | func (c *Chain) processBlock(block *types.Block) (bool, error) { |
464 | + fmt.Println("[processBlock]") | |
465 | + prevOut := bc.Hash{V0: 13401662211606668461, V1: 16715925272045549698, V2: 14986839123336726356, V3: 599535074188477126} | |
466 | + entry, err := c.store.GetUtxo(&prevOut) | |
467 | + fmt.Println("processBlock entry:", entry, "err:", err) | |
468 | + | |
466 | 469 | blockHash := block.Hash() |
467 | 470 | if c.BlockExist(&blockHash) { |
468 | 471 | log.WithFields(log.Fields{"module": logModule, "hash": blockHash.String(), "height": block.Height}).Debug("block has been processed") |
@@ -480,13 +483,9 @@ func (c *Chain) processBlock(block *types.Block) (bool, error) { | ||
480 | 483 | return false, err |
481 | 484 | } |
482 | 485 | |
483 | - fmt.Println("saveBlock") | |
484 | - | |
485 | 486 | bestBlock := c.saveSubBlock(block) |
486 | 487 | bestBlockHeader := &bestBlock.BlockHeader |
487 | 488 | |
488 | - fmt.Println("end save sub block") | |
489 | - | |
490 | 489 | c.cond.L.Lock() |
491 | 490 | defer c.cond.L.Unlock() |
492 | 491 | if bestBlockHeader.PreviousBlockHash == c.bestBlockHeader.Hash() { |
@@ -495,7 +494,6 @@ func (c *Chain) processBlock(block *types.Block) (bool, error) { | ||
495 | 494 | return false, c.connectBlock(bestBlock) |
496 | 495 | } |
497 | 496 | |
498 | - fmt.Println("doing") | |
499 | 497 | if bestBlockHeader.Height > c.bestBlockHeader.Height { |
500 | 498 | log.WithFields(log.Fields{"module": logModule}).Debug("start to reorganize chain") |
501 | 499 | return false, c.reorganizeChain(bestBlockHeader) |
@@ -22,12 +22,10 @@ func NewUtxoViewpoint() *UtxoViewpoint { | ||
22 | 22 | } |
23 | 23 | |
24 | 24 | func (view *UtxoViewpoint) ApplyTransaction(block *bc.Block, tx *bc.Tx, statusFail bool) error { |
25 | - fmt.Println("UtxoViewpoint ApplyTransaction") | |
26 | 25 | if err := view.applyCrossChainUtxo(block, tx); err != nil { |
27 | 26 | return err |
28 | 27 | } |
29 | 28 | |
30 | - fmt.Println("view.applySpendUtxo") | |
31 | 29 | if err := view.applySpendUtxo(block, tx, statusFail); err != nil { |
32 | 30 | return err |
33 | 31 | } |
@@ -42,7 +40,6 @@ func (view *UtxoViewpoint) ApplyBlock(block *bc.Block, txStatus *bc.TransactionS | ||
42 | 40 | return err |
43 | 41 | } |
44 | 42 | |
45 | - fmt.Println("UtxoViewpoint ApplyBlock", i, tx) | |
46 | 43 | if err := view.ApplyTransaction(block, tx, statusFail); err != nil { |
47 | 44 | return err |
48 | 45 | } |
@@ -159,8 +156,8 @@ func (view *UtxoViewpoint) applySpendUtxo(block *bc.Block, tx *bc.Tx, statusFail | ||
159 | 156 | continue |
160 | 157 | } |
161 | 158 | |
162 | - fmt.Println("assetID:", assetID) | |
163 | - fmt.Println("prevout", prevout) | |
159 | + fmt.Println("[fuck error ]assetID:", assetID.String()) | |
160 | + fmt.Println("[fuck error ]prevout", prevout, prevout.String()) | |
164 | 161 | entry, ok := view.Entries[prevout] |
165 | 162 | if !ok { |
166 | 163 | return errors.New("fail to find utxo entry") |
@@ -3,7 +3,6 @@ package validation | ||
3 | 3 | import ( |
4 | 4 | "bytes" |
5 | 5 | "encoding/hex" |
6 | - "fmt" | |
7 | 6 | "time" |
8 | 7 | |
9 | 8 | log "github.com/sirupsen/logrus" |
@@ -123,19 +122,15 @@ func ValidateBlock(b *bc.Block, parent *types.BlockHeader, rewards []state.Coinb | ||
123 | 122 | return errors.WithDetailf(errMismatchedMerkleRoot, "transaction id merkle root. compute: %v, given: %v", txMerkleRoot, *b.TransactionsRoot) |
124 | 123 | } |
125 | 124 | |
126 | - fmt.Println("b.TransactionStatus.VerifyStatus", b.TransactionStatus.VerifyStatus, len(b.TransactionStatus.VerifyStatus)) | |
127 | - for i := 0; i < len(b.TransactionStatus.VerifyStatus); i++ { | |
128 | - fmt.Println("txStatus", i, b.TransactionStatus.VerifyStatus[i]) | |
129 | - } | |
125 | + // fmt.Println("b.TransactionStatus.VerifyStatus", b.TransactionStatus.VerifyStatus, len(b.TransactionStatus.VerifyStatus)) | |
126 | + // for i := 0; i < len(b.TransactionStatus.VerifyStatus); i++ { | |
127 | + // fmt.Println("txStatus", i, b.TransactionStatus.VerifyStatus[i]) | |
128 | + // } | |
130 | 129 | txStatusHash, err := types.TxStatusMerkleRoot(b.TransactionStatus.VerifyStatus) |
131 | 130 | if err != nil { |
132 | 131 | return errors.Wrap(err, "computing transaction status merkle root") |
133 | 132 | } |
134 | 133 | if txStatusHash != *b.TransactionStatusHash { |
135 | - fmt.Println("!!! here !!") | |
136 | - fmt.Println("txStatusHash", txStatusHash) | |
137 | - fmt.Println("TransactionStatusHash", b.TransactionStatusHash) | |
138 | - fmt.Println("TransactionStatusHash", *b.TransactionStatusHash) | |
139 | 134 | return errors.WithDetailf(errMismatchedMerkleRoot, "transaction status merkle root. compute: %v, given: %v", txStatusHash, *b.TransactionStatusHash) |
140 | 135 | } |
141 | 136 |
@@ -597,11 +597,9 @@ func applySoftFork001(vs *validationState, err error) { | ||
597 | 597 | // ValidateTx validates a transaction. |
598 | 598 | func ValidateTx(tx *bc.Tx, block *bc.Block) (*GasState, error) { |
599 | 599 | gasStatus := &GasState{GasValid: false} |
600 | - fmt.Println("block.Version, tx.Version", block.Version, tx.Version) | |
601 | 600 | if block.Version == 1 && tx.Version != 1 { |
602 | 601 | return gasStatus, errors.WithDetailf(ErrTxVersion, "block version %d, transaction version %d", block.Version, tx.Version) |
603 | 602 | } |
604 | - fmt.Println("???") | |
605 | 603 | if tx.SerializedSize == 0 { |
606 | 604 | return gasStatus, ErrWrongTransactionSize |
607 | 605 | } |
@@ -20,7 +20,6 @@ import ( | ||
20 | 20 | dbm "github.com/bytom/vapor/database/leveldb" |
21 | 21 | "github.com/bytom/vapor/errors" |
22 | 22 | "github.com/bytom/vapor/event" |
23 | - "github.com/bytom/vapor/proposal" | |
24 | 23 | "github.com/bytom/vapor/protocol" |
25 | 24 | "github.com/bytom/vapor/protocol/bc" |
26 | 25 | "github.com/bytom/vapor/protocol/bc/types" |
@@ -152,6 +151,10 @@ func getConsensusResult(c *protocol.Chain, store *database.Store, seq uint64, bl | ||
152 | 151 | } |
153 | 152 | |
154 | 153 | func TestRollback(t *testing.T) { |
154 | + fmt.Println("\n\n\n\n") | |
155 | + fmt.Println("consensus.ActiveNetParams.name", consensus.ActiveNetParams.Name) | |
156 | + consensus.ActiveNetParams.VotePendingBlockNumber = 0 | |
157 | + fmt.Println("consensus.ActiveNetParams.VotePendingBlockNumber:", consensus.ActiveNetParams.VotePendingBlockNumber) | |
155 | 158 | // genesisBlock := config.GenesisBlock() |
156 | 159 | testXpub, _ := hex.DecodeString("4d6f710dae8094c111450ca20e054c3aed59dfcb2d29543c29901a5903755e69273c2d8f2642a7baf94ebac88f1625af9f5eaf3b13a90de27eec3de78b9fb9ca") |
157 | 160 |
@@ -206,7 +209,7 @@ func TestRollback(t *testing.T) { | ||
206 | 209 | { |
207 | 210 | desc: "first round block", |
208 | 211 | startRunNum: 1, |
209 | - runBlockNum: 0, | |
212 | + runBlockNum: 1, | |
210 | 213 | }, |
211 | 214 | // { |
212 | 215 | // desc: "second add blocks", |
@@ -246,23 +249,11 @@ func TestRollback(t *testing.T) { | ||
246 | 249 | t.Fatal(err) |
247 | 250 | } |
248 | 251 | |
249 | - block, err := NewBlockTemplate(chain, accounts, timeStamp, warnDuration, criticalDuration) | |
252 | + block, err := NewBlockTemplate(chain, db, accounts, timeStamp, warnDuration, criticalDuration) | |
250 | 253 | if err != nil { |
251 | 254 | t.Fatal(err) |
252 | 255 | } |
253 | 256 | |
254 | - // bcBlock := types.MapBlock(block) | |
255 | - // verifyStatus := bcBlock.TransactionStatus.VerifyStatus | |
256 | - // fmt.Println("why", verifyStatus) | |
257 | - // fmt.Println("rollback_test, verifyStatus", len(verifyStatus)) | |
258 | - // for index := 0; index < len(verifyStatus); index++ { | |
259 | - // fmt.Println("verifyStatus[", index, "]", verifyStatus[index]) | |
260 | - // } | |
261 | - // fmt.Println("i:", i, len(block.Transactions)) | |
262 | - | |
263 | - // sleep(1) | |
264 | - // block.Transactions = append(block.Transactions, transactions...) | |
265 | - | |
266 | 257 | if _, err := chain.ProcessBlock(block); err != nil { |
267 | 258 | t.Fatal(err) |
268 | 259 | } |
@@ -297,7 +288,7 @@ func TestRollback(t *testing.T) { | ||
297 | 288 | } |
298 | 289 | |
299 | 290 | //block, err := proposal.NewBlockTemplate(chain, txPool, nil, timeStamp) |
300 | - block, err := proposal.NewBlockTemplate(chain, accounts, timeStamp, warnDuration, criticalDuration) | |
291 | + block, err := NewBlockTemplate(chain, db, accounts, timeStamp, warnDuration, criticalDuration) | |
301 | 292 | //block.Transactions = transactions |
302 | 293 | |
303 | 294 | // bcBlock := types.MapBlock(block) |
@@ -12,6 +12,9 @@ import ( | ||
12 | 12 | "github.com/bytom/vapor/account" |
13 | 13 | "github.com/bytom/vapor/blockchain/txbuilder" |
14 | 14 | "github.com/bytom/vapor/consensus" |
15 | + "github.com/bytom/vapor/database" | |
16 | + dbm "github.com/bytom/vapor/database/leveldb" | |
17 | + "github.com/bytom/vapor/database/storage" | |
15 | 18 | "github.com/bytom/vapor/errors" |
16 | 19 | "github.com/bytom/vapor/protocol" |
17 | 20 | "github.com/bytom/vapor/protocol/bc" |
@@ -37,13 +40,15 @@ func (a byTime) Swap(i, j int) { a[i], a[j] = a[j], a[i] } | ||
37 | 40 | func (a byTime) Less(i, j int) bool { return a[i].Added.Before(a[j].Added) } |
38 | 41 | |
39 | 42 | // NewBlockTemplate returns a new block template that is ready to be solved |
40 | -func NewBlockTemplate(chain *protocol.Chain, accountManager *account.Manager, timestamp uint64, warnDuration, criticalDuration time.Duration) (*types.Block, error) { | |
41 | - builder := newBlockBuilder(chain, accountManager, timestamp, warnDuration, criticalDuration) | |
43 | +func NewBlockTemplate(chain *protocol.Chain, db dbm.DB, accountManager *account.Manager, timestamp uint64, warnDuration, criticalDuration time.Duration) (*types.Block, error) { | |
44 | + fmt.Println("NewBlockTemplate") | |
45 | + builder := newBlockBuilder(chain, db, accountManager, timestamp, warnDuration, criticalDuration) | |
42 | 46 | return builder.build() |
43 | 47 | } |
44 | 48 | |
45 | 49 | type blockBuilder struct { |
46 | 50 | chain *protocol.Chain |
51 | + db dbm.DB | |
47 | 52 | accountManager *account.Manager |
48 | 53 | |
49 | 54 | block *types.Block |
@@ -56,7 +61,7 @@ type blockBuilder struct { | ||
56 | 61 | gasLeft int64 |
57 | 62 | } |
58 | 63 | |
59 | -func newBlockBuilder(chain *protocol.Chain, accountManager *account.Manager, timestamp uint64, warnDuration, criticalDuration time.Duration) *blockBuilder { | |
64 | +func newBlockBuilder(chain *protocol.Chain, db dbm.DB, accountManager *account.Manager, timestamp uint64, warnDuration, criticalDuration time.Duration) *blockBuilder { | |
60 | 65 | preBlockHeader := chain.BestBlockHeader() |
61 | 66 | block := &types.Block{ |
62 | 67 | BlockHeader: types.BlockHeader{ |
@@ -71,6 +76,7 @@ func newBlockBuilder(chain *protocol.Chain, accountManager *account.Manager, tim | ||
71 | 76 | |
72 | 77 | builder := &blockBuilder{ |
73 | 78 | chain: chain, |
79 | + db: db, | |
74 | 80 | accountManager: accountManager, |
75 | 81 | block: block, |
76 | 82 | txStatus: bc.NewTransactionStatus(), |
@@ -105,6 +111,7 @@ func (b *blockBuilder) applyCoinbaseTransaction() error { | ||
105 | 111 | |
106 | 112 | func (b *blockBuilder) applyVoteTransaction() error { |
107 | 113 | tx, err := b.createVoteTx(b.accountManager, b.block.Height) |
114 | + | |
108 | 115 | if err != nil { |
109 | 116 | return errors.Wrap(err, "fail on create vote tx") |
110 | 117 | } |
@@ -120,11 +127,32 @@ func (b *blockBuilder) applyVoteTransaction() error { | ||
120 | 127 | } |
121 | 128 | b.gasLeft -= gasState.GasUsed |
122 | 129 | |
130 | + batch := b.db.NewBatch() | |
131 | + view := &state.UtxoViewpoint{ | |
132 | + Entries: map[bc.Hash]*storage.UtxoEntry{ | |
133 | + tx.Tx.SpentOutputIDs[0]: &storage.UtxoEntry{Type: storage.VoteUTXOType, BlockHeight: 0, Spent: false}, | |
134 | + }, | |
135 | + } | |
136 | + //fmt.Println("[important] applyVoteTransaction go to save SpentOutputIDs", tx.Tx.SpentOutputIDs[0].String()) | |
137 | + if err := database.SaveUtxoView(batch, view); err != nil { | |
138 | + return err | |
139 | + } | |
140 | + batch.Write() | |
141 | + //fmt.Println("[important] batch write") | |
142 | + | |
143 | + // prevout := tx.Tx.SpentOutputIDs[0] | |
144 | + // utxoEntry, err := database.GetUtxo(b.db, &prevout) | |
145 | + // fmt.Println("[important] utxoEntry:", utxoEntry.String(), "err", err) | |
146 | + // txs := []*types.Tx{} | |
147 | + // txs = append(txs, tx) | |
148 | + // if err := b.applyTransactions(txs, timeoutWarn); err != nil { | |
149 | + // return err | |
150 | + // } | |
151 | + | |
123 | 152 | return err |
124 | 153 | } |
125 | 154 | |
126 | 155 | func (b *blockBuilder) applyTransactions(txs []*types.Tx, timeoutStatus uint8) error { |
127 | - fmt.Println("test.applyTransactions") | |
128 | 156 | tempTxs := []*types.Tx{} |
129 | 157 | for i := 0; i < len(txs); i++ { |
130 | 158 | if tempTxs = append(tempTxs, txs[i]); len(tempTxs) < batchApplyNum && i != len(txs)-1 { |
@@ -236,11 +264,6 @@ func (b *blockBuilder) calcBlockCommitment() (err error) { | ||
236 | 264 | } |
237 | 265 | |
238 | 266 | b.block.BlockHeader.BlockCommitment.TransactionStatusHash, err = types.TxStatusMerkleRoot(b.txStatus.VerifyStatus) |
239 | - for i := 0; i < len(b.txStatus.VerifyStatus); i++ { | |
240 | - fmt.Println("txStatus", i, b.txStatus.VerifyStatus[i]) | |
241 | - } | |
242 | - fmt.Println("b.txStatus.VerifyStatus", b.txStatus.VerifyStatus, len(b.txStatus.VerifyStatus)) | |
243 | - fmt.Println("b.block.BlockHeader.BlockCommitment.TransactionStatusHash", b.block.BlockHeader.BlockCommitment.TransactionStatusHash) | |
244 | 267 | return err |
245 | 268 | } |
246 | 269 |
@@ -282,11 +305,17 @@ func (b *blockBuilder) createVoteTx(accountManager *account.Manager, blockHeight | ||
282 | 305 | } |
283 | 306 | |
284 | 307 | builder := txbuilder.NewBuilder(time.Now()) |
285 | - if err = builder.AddInput(types.NewVetoInput(nil, bc.NewHash([32]byte{0xff}), *consensus.BTMAssetID, 100000000, 0, []byte{0x51}, testXpub), &txbuilder.SigningInstruction{}); err != nil { | |
308 | + // if err = builder.AddInput(types.NewVetoInput(nil, bc.NewHash([32]byte{0xff}), *consensus.BTMAssetID, 100000000, 0, []byte{0x51}, testXpub), &txbuilder.SigningInstruction{}); err != nil { | |
309 | + // return nil, err | |
310 | + // } | |
311 | + // if err = builder.AddOutput(types.NewIntraChainOutput(*consensus.BTMAssetID, 100000000, script)); err != nil { | |
312 | + // return nil, err | |
313 | + // } | |
314 | + | |
315 | + if err := builder.AddInput(types.NewSpendInput(nil, bc.NewHash([32]byte{0, 1}), *consensus.BTMAssetID, 100000000, 0, script), &txbuilder.SigningInstruction{}); err != nil { | |
286 | 316 | return nil, err |
287 | 317 | } |
288 | - | |
289 | - if err = builder.AddOutput(types.NewIntraChainOutput(*consensus.BTMAssetID, 100000000, script)); err != nil { | |
318 | + if err := builder.AddOutput(types.NewVoteOutput(*consensus.BTMAssetID, 100000000, script, testXpub)); err != nil { | |
290 | 319 | return nil, err |
291 | 320 | } |
292 | 321 |
@@ -305,6 +334,13 @@ func (b *blockBuilder) createVoteTx(accountManager *account.Manager, blockHeight | ||
305 | 334 | TxData: *txData, |
306 | 335 | Tx: types.MapTx(txData), |
307 | 336 | } |
337 | + | |
338 | + fmt.Println("tx.Tx.String", tx.Tx.String()) | |
339 | + //a := tx.Tx.SpentOutputIDs | |
340 | + for _, prevout := range tx.Tx.SpentOutputIDs { | |
341 | + fmt.Println("createVoteTx SpentOutputIDs", prevout.String()) | |
342 | + } | |
343 | + | |
308 | 344 | return tx, nil |
309 | 345 | } |
310 | 346 |
@@ -333,7 +369,7 @@ func createCoinbaseTxByReward(accountManager *account.Manager, blockHeight uint6 | ||
333 | 369 | script, err = accountManager.GetCoinbaseControlProgram() |
334 | 370 | arbitrary = append(arbitrary, accountManager.GetCoinbaseArbitrary()...) |
335 | 371 | } |
336 | - fmt.Println("blockHeight", blockHeight, "script:", script) | |
372 | + | |
337 | 373 | if err != nil { |
338 | 374 | return nil, err |
339 | 375 | } |