Skip to content

Commit de5937a

Browse files
committed
cleanup + check the length of the statuses
Signed-off-by: Angelo De Caro <adc@zurich.ibm.com>
1 parent 4a81d83 commit de5937a

File tree

6 files changed

+63
-30
lines changed

6 files changed

+63
-30
lines changed

platform/fabricx/core/queryservice/query.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ func (s *RemoteQueryService) GetTransactionStatus(txID string) (int32, error) {
8080
return 0, errors.Wrap(err, "query get rows")
8181
}
8282
logger.Debugf("QS GetState: got response in %v", time.Since(now))
83+
if len(res.Statuses) == 0 {
84+
logger.Errorf("QS GetState: no statuses for tx %s", txID)
85+
return 0, errors.Errorf("QS GetState: no statuses for tx %s", txID)
86+
}
8387
return int32(res.Statuses[0].StatusWithHeight.Code), nil
8488
}
8589

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
Copyright IBM Corp. All Rights Reserved.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
package driver
8+
9+
import (
10+
"github.com/hyperledger-labs/fabric-smart-client/platform/common/driver"
11+
"github.com/hyperledger-labs/fabric-smart-client/platform/fabric"
12+
fdriver "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/driver"
13+
"github.com/hyperledger-labs/fabric-smart-client/platform/fabricx/core/finality"
14+
)
15+
16+
const (
17+
Valid = fdriver.Valid
18+
Invalid = fdriver.Invalid
19+
Unknown = fdriver.Unknown
20+
Busy = fdriver.Busy
21+
)
22+
23+
type (
24+
TxID = driver.TxID
25+
FinalityListener = fabric.FinalityListener
26+
FinalityListenerManager = finality.ListenerManager
27+
)

platform/fabricx/driver/qs.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ package driver
88

99
import (
1010
"github.com/hyperledger-labs/fabric-smart-client/platform/common/driver"
11+
fdriver "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/driver"
1112
)
1213

1314
type (
14-
Namespace = driver.Namespace
15-
PKey = driver.PKey
16-
VaultValue = driver.VaultValue
15+
ValidationCode = fdriver.ValidationCode
16+
Namespace = driver.Namespace
17+
PKey = driver.PKey
18+
VaultValue = driver.VaultValue
1719
)
1820

1921
type QueryService interface {

platform/fabricx/finality.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,19 @@ SPDX-License-Identifier: Apache-2.0
77
package fabricx
88

99
import (
10-
"github.com/hyperledger-labs/fabric-smart-client/platform/common/driver"
11-
"github.com/hyperledger-labs/fabric-smart-client/platform/fabric"
12-
"github.com/hyperledger-labs/fabric-smart-client/platform/fabricx/core/finality"
10+
"github.com/hyperledger-labs/fabric-smart-client/platform/fabricx/driver"
1311
)
1412

1513
type (
1614
TxID = driver.TxID
17-
FinalityListener = fabric.FinalityListener
15+
FinalityListener = driver.FinalityListener
1816
)
1917

2018
type Finality struct {
21-
manager finality.ListenerManager
19+
manager driver.FinalityListenerManager
2220
}
2321

24-
func NewFinality(manager finality.ListenerManager) *Finality {
22+
func NewFinality(manager driver.FinalityListenerManager) *Finality {
2523
return &Finality{manager: manager}
2624
}
2725

platform/fabricx/fns.go

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ var (
2323
logger = logging.MustGetLogger()
2424
)
2525

26-
// NetworkService models a Fabric Network
26+
// NetworkService models a FabricX Network Service
2727
type NetworkService struct {
2828
*fabric.NetworkService
2929
queryService *QueryService
@@ -55,16 +55,16 @@ func NewNetworkService(
5555
}, nil
5656
}
5757

58-
func (ns *NetworkService) FabricNetworkService() *fabric.NetworkService {
59-
return ns.NetworkService
58+
func (s *NetworkService) FabricNetworkService() *fabric.NetworkService {
59+
return s.NetworkService
6060
}
6161

62-
func (ns *NetworkService) QueryService() *QueryService {
63-
return ns.queryService
62+
func (s *NetworkService) QueryService() *QueryService {
63+
return s.queryService
6464
}
6565

66-
func (ns *NetworkService) FinalityService() (*Finality, error) {
67-
return ns.finalityProvider.Get("")
66+
func (s *NetworkService) FinalityService() (*Finality, error) {
67+
return s.finalityProvider.Get("")
6868
}
6969

7070
type NetworkServiceProvider struct {
@@ -94,12 +94,12 @@ func NewNetworkServiceProvider(
9494
}
9595
}
9696

97-
func (nsp *NetworkServiceProvider) FabricNetworkServiceProvider() *fabric.NetworkServiceProvider {
98-
return nsp.fnsProvider
97+
func (p *NetworkServiceProvider) FabricNetworkServiceProvider() *fabric.NetworkServiceProvider {
98+
return p.fnsProvider
9999
}
100100

101-
func (nsp *NetworkServiceProvider) FabricNetworkService(id string) (*NetworkService, error) {
102-
return nsp.providers.Get(id)
101+
func (p *NetworkServiceProvider) FabricNetworkService(id string) (*NetworkService, error) {
102+
return p.providers.Get(id)
103103
}
104104

105105
func GetNetworkServiceProvider(sp services.Provider) (*NetworkServiceProvider, error) {
@@ -110,10 +110,6 @@ func GetNetworkServiceProvider(sp services.Provider) (*NetworkServiceProvider, e
110110
return s.(*NetworkServiceProvider), nil
111111
}
112112

113-
func GetFabricNetworkNames(sp services.Provider) ([]string, error) {
114-
return fabric.GetFabricNetworkNames(sp)
115-
}
116-
117113
// GetFabricNetworkService returns the Fabric Network Service for the passed id, nil if not found
118114
func GetFabricNetworkService(sp services.Provider, id string) (*NetworkService, error) {
119115
provider, err := GetNetworkServiceProvider(sp)

platform/fabricx/qs.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,24 @@ SPDX-License-Identifier: Apache-2.0
77
package fabricx
88

99
import (
10-
fdriver "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/driver"
1110
"github.com/hyperledger-labs/fabric-smart-client/platform/fabricx/driver"
1211
"github.com/hyperledger/fabric-x-committer/api/protoblocktx"
1312
)
1413

1514
type (
16-
ValidationCode = fdriver.ValidationCode
15+
ValidationCode = driver.ValidationCode
1716
Namespace = driver.Namespace
1817
PKey = driver.PKey
1918
VaultValue = driver.VaultValue
2019
)
2120

21+
const (
22+
Valid = driver.Valid
23+
Invalid = driver.Invalid
24+
Unknown = driver.Unknown
25+
Busy = driver.Busy
26+
)
27+
2228
type QueryService struct {
2329
driver.QueryService
2430
}
@@ -30,14 +36,14 @@ func NewQueryService(queryService driver.QueryService) *QueryService {
3036
func (q *QueryService) GetTxStatus(txID string) (ValidationCode, error) {
3137
c, err := q.GetTransactionStatus(txID)
3238
if err != nil {
33-
return fdriver.Unknown, err
39+
return Unknown, err
3440
}
3541
switch protoblocktx.Status(c) {
3642
case protoblocktx.Status_NOT_VALIDATED:
37-
return fdriver.Unknown, nil
43+
return Unknown, nil
3844
case protoblocktx.Status_COMMITTED:
39-
return fdriver.Valid, nil
45+
return Valid, nil
4046
default:
41-
return fdriver.Invalid, nil
47+
return Invalid, nil
4248
}
4349
}

0 commit comments

Comments
 (0)