Skip to content

Commit 96531e3

Browse files
committed
feat: remove fake websocket code from GetTransactionStatus
Signed-off-by: Simon Gellis <[email protected]>
1 parent bc93388 commit 96531e3

File tree

5 files changed

+12
-76
lines changed

5 files changed

+12
-76
lines changed

internal/blockchain/cardano/cardano.go

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,6 @@ import (
3838
"github.com/hyperledger/firefly/pkg/core"
3939
)
4040

41-
const (
42-
cardanoTxStatusPending string = "Pending"
43-
)
44-
45-
const (
46-
ReceiptTransactionSuccess string = "TransactionSuccess"
47-
ReceiptTransactionFailed string = "TransactionFailed"
48-
)
49-
5041
type Cardano struct {
5142
ctx context.Context
5243
cancelCtx context.CancelFunc
@@ -474,37 +465,6 @@ func (c *Cardano) GetTransactionStatus(ctx context.Context, operation *core.Oper
474465
return nil, common.WrapRESTError(ctx, &resErr, res, err, coremsgs.MsgCardanoconnectRESTErr)
475466
}
476467

477-
receiptInfo := statusResponse.GetObject("receipt")
478-
txStatus := statusResponse.GetString("status")
479-
480-
if txStatus != "" {
481-
var replyType string
482-
if txStatus == "Succeeded" {
483-
replyType = ReceiptTransactionSuccess
484-
} else {
485-
replyType = ReceiptTransactionFailed
486-
}
487-
// If the status has changed, mock up blockchain receipt as if we'd received it
488-
// as a web socket notification
489-
if (operation.Status == core.OpStatusPending || operation.Status == core.OpStatusInitialized) && txStatus != cardanoTxStatusPending {
490-
receipt := &common.BlockchainReceiptNotification{
491-
Headers: common.BlockchainReceiptHeaders{
492-
ReceiptID: statusResponse.GetString("id"),
493-
ReplyType: replyType,
494-
},
495-
TxHash: statusResponse.GetString("transactionHash"),
496-
Message: statusResponse.GetString("errorMessage"),
497-
ProtocolID: receiptInfo.GetString("protocolId")}
498-
err := common.HandleReceipt(ctx, operation.Namespace, c, receipt, c.callbacks)
499-
if err != nil {
500-
log.L(ctx).Warnf("Failed to handle receipt")
501-
}
502-
}
503-
} else {
504-
// Don't expect to get here so issue a warning
505-
log.L(ctx).Warnf("Transaction status didn't include txStatus information")
506-
}
507-
508468
return statusResponse, nil
509469
}
510470

internal/blockchain/cardano/cardano_test.go

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -867,19 +867,9 @@ func TestGetTransactionStatusSuccess(t *testing.T) {
867867
return httpmock.NewJsonResponderOrPanic(200, transactionStatus)(req)
868868
})
869869

870-
tm := &coremocks.OperationCallbacks{}
871-
c.SetOperationHandler("ns1", tm)
872-
tm.On("OperationUpdate", mock.MatchedBy(func(update *core.OperationUpdateAsync) bool {
873-
return update.NamespacedOpID == "ns1:9ffc50ff-6bfe-4502-adc7-93aea54cc059" &&
874-
update.Status == core.OpStatusSucceeded &&
875-
update.BlockchainTXID == "txHash" &&
876-
update.Plugin == "cardano"
877-
})).Return(errors.New("won't stop processing"))
878-
879870
status, err := c.GetTransactionStatus(context.Background(), op)
880871
assert.NoError(t, err)
881872
assert.NotNil(t, status)
882-
tm.AssertExpectations(t)
883873
}
884874

885875
func TestGetTransactionStatusFailure(t *testing.T) {
@@ -904,19 +894,9 @@ func TestGetTransactionStatusFailure(t *testing.T) {
904894
return httpmock.NewJsonResponderOrPanic(200, transactionStatus)(req)
905895
})
906896

907-
tm := &coremocks.OperationCallbacks{}
908-
c.SetOperationHandler("ns1", tm)
909-
tm.On("OperationUpdate", mock.MatchedBy(func(update *core.OperationUpdateAsync) bool {
910-
return update.NamespacedOpID == "ns1:9ffc50ff-6bfe-4502-adc7-93aea54cc059" &&
911-
update.Status == core.OpStatusFailed &&
912-
update.ErrorMessage == "Something went wrong" &&
913-
update.Plugin == "cardano"
914-
})).Return(errors.New("won't stop processing"))
915-
916897
status, err := c.GetTransactionStatus(context.Background(), op)
917898
assert.NoError(t, err)
918899
assert.NotNil(t, status)
919-
tm.AssertExpectations(t)
920900
}
921901

922902
func TestGetTransactionStatusEmptyObject(t *testing.T) {

internal/blockchain/common/common.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,12 @@ type BlockchainReceiptNotification struct {
116116
ContractLocation *fftypes.JSONAny `json:"contractLocation,omitempty"`
117117
}
118118

119+
// possible values of BlockchainReceiptHeaders.ReplyType
120+
const (
121+
ReceiptTransactionSuccess string = "TransactionSuccess"
122+
ReceiptTransactionFailed string = "TransactionFailed"
123+
)
124+
119125
type BlockchainRESTError struct {
120126
Error string `json:"error,omitempty"`
121127
// See https://github.com/hyperledger/firefly-transaction-manager/blob/main/pkg/ffcapi/submission_error.go

internal/blockchain/ethereum/ethereum.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright © 2024 Kaleido, Inc.
1+
// Copyright © 2025 Kaleido, Inc.
22
//
33
// SPDX-License-Identifier: Apache-2.0
44
//
@@ -52,11 +52,6 @@ const (
5252
ethTxStatusPending string = "Pending"
5353
)
5454

55-
const (
56-
ReceiptTransactionSuccess string = "TransactionSuccess"
57-
ReceiptTransactionFailed string = "TransactionFailed"
58-
)
59-
6055
type Ethereum struct {
6156
ctx context.Context
6257
cancelCtx context.CancelFunc
@@ -1209,9 +1204,9 @@ func (e *Ethereum) GetTransactionStatus(ctx context.Context, operation *core.Ope
12091204
if txStatus != "" {
12101205
var replyType string
12111206
if txStatus == "Succeeded" {
1212-
replyType = ReceiptTransactionSuccess
1207+
replyType = common.ReceiptTransactionSuccess
12131208
} else {
1214-
replyType = ReceiptTransactionFailed
1209+
replyType = common.ReceiptTransactionFailed
12151210
}
12161211
// If the status has changed, mock up blockchain receipt as if we'd received it
12171212
// as a web socket notification

internal/blockchain/tezos/tezos.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright © 2024 Kaleido, Inc.
1+
// Copyright © 2025 Kaleido, Inc.
22
//
33
// SPDX-License-Identifier: Apache-2.0
44
//
@@ -44,11 +44,6 @@ const (
4444
tezosTxStatusPending string = "Pending"
4545
)
4646

47-
const (
48-
ReceiptTransactionSuccess string = "TransactionSuccess"
49-
ReceiptTransactionFailed string = "TransactionFailed"
50-
)
51-
5247
type Tezos struct {
5348
ctx context.Context
5449
cancelCtx context.CancelFunc
@@ -576,9 +571,9 @@ func (t *Tezos) GetTransactionStatus(ctx context.Context, operation *core.Operat
576571
if txStatus != "" {
577572
var replyType string
578573
if txStatus == "Succeeded" {
579-
replyType = ReceiptTransactionSuccess
574+
replyType = common.ReceiptTransactionSuccess
580575
} else {
581-
replyType = ReceiptTransactionFailed
576+
replyType = common.ReceiptTransactionFailed
582577
}
583578
// If the status has changed, mock up blockchain receipt as if we'd received it
584579
// as a web socket notification

0 commit comments

Comments
 (0)