Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added transaction processed status #386

Merged
merged 13 commits into from
Jun 26, 2023
6 changes: 3 additions & 3 deletions api/groups/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package groups
import (
"math/big"

"github.com/multiversx/mx-chain-core-go/data/transaction"
"github.com/multiversx/mx-chain-core-go/data/vm"
"github.com/multiversx/mx-chain-proxy-go/common"
"github.com/multiversx/mx-chain-proxy-go/data"
Expand Down Expand Up @@ -97,8 +96,9 @@ type TransactionFacadeHandler interface {
SendUserFunds(receiver string, value *big.Int) error
TransactionCostRequest(tx *data.Transaction) (*data.TxCostResponseData, error)
GetTransactionStatus(txHash string, sender string) (string, error)
GetTransaction(txHash string, withResults bool) (*transaction.ApiTransactionResult, error)
GetTransactionByHashAndSenderAddress(txHash string, sndAddr string, withEvents bool) (*transaction.ApiTransactionResult, int, error)
GetProcessedTransactionStatus(txHash string, sender string) (string, error)
GetTransaction(txHash string, withResults bool) (*data.ExtendedApiTransactionResult, error)
GetTransactionByHashAndSenderAddress(txHash string, sndAddr string, withEvents bool) (*data.ExtendedApiTransactionResult, int, error)
GetTransactionsPool(fields string) (*data.TransactionsPool, error)
GetTransactionsPoolForShard(shardID uint32, fields string) (*data.TransactionsPool, error)
GetTransactionsPoolForSender(sender, fields string) (*data.TransactionsPoolForSender, error)
Expand Down
15 changes: 10 additions & 5 deletions api/mock/facadeStub.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"math/big"

"github.com/multiversx/mx-chain-core-go/core"
"github.com/multiversx/mx-chain-core-go/data/transaction"
"github.com/multiversx/mx-chain-core-go/data/vm"
"github.com/multiversx/mx-chain-proxy-go/common"
"github.com/multiversx/mx-chain-proxy-go/data"
Expand All @@ -23,7 +22,7 @@ type FacadeStub struct {
GetNFTTokenIDsRegisteredByAddressCalled func(address string, options common.AccountQueryOptions) (*data.GenericAPIResponse, error)
GetAllESDTTokensCalled func(address string, options common.AccountQueryOptions) (*data.GenericAPIResponse, error)
GetTransactionsHandler func(address string) ([]data.DatabaseTransaction, error)
GetTransactionHandler func(txHash string, withResults bool) (*transaction.ApiTransactionResult, error)
GetTransactionHandler func(txHash string, withResults bool) (*data.ExtendedApiTransactionResult, error)
GetTransactionsPoolHandler func(fields string) (*data.TransactionsPool, error)
GetTransactionsPoolForShardHandler func(shardID uint32, fields string) (*data.TransactionsPool, error)
GetTransactionsPoolForSenderHandler func(sender, fields string) (*data.TransactionsPoolForSender, error)
Expand All @@ -38,6 +37,7 @@ type FacadeStub struct {
ValidatorStatisticsHandler func() (map[string]*data.ValidatorApiResponse, error)
TransactionCostRequestHandler func(tx *data.Transaction) (*data.TxCostResponseData, error)
GetTransactionStatusHandler func(txHash string, sender string) (string, error)
GetProcessedTransactionStatusHandler func(txHash string, sender string) (string, error)
GetConfigMetricsHandler func() (*data.GenericAPIResponse, error)
GetNetworkMetricsHandler func(shardID uint32) (*data.GenericAPIResponse, error)
GetAllIssuedESDTsHandler func(tokenType string) (*data.GenericAPIResponse, error)
Expand All @@ -47,7 +47,7 @@ type FacadeStub struct {
GetDelegatedInfoCalled func() (*data.GenericAPIResponse, error)
GetRatingsConfigCalled func() (*data.GenericAPIResponse, error)
GetBlockByShardIDAndNonceHandler func(shardID uint32, nonce uint64) (data.AtlasBlock, error)
GetTransactionByHashAndSenderAddressHandler func(txHash string, sndAddr string, withResults bool) (*transaction.ApiTransactionResult, int, error)
GetTransactionByHashAndSenderAddressHandler func(txHash string, sndAddr string, withResults bool) (*data.ExtendedApiTransactionResult, int, error)
GetBlockByHashCalled func(shardID uint32, hash string, options common.BlockQueryOptions) (*data.BlockApiResponse, error)
GetBlockByNonceCalled func(shardID uint32, nonce uint64, options common.BlockQueryOptions) (*data.BlockApiResponse, error)
GetBlocksByRoundCalled func(round uint64, options common.BlockQueryOptions) (*data.BlocksApiResponse, error)
Expand Down Expand Up @@ -316,12 +316,12 @@ func (f *FacadeStub) GetTransactions(address string) ([]data.DatabaseTransaction
}

// GetTransactionByHashAndSenderAddress -
func (f *FacadeStub) GetTransactionByHashAndSenderAddress(txHash string, sndAddr string, withEvents bool) (*transaction.ApiTransactionResult, int, error) {
func (f *FacadeStub) GetTransactionByHashAndSenderAddress(txHash string, sndAddr string, withEvents bool) (*data.ExtendedApiTransactionResult, int, error) {
return f.GetTransactionByHashAndSenderAddressHandler(txHash, sndAddr, withEvents)
}

// GetTransaction -
func (f *FacadeStub) GetTransaction(txHash string, withResults bool) (*transaction.ApiTransactionResult, error) {
func (f *FacadeStub) GetTransaction(txHash string, withResults bool) (*data.ExtendedApiTransactionResult, error) {
return f.GetTransactionHandler(txHash, withResults)
}

Expand Down Expand Up @@ -400,6 +400,11 @@ func (f *FacadeStub) GetTransactionStatus(txHash string, sender string) (string,
return f.GetTransactionStatusHandler(txHash, sender)
}

// GetProcessedTransactionStatus -
func (f *FacadeStub) GetProcessedTransactionStatus(txHash string, sender string) (string, error) {
return f.GetProcessedTransactionStatusHandler(txHash, sender)
}

// SendUserFunds -
func (f *FacadeStub) SendUserFunds(receiver string, value *big.Int) error {
return f.SendUserFundsCalled(receiver, value)
Expand Down
6 changes: 6 additions & 0 deletions data/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package data

import "github.com/multiversx/mx-chain-core-go/data/transaction"

// TxStatusUnknown defines the response that should be received from an observer when transaction status is unknown
const TxStatusUnknown transaction.TxStatus = "unknown"
7 changes: 7 additions & 0 deletions data/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,13 @@ type ExtendedApiSmartContractResult struct {
Used bool `json:"-"`
}

// ExtendedApiTransactionResult extends the original transaction.ApiTransactionResult with extra fields
// ProcessedStatus: will contain the transaction status after local processing
type ExtendedApiTransactionResult struct {
*transaction.ApiTransactionResult
ProcessedStatus transaction.TxStatus `json:"processingStatus,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might add a TODO to move it into mx-chain-core-go for rc/v1.6.0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}

// ResponseTxCost defines a response from the node holding the transaction cost
type ResponseTxCost struct {
Data TxCostResponseData `json:"data"`
Expand Down
10 changes: 7 additions & 3 deletions facade/baseFacade.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"math/big"

"github.com/multiversx/mx-chain-core-go/core"
"github.com/multiversx/mx-chain-core-go/data/transaction"
"github.com/multiversx/mx-chain-core-go/data/vm"
"github.com/multiversx/mx-chain-proxy-go/api/groups"
"github.com/multiversx/mx-chain-proxy-go/common"
Expand Down Expand Up @@ -216,8 +215,13 @@ func (epf *ProxyFacade) GetTransactionStatus(txHash string, sender string) (stri
return epf.txProc.GetTransactionStatus(txHash, sender)
}

// GetProcessedTransactionStatus should return transaction status after internal processing of the transaction results
func (epf *ProxyFacade) GetProcessedTransactionStatus(txHash string, sender string) (string, error) {
return epf.txProc.GetProcessedTransactionStatus(txHash, sender)
}

// GetTransaction should return a transaction by hash
func (epf *ProxyFacade) GetTransaction(txHash string, withResults bool) (*transaction.ApiTransactionResult, error) {
func (epf *ProxyFacade) GetTransaction(txHash string, withResults bool) (*data.ExtendedApiTransactionResult, error) {
return epf.txProc.GetTransaction(txHash, withResults)
}

Expand All @@ -232,7 +236,7 @@ func (epf *ProxyFacade) ReloadFullHistoryObservers() data.NodesReloadResponse {
}

// GetTransactionByHashAndSenderAddress should return a transaction by hash and sender address
func (epf *ProxyFacade) GetTransactionByHashAndSenderAddress(txHash string, sndAddr string, withEvents bool) (*transaction.ApiTransactionResult, int, error) {
func (epf *ProxyFacade) GetTransactionByHashAndSenderAddress(txHash string, sndAddr string, withEvents bool) (*data.ExtendedApiTransactionResult, int, error) {
return epf.txProc.GetTransactionByHashAndSenderAddress(txHash, sndAddr, withEvents)
}

Expand Down
6 changes: 3 additions & 3 deletions facade/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package facade
import (
"math/big"

"github.com/multiversx/mx-chain-core-go/data/transaction"
"github.com/multiversx/mx-chain-core-go/data/vm"
crypto "github.com/multiversx/mx-chain-crypto-go"
"github.com/multiversx/mx-chain-proxy-go/common"
Expand Down Expand Up @@ -40,8 +39,9 @@ type TransactionProcessor interface {
SimulateTransaction(tx *data.Transaction, checkSignature bool) (*data.GenericAPIResponse, error)
TransactionCostRequest(tx *data.Transaction) (*data.TxCostResponseData, error)
GetTransactionStatus(txHash string, sender string) (string, error)
GetTransaction(txHash string, withEvents bool) (*transaction.ApiTransactionResult, error)
GetTransactionByHashAndSenderAddress(txHash string, sndAddr string, withEvents bool) (*transaction.ApiTransactionResult, int, error)
GetTransaction(txHash string, withEvents bool) (*data.ExtendedApiTransactionResult, error)
GetProcessedTransactionStatus(txHash string, sender string) (string, error)
GetTransactionByHashAndSenderAddress(txHash string, sndAddr string, withEvents bool) (*data.ExtendedApiTransactionResult, int, error)
ComputeTransactionHash(tx *data.Transaction) (string, error)
GetTransactionsPool(fields string) (*data.TransactionsPool, error)
GetTransactionsPoolForShard(shardID uint32, fields string) (*data.TransactionsPool, error)
Expand Down
90 changes: 69 additions & 21 deletions facade/mock/transactionProcessorStub.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
package mock

import (
"errors"
"math/big"

"github.com/multiversx/mx-chain-core-go/data/transaction"
"github.com/multiversx/mx-chain-proxy-go/data"
)

var errNotImplemented = errors.New("not implement")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not implemented *

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, thanks


// TransactionProcessorStub -
type TransactionProcessorStub struct {
SendTransactionCalled func(tx *data.Transaction) (int, string, error)
SendMultipleTransactionsCalled func(txs []*data.Transaction) (data.MultipleTransactionsResponseData, error)
SimulateTransactionCalled func(tx *data.Transaction, checkSignature bool) (*data.GenericAPIResponse, error)
SendUserFundsCalled func(receiver string, value *big.Int) error
TransactionCostRequestHandler func(tx *data.Transaction) (*data.TxCostResponseData, error)
GetTransactionStatusHandler func(txHash string, sender string) (string, error)
GetTransactionCalled func(txHash string, withEvents bool) (*transaction.ApiTransactionResult, error)
GetTransactionByHashAndSenderAddressCalled func(txHash string, sndAddr string, withEvents bool) (*transaction.ApiTransactionResult, int, error)
TransactionCostRequestCalled func(tx *data.Transaction) (*data.TxCostResponseData, error)
GetTransactionStatusCalled func(txHash string, sender string) (string, error)
GetProcessedTransactionStatusCalled func(txHash string, sender string) (string, error)
GetTransactionCalled func(txHash string, withEvents bool) (*data.ExtendedApiTransactionResult, error)
GetTransactionByHashAndSenderAddressCalled func(txHash string, sndAddr string, withEvents bool) (*data.ExtendedApiTransactionResult, int, error)
ComputeTransactionHashCalled func(tx *data.Transaction) (string, error)
GetTransactionsPoolCalled func(fields string) (*data.TransactionsPool, error)
GetTransactionsPoolForShardCalled func(shardID uint32, fields string) (*data.TransactionsPool, error)
Expand All @@ -27,47 +30,92 @@ type TransactionProcessorStub struct {

// SimulateTransaction -
func (tps *TransactionProcessorStub) SimulateTransaction(tx *data.Transaction, checkSignature bool) (*data.GenericAPIResponse, error) {
return tps.SimulateTransactionCalled(tx, checkSignature)
if tps.SimulateTransactionCalled != nil {
return tps.SimulateTransactionCalled(tx, checkSignature)
}

return nil, errNotImplemented
}

// SendTransaction -
func (tps *TransactionProcessorStub) SendTransaction(tx *data.Transaction) (int, string, error) {
return tps.SendTransactionCalled(tx)
if tps.SendTransactionCalled != nil {
return tps.SendTransactionCalled(tx)
}

return 0, "", errNotImplemented
}

// SendMultipleTransactions -
func (tps *TransactionProcessorStub) SendMultipleTransactions(txs []*data.Transaction) (data.MultipleTransactionsResponseData, error) {
return tps.SendMultipleTransactionsCalled(txs)
if tps.SendMultipleTransactionsCalled != nil {
return tps.SendMultipleTransactionsCalled(txs)
}

return data.MultipleTransactionsResponseData{}, errNotImplemented
}

// ComputeTransactionHash -
func (tps *TransactionProcessorStub) ComputeTransactionHash(tx *data.Transaction) (string, error) {
return tps.ComputeTransactionHashCalled(tx)
if tps.ComputeTransactionHashCalled != nil {
return tps.ComputeTransactionHashCalled(tx)
}

return "", errNotImplemented
}

// SendUserFunds -
func (tps *TransactionProcessorStub) SendUserFunds(receiver string, value *big.Int) error {
return tps.SendUserFundsCalled(receiver, value)
if tps.SendUserFundsCalled != nil {
return tps.SendUserFundsCalled(receiver, value)
}

return errNotImplemented
}

// GetTransactionStatus -
func (tps *TransactionProcessorStub) GetTransactionStatus(txHash string, sender string) (string, error) {
return tps.GetTransactionStatusHandler(txHash, sender)
if tps.GetTransactionStatusCalled != nil {
return tps.GetTransactionStatusCalled(txHash, sender)
}

return "", errNotImplemented
}

// GetProcessedTransactionStatus -
func (tps *TransactionProcessorStub) GetProcessedTransactionStatus(txHash string, sender string) (string, error) {
if tps.GetProcessedTransactionStatusCalled != nil {
return tps.GetProcessedTransactionStatusCalled(txHash, sender)
}

return "", errNotImplemented
}

// GetTransaction -
func (tps *TransactionProcessorStub) GetTransaction(txHash string, withEvents bool) (*transaction.ApiTransactionResult, error) {
return tps.GetTransactionCalled(txHash, withEvents)
func (tps *TransactionProcessorStub) GetTransaction(txHash string, withEvents bool) (*data.ExtendedApiTransactionResult, error) {
if tps.GetTransactionCalled != nil {
return tps.GetTransactionCalled(txHash, withEvents)
}

return nil, errNotImplemented
}

// GetTransactionByHashAndSenderAddress -
func (tps *TransactionProcessorStub) GetTransactionByHashAndSenderAddress(txHash string, sndAddr string, withEvents bool) (*transaction.ApiTransactionResult, int, error) {
return tps.GetTransactionByHashAndSenderAddressCalled(txHash, sndAddr, withEvents)
func (tps *TransactionProcessorStub) GetTransactionByHashAndSenderAddress(txHash string, sndAddr string, withEvents bool) (*data.ExtendedApiTransactionResult, int, error) {
if tps.GetTransactionByHashAndSenderAddressCalled != nil {
return tps.GetTransactionByHashAndSenderAddressCalled(txHash, sndAddr, withEvents)
}

return nil, 0, errNotImplemented
}

// TransactionCostRequest -
func (tps *TransactionProcessorStub) TransactionCostRequest(tx *data.Transaction) (*data.TxCostResponseData, error) {
return tps.TransactionCostRequestHandler(tx)
if tps.TransactionCostRequestCalled != nil {
return tps.TransactionCostRequestCalled(tx)
}

return nil, errNotImplemented
}

// GetTransactionsPool -
Expand All @@ -76,7 +124,7 @@ func (tps *TransactionProcessorStub) GetTransactionsPool(fields string) (*data.T
return tps.GetTransactionsPoolCalled(fields)
}

return nil, nil
return nil, errNotImplemented
}

// GetTransactionsPoolForShard -
Expand All @@ -85,7 +133,7 @@ func (tps *TransactionProcessorStub) GetTransactionsPoolForShard(shardID uint32,
return tps.GetTransactionsPoolForShardCalled(shardID, fields)
}

return nil, nil
return nil, errNotImplemented
}

// GetTransactionsPoolForSender -
Expand All @@ -94,7 +142,7 @@ func (tps *TransactionProcessorStub) GetTransactionsPoolForSender(sender, fields
return tps.GetTransactionsPoolForSenderCalled(sender, fields)
}

return nil, nil
return nil, errNotImplemented
}

// GetLastPoolNonceForSender -
Expand All @@ -103,7 +151,7 @@ func (tps *TransactionProcessorStub) GetLastPoolNonceForSender(sender string) (u
return tps.GetLastPoolNonceForSenderCalled(sender)
}

return 0, nil
return 0, errNotImplemented
}

// GetTransactionsPoolNonceGapsForSender -
Expand All @@ -112,5 +160,5 @@ func (tps *TransactionProcessorStub) GetTransactionsPoolNonceGapsForSender(sende
return tps.GetTransactionsPoolNonceGapsForSenderCalled(sender)
}

return nil, nil
return nil, errNotImplemented
}
6 changes: 6 additions & 0 deletions process/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package process
import (
"time"

"github.com/multiversx/mx-chain-core-go/data/transaction"
proxyData "github.com/multiversx/mx-chain-proxy-go/data"
)

Expand All @@ -25,3 +26,8 @@ func ComputeTokenStorageKey(tokenID string, nonce uint64) string {
func GetShortHashSize() int {
return shortHashSize
}

// ComputeTransactionStatus -
func (tp *TransactionProcessor) ComputeTransactionStatus(tx *transaction.ApiTransactionResult, withResults bool) transaction.TxStatus {
return tp.computeTransactionStatus(tx, withResults)
}
Loading