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

Sc calls executor #305

Merged
merged 4 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions clients/multiversx/mxClientDataGetter.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"sync"

"github.com/multiversx/mx-bridge-eth-go/clients"
"github.com/multiversx/mx-bridge-eth-go/errors"
"github.com/multiversx/mx-chain-core-go/core/check"
logger "github.com/multiversx/mx-chain-logger-go"
"github.com/multiversx/mx-sdk-go/builders"
Expand Down Expand Up @@ -111,7 +112,7 @@ func (dataGetter *mxClientDataGetter) ExecuteQueryReturningBytes(ctx context.Con
"response.ReturnCode", response.Data.ReturnCode,
"response.ReturnData", fmt.Sprintf("%+v", response.Data.ReturnData))
if response.Data.ReturnCode != okCodeAfterExecution {
return nil, NewQueryResponseError(
return nil, errors.NewQueryResponseError(
response.Data.ReturnCode,
response.Data.ReturnMessage,
request.FuncName,
Expand Down Expand Up @@ -178,7 +179,7 @@ func (dataGetter *mxClientDataGetter) parseBool(buff []byte, funcName string, ad

result, err := strconv.ParseBool(fmt.Sprintf("%d", buff[0]))
if err != nil {
return false, NewQueryResponseError(
return false, errors.NewQueryResponseError(
internalError,
fmt.Sprintf("error converting the received bytes to bool, %s", err.Error()),
funcName,
Expand Down Expand Up @@ -206,7 +207,7 @@ func (dataGetter *mxClientDataGetter) ExecuteQueryReturningUint64(ctx context.Co

num, err := parseUInt64FromByteSlice(response[0])
if err != nil {
return 0, NewQueryResponseError(
return 0, errors.NewQueryResponseError(
internalError,
err.Error(),
request.FuncName,
Expand Down
9 changes: 5 additions & 4 deletions clients/multiversx/mxClientDataGetter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"testing"

"github.com/multiversx/mx-bridge-eth-go/clients"
bridgeErrors "github.com/multiversx/mx-bridge-eth-go/errors"
"github.com/multiversx/mx-bridge-eth-go/parsers"
bridgeTests "github.com/multiversx/mx-bridge-eth-go/testsCommon/bridge"
"github.com/multiversx/mx-bridge-eth-go/testsCommon/interactors"
Expand Down Expand Up @@ -198,7 +199,7 @@ func TestMXClientDataGetter_ExecuteQueryReturningBytes(t *testing.T) {

dg, _ := NewMXClientDataGetter(args)

expectedErr := NewQueryResponseError(returnCode, returnMessage, calledFunction, getBech32Address(dg.multisigContractAddress), calledArgs...)
expectedErr := bridgeErrors.NewQueryResponseError(returnCode, returnMessage, calledFunction, getBech32Address(dg.multisigContractAddress), calledArgs...)
dg.proxy = &interactors.ProxyStub{
ExecuteVMQueryCalled: func(ctx context.Context, vmRequest *data.VmValueRequest) (*data.VmValuesResponseData, error) {
return &data.VmValuesResponseData{
Expand Down Expand Up @@ -306,7 +307,7 @@ func TestMXClientDataGetter_ExecuteQueryReturningBool(t *testing.T) {
dg, _ := NewMXClientDataGetter(args)
dg.proxy = createMockProxy([][]byte{[]byte("random bytes")})

expectedError := NewQueryResponseError(
expectedError := bridgeErrors.NewQueryResponseError(
internalError,
`error converting the received bytes to bool, strconv.ParseBool: parsing "114": invalid syntax`,
"",
Expand Down Expand Up @@ -374,7 +375,7 @@ func TestMXClientDataGetter_ExecuteQueryReturningUint64(t *testing.T) {
dg, _ := NewMXClientDataGetter(args)
dg.proxy = createMockProxy([][]byte{[]byte("random bytes")})

expectedError := NewQueryResponseError(
expectedError := bridgeErrors.NewQueryResponseError(
internalError,
errNotUint64Bytes.Error(),
"",
Expand Down Expand Up @@ -960,7 +961,7 @@ func TestMXClientDataGetter_GetTransactionsStatuses(t *testing.T) {

result, err := dg.GetTransactionsStatuses(context.Background(), batchID)
assert.Nil(t, result)
expectedErr := NewQueryResponseError(internalError, `error converting the received bytes to bool, strconv.ParseBool: parsing "56": invalid syntax`,
expectedErr := bridgeErrors.NewQueryResponseError(internalError, `error converting the received bytes to bool, strconv.ParseBool: parsing "56": invalid syntax`,
"getStatusesAfterExecution", "erd1qqqqqqqqqqqqqpgqzyuaqg3dl7rqlkudrsnm5ek0j3a97qevd8sszj0glf")
assert.Equal(t, expectedErr, err)
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package multiversx
package errors

import "fmt"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package multiversx
package errors

import (
"testing"
Expand Down
14 changes: 14 additions & 0 deletions executors/multiversx/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package multiversx

import "errors"

var (
errInvalidNumberOfResponseLines = errors.New("invalid number of responses")
errNilProxy = errors.New("nil proxy")
errNilCodec = errors.New("nil codec")
errNilFilter = errors.New("nil filter")
errNilLogger = errors.New("nil logger")
errNilNonceTxHandler = errors.New("nil nonce transaction handler")
errNilPrivateKey = errors.New("nil private key")
errNilSingleSigner = errors.New("nil single signer")
)
49 changes: 49 additions & 0 deletions executors/multiversx/interface.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package multiversx

import (
"context"

"github.com/multiversx/mx-bridge-eth-go/parsers"
"github.com/multiversx/mx-chain-core-go/data/api"
"github.com/multiversx/mx-chain-core-go/data/transaction"
"github.com/multiversx/mx-sdk-go/core"
"github.com/multiversx/mx-sdk-go/data"
)

// Proxy defines the behavior of a proxy able to serve MultiversX blockchain requests
type Proxy interface {
GetNetworkConfig(ctx context.Context) (*data.NetworkConfig, error)
SendTransaction(ctx context.Context, tx *transaction.FrontendTransaction) (string, error)
SendTransactions(ctx context.Context, txs []*transaction.FrontendTransaction) ([]string, error)
ExecuteVMQuery(ctx context.Context, vmRequest *data.VmValueRequest) (*data.VmValuesResponseData, error)
GetAccount(ctx context.Context, address core.AddressHandler) (*data.Account, error)
GetNetworkStatus(ctx context.Context, shardID uint32) (*data.NetworkStatus, error)
GetShardOfAddress(ctx context.Context, bech32Address string) (uint32, error)
GetESDTTokenData(ctx context.Context, address core.AddressHandler, tokenIdentifier string, queryOptions api.AccountQueryOptions) (*data.ESDTFungibleTokenData, error)
GetTransactionInfoWithResults(ctx context.Context, hash string) (*data.TransactionInfo, error)
ProcessTransactionStatus(ctx context.Context, hexTxHash string) (transaction.TxStatus, error)
IsInterfaceNil() bool
}

// NonceTransactionsHandler represents the interface able to handle the current nonce and the transactions resend mechanism
type NonceTransactionsHandler interface {
ApplyNonceAndGasPrice(ctx context.Context, address core.AddressHandler, tx *transaction.FrontendTransaction) error
SendTransaction(ctx context.Context, tx *transaction.FrontendTransaction) (string, error)
Close() error
IsInterfaceNil() bool
}

// ScCallsExecuteFilter defines the operations supported by a filter that allows selective executions of batches
type ScCallsExecuteFilter interface {
ShouldExecute(callData parsers.ProxySCCompleteCallData) bool
IsInterfaceNil() bool
}

// Codec defines the operations implemented by a MultiversX codec
type Codec interface {
EncodeCallData(callData parsers.CallData) []byte
EncodeProxySCCompleteCallData(completeData parsers.ProxySCCompleteCallData) ([]byte, error)
DecodeCallData(buff []byte) (parsers.CallData, error)
DecodeProxySCCompleteCallData(buff []byte) (parsers.ProxySCCompleteCallData, error)
IsInterfaceNil() bool
}
Loading
Loading