• R/O
  • HTTP
  • SSH
  • HTTPS

vapor: 提交

Golang implemented sidechain for Bytom


Commit MetaInfo

修订版43c887470920a4a7592eabb0339977bbd6f0e3d1 (tree)
时间2020-02-24 20:38:58
作者ipqhjjybj <ipqhjjybj@qq.c...>
Commiteripqhjjybj

Log Message

s

更改概述

差异

--- a/database/utxo_view.go
+++ b/database/utxo_view.go
@@ -79,17 +79,13 @@ func GetUtxo(db dbm.DB, hash *bc.Hash) (*storage.UtxoEntry, error) {
7979 }
8080
8181 func saveUtxoView(batch dbm.Batch, view *state.UtxoViewpoint) error {
82- fmt.Println("[important] now go to saveUtxoView len entries:", len(view.Entries))
8382 for key, entry := range view.Entries {
84- fmt.Println("[important] saveUtxoView key:", key.String(), " entry:", entry.String())
8583 if entry.Type == storage.CrosschainUTXOType && !entry.Spent {
86- fmt.Println("[important] delete key:", calcUtxoKey(&key))
8784 batch.Delete(calcUtxoKey(&key))
8885 continue
8986 }
9087
9188 if entry.Type == storage.NormalUTXOType && entry.Spent {
92- fmt.Println("[important] delete key:", calcUtxoKey(&key))
9389 batch.Delete(calcUtxoKey(&key))
9490 continue
9591 }
@@ -98,7 +94,6 @@ func saveUtxoView(batch dbm.Batch, view *state.UtxoViewpoint) error {
9894 if err != nil {
9995 return errors.Wrap(err, "marshaling utxo entry")
10096 }
101- fmt.Println("[important set] calcUtxoKey(&key)", calcUtxoKey(&key))
10297 batch.Set(calcUtxoKey(&key), b)
10398 }
10499 return nil
--- a/test/rollback_test.go
+++ b/test/rollback_test.go
@@ -78,16 +78,14 @@ const (
7878 // derivied private key: c80fbc34475fc9447753c00820d8448851c87f07e6bdde349260862c9bca5b4bb2e62c15e129067af869ebdf66e5829e61d6f2e47447395cc18c4166b06e8473
7979 // derivied public key: 59184c0f1f4f13b8b256ac82df30dc12cfd66b6e09a28054933f848dc51b9a89b2e62c15e129067af869ebdf66e5829e61d6f2e47447395cc18c4166b06e8473
8080
81+// example to get key , derivateKey
8182 func getKey() {
8283 xprv, _ := chainkd.NewXPrv(nil)
8384 fmt.Println("secretKey:", xprv)
84-
8585 xpub := xprv.XPub()
8686 fmt.Println("publicKey:", xpub)
87-
8887 derivateKey := xprv.Derive(fedConsensusPath)
8988 fmt.Println("derivateSecretKey:", derivateKey)
90-
9189 derivatePublicKey := derivateKey.XPub()
9290 fmt.Println("derivatePublicKey", derivatePublicKey)
9391 }
--- a/test/rollback_util.go
+++ b/test/rollback_util.go
@@ -111,7 +111,6 @@ func (b *blockBuilder) applyCoinbaseTransaction() error {
111111
112112 func (b *blockBuilder) applyVoteTransaction() error {
113113 tx, err := b.createVoteTx(b.accountManager, b.block.Height)
114-
115114 if err != nil {
116115 return errors.Wrap(err, "fail on create vote tx")
117116 }
@@ -125,18 +124,20 @@ func (b *blockBuilder) applyVoteTransaction() error {
125124 if err := b.txStatus.SetStatus(1, false); err != nil {
126125 return err
127126 }
127+
128128 b.gasLeft -= gasState.GasUsed
129+ entries := map[bc.Hash]*storage.UtxoEntry{}
130+ for _, prevOut := range tx.Tx.SpentOutputIDs {
131+ utxoEntry := &storage.UtxoEntry{Type: storage.VoteUTXOType, BlockHeight: b.block.Height, Spent: false}
132+ entries[prevOut] = utxoEntry
133+ }
129134
130135 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: b.block.Height, Spent: false},
134- },
135- }
136- fmt.Println("[important] applyVoteTransaction go to save SpentOutputIDs", tx.Tx.SpentOutputIDs[0].String())
136+ view := &state.UtxoViewpoint{Entries: entries}
137137 if err := database.SaveUtxoView(batch, view); err != nil {
138138 return err
139139 }
140+
140141 batch.Write()
141142
142143 return err
@@ -149,7 +150,6 @@ func (b *blockBuilder) applyTransactions(txs []*types.Tx, timeoutStatus uint8) e
149150 continue
150151 }
151152
152- fmt.Println("test", "i=", i, "preValidateTxs")
153153 results, gasLeft := preValidateTxs(tempTxs, b.chain, b.utxoView, b.gasLeft)
154154 for _, result := range results {
155155 if result.err != nil && !result.gasOnly {
@@ -295,16 +295,20 @@ func (b *blockBuilder) createVoteTx(accountManager *account.Manager, blockHeight
295295 }
296296
297297 builder := txbuilder.NewBuilder(time.Now())
298- // if err = builder.AddInput(types.NewVetoInput(nil, bc.NewHash([32]byte{0xff}), *consensus.BTMAssetID, 100000000, 0, []byte{0x51}, testXpub), &txbuilder.SigningInstruction{}); err != nil {
299- // return nil, err
300- // }
301- // if err = builder.AddOutput(types.NewIntraChainOutput(*consensus.BTMAssetID, 100000000, script)); err != nil {
302- // return nil, err
303- // }
298+
299+ if blockHeight > 1 {
300+ if err = builder.AddInput(types.NewVetoInput(nil, bc.NewHash([32]byte{0xff}), *consensus.BTMAssetID, 10000000+blockHeight, 0, []byte{0x51}, testXpub), &txbuilder.SigningInstruction{}); err != nil {
301+ return nil, err
302+ }
303+ if err = builder.AddOutput(types.NewIntraChainOutput(*consensus.BTMAssetID, 10000000, script)); err != nil {
304+ return nil, err
305+ }
306+ }
304307
305308 if err := builder.AddInput(types.NewSpendInput(nil, bc.NewHash([32]byte{0, 1}), *consensus.BTMAssetID, 100000000+blockHeight, 0, script), &txbuilder.SigningInstruction{}); err != nil {
306309 return nil, err
307310 }
311+
308312 if err := builder.AddOutput(types.NewVoteOutput(*consensus.BTMAssetID, 100000000, script, testXpub)); err != nil {
309313 return nil, err
310314 }
@@ -325,12 +329,6 @@ func (b *blockBuilder) createVoteTx(accountManager *account.Manager, blockHeight
325329 Tx: types.MapTx(txData),
326330 }
327331
328- fmt.Println("tx.Tx.String", tx.Tx.String())
329- //a := tx.Tx.SpentOutputIDs
330- for _, prevout := range tx.Tx.SpentOutputIDs {
331- fmt.Println("createVoteTx SpentOutputIDs", prevout.String())
332- }
333-
334332 return tx, nil
335333 }
336334
Show on old repository browser