Skip to content

Commit

Permalink
common interface for tx interactions
Browse files Browse the repository at this point in the history
  • Loading branch information
axenteoctavian committed Feb 13, 2024
1 parent f812014 commit f784450
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 30 deletions.
29 changes: 29 additions & 0 deletions common/interface.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package common

import (
"context"

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

// TxInteractor defines a tx interactor with multiversx blockchain
type TxInteractor interface {
ApplyUserSignature(cryptoHolder core.CryptoComponentsHolder, tx *transaction.FrontendTransaction) error
IsInterfaceNil() bool
}

// Proxy defines the proxy to interact with MultiversX blockchain
type Proxy interface {
GetAccount(ctx context.Context, address core.AddressHandler) (*data.Account, error)
GetNetworkConfig(ctx context.Context) (*data.NetworkConfig, error)
IsInterfaceNil() bool
}

// TxNonceSenderHandler should handle nonce management and tx interactions
type TxNonceSenderHandler interface {
ApplyNonceAndGasPrice(ctx context.Context, address core.AddressHandler, tx *transaction.FrontendTransaction) error
SendTransaction(ctx context.Context, tx *transaction.FrontendTransaction) (string, error)
IsInterfaceNil() bool
}
25 changes: 0 additions & 25 deletions server/txSender/interface.go
Original file line number Diff line number Diff line change
@@ -1,36 +1,11 @@
package txSender

import (
"context"

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

// TxInteractor defines a tx interactor with multiversx blockchain
type TxInteractor interface {
ApplyUserSignature(cryptoHolder core.CryptoComponentsHolder, tx *transaction.FrontendTransaction) error
IsInterfaceNil() bool
}

// Proxy defines the proxy to interact with MultiversX blockchain
type Proxy interface {
GetAccount(ctx context.Context, address core.AddressHandler) (*data.Account, error)
GetNetworkConfig(ctx context.Context) (*data.NetworkConfig, error)
IsInterfaceNil() bool
}

// DataFormatter should format txs data for bridge operations
type DataFormatter interface {
CreateTxsData(data *sovereign.BridgeOperations) [][]byte
IsInterfaceNil() bool
}

// TxNonceSenderHandler should handle nonce management and tx interactions
type TxNonceSenderHandler interface {
ApplyNonceAndGasPrice(ctx context.Context, address core.AddressHandler, tx *transaction.FrontendTransaction) error
SendTransaction(ctx context.Context, tx *transaction.FrontendTransaction) (string, error)
IsInterfaceNil() bool
}
11 changes: 6 additions & 5 deletions server/txSender/txSender.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package txSender

import (
"context"
"github.com/multiversx/mx-chain-sovereign-bridge-go/common"

"github.com/multiversx/mx-chain-core-go/core/check"
"github.com/multiversx/mx-chain-core-go/data/sovereign"
Expand All @@ -13,18 +14,18 @@ import (
// TxSenderArgs holds args to create a new tx sender
type TxSenderArgs struct {
Wallet core.CryptoComponentsHolder
Proxy Proxy
TxInteractor TxInteractor
TxNonceHandler TxNonceSenderHandler
Proxy common.Proxy
TxInteractor common.TxInteractor
TxNonceHandler common.TxNonceSenderHandler
DataFormatter DataFormatter
SCBridgeAddress string
}

type txSender struct {
wallet core.CryptoComponentsHolder
netConfigs *data.NetworkConfig
txInteractor TxInteractor
txNonceHandler TxNonceSenderHandler
txInteractor common.TxInteractor
txNonceHandler common.TxNonceSenderHandler
dataFormatter DataFormatter
scBridgeAddress string
}
Expand Down

0 comments on commit f784450

Please sign in to comment.