txMeta storage as struct

This commit is contained in:
Taylor Gerring 2015-04-01 12:14:35 +02:00
parent b860b67693
commit 86ba7432a9
2 changed files with 26 additions and 31 deletions

View File

@ -235,7 +235,7 @@ func (sm *BlockProcessor) processWithParent(block, parent *types.Block) (td *big
// This puts transactions in a extra db for rpc // This puts transactions in a extra db for rpc
for i, tx := range block.Transactions() { for i, tx := range block.Transactions() {
putTx(sm.extraDb, tx, block, i) putTx(sm.extraDb, tx, block, uint64(i))
} }
if uncle { if uncle {
@ -359,7 +359,7 @@ func (sm *BlockProcessor) GetLogs(block *types.Block) (logs state.Logs, err erro
return state.Logs(), nil return state.Logs(), nil
} }
func putTx(db common.Database, tx *types.Transaction, block *types.Block, i int) { func putTx(db common.Database, tx *types.Transaction, block *types.Block, i uint64) {
rlpEnc, err := rlp.EncodeToBytes(tx) rlpEnc, err := rlp.EncodeToBytes(tx)
if err != nil { if err != nil {
statelogger.Infoln("Failed encoding tx", err) statelogger.Infoln("Failed encoding tx", err)
@ -367,24 +367,18 @@ func putTx(db common.Database, tx *types.Transaction, block *types.Block, i int)
} }
db.Put(tx.Hash().Bytes(), rlpEnc) db.Put(tx.Hash().Bytes(), rlpEnc)
rlpEnc, err = rlp.EncodeToBytes(block.Hash().Bytes()) var txExtra struct {
BlockHash common.Hash
BlockIndex uint64
Index uint64
}
txExtra.BlockHash = block.Hash()
txExtra.BlockIndex = block.NumberU64()
txExtra.Index = i
rlpMeta, err := rlp.EncodeToBytes(txExtra)
if err != nil { if err != nil {
statelogger.Infoln("Failed encoding meta", err) statelogger.Infoln("Failed encoding meta", err)
return return
} }
db.Put(append(tx.Hash().Bytes(), 0x0001), rlpEnc) db.Put(append(tx.Hash().Bytes(), 0x0001), rlpMeta)
rlpEnc, err = rlp.EncodeToBytes(block.Number().Bytes())
if err != nil {
statelogger.Infoln("Failed encoding meta", err)
return
}
db.Put(append(tx.Hash().Bytes(), 0x0002), rlpEnc)
rlpEnc, err = rlp.EncodeToBytes(i)
if err != nil {
statelogger.Infoln("Failed encoding meta", err)
return
}
db.Put(append(tx.Hash().Bytes(), 0x0003), rlpEnc)
} }

View File

@ -19,6 +19,7 @@ import (
"github.com/ethereum/go-ethereum/event/filter" "github.com/ethereum/go-ethereum/event/filter"
"github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/miner" "github.com/ethereum/go-ethereum/miner"
"github.com/ethereum/go-ethereum/rlp"
) )
var ( var (
@ -191,20 +192,20 @@ func (self *XEth) EthTransactionByHash(hash string) (tx *types.Transaction, blha
tx = types.NewTransactionFromBytes(data) tx = types.NewTransactionFromBytes(data)
} }
// blockhash // meta
data, _ = self.backend.ExtraDb().Get(append(common.FromHex(hash), 0x0001)) var txExtra struct {
if len(data) != 0 { BlockHash common.Hash
blhash = common.BytesToHash(data) BlockIndex int64
Index uint64
} }
// blocknum
data, _ = self.backend.ExtraDb().Get(append(common.FromHex(hash), 0x0002)) v, _ := self.backend.ExtraDb().Get(append(common.FromHex(hash), 0x0001))
if len(data) != 0 { r := bytes.NewReader(v)
blnum = common.Bytes2Big(data) err := rlp.Decode(r, &txExtra)
} if err == nil {
// txindex blhash = txExtra.BlockHash
data, _ = self.backend.ExtraDb().Get(append(common.FromHex(hash), 0x0003)) blnum = big.NewInt(txExtra.BlockIndex)
if len(data) != 0 { txi = txExtra.Index
txi = common.BytesToNumber(data)
} }
return return