Merge pull request #123 from meshplus/refactor/readonly-return-type

refactor(api): refactor readonly tx api return type
This commit is contained in:
Alexader 2020-07-24 15:47:14 +08:00 committed by GitHub
commit 9ae57938c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 10 additions and 11 deletions

View File

@ -28,7 +28,7 @@ func (cbs *ChainBrokerService) SendTransaction(ctx context.Context, tx *pb.SendT
return &pb.TransactionHashMsg{TxHash: hash}, nil
}
func (cbs *ChainBrokerService) SendView(_ context.Context, tx *pb.SendTransactionRequest) (*pb.Response, error) {
func (cbs *ChainBrokerService) SendView(_ context.Context, tx *pb.SendTransactionRequest) (*pb.Receipt, error) {
if err := cbs.checkTransaction(tx); err != nil {
return nil, err
}
@ -100,7 +100,7 @@ func (cbs *ChainBrokerService) sendTransaction(req *pb.SendTransactionRequest) (
return tx.TransactionHash.Hex(), nil
}
func (cbs *ChainBrokerService) sendView(req *pb.SendTransactionRequest) (*pb.Response, error) {
func (cbs *ChainBrokerService) sendView(req *pb.SendTransactionRequest) (*pb.Receipt, error) {
tx := &pb.Transaction{
Version: req.Version,
From: req.From,

2
go.mod
View File

@ -23,7 +23,7 @@ require (
github.com/magiconair/properties v1.8.1
github.com/meshplus/bitxhub-core v0.1.0-rc1.0.20200526060151-b0efad4a2046
github.com/meshplus/bitxhub-kit v1.0.1-0.20200525060338-39d86f7542ae
github.com/meshplus/bitxhub-model v1.0.0-rc4.0.20200714082154-970b730cdb6c
github.com/meshplus/bitxhub-model v1.0.0-rc4.0.20200724062514-baa44473e4d8
github.com/mitchellh/go-homedir v1.1.0
github.com/multiformats/go-multiaddr v0.2.0
github.com/pkg/errors v0.9.1

6
go.sum
View File

@ -510,10 +510,8 @@ github.com/meshplus/bitxhub-kit v1.0.1-0.20200525060338-39d86f7542ae h1:xp8+WxUW
github.com/meshplus/bitxhub-kit v1.0.1-0.20200525060338-39d86f7542ae/go.mod h1:8Pprmnq+2fFi5kJP0qcbwPl/fe22nro0OamjtwD0LJM=
github.com/meshplus/bitxhub-model v1.0.0-rc4.0.20200514093243-7e8ae60d1c19 h1:D0n0/NqaueI6r+/cJIjYzWwjZ9j/5l36r/c8MYqTdXg=
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.20200714081853-9d050b7250ad h1:lZQQlcwrI4BGKVdA4O2VW93K4P7wL04o3ODoFUESOBo=
github.com/meshplus/bitxhub-model v1.0.0-rc4.0.20200714081853-9d050b7250ad/go.mod h1:QK8aACbxtZEA3Hk1BOCirW0uxMWLsMrLDpWz9FweIKM=
github.com/meshplus/bitxhub-model v1.0.0-rc4.0.20200714082154-970b730cdb6c h1:RD+QMpgFKfdwy0rdmyaF2EX6Ris6pmz5scmGAuR/CYY=
github.com/meshplus/bitxhub-model v1.0.0-rc4.0.20200714082154-970b730cdb6c/go.mod h1:QK8aACbxtZEA3Hk1BOCirW0uxMWLsMrLDpWz9FweIKM=
github.com/meshplus/bitxhub-model v1.0.0-rc4.0.20200724062514-baa44473e4d8 h1:FlD+ETNIVTJ3gyceEdqqo6wvBkrYiTfLB6XM0tGH1Yw=
github.com/meshplus/bitxhub-model v1.0.0-rc4.0.20200724062514-baa44473e4d8/go.mod h1:QK8aACbxtZEA3Hk1BOCirW0uxMWLsMrLDpWz9FweIKM=
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
github.com/miekg/dns v1.1.12/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
github.com/miekg/pkcs11 v1.0.3 h1:iMwmD7I5225wv84WxIG/bmxz9AXjWvTWIbM/TYHvWtw=

View File

@ -19,7 +19,7 @@ type CoreAPI interface {
type BrokerAPI interface {
HandleTransaction(tx *pb.Transaction) error
HandleView(tx *pb.Transaction) (*pb.Response, error)
HandleView(tx *pb.Transaction) (*pb.Receipt, error)
GetTransaction(types.Hash) (*pb.Transaction, error)
GetTransactionMeta(types.Hash) (*pb.TransactionMeta, error)
GetReceipt(types.Hash) (*pb.Receipt, error)

View File

@ -28,14 +28,14 @@ func (b *BrokerAPI) HandleTransaction(tx *pb.Transaction) error {
return nil
}
func (b *BrokerAPI) HandleView(tx *pb.Transaction) (*pb.Response, error) {
func (b *BrokerAPI) HandleView(tx *pb.Transaction) (*pb.Receipt, error) {
b.logger.WithFields(logrus.Fields{
"hash": tx.TransactionHash.String(),
}).Debugf("Receive view")
receipts := b.bxh.ViewExecutor.ApplyReadonlyTransactions([]*pb.Transaction{tx})
return &pb.Response{Data: receipts[0].Ret}, nil
return receipts[0], nil
}
func (b *BrokerAPI) GetTransaction(hash types.Hash) (*pb.Transaction, error) {

View File

@ -69,7 +69,8 @@ func testSendView(suite *API) {
receipt, err := suite.api.Broker().HandleView(tx)
suite.Nil(err)
suite.Equal(value, string(receipt.Data))
suite.Equal(receipt.Status, pb.Receipt_SUCCESS)
suite.Equal(value, string(receipt.Ret))
}
func TestAPI(t *testing.T) {