Skip to content

Commit f76cfda

Browse files
libangzhuvipwzw
authored andcommitted
[[FIX]] fix issue #1279
1 parent 5c6b008 commit f76cfda

File tree

3 files changed

+30
-43
lines changed

3 files changed

+30
-43
lines changed

blockchain/blockstore.go

+10-22
Original file line numberDiff line numberDiff line change
@@ -404,13 +404,10 @@ func (bs *BlockStore) HasTx(key []byte) (bool, error) {
404404
cfg := bs.client.GetConfig()
405405
if cfg.IsEnable("quickIndex") {
406406
if _, err := bs.db.Get(types.CalcTxShortKey(key)); err != nil {
407-
if _, etxErr := bs.db.Get(cfg.CalcEtxKey(key)); etxErr != nil {
408-
if err == dbm.ErrNotFoundInDb {
409-
return false, nil
410-
}
411-
return false, err
407+
if err == dbm.ErrNotFoundInDb {
408+
return false, nil
412409
}
413-
410+
return false, err
414411
}
415412
//通过短hash查询交易存在时,需要再通过全hash索引查询一下。
416413
//避免短hash重复,而全hash不一样的情况
@@ -420,12 +417,10 @@ func (bs *BlockStore) HasTx(key []byte) (bool, error) {
420417
// 直接查全哈希,单次查询平均耗时24000ns
421418
}
422419
if _, err := bs.db.Get(cfg.CalcTxKey(key)); err != nil {
423-
if _, etxErr := bs.db.Get(cfg.CalcEtxKey(key)); etxErr != nil {
424-
if err == dbm.ErrNotFoundInDb {
425-
return false, nil
426-
}
427-
return false, err
420+
if err == dbm.ErrNotFoundInDb {
421+
return false, nil
428422
}
423+
return false, err
429424
}
430425
return true, nil
431426
}
@@ -668,24 +663,17 @@ func (bs *BlockStore) GetTx(hash []byte) (*types.TxResult, error) {
668663
if rawBytes == nil || err != nil {
669664
//查询eth 交易哈希对应的Chin33的交易
670665
realHash, etxerr := bs.db.Get(cfg.CalcEtxKey(hash))
671-
if etxerr == nil && realHash != nil {
666+
if etxerr == nil && realHash != nil { // 查到eth txhash 映射关系
672667
rawBytes, err = bs.db.Get(cfg.CalcTxKey(realHash))
673-
if rawBytes == nil || err != nil {
674-
if err != dbm.ErrNotFoundInDb {
675-
storeLog.Error("GetTx", "hash", common.ToHex(hash), "err", err)
676-
}
677-
err = errors.New("tx not exist")
678-
return nil, err
679-
}
680-
} else {
681-
//查不到映射关系
668+
}
669+
if err != nil {
682670
if err != dbm.ErrNotFoundInDb {
683671
storeLog.Error("GetTx", "hash", common.ToHex(hash), "err", err)
684672
}
673+
685674
err = errors.New("tx not exist")
686675
return nil, err
687676
}
688-
689677
}
690678

691679
var txResult types.TxResult

rpc/ethrpc/eth/eth.go

+9-6
Original file line numberDiff line numberDiff line change
@@ -143,20 +143,23 @@ func (e *ethHandler) GetBlockByHash(txhash common.Hash, full bool) (*types.Block
143143
//GetTransactionByHash eth_getTransactionByHash
144144
func (e *ethHandler) GetTransactionByHash(txhash common.Hash) (*types.Transaction, error) {
145145
log.Debug("GetTransactionByHash", "txhash", txhash)
146-
var req ctypes.ReqHashes
147-
req.Hashes = append(req.Hashes, txhash.Bytes())
148-
txdetails, err := e.cli.GetTransactionByHash(&req)
146+
var req ctypes.ReqHash
147+
req.Hash = txhash.Bytes()
148+
149+
txdetail, err := e.cli.QueryTx(&req)
149150
if err != nil {
150151
return nil, err
151152
}
152153
var blockHash []byte
153-
if len(txdetails.GetTxs()) != 0 {
154-
blockNum := txdetails.GetTxs()[0].Height
154+
if txdetail.Tx != nil {
155+
blockNum := txdetail.GetHeight()
155156
hashReply, err := e.cli.GetBlockHash(&ctypes.ReqInt{Height: blockNum})
156157
if err == nil {
157158
blockHash = hashReply.GetHash()
158159
}
159-
txs, _, err := types.TxDetailsToEthReceipts(txdetails, common.BytesToHash(blockHash), e.cfg)
160+
var txdetails ctypes.TransactionDetails
161+
txdetails.Txs = append(txdetails.Txs, txdetail)
162+
txs, _, err := types.TxDetailsToEthReceipts(&txdetails, common.BytesToHash(blockHash), e.cfg)
160163
if err != nil {
161164
return nil, err
162165
}

types/tx.go

+11-15
Original file line numberDiff line numberDiff line change
@@ -901,23 +901,19 @@ func (tx *Transaction) Clone() *Transaction {
901901

902902
//GetEthTxHash 获取eth 兼容交易的交易哈希
903903
func (tx *Transaction) GetEthTxHash() []byte {
904-
if IsEthSignID(tx.GetSignature().GetTy()) {
905-
payload := tx.GetPayload()
906-
var evmaction EVMContractAction4Chain33
907-
err := Decode(payload, &evmaction)
908-
if err == nil {
909-
note := evmaction.GetNote()
910-
var etx etypes.Transaction
911-
etxBytes, err := common.FromHex(note)
912-
if err == nil {
913-
if err = etx.UnmarshalBinary(etxBytes); err == nil {
914-
return etx.Hash().Bytes()
915-
}
916-
917-
}
904+
if !IsEthSignID(tx.GetSignature().GetTy()) {
905+
return nil
906+
}
907+
var evmaction EVMContractAction4Chain33
908+
err := Decode(tx.GetPayload(), &evmaction)
909+
if err == nil {
910+
var etx etypes.Transaction
911+
etxBytes, err := common.FromHex(evmaction.GetNote())
912+
if err == nil && etx.UnmarshalBinary(etxBytes) == nil {
913+
return etx.Hash().Bytes()
918914
}
919-
920915
}
916+
921917
return nil
922918
}
923919

0 commit comments

Comments
 (0)