Skip to content

Commit

Permalink
Merge pull request #78 from 0xcregis/release-0.5.1
Browse files Browse the repository at this point in the history
fix: Release 0.5.1
  • Loading branch information
sunjiangjun authored Nov 14, 2023
2 parents 88e46ec + 3840e18 commit 2ba4de3
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 13 deletions.
14 changes: 10 additions & 4 deletions collect/service/cmd/chain/bnb/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (s *Service) GetBlockByHash(blockHash string, eLog *logrus.Entry, flag bool
return nil, nil
}

r := &collect.BlockInterface{BlockHash: block.BlockHash, BlockNumber: block.BlockNumber, Block: block}
r := &collect.BlockInterface{BlockHash: block.BlockHash, BlockNumber: block.BlockNumber, Block: block, BlockTime: block.BlockTime}
if !flag { //仅区块,不涉及交易
return r, nil
}
Expand Down Expand Up @@ -118,7 +118,6 @@ func (s *Service) GetBlockByHash(blockHash string, eLog *logrus.Entry, flag bool
txs = append(txs, t)
}
}
//r := &service.BlockInterface{BlockHash: block.BlockHash, BlockNumber: block.BlockNumber, Block: block}
return r, txs
}

Expand Down Expand Up @@ -158,7 +157,7 @@ func (s *Service) GetBlockByNumber(blockNumber string, eLog *logrus.Entry, flag
return nil, nil
}

r := &collect.BlockInterface{BlockHash: block.BlockHash, BlockNumber: block.BlockNumber, Block: block}
r := &collect.BlockInterface{BlockHash: block.BlockHash, BlockNumber: block.BlockNumber, Block: block, BlockTime: block.BlockTime}
if !flag { //仅区块数据,不涉及交易
return r, nil
}
Expand Down Expand Up @@ -191,7 +190,6 @@ func (s *Service) GetBlockByNumber(blockNumber string, eLog *logrus.Entry, flag
eLog.Warnf("the tx is ignored,hash=%v", tx.TxHash)
}
}
//r := &service.BlockInterface{BlockHash: block.BlockHash, BlockNumber: block.BlockNumber, Block: block}
return r, txs
}

Expand Down Expand Up @@ -220,6 +218,14 @@ func (s *Service) GetTx(txHash string, eLog *logrus.Entry) *collect.TxInterface
return nil
}

//fix tx.time
if len(tx.TxTime) < 1 {
b, _ := s.GetBlockByNumber(tx.BlockNumber, eLog, false)
if b != nil {
tx.TxTime = b.BlockTime
}
}

receipt, err := s.GetReceipt(tx.TxHash, eLog)
if err != nil {
eLog.Errorf("GetTx|BlockChainCode=%v,err=%v,txHash=%v", s.chain.BlockChainCode, err.Error(), tx.TxHash)
Expand Down
14 changes: 10 additions & 4 deletions collect/service/cmd/chain/ether/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (s *Service) GetBlockByHash(blockHash string, eLog *logrus.Entry, flag bool
return nil, nil
}

r := &collect.BlockInterface{BlockHash: block.BlockHash, BlockNumber: block.BlockNumber, Block: block}
r := &collect.BlockInterface{BlockHash: block.BlockHash, BlockNumber: block.BlockNumber, Block: block, BlockTime: block.BlockTime}
if !flag { //仅区块,不涉及交易
return r, nil
}
Expand Down Expand Up @@ -118,7 +118,6 @@ func (s *Service) GetBlockByHash(blockHash string, eLog *logrus.Entry, flag bool
txs = append(txs, t)
}
}
//r := &service.BlockInterface{BlockHash: block.BlockHash, BlockNumber: block.BlockNumber, Block: block}
return r, txs
}

Expand Down Expand Up @@ -158,7 +157,7 @@ func (s *Service) GetBlockByNumber(blockNumber string, eLog *logrus.Entry, flag
return nil, nil
}

r := &collect.BlockInterface{BlockHash: block.BlockHash, BlockNumber: block.BlockNumber, Block: block}
r := &collect.BlockInterface{BlockHash: block.BlockHash, BlockNumber: block.BlockNumber, Block: block, BlockTime: block.BlockTime}
if !flag { //仅区块数据,不涉及交易
return r, nil
}
Expand Down Expand Up @@ -191,7 +190,6 @@ func (s *Service) GetBlockByNumber(blockNumber string, eLog *logrus.Entry, flag
eLog.Warnf("the tx is ignored,hash=%v", tx.TxHash)
}
}
//r := &service.BlockInterface{BlockHash: block.BlockHash, BlockNumber: block.BlockNumber, Block: block}
return r, txs
}

Expand Down Expand Up @@ -220,6 +218,14 @@ func (s *Service) GetTx(txHash string, eLog *logrus.Entry) *collect.TxInterface
return nil
}

//fix tx.time
if len(tx.TxTime) < 1 {
b, _ := s.GetBlockByNumber(tx.BlockNumber, eLog, false)
if b != nil {
tx.TxTime = b.BlockTime
}
}

receipt, err := s.GetReceipt(tx.TxHash, eLog)
if err != nil {
eLog.Errorf("GetTx|BlockChainCode=%v,err=%v,txHash=%v", s.chain.BlockChainCode, err.Error(), tx.TxHash)
Expand Down
6 changes: 5 additions & 1 deletion collect/service/cmd/chain/ether/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ func TestService_GetBlockByNumber(t *testing.T) {
func TestService_GetTx(t *testing.T) {
s, _, x := Init()
tx := s.GetTx("0xb7959ab3ed0f8b424f897ba8ec28168358079be0030a9337d20252f7d4c18cfd", x.WithFields(logrus.Fields{}))
t.Log(tx)
if tx == nil {
t.Error("fail")
} else {
t.Logf("%+v", tx.Tx)
}
}

func TestService_GetReceipt(t *testing.T) {
Expand Down
14 changes: 10 additions & 4 deletions collect/service/cmd/chain/polygonpos/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (s *Service) GetBlockByHash(blockHash string, eLog *logrus.Entry, flag bool
return nil, nil
}

r := &collect.BlockInterface{BlockHash: block.BlockHash, BlockNumber: block.BlockNumber, Block: block}
r := &collect.BlockInterface{BlockHash: block.BlockHash, BlockNumber: block.BlockNumber, Block: block, BlockTime: block.BlockTime}
if !flag { //仅区块,不涉及交易
return r, nil
}
Expand Down Expand Up @@ -118,7 +118,6 @@ func (s *Service) GetBlockByHash(blockHash string, eLog *logrus.Entry, flag bool
txs = append(txs, t)
}
}
//r := &service.BlockInterface{BlockHash: block.BlockHash, BlockNumber: block.BlockNumber, Block: block}
return r, txs
}

Expand Down Expand Up @@ -158,7 +157,7 @@ func (s *Service) GetBlockByNumber(blockNumber string, eLog *logrus.Entry, flag
return nil, nil
}

r := &collect.BlockInterface{BlockHash: block.BlockHash, BlockNumber: block.BlockNumber, Block: block}
r := &collect.BlockInterface{BlockHash: block.BlockHash, BlockNumber: block.BlockNumber, Block: block, BlockTime: block.BlockTime}
if !flag { //仅区块数据,不涉及交易
return r, nil
}
Expand Down Expand Up @@ -191,7 +190,6 @@ func (s *Service) GetBlockByNumber(blockNumber string, eLog *logrus.Entry, flag
eLog.Warnf("the tx is ignored,hash=%v", tx.TxHash)
}
}
//r := &service.BlockInterface{BlockHash: block.BlockHash, BlockNumber: block.BlockNumber, Block: block}
return r, txs
}

Expand Down Expand Up @@ -220,6 +218,14 @@ func (s *Service) GetTx(txHash string, eLog *logrus.Entry) *collect.TxInterface
return nil
}

//fix tx.time
if len(tx.TxTime) < 1 {
b, _ := s.GetBlockByNumber(tx.BlockNumber, eLog, false)
if b != nil {
tx.TxTime = b.BlockTime
}
}

receipt, err := s.GetReceipt(tx.TxHash, eLog)
if err != nil {
eLog.Errorf("GetTx|BlockChainCode=%v,err=%v,txHash=%v", s.chain.BlockChainCode, err.Error(), tx.TxHash)
Expand Down
1 change: 1 addition & 0 deletions collect/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ type Block struct {

type BlockInterface struct {
BlockHash string `json:"hash" gorm:"column:hash"`
BlockTime string `json:"blockTime"`
BlockNumber string `json:"number" gorm:"column:block_number"`
Block interface{} `json:"block"`
}

0 comments on commit 2ba4de3

Please sign in to comment.