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

export relayed txs builder #184

Merged
merged 2 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
16 changes: 9 additions & 7 deletions builders/relayedTxV1Builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,51 @@ import (
"math/big"

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

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

type relayedTxV1Builder struct {
// RelayedTxV1Builder is a builder for relayed transaction v1
type RelayedTxV1Builder struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

missing comment

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

innerTransaction *transaction.FrontendTransaction
relayerAccount *data.Account
networkConfig *data.NetworkConfig
}

// NewRelayedTxV1Builder creates a new relayed transaction v1 builder
func NewRelayedTxV1Builder() *relayedTxV1Builder {
return &relayedTxV1Builder{
func NewRelayedTxV1Builder() *RelayedTxV1Builder {
return &RelayedTxV1Builder{
innerTransaction: nil,
relayerAccount: nil,
networkConfig: nil,
}
}

// SetInnerTransaction sets the inner transaction to be relayed
func (rtb *relayedTxV1Builder) SetInnerTransaction(tx *transaction.FrontendTransaction) *relayedTxV1Builder {
func (rtb *RelayedTxV1Builder) SetInnerTransaction(tx *transaction.FrontendTransaction) *RelayedTxV1Builder {
rtb.innerTransaction = tx

return rtb
}

// SetRelayerAccount sets the relayer account
func (rtb *relayedTxV1Builder) SetRelayerAccount(account *data.Account) *relayedTxV1Builder {
func (rtb *RelayedTxV1Builder) SetRelayerAccount(account *data.Account) *RelayedTxV1Builder {
rtb.relayerAccount = account

return rtb
}

// SetNetworkConfig sets the network config
func (rtb *relayedTxV1Builder) SetNetworkConfig(config *data.NetworkConfig) *relayedTxV1Builder {
func (rtb *RelayedTxV1Builder) SetNetworkConfig(config *data.NetworkConfig) *RelayedTxV1Builder {
rtb.networkConfig = config

return rtb
}

// Build builds the relayed transaction v1
// The returned transaction will not be signed
func (rtb *relayedTxV1Builder) Build() (*transaction.FrontendTransaction, error) {
func (rtb *RelayedTxV1Builder) Build() (*transaction.FrontendTransaction, error) {
if rtb.innerTransaction == nil {
return nil, ErrNilInnerTransaction
}
Expand Down
18 changes: 10 additions & 8 deletions builders/relayedTxV2Builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,57 +6,59 @@ import (
"math/big"

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

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

type relayedTxV2Builder struct {
// RelayedTxV2Builder is a builder for relayed transaction v2
type RelayedTxV2Builder struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

missing comment

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

innerTransaction *transaction.FrontendTransaction
gasLimitNeededForInnerTransaction uint64
relayerAccount *data.Account
networkConfig *data.NetworkConfig
}

// NewRelayedTxV2Builder creates a new relayed transaction v2 builder
func NewRelayedTxV2Builder() *relayedTxV2Builder {
return &relayedTxV2Builder{
func NewRelayedTxV2Builder() *RelayedTxV2Builder {
return &RelayedTxV2Builder{
innerTransaction: nil,
relayerAccount: nil,
networkConfig: nil,
}
}

// SetInnerTransaction sets the inner transaction to be relayed
func (rtb *relayedTxV2Builder) SetInnerTransaction(tx *transaction.FrontendTransaction) *relayedTxV2Builder {
func (rtb *RelayedTxV2Builder) SetInnerTransaction(tx *transaction.FrontendTransaction) *RelayedTxV2Builder {
rtb.innerTransaction = tx

return rtb
}

// SetRelayerAccount sets the relayer account (that will send the wrapped transaction)
func (rtb *relayedTxV2Builder) SetRelayerAccount(account *data.Account) *relayedTxV2Builder {
func (rtb *RelayedTxV2Builder) SetRelayerAccount(account *data.Account) *RelayedTxV2Builder {
rtb.relayerAccount = account

return rtb
}

// SetGasLimitNeededForInnerTransaction sets the gas limit needed for the inner transaction
func (rtb *relayedTxV2Builder) SetGasLimitNeededForInnerTransaction(gasLimit uint64) *relayedTxV2Builder {
func (rtb *RelayedTxV2Builder) SetGasLimitNeededForInnerTransaction(gasLimit uint64) *RelayedTxV2Builder {
rtb.gasLimitNeededForInnerTransaction = gasLimit

return rtb
}

// SetNetworkConfig sets the network config
func (rtb *relayedTxV2Builder) SetNetworkConfig(config *data.NetworkConfig) *relayedTxV2Builder {
func (rtb *RelayedTxV2Builder) SetNetworkConfig(config *data.NetworkConfig) *RelayedTxV2Builder {
rtb.networkConfig = config

return rtb
}

// Build builds the relayed transaction v1
// The returned transaction will not be signed
func (rtb *relayedTxV2Builder) Build() (*transaction.FrontendTransaction, error) {
func (rtb *RelayedTxV2Builder) Build() (*transaction.FrontendTransaction, error) {
if rtb.innerTransaction == nil {
return nil, ErrNilInnerTransaction
}
Expand Down
16 changes: 9 additions & 7 deletions builders/relayedTxV3Builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,50 @@ package builders

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

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

type relayedTxV3Builder struct {
// RelayedTxV3Builder is a builder for relayed transactions v3
type RelayedTxV3Builder struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

missing comment

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

innerTransactions []*transaction.FrontendTransaction
relayerAccount *data.Account
networkConfig *data.NetworkConfig
}

// NewRelayedTxV3Builder creates a new relayed transaction v2 builder
func NewRelayedTxV3Builder() *relayedTxV3Builder {
return &relayedTxV3Builder{
func NewRelayedTxV3Builder() *RelayedTxV3Builder {
return &RelayedTxV3Builder{
innerTransactions: nil,
relayerAccount: nil,
networkConfig: nil,
}
}

// SetInnerTransactions sets the inner transactions to be relayed
func (rtb *relayedTxV3Builder) SetInnerTransactions(innerTxs []*transaction.FrontendTransaction) *relayedTxV3Builder {
func (rtb *RelayedTxV3Builder) SetInnerTransactions(innerTxs []*transaction.FrontendTransaction) *RelayedTxV3Builder {
rtb.innerTransactions = innerTxs

return rtb
}

// SetRelayerAccount sets the relayer account (that will send the wrapped transaction)
func (rtb *relayedTxV3Builder) SetRelayerAccount(account *data.Account) *relayedTxV3Builder {
func (rtb *RelayedTxV3Builder) SetRelayerAccount(account *data.Account) *RelayedTxV3Builder {
rtb.relayerAccount = account

return rtb
}

// SetNetworkConfig sets the network config
func (rtb *relayedTxV3Builder) SetNetworkConfig(config *data.NetworkConfig) *relayedTxV3Builder {
func (rtb *RelayedTxV3Builder) SetNetworkConfig(config *data.NetworkConfig) *RelayedTxV3Builder {
rtb.networkConfig = config

return rtb
}

// Build builds the relayed transaction v3
// The returned transaction will not be signed
func (rtb *relayedTxV3Builder) Build() (*transaction.FrontendTransaction, error) {
func (rtb *RelayedTxV3Builder) Build() (*transaction.FrontendTransaction, error) {
if len(rtb.innerTransactions) == 0 {
return nil, ErrEmptyInnerTransactions
}
Expand Down