Skip to content

Commit

Permalink
Merge pull request #331 from multiversx/revert_relayedv3
Browse files Browse the repository at this point in the history
Revert relayed v3
  • Loading branch information
sstanculeanu authored Oct 25, 2024
2 parents 1ec562b + 75bab2a commit 8aa3248
Show file tree
Hide file tree
Showing 13 changed files with 96 additions and 377 deletions.
2 changes: 0 additions & 2 deletions data/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,6 @@ type TransactionHandler interface {
GetSndAddr() []byte
GetGasLimit() uint64
GetGasPrice() uint64
GetUserTransactions() []TransactionHandler

SetValue(*big.Int)
SetData([]byte)
Expand Down Expand Up @@ -399,7 +398,6 @@ type TransactionWithFeeHandler interface {
GetData() []byte
GetRcvAddr() []byte
GetValue() *big.Int
GetUserTransactions() []TransactionHandler
}

// UserAccountHandler models a user account
Expand Down
5 changes: 0 additions & 5 deletions data/receipt/receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,6 @@ func (_ *Receipt) GetRcvUserName() []byte {
return nil
}

// GetUserTransactions returns nil as Receipt does not have user transactions
func (rpt *Receipt) GetUserTransactions() []data.TransactionHandler {
return nil
}

// CheckIntegrity checks for not nil fields and negative value
func (rpt *Receipt) CheckIntegrity() error {
return nil
Expand Down
1 change: 0 additions & 1 deletion data/receipt/receipt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ func TestReceipt_SettersAndGetters(t *testing.T) {
assert.Equal(t, uint64(0), r.GetNonce())
assert.Equal(t, uint64(0), r.GetGasPrice())
assert.Equal(t, uint64(0), r.GetGasLimit())
assert.Nil(t, r.GetUserTransactions())
}

func TestReceipt_CheckIntegrityReturnsNil(t *testing.T) {
Expand Down
5 changes: 0 additions & 5 deletions data/rewardTx/rewardTx.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@ func (rtx *RewardTx) GetRcvUserName() []byte {
return nil
}

// GetUserTransactions returns nil as RewardTx does not have user transactions
func (rtx *RewardTx) GetUserTransactions() []data.TransactionHandler {
return nil
}

// CheckIntegrity checks for not nil fields and negative value
func (rtx *RewardTx) CheckIntegrity() error {
if len(rtx.RcvAddr) == 0 {
Expand Down
1 change: 0 additions & 1 deletion data/rewardTx/rewardTx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ func TestRewardTx_GettersAndSetters(t *testing.T) {
assert.Equal(t, uint64(0), rwdTx.GetGasLimit())
assert.Equal(t, uint64(0), rwdTx.GetGasPrice())
assert.Equal(t, uint64(0), rwdTx.GetNonce())
assert.Nil(t, rwdTx.GetUserTransactions())
}

func TestRewardTx_CheckIntegrityShouldWork(t *testing.T) {
Expand Down
5 changes: 0 additions & 5 deletions data/smartContractResult/smartContractResult.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ func (_ *SmartContractResult) GetRcvUserName() []byte {
return nil
}

// GetUserTransactions returns nil as SmartContractResult does not have user transactions
func (scr *SmartContractResult) GetUserTransactions() []data.TransactionHandler {
return nil
}

// TrimSlicePtr creates a copy of the provided slice without the excess capacity
func TrimSlicePtr(in []*SmartContractResult) []*SmartContractResult {
if len(in) == 0 {
Expand Down
1 change: 0 additions & 1 deletion data/smartContractResult/smartContractResult_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ func TestSmartContractResult_SettersAndGetters(t *testing.T) {
assert.Equal(t, gasLimit, scr.GetGasLimit())
assert.Equal(t, gasPrice, scr.GetGasPrice())
assert.Equal(t, nonce, scr.GetNonce())
assert.Nil(t, scr.GetUserTransactions())
}

func TestTrimSlicePtr(t *testing.T) {
Expand Down
1 change: 0 additions & 1 deletion data/transaction/apiTransactionResult.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ type ApiTransactionResult struct {
Options uint32 `json:"options"`
GuardianAddr string `json:"guardian,omitempty"`
GuardianSignature string `json:"guardianSignature,omitempty"`
InnerTransactions []*FrontendTransaction `json:"innerTransactions,omitempty"`
}

// ApiSmartContractResult represents a smart contract result with changed fields' types in order to make it friendly for API's json
Expand Down
32 changes: 15 additions & 17 deletions data/transaction/frontendTransaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,19 @@ package transaction

// FrontendTransaction represents the DTO used in transaction signing/validation.
type FrontendTransaction struct {
Nonce uint64 `json:"nonce"`
Value string `json:"value"`
Receiver string `json:"receiver"`
Sender string `json:"sender"`
SenderUsername []byte `json:"senderUsername,omitempty"`
ReceiverUsername []byte `json:"receiverUsername,omitempty"`
GasPrice uint64 `json:"gasPrice"`
GasLimit uint64 `json:"gasLimit"`
Data []byte `json:"data,omitempty"`
Signature string `json:"signature,omitempty"`
ChainID string `json:"chainID"`
Version uint32 `json:"version"`
Options uint32 `json:"options,omitempty"`
GuardianAddr string `json:"guardian,omitempty"`
GuardianSignature string `json:"guardianSignature,omitempty"`
Relayer string `json:"relayer,omitempty"`
InnerTransactions []*FrontendTransaction `json:"innerTransactions,omitempty"`
Nonce uint64 `json:"nonce"`
Value string `json:"value"`
Receiver string `json:"receiver"`
Sender string `json:"sender"`
SenderUsername []byte `json:"senderUsername,omitempty"`
ReceiverUsername []byte `json:"receiverUsername,omitempty"`
GasPrice uint64 `json:"gasPrice"`
GasLimit uint64 `json:"gasLimit"`
Data []byte `json:"data,omitempty"`
Signature string `json:"signature,omitempty"`
ChainID string `json:"chainID"`
Version uint32 `json:"version"`
Options uint32 `json:"options,omitempty"`
GuardianAddr string `json:"guardian,omitempty"`
GuardianSignature string `json:"guardianSignature,omitempty"`
}
96 changes: 25 additions & 71 deletions data/transaction/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
package transaction

import (
"encoding/hex"
"math/big"

"github.com/multiversx/mx-chain-core-go/core"
Expand Down Expand Up @@ -37,17 +36,6 @@ func (tx *Transaction) SetSndAddr(addr []byte) {
tx.SndAddr = addr
}

// GetUserTransactions returns the inner transactions
func (tx *Transaction) GetUserTransactions() []data.TransactionHandler {
innerTxs := tx.GetInnerTransactions()
txsHandlers := make([]data.TransactionHandler, len(innerTxs))
for i := 0; i < len(innerTxs); i++ {
txsHandlers[i] = innerTxs[i]
}

return txsHandlers
}

// TrimSlicePtr creates a copy of the provided slice without the excess capacity
func TrimSlicePtr(in []*Transaction) []*Transaction {
if len(in) == 0 {
Expand Down Expand Up @@ -80,25 +68,38 @@ func (tx *Transaction) GetDataForSigning(encoder data.Encoder, marshaller data.M
return nil, ErrNilHasher
}

ftx, err := tx.prepareTx(encoder)
receiverAddr, err := encoder.Encode(tx.RcvAddr)
if err != nil {
return nil, err
}

numInnerTxs := len(tx.InnerTransactions)
if numInnerTxs > 0 {
ftx.InnerTransactions = make([]*FrontendTransaction, numInnerTxs)
var errPrepare error
for i := 0; i < numInnerTxs; i++ {
ftx.InnerTransactions[i], errPrepare = tx.InnerTransactions[i].prepareTx(encoder)
if errPrepare != nil {
return nil, errPrepare
}
senderAddr, err := encoder.Encode(tx.SndAddr)
if err != nil {
return nil, err
}

ftx.InnerTransactions[i].Signature = hex.EncodeToString(tx.InnerTransactions[i].Signature)
ftx.InnerTransactions[i].GuardianSignature = hex.EncodeToString(tx.InnerTransactions[i].GuardianSignature)
ftx := &FrontendTransaction{
Nonce: tx.Nonce,
Value: tx.Value.String(),
Receiver: receiverAddr,
Sender: senderAddr,
GasPrice: tx.GasPrice,
GasLimit: tx.GasLimit,
SenderUsername: tx.SndUserName,
ReceiverUsername: tx.RcvUserName,
Data: tx.Data,
ChainID: string(tx.ChainID),
Version: tx.Version,
Options: tx.Options,
}

if len(tx.GuardianAddr) > 0 {
guardianAddr, errGuardian := encoder.Encode(tx.GuardianAddr)
if errGuardian != nil {
return nil, errGuardian
}

ftx.GuardianAddr = guardianAddr
}

ftxBytes, err := marshaller.Marshal(ftx)
Expand Down Expand Up @@ -146,50 +147,3 @@ func (tx *Transaction) CheckIntegrity() error {

return nil
}

func (tx *Transaction) prepareTx(encoder data.Encoder) (*FrontendTransaction, error) {
receiverAddr, err := encoder.Encode(tx.RcvAddr)
if err != nil {
return nil, err
}

senderAddr, err := encoder.Encode(tx.SndAddr)
if err != nil {
return nil, err
}

ftx := &FrontendTransaction{
Nonce: tx.Nonce,
Value: tx.Value.String(),
Receiver: receiverAddr,
Sender: senderAddr,
GasPrice: tx.GasPrice,
GasLimit: tx.GasLimit,
SenderUsername: tx.SndUserName,
ReceiverUsername: tx.RcvUserName,
Data: tx.Data,
ChainID: string(tx.ChainID),
Version: tx.Version,
Options: tx.Options,
}

if len(tx.RelayerAddr) > 0 {
relayerAddr, errRelayer := encoder.Encode(tx.RelayerAddr)
if errRelayer != nil {
return nil, errRelayer
}

ftx.Relayer = relayerAddr
}

if len(tx.GuardianAddr) > 0 {
guardianAddr, errGuardian := encoder.Encode(tx.GuardianAddr)
if errGuardian != nil {
return nil, errGuardian
}

ftx.GuardianAddr = guardianAddr
}

return ftx, nil
}
Loading

0 comments on commit 8aa3248

Please sign in to comment.