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

relayed v3 indexer integration #306

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion data/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ type Transaction struct {
GuardianSignature string `json:"guardianSignature,omitempty"`
ErrorEvent bool `json:"errorEvent,omitempty"`
CompletedEvent bool `json:"completedEvent,omitempty"`
RelayedAddr string `json:"relayed,omitempty"`
RelayedAddr string `json:"relayer,omitempty"`
RelayedSignature string `json:"relayerSignature,omitempty"`
ExecutionOrder int `json:"-"`
SmartContractResults []*ScResult `json:"-"`
Hash string `json:"-"`
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/gin-contrib/cors v1.4.0
github.com/gin-gonic/gin v1.9.1
github.com/multiversx/mx-chain-communication-go v1.1.0
github.com/multiversx/mx-chain-core-go v1.2.21
github.com/multiversx/mx-chain-core-go v1.2.24-0.20241029140551-8ed69b598c83
github.com/multiversx/mx-chain-logger-go v1.0.15
github.com/multiversx/mx-chain-vm-common-go v1.5.13
github.com/prometheus/client_model v0.4.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o=
github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc=
github.com/multiversx/mx-chain-communication-go v1.1.0 h1:J7bX6HoN3HiHY7cUeEjG8AJWgQDDPcY+OPDOsSUOkRE=
github.com/multiversx/mx-chain-communication-go v1.1.0/go.mod h1:WK6bP4pGEHGDDna/AYRIMtl6G9OA0NByI1Lw8PmOnRM=
github.com/multiversx/mx-chain-core-go v1.2.21 h1:+XVKznPTlUU5EFS1A8chtS8fStW60upRIyF4Pgml19I=
github.com/multiversx/mx-chain-core-go v1.2.21/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE=
github.com/multiversx/mx-chain-core-go v1.2.24-0.20241029140551-8ed69b598c83 h1:VuFFYZ9hpMacAcqcKM0hg6j4D16qKAGihi3X6PaF8qs=
github.com/multiversx/mx-chain-core-go v1.2.24-0.20241029140551-8ed69b598c83/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE=
github.com/multiversx/mx-chain-crypto-go v1.2.12 h1:zWip7rpUS4CGthJxfKn5MZfMfYPjVjIiCID6uX5BSOk=
github.com/multiversx/mx-chain-logger-go v1.0.15 h1:HlNdK8etyJyL9NQ+6mIXyKPEBo+wRqOwi3n+m2QIHXc=
github.com/multiversx/mx-chain-logger-go v1.0.15/go.mod h1:t3PRKaWB1M+i6gUfD27KXgzLJJC+mAQiN+FLlL1yoGQ=
Expand Down
6 changes: 6 additions & 0 deletions process/elasticproc/transactions/transactionDBBuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ func (dtb *dbTransactionBuilder) prepareTransaction(
if len(tx.GuardianAddr) > 0 {
guardianAddress = dtb.addressPubkeyConverter.SilentEncode(tx.GuardianAddr, log)
}
relayedAddress := ""
if len(tx.RelayerAddr) > 0 {
relayedAddress = dtb.addressPubkeyConverter.SilentEncode(tx.RelayerAddr, log)
}

senderUserName := converters.TruncateFieldIfExceedsMaxLengthBase64(string(tx.SndUserName))
receiverUserName := converters.TruncateFieldIfExceedsMaxLengthBase64(string(tx.RcvUserName))
Expand Down Expand Up @@ -119,6 +123,8 @@ func (dtb *dbTransactionBuilder) prepareTransaction(
GuardianSignature: hex.EncodeToString(tx.GuardianSignature),
ExecutionOrder: int(txInfo.ExecutionOrder),
Operation: res.Operation,
RelayedSignature: hex.EncodeToString(tx.RelayerSignature),
RelayedAddr: relayedAddress,
}

eTx.Function = converters.TruncateFieldIfExceedsMaxLength(res.Function)
Expand Down
74 changes: 74 additions & 0 deletions process/elasticproc/transactions/transactionDBBuilder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,80 @@ func TestGetTransactionByType_RewardTx(t *testing.T) {
require.Equal(t, expectedTx, resultTx)
}

func TestRelayedV3Transaction(t *testing.T) {
t.Parallel()

txHash := []byte("txHash")
mbHash := []byte("mbHash")
mb := &block.MiniBlock{TxHashes: [][]byte{txHash}, Type: block.InvalidBlock}
header := &block.Header{Nonce: 2}
status := transaction.TxStatusInvalid.String()
gasPrice := uint64(1000)
gasLimit := uint64(1000)
cp := createCommonProcessor()

tx := &transaction.Transaction{
Nonce: 1,
Value: big.NewInt(1000),
RcvAddr: []byte("receiver"),
SndAddr: []byte("sender"),
GasPrice: gasPrice,
GasLimit: gasLimit,
Data: []byte("data"),
ChainID: []byte("1"),
Version: 1,
Signature: []byte("signature"),
RcvUserName: []byte("rcv"),
SndUserName: []byte("snd"),
RelayerAddr: []byte("relayer"),
RelayerSignature: []byte("relayerSignature"),
}

expectedTx := &data.Transaction{
Hash: hex.EncodeToString(txHash),
MBHash: hex.EncodeToString(mbHash),
Nonce: tx.Nonce,
Round: header.Round,
Value: tx.Value.String(),
ValueNum: 1e-15,
Receiver: cp.addressPubkeyConverter.SilentEncode(tx.RcvAddr, log),
Sender: cp.addressPubkeyConverter.SilentEncode(tx.SndAddr, log),
ReceiverShard: uint32(2),
SenderShard: mb.SenderShardID,
GasPrice: gasPrice,
GasLimit: gasLimit,
GasUsed: uint64(500),
InitialPaidFee: "100",
Data: tx.Data,
Signature: hex.EncodeToString(tx.Signature),
Timestamp: time.Duration(header.GetTimeStamp()),
Status: status,
Fee: "100",
FeeNum: 1e-16,
ReceiverUserName: []byte("rcv"),
SenderUserName: []byte("snd"),
Operation: "transfer",
Version: 1,
Receivers: []string{},
ESDTValuesNum: []float64{},
RelayedAddr: hex.EncodeToString(tx.RelayerAddr),
RelayedSignature: hex.EncodeToString(tx.RelayerSignature),
}

txInfo := &outport.TxInfo{
Transaction: tx,
FeeInfo: &outport.FeeInfo{
GasUsed: 500,
Fee: big.NewInt(100),
InitialPaidFee: big.NewInt(100),
},
ExecutionOrder: 0,
}

dbTx := cp.prepareTransaction(txInfo, txHash, mbHash, mb, header, status, 3)
require.Equal(t, expectedTx, dbTx)
}

func TestGetMoveBalanceTransactionInvalid(t *testing.T) {
t.Parallel()

Expand Down
Loading