fix(*): fix nil Hash for quering tx, receipt and block

This commit is contained in:
Alexader 2020-10-23 15:29:47 +08:00
parent c96b0ddf60
commit 169e678d31
5 changed files with 21 additions and 23 deletions

View File

@ -2,6 +2,7 @@ package grpc
import (
"context"
"fmt"
"github.com/meshplus/bitxhub-kit/types"
"github.com/meshplus/bitxhub-model/pb"
@ -9,6 +10,8 @@ import (
func (cbs *ChainBrokerService) GetReceipt(ctx context.Context, req *pb.TransactionHashMsg) (*pb.Receipt, error) {
hash := types.NewHashByStr(req.TxHash)
if hash == nil {
return nil, fmt.Errorf("invalid format of receipt hash for querying receipt")
}
return cbs.api.Broker().GetReceipt(hash)
}

View File

@ -47,6 +47,12 @@ func (cbs *ChainBrokerService) checkTransaction(tx *pb.Transaction) error {
if tx.Payload == nil && tx.Amount == 0 && tx.IBTP == nil {
return fmt.Errorf("tx payload, ibtp and amount can't all be empty")
}
if tx.From == nil {
return fmt.Errorf("tx from address is nil")
}
if tx.To == nil {
tx.To = &types.Address{}
}
emptyAddress := &types.Address{}
if tx.From.String() == emptyAddress.String() {
@ -102,6 +108,9 @@ func (cbs *ChainBrokerService) sendView(tx *pb.Transaction) (*pb.Receipt, error)
func (cbs *ChainBrokerService) GetTransaction(ctx context.Context, req *pb.TransactionHashMsg) (*pb.GetTransactionResponse, error) {
hash := types.NewHashByStr(req.TxHash)
if hash == nil {
return nil, fmt.Errorf("invalid format of tx hash for querying transaction")
}
tx, err := cbs.api.Broker().GetTransaction(hash)
if err != nil {
return nil, err

2
go.mod
View File

@ -19,7 +19,7 @@ require (
github.com/libp2p/go-libp2p-core v0.5.6
github.com/magiconair/properties v1.8.1
github.com/meshplus/bitxhub-core v0.1.0-rc1.0.20201022032823-4591a8883995
github.com/meshplus/bitxhub-kit v1.1.2-0.20201021105954-468d0a9d7957
github.com/meshplus/bitxhub-kit v1.1.2-0.20201023073721-052e6b89ea39
github.com/meshplus/bitxhub-model v1.1.2-0.20201021152621-0b3c17c54b23
github.com/meshplus/go-lightp2p v0.0.0-20200817105923-6b3aee40fa54
github.com/mitchellh/go-homedir v1.1.0

22
go.sum
View File

@ -52,10 +52,6 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/bitxhub/parallel-executor v0.0.0-20201016065313-8057d544998e h1:nz0MelhdC0A8yPGAL2gM/94xD8KgRVjYX0QejiP/f0Q=
github.com/bitxhub/parallel-executor v0.0.0-20201016065313-8057d544998e/go.mod h1:rMcZvKgOfyIesmOimA6LXjAvGZyJAXhPPRejEYmsS+k=
github.com/bitxhub/parallel-executor v0.0.0-20201022141235-a2d73478b5a0 h1:GcQzZb6D130tRBPauKjDP1blqOpqXH5OTgr76SECz1s=
github.com/bitxhub/parallel-executor v0.0.0-20201022141235-a2d73478b5a0/go.mod h1:nQGC3gfSjr5iWLTuQdbn9d1HjfXaxV2XsLovIyVSDi8=
github.com/btcsuite/btcd v0.0.0-20171128150713-2e60448ffcc6/go.mod h1:Dmm/EzmjnCiweXmzRIAiUWCInVmPgjkzgv5k4tVyXiQ=
github.com/btcsuite/btcd v0.0.0-20190115013929-ed77733ec07d/go.mod h1:d3C0AkH6BRcvO8T0UEPu53cnw4IbV63x1bEjildYhO0=
github.com/btcsuite/btcd v0.0.0-20190213025234-306aecffea32/go.mod h1:DrZx5ec/dmnfpw9KyYoQyYo7d0KEvTkk/5M/vbZjAr8=
@ -577,10 +573,6 @@ github.com/meshplus/bitxhub v1.0.0-rc2/go.mod h1:ijWzPl7GExD3IKXJ0LhV4q680kDy1IF
github.com/meshplus/bitxhub-core v0.1.0-rc1/go.mod h1:ayq95vbGEh/G2nKyPeXPc62zanWhDuusVpIDAHm4Rk0=
github.com/meshplus/bitxhub-core v0.1.0-rc1.0.20201016031620-9d2d859c4069 h1:tAKmTgR/I4JbQcrP9I+dFtApQdWc9e7dzG0NqDd65fg=
github.com/meshplus/bitxhub-core v0.1.0-rc1.0.20201016031620-9d2d859c4069/go.mod h1:z60hNhn5jgGgQiUOE0AKK2vM3WKQfekhljHjDI5j/Nw=
github.com/meshplus/bitxhub-core v0.1.0-rc1.0.20201021060002-1c1bbd9b125b h1:5t2GrGqn4Y5HwdCVoICFVFGfKdwOgXDtsJFfBXiB/aY=
github.com/meshplus/bitxhub-core v0.1.0-rc1.0.20201021060002-1c1bbd9b125b/go.mod h1:rwnRbid5w7VvQqKTix2yEttI5kaCyCgmV+IZwcewz6Q=
github.com/meshplus/bitxhub-core v0.1.0-rc1.0.20201021153523-274a013bfd41 h1:4D9k/vhslbJjT4e2chBlvLYQrDh7jJ0IxK1gMl0BmJg=
github.com/meshplus/bitxhub-core v0.1.0-rc1.0.20201021153523-274a013bfd41/go.mod h1:/SQKAylZzPup1JTc3WoApLEsB4uV3enXB2ib6jLpYUk=
github.com/meshplus/bitxhub-core v0.1.0-rc1.0.20201022032823-4591a8883995 h1:0QCTie7+Xb+qEKlteh7v39ieiF/QXtOxq0vHUbhAqcQ=
github.com/meshplus/bitxhub-core v0.1.0-rc1.0.20201022032823-4591a8883995/go.mod h1:/SQKAylZzPup1JTc3WoApLEsB4uV3enXB2ib6jLpYUk=
github.com/meshplus/bitxhub-kit v1.0.0-rc1/go.mod h1:ra/AhOkPvpElI+wXrB9G6DjdcrdxFU3vMwA5MYKr9D0=
@ -588,24 +580,14 @@ github.com/meshplus/bitxhub-kit v1.0.0-rc2/go.mod h1:1XDQRhdVkFDwQH3SgKKyy+cpUyf
github.com/meshplus/bitxhub-kit v1.0.0/go.mod h1:7cWyhXWZfrQ3+EaxkRoXfuiG3Y5R9DXYJomeZKkETW8=
github.com/meshplus/bitxhub-kit v1.0.1-0.20200903112208-fb288271c55c/go.mod h1:8Pprmnq+2fFi5kJP0qcbwPl/fe22nro0OamjtwD0LJM=
github.com/meshplus/bitxhub-kit v1.0.1-0.20200914065214-5161497a783c/go.mod h1:Whtgcr25HOF6iJv0Ib5/BPnEXq9iNFO89j8JQkElISk=
github.com/meshplus/bitxhub-kit v1.1.1 h1:vkPO88oA3+Kpc0N8lIgfj/U52KBuI+633hPbMYt1xm8=
github.com/meshplus/bitxhub-kit v1.1.1/go.mod h1:r4l4iqn0RPJreb/OmoYKfjCjQJrXpZX++6Qc31VG/1k=
github.com/meshplus/bitxhub-kit v1.1.2-0.20201021090332-9830eaa971d4 h1:4nlHdSmzaigzpeMS/bcP60T5/Hwnv3TmGLRFf+9k1t8=
github.com/meshplus/bitxhub-kit v1.1.2-0.20201021090332-9830eaa971d4/go.mod h1:r4l4iqn0RPJreb/OmoYKfjCjQJrXpZX++6Qc31VG/1k=
github.com/meshplus/bitxhub-kit v1.1.2-0.20201021105954-468d0a9d7957 h1:1a3wYo2HQw9/yg5LfAPJ1En90pPbMwRlaVssxOLG97w=
github.com/meshplus/bitxhub-kit v1.1.2-0.20201021105954-468d0a9d7957/go.mod h1:r4l4iqn0RPJreb/OmoYKfjCjQJrXpZX++6Qc31VG/1k=
github.com/meshplus/bitxhub-kit v1.1.2-0.20201023073721-052e6b89ea39 h1:zgkQfnwsJZgyj3aGECrQ3HFOAcekjVRxbWUEERPW5u0=
github.com/meshplus/bitxhub-kit v1.1.2-0.20201023073721-052e6b89ea39/go.mod h1:r4l4iqn0RPJreb/OmoYKfjCjQJrXpZX++6Qc31VG/1k=
github.com/meshplus/bitxhub-model v1.0.0-rc3/go.mod h1:ZCctQIYTlE3vJ8Lhkrgs9bWwNA+Dw4JzojOSIzLVU6E=
github.com/meshplus/bitxhub-model v1.0.0-rc4.0.20200514093243-7e8ae60d1c19/go.mod h1:QK8aACbxtZEA3Hk1BOCirW0uxMWLsMrLDpWz9FweIKM=
github.com/meshplus/bitxhub-model v1.0.0-rc4.0.20201009112846-79d2e6ddf10d h1:q4Vig+IVhBvARLyeOsFw8gAdor0ajiBl6lGch1N65sk=
github.com/meshplus/bitxhub-model v1.0.0-rc4.0.20201009112846-79d2e6ddf10d/go.mod h1:QK8aACbxtZEA3Hk1BOCirW0uxMWLsMrLDpWz9FweIKM=
github.com/meshplus/bitxhub-model v1.1.1 h1:/0Si29e14YW1GUbkJbCL8A70yXzxyiV/u36kxFC+gqI=
github.com/meshplus/bitxhub-model v1.1.1/go.mod h1:lUl9vPZXM9tP+B0ABRW/2eOW/6KCmjFTdoiTj5Vut/A=
github.com/meshplus/bitxhub-model v1.1.2-0.20201021121200-409ba3cf9d4b h1:cyK/HwEygdDhZGXUVzd/EoqXmL38dBum1aWEwj7IPks=
github.com/meshplus/bitxhub-model v1.1.2-0.20201021121200-409ba3cf9d4b/go.mod h1:lUl9vPZXM9tP+B0ABRW/2eOW/6KCmjFTdoiTj5Vut/A=
github.com/meshplus/bitxhub-model v1.1.2-0.20201021121624-82edb1eb4937 h1:FILaXFyfTDqP4p0Vbg37giRv1LyWdIPLGQ/3zd3U7fs=
github.com/meshplus/bitxhub-model v1.1.2-0.20201021121624-82edb1eb4937/go.mod h1:lUl9vPZXM9tP+B0ABRW/2eOW/6KCmjFTdoiTj5Vut/A=
github.com/meshplus/bitxhub-model v1.1.2-0.20201021151909-ce32cce89a79 h1:P7JByZx34rUbplyRKyOWMdWJ5t6KAhlZ9JoPiII7vr0=
github.com/meshplus/bitxhub-model v1.1.2-0.20201021151909-ce32cce89a79/go.mod h1:4qWBZx5wv7WZzUqiuBsbkQqQ2Ju8aOFpsoNpBBNy8Us=
github.com/meshplus/bitxhub-model v1.1.2-0.20201021152621-0b3c17c54b23 h1:ys+2VjPrt6nr5xEVgRsVxowipkF425IOcI5HV53M5bA=
github.com/meshplus/bitxhub-model v1.1.2-0.20201021152621-0b3c17c54b23/go.mod h1:4qWBZx5wv7WZzUqiuBsbkQqQ2Ju8aOFpsoNpBBNy8Us=
github.com/meshplus/go-bitxhub-client v1.0.0-rc3/go.mod h1:FpiCyf6KhydcqthrHdvvPhbPIcD92b+Ju8T7WvQtSyM=

View File

@ -77,7 +77,11 @@ func (b *BrokerAPI) GetBlock(mode string, value string) (*pb.Block, error) {
}
return b.bxh.Ledger.GetBlock(height)
case "HASH":
return b.bxh.Ledger.GetBlockByHash(types.NewHashByStr(value))
hash := types.NewHashByStr(value)
if hash == nil {
return nil, fmt.Errorf("invalid format of block hash for querying block")
}
return b.bxh.Ledger.GetBlockByHash(hash)
default:
return nil, fmt.Errorf("wrong args about getting block: %s", mode)
}