From 158ecb057f1c335ede4fce50fb4992e086feb8eb Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 8 Sep 2023 14:47:37 +0300 Subject: [PATCH 01/22] inner transactions on transaction --- data/interface.go | 1 + data/transaction/apiTransactionResult.go | 1 + data/transaction/frontendTransaction.go | 31 ++--- data/transaction/transaction.go | 58 +++++++--- data/transaction/transaction.pb.go | 137 ++++++++++++++++------- data/transaction/transaction.proto | 1 + data/transaction/transaction_test.go | 107 +++++++++++++++--- 7 files changed, 256 insertions(+), 80 deletions(-) diff --git a/data/interface.go b/data/interface.go index 80b039da2..748868fe7 100644 --- a/data/interface.go +++ b/data/interface.go @@ -296,6 +296,7 @@ type Encoder interface { // Marshaller is able to encode an object to its byte slice representation type Marshaller interface { Marshal(obj interface{}) ([]byte, error) + Unmarshal(obj interface{}, buff []byte) error IsInterfaceNil() bool } diff --git a/data/transaction/apiTransactionResult.go b/data/transaction/apiTransactionResult.go index ca9671b10..8f619d064 100644 --- a/data/transaction/apiTransactionResult.go +++ b/data/transaction/apiTransactionResult.go @@ -69,6 +69,7 @@ type ApiTransactionResult struct { Options uint32 `json:"options"` GuardianAddr string `json:"guardian,omitempty"` GuardianSignature string `json:"guardianSignature,omitempty"` + InnerTransactions []data.TransactionHandler `json:"innerTransactions,omitempty"` } // ApiSmartContractResult represents a smart contract result with changed fields' types in order to make it friendly for API's json diff --git a/data/transaction/frontendTransaction.go b/data/transaction/frontendTransaction.go index b5b55c2a4..8b706e767 100644 --- a/data/transaction/frontendTransaction.go +++ b/data/transaction/frontendTransaction.go @@ -2,19 +2,20 @@ 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"` + 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"` + InnerTransactions []*FrontendTransaction `json:"innerTransactions,omitempty"` } diff --git a/data/transaction/transaction.go b/data/transaction/transaction.go index b5b42531c..83f78153d 100644 --- a/data/transaction/transaction.go +++ b/data/transaction/transaction.go @@ -2,6 +2,7 @@ package transaction import ( + "encoding/hex" "math/big" "github.com/multiversx/mx-chain-core-go/core" @@ -36,6 +37,11 @@ func (tx *Transaction) SetSndAddr(addr []byte) { tx.SndAddr = addr } +// SetInnerTransactions sets the inner transactions of the transaction +func (tx *Transaction) SetInnerTransactions(innerTransactions []byte) { + tx.InnerTransactions = innerTransactions +} + // TrimSlicePtr creates a copy of the provided slice without the excess capacity func TrimSlicePtr(in []*Transaction) []*Transaction { if len(in) == 0 { @@ -68,6 +74,44 @@ func (tx *Transaction) GetDataForSigning(encoder data.Encoder, marshaller data.M return nil, ErrNilHasher } + ftx, err := tx.prepareTx(encoder) + if err != nil { + return nil, err + } + + innerTxs := make([]*Transaction, 0) + err = marshaller.Unmarshal(&innerTxs, tx.InnerTransactions) + if err != nil { + return nil, err + } + for _, innerTx := range innerTxs { + innerFtx, innerErr := innerTx.prepareTx(encoder) + if innerErr != nil { + return nil, err + } + + innerFtx.Signature = hex.EncodeToString(innerTx.Signature) + innerFtx.GuardianSignature = hex.EncodeToString(innerTx.GuardianSignature) + + ftx.InnerTransactions = append(ftx.InnerTransactions, innerFtx) + } + + ftxBytes, err := marshaller.Marshal(ftx) + if err != nil { + return nil, err + } + + shouldSignOnTxHash := tx.Version > core.InitialVersionOfTransaction && tx.HasOptionHashSignSet() + if !shouldSignOnTxHash { + return ftxBytes, nil + } + + ftxHash := hasher.Compute(string(ftxBytes)) + + return ftxHash, nil +} + +func (tx *Transaction) prepareTx(encoder data.Encoder) (*FrontendTransaction, error) { receiverAddr, err := encoder.Encode(tx.RcvAddr) if err != nil { return nil, err @@ -102,19 +146,7 @@ func (tx *Transaction) GetDataForSigning(encoder data.Encoder, marshaller data.M ftx.GuardianAddr = guardianAddr } - ftxBytes, err := marshaller.Marshal(ftx) - if err != nil { - return nil, err - } - - shouldSignOnTxHash := tx.Version > core.InitialVersionOfTransaction && tx.HasOptionHashSignSet() - if !shouldSignOnTxHash { - return ftxBytes, nil - } - - ftxHash := hasher.Compute(string(ftxBytes)) - - return ftxHash, nil + return ftx, nil } // HasOptionGuardianSet returns true if the guarded transaction option is set diff --git a/data/transaction/transaction.pb.go b/data/transaction/transaction.pb.go index a8b2dd871..c6dfba036 100644 --- a/data/transaction/transaction.pb.go +++ b/data/transaction/transaction.pb.go @@ -45,6 +45,7 @@ type Transaction struct { Options uint32 `protobuf:"varint,13,opt,name=Options,proto3" json:"options,omitempty"` GuardianAddr []byte `protobuf:"bytes,14,opt,name=GuardianAddr,proto3" json:"guardian,omitempty"` GuardianSignature []byte `protobuf:"bytes,15,opt,name=GuardianSignature,proto3" json:"guardianSignature,omitempty"` + InnerTransactions []byte `protobuf:"bytes,16,opt,name=InnerTransactions,proto3" json:"innerTransactions,omitempty"` } func (m *Transaction) Reset() { *m = Transaction{} } @@ -180,6 +181,13 @@ func (m *Transaction) GetGuardianSignature() []byte { return nil } +func (m *Transaction) GetInnerTransactions() []byte { + if m != nil { + return m.InnerTransactions + } + return nil +} + func init() { proto.RegisterType((*Transaction)(nil), "proto.Transaction") } @@ -187,43 +195,44 @@ func init() { func init() { proto.RegisterFile("transaction.proto", fileDescriptor_2cc4e03d2c28c490) } var fileDescriptor_2cc4e03d2c28c490 = []byte{ - // 573 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x93, 0x31, 0x6f, 0xd4, 0x3e, - 0x18, 0xc6, 0xe3, 0xff, 0xbf, 0x77, 0x69, 0x7d, 0xd7, 0xa2, 0x1a, 0x15, 0x02, 0x48, 0x76, 0x85, - 0xa0, 0xea, 0xc0, 0x5d, 0x24, 0x10, 0x0b, 0x9d, 0xb8, 0x16, 0x55, 0x95, 0xa0, 0xa0, 0x14, 0x3a, - 0xb0, 0xf9, 0x12, 0x93, 0xb3, 0xd4, 0xd8, 0x95, 0xe3, 0x9c, 0xca, 0x80, 0xc4, 0x47, 0xe0, 0x63, - 0x20, 0x36, 0xbe, 0x05, 0x63, 0xc7, 0x4e, 0x81, 0xe6, 0x16, 0x94, 0xa9, 0x1f, 0x01, 0xc5, 0xb9, - 0x34, 0x6e, 0x99, 0x98, 0x62, 0xff, 0xde, 0xe7, 0x79, 0x1f, 0xcb, 0xce, 0x0b, 0x57, 0xb5, 0xa2, - 0x22, 0xa5, 0xa1, 0xe6, 0x52, 0x0c, 0x8f, 0x95, 0xd4, 0x12, 0x75, 0xcc, 0xe7, 0xee, 0x20, 0xe6, - 0x7a, 0x92, 0x8d, 0x87, 0xa1, 0x4c, 0xfc, 0x58, 0xc6, 0xd2, 0x37, 0x78, 0x9c, 0x7d, 0x30, 0x3b, - 0xb3, 0x31, 0xab, 0xda, 0x75, 0xff, 0x7b, 0x17, 0xf6, 0xde, 0xb6, 0xbd, 0x10, 0x81, 0x9d, 0x7d, - 0x29, 0x42, 0xe6, 0x81, 0x75, 0xb0, 0xb9, 0x30, 0x5a, 0x2a, 0x73, 0xd2, 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0x2d, 0x30, 0x38, 0x2b, 0x30, 0xf8, 0x55, 0x60, 0xf0, - 0xbb, 0xc0, 0xce, 0x45, 0x81, 0xc1, 0x97, 0x19, 0x76, 0x4e, 0x67, 0xd8, 0x39, 0x9b, 0x61, 0xe7, - 0xfd, 0xf6, 0x3f, 0xcc, 0x84, 0x6f, 0x8d, 0xf8, 0x96, 0xb5, 0x1e, 0x77, 0xcd, 0xe4, 0x3e, 0xf9, - 0x13, 0x00, 0x00, 0xff, 0xff, 0x38, 0xda, 0x76, 0x84, 0x04, 0x04, 0x00, 0x00, + // 587 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x54, 0xcf, 0x4e, 0x14, 0x3d, + 0x00, 0xdf, 0x7e, 0x1f, 0xcb, 0x40, 0x77, 0x41, 0xa9, 0x41, 0xab, 0x26, 0x2d, 0x31, 0x4a, 0x38, + 0xb8, 0x3b, 0x89, 0xc6, 0x8b, 0x9c, 0x5c, 0x30, 0x64, 0x13, 0x45, 0x33, 0x28, 0x07, 0x6f, 0xdd, + 0x99, 0x3a, 0xdb, 0x84, 0x69, 0x49, 0xa7, 0xbb, 0xc1, 0x83, 0x09, 0x8f, 0xe0, 0x63, 0x18, 0x9f, + 0xc4, 0x23, 0x47, 0x4e, 0xa3, 0x0c, 0x17, 0x33, 0x27, 0x1e, 0xc1, 0x4c, 0x67, 0x87, 0x29, 0x70, + 0xf2, 0x34, 0xed, 0xef, 0x6f, 0xd3, 0x4e, 0x0b, 0x57, 0x8c, 0x66, 0x32, 0x65, 0xa1, 0x11, 0x4a, + 0xf6, 0x0f, 0xb5, 0x32, 0x0a, 0xb5, 0xed, 0xe7, 0x41, 0x2f, 0x16, 0x66, 0x3c, 0x19, 0xf5, 0x43, + 0x95, 0xf8, 0xb1, 0x8a, 0x95, 0x6f, 0xe1, 0xd1, 0xe4, 0xb3, 0x9d, 0xd9, 0x89, 0x1d, 0x55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 0xcb, 0xb8, 0xa1, 0x94, 0x5c, + 0x3b, 0xf7, 0x26, 0xc5, 0xb7, 0x9b, 0x38, 0x71, 0x9d, 0x74, 0xe3, 0x6e, 0x38, 0x07, 0x5f, 0x4f, + 0xce, 0x48, 0xeb, 0xf4, 0x8c, 0xb4, 0x2e, 0xce, 0x08, 0x38, 0xce, 0x09, 0xf8, 0x9e, 0x13, 0xf0, + 0x33, 0x27, 0xe0, 0x24, 0x27, 0xe0, 0x34, 0x27, 0xe0, 0x77, 0x4e, 0xc0, 0x9f, 0x9c, 0xb4, 0x2e, + 0x72, 0x02, 0xbe, 0x9d, 0x93, 0xd6, 0xc9, 0x39, 0x69, 0x9d, 0x9e, 0x93, 0xd6, 0xa7, 0xad, 0x7f, + 0xb8, 0x62, 0xbe, 0xf3, 0x62, 0x6c, 0x3a, 0xe3, 0xd1, 0xbc, 0x7d, 0x08, 0x9e, 0xff, 0x0d, 0x00, + 0x00, 0xff, 0xff, 0x89, 0xbf, 0x61, 0x05, 0x53, 0x04, 0x00, 0x00, } func (this *Transaction) Equal(that interface{}) bool { @@ -293,13 +302,16 @@ func (this *Transaction) Equal(that interface{}) bool { if !bytes.Equal(this.GuardianSignature, that1.GuardianSignature) { return false } + if !bytes.Equal(this.InnerTransactions, that1.InnerTransactions) { + return false + } return true } func (this *Transaction) GoString() string { if this == nil { return "nil" } - s := make([]string, 0, 19) + s := make([]string, 0, 20) s = append(s, "&transaction.Transaction{") s = append(s, "Nonce: "+fmt.Sprintf("%#v", this.Nonce)+",\n") s = append(s, "Value: "+fmt.Sprintf("%#v", this.Value)+",\n") @@ -316,6 +328,7 @@ func (this *Transaction) GoString() string { s = append(s, "Options: "+fmt.Sprintf("%#v", this.Options)+",\n") s = append(s, "GuardianAddr: "+fmt.Sprintf("%#v", this.GuardianAddr)+",\n") s = append(s, "GuardianSignature: "+fmt.Sprintf("%#v", this.GuardianSignature)+",\n") + s = append(s, "InnerTransactions: "+fmt.Sprintf("%#v", this.InnerTransactions)+",\n") s = append(s, "}") return strings.Join(s, "") } @@ -347,6 +360,15 @@ func (m *Transaction) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.InnerTransactions) > 0 { + i -= len(m.InnerTransactions) + copy(dAtA[i:], m.InnerTransactions) + i = encodeVarintTransaction(dAtA, i, uint64(len(m.InnerTransactions))) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0x82 + } if len(m.GuardianSignature) > 0 { i -= len(m.GuardianSignature) copy(dAtA[i:], m.GuardianSignature) @@ -522,6 +544,10 @@ func (m *Transaction) Size() (n int) { if l > 0 { n += 1 + l + sovTransaction(uint64(l)) } + l = len(m.InnerTransactions) + if l > 0 { + n += 2 + l + sovTransaction(uint64(l)) + } return n } @@ -551,6 +577,7 @@ func (this *Transaction) String() string { `Options:` + fmt.Sprintf("%v", this.Options) + `,`, `GuardianAddr:` + fmt.Sprintf("%v", this.GuardianAddr) + `,`, `GuardianSignature:` + fmt.Sprintf("%v", this.GuardianSignature) + `,`, + `InnerTransactions:` + fmt.Sprintf("%v", this.InnerTransactions) + `,`, `}`, }, "") return s @@ -1031,6 +1058,40 @@ func (m *Transaction) Unmarshal(dAtA []byte) error { m.GuardianSignature = []byte{} } iNdEx = postIndex + case 16: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field InnerTransactions", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTransaction + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTransaction + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTransaction + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.InnerTransactions = append(m.InnerTransactions[:0], dAtA[iNdEx:postIndex]...) + if m.InnerTransactions == nil { + m.InnerTransactions = []byte{} + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipTransaction(dAtA[iNdEx:]) diff --git a/data/transaction/transaction.proto b/data/transaction/transaction.proto index 2e8e168d5..d1a156ae2 100644 --- a/data/transaction/transaction.proto +++ b/data/transaction/transaction.proto @@ -30,4 +30,5 @@ message Transaction { uint32 Options = 13 [(gogoproto.jsontag) = "options,omitempty"]; bytes GuardianAddr = 14 [(gogoproto.jsontag) = "guardian,omitempty"]; bytes GuardianSignature = 15 [(gogoproto.jsontag) = "guardianSignature,omitempty"]; + bytes InnerTransactions = 16 [(gogoproto.jsontag) = "innerTransactions,omitempty"]; } diff --git a/data/transaction/transaction_test.go b/data/transaction/transaction_test.go index 023066537..7da781ffe 100644 --- a/data/transaction/transaction_test.go +++ b/data/transaction/transaction_test.go @@ -23,6 +23,7 @@ func TestTransaction_SettersAndGetters(t *testing.T) { gasLimit := uint64(5) sender := []byte("sndr") receiver := []byte("receiver") + innerTxs := []byte("inner txs") tx := &transaction.Transaction{ Nonce: nonce, @@ -35,6 +36,7 @@ func TestTransaction_SettersAndGetters(t *testing.T) { tx.SetData(txData) tx.SetValue(value) tx.SetRcvAddr(receiver) + tx.SetInnerTransactions(innerTxs) assert.Equal(t, nonce, tx.GetNonce()) assert.Equal(t, value, tx.GetValue()) @@ -43,6 +45,7 @@ func TestTransaction_SettersAndGetters(t *testing.T) { assert.Equal(t, gasLimit, tx.GetGasLimit()) assert.Equal(t, sender, tx.GetSndAddr()) assert.Equal(t, receiver, tx.GetRcvAddr()) + assert.Equal(t, innerTxs, tx.GetInnerTransactions()) } func TestTransaction_MarshalUnmarshalJsonShouldWork(t *testing.T) { @@ -50,14 +53,15 @@ func TestTransaction_MarshalUnmarshalJsonShouldWork(t *testing.T) { value := big.NewInt(445566) tx := &transaction.Transaction{ - Nonce: 112233, - Value: new(big.Int).Set(value), - RcvAddr: []byte("receiver"), - SndAddr: []byte("sender"), - GasPrice: 1234, - GasLimit: 5678, - Data: []byte("data"), - Signature: []byte("signature"), + Nonce: 112233, + Value: new(big.Int).Set(value), + RcvAddr: []byte("receiver"), + SndAddr: []byte("sender"), + GasPrice: 1234, + GasLimit: 5678, + Data: []byte("data"), + Signature: []byte("signature"), + InnerTransactions: []byte("inner txs"), } buff, err := json.Marshal(tx) @@ -220,7 +224,8 @@ func TestTransaction_GetDataForSigningShouldWork(t *testing.T) { tx := &transaction.Transaction{} numEncodeCalled := 0 - marshalizerWasCalled := false + marshallWasCalled := false + unmarshallWasCalled := false hasherWasCalled := false buff, err := tx.GetDataForSigning( &mock.PubkeyConverterStub{ @@ -231,10 +236,15 @@ func TestTransaction_GetDataForSigningShouldWork(t *testing.T) { }, &mock.MarshalizerStub{ MarshalCalled: func(obj interface{}) (bytes []byte, err error) { - marshalizerWasCalled = true + marshallWasCalled = true return make([]byte, 0), nil }, + UnmarshalCalled: func(obj interface{}, buff []byte) error { + unmarshallWasCalled = true + + return nil + }, }, &mock.HasherStub{ ComputeCalled: func(s string) []byte { @@ -247,11 +257,73 @@ func TestTransaction_GetDataForSigningShouldWork(t *testing.T) { assert.Equal(t, 0, len(buff)) assert.Nil(t, err) - assert.True(t, marshalizerWasCalled) + assert.True(t, marshallWasCalled) + assert.True(t, unmarshallWasCalled) assert.False(t, hasherWasCalled) assert.Equal(t, 2, numEncodeCalled) }) + t.Run("inner txs, without hash sign option set", func(t *testing.T) { + t.Parallel() + + tx1 := &transaction.Transaction{ + Nonce: 1, + } + tx2 := &transaction.Transaction{ + Nonce: 2, + } + innerTxsBuff, err := json.Marshal([]*transaction.Transaction{tx1, tx2}) + assert.NoError(t, err) + tx := &transaction.Transaction{ + Nonce: 3, + InnerTransactions: innerTxsBuff, + } + + numEncodeCalled := 0 + marshallWasCalled := false + unmarshallWasCalled := false + hasherWasCalled := false + buff, err := tx.GetDataForSigning( + &mock.PubkeyConverterStub{ + EncodeCalled: func(pkBytes []byte) (string, error) { + numEncodeCalled++ + return "", nil + }, + }, + &mock.MarshalizerStub{ + MarshalCalled: func(obj interface{}) (bytes []byte, err error) { + marshallWasCalled = true + + return json.Marshal(obj) + }, + UnmarshalCalled: func(obj interface{}, buff []byte) error { + unmarshallWasCalled = true + + return json.Unmarshal(buff, obj) + }, + }, + &mock.HasherStub{ + ComputeCalled: func(s string) []byte { + hasherWasCalled = true + + return make([]byte, 0) + }, + }, + ) + + assert.Nil(t, err) + + var ftx transaction.FrontendTransaction + err = json.Unmarshal(buff, &ftx) + assert.Nil(t, err) + assert.Equal(t, 2, len(ftx.InnerTransactions)) + + assert.True(t, marshallWasCalled) + assert.True(t, unmarshallWasCalled) + assert.False(t, hasherWasCalled) + assert.Equal(t, 6, numEncodeCalled) + }) + t.Run("with hash sign option set", func(t *testing.T) { t.Parallel() @@ -260,7 +332,8 @@ func TestTransaction_GetDataForSigningShouldWork(t *testing.T) { tx.Options ^= transaction.MaskSignedWithHash numEncodeCalled := 0 - marshalizerWasCalled := false + marshallWasCalled := false + unmarshallWasCalled := false hasherWasCalled := false expectedHash := []byte("expectedHash") buff, err := tx.GetDataForSigning( @@ -272,10 +345,15 @@ func TestTransaction_GetDataForSigningShouldWork(t *testing.T) { }, &mock.MarshalizerStub{ MarshalCalled: func(obj interface{}) (bytes []byte, err error) { - marshalizerWasCalled = true + marshallWasCalled = true return make([]byte, 0), nil }, + UnmarshalCalled: func(obj interface{}, buff []byte) error { + unmarshallWasCalled = true + + return nil + }, }, &mock.HasherStub{ ComputeCalled: func(s string) []byte { @@ -287,7 +365,8 @@ func TestTransaction_GetDataForSigningShouldWork(t *testing.T) { ) assert.Nil(t, err) - assert.True(t, marshalizerWasCalled) + assert.True(t, marshallWasCalled) + assert.True(t, unmarshallWasCalled) assert.True(t, hasherWasCalled) assert.Equal(t, expectedHash, buff) assert.Equal(t, 2, numEncodeCalled) From 6ac41d9be0a3f5ed99cef8dfea97d53cfc2a29f6 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 8 Sep 2023 14:50:59 +0300 Subject: [PATCH 02/22] fix test --- data/transaction/transaction_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/data/transaction/transaction_test.go b/data/transaction/transaction_test.go index 7da781ffe..ff4221254 100644 --- a/data/transaction/transaction_test.go +++ b/data/transaction/transaction_test.go @@ -186,6 +186,9 @@ func TestTransaction_GetDataForSigningMarshalizerErrShouldErr(t *testing.T) { MarshalCalled: func(obj interface{}) (bytes []byte, err error) { return nil, expectedErr }, + UnmarshalCalled: func(obj interface{}, buff []byte) error { + return nil + }, }, &mock.HasherMock{}, ) From b0fb32803ee5a28f9061ec5f85e0e540db39f90f Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 8 Sep 2023 15:20:56 +0300 Subject: [PATCH 03/22] added extra check --- data/transaction/transaction.go | 89 ++++++++++++++++------------ data/transaction/transaction_test.go | 14 ----- 2 files changed, 51 insertions(+), 52 deletions(-) diff --git a/data/transaction/transaction.go b/data/transaction/transaction.go index 83f78153d..4851ff6f1 100644 --- a/data/transaction/transaction.go +++ b/data/transaction/transaction.go @@ -79,21 +79,11 @@ func (tx *Transaction) GetDataForSigning(encoder data.Encoder, marshaller data.M return nil, err } - innerTxs := make([]*Transaction, 0) - err = marshaller.Unmarshal(&innerTxs, tx.InnerTransactions) - if err != nil { - return nil, err - } - for _, innerTx := range innerTxs { - innerFtx, innerErr := innerTx.prepareTx(encoder) - if innerErr != nil { + if len(tx.InnerTransactions) > 0 { + ftx.InnerTransactions, err = tx.prepareInnerTxs(encoder, marshaller) + if err != nil { return nil, err } - - innerFtx.Signature = hex.EncodeToString(innerTx.Signature) - innerFtx.GuardianSignature = hex.EncodeToString(innerTx.GuardianSignature) - - ftx.InnerTransactions = append(ftx.InnerTransactions, innerFtx) } ftxBytes, err := marshaller.Marshal(ftx) @@ -111,6 +101,37 @@ func (tx *Transaction) GetDataForSigning(encoder data.Encoder, marshaller data.M return ftxHash, nil } +// HasOptionGuardianSet returns true if the guarded transaction option is set +func (tx *Transaction) HasOptionGuardianSet() bool { + return tx.Options&MaskGuardedTransaction > 0 +} + +// HasOptionHashSignSet returns true if the signed with hash option is set +func (tx *Transaction) HasOptionHashSignSet() bool { + return tx.Options&MaskSignedWithHash > 0 +} + +// CheckIntegrity checks for not nil fields and negative value +func (tx *Transaction) CheckIntegrity() error { + if tx.Signature == nil { + return data.ErrNilSignature + } + if tx.Value == nil { + return data.ErrNilValue + } + if tx.Value.Sign() < 0 { + return data.ErrNegativeValue + } + if len(tx.RcvUserName) > core.MaxUserNameLength { + return data.ErrInvalidUserNameLength + } + if len(tx.SndUserName) > core.MaxUserNameLength { + return data.ErrInvalidUserNameLength + } + + return nil +} + func (tx *Transaction) prepareTx(encoder data.Encoder) (*FrontendTransaction, error) { receiverAddr, err := encoder.Encode(tx.RcvAddr) if err != nil { @@ -149,33 +170,25 @@ func (tx *Transaction) prepareTx(encoder data.Encoder) (*FrontendTransaction, er return ftx, nil } -// HasOptionGuardianSet returns true if the guarded transaction option is set -func (tx *Transaction) HasOptionGuardianSet() bool { - return tx.Options&MaskGuardedTransaction > 0 -} +func (tx *Transaction) prepareInnerTxs(encoder data.Encoder, marshaller data.Marshaller) ([]*FrontendTransaction, error) { + innerTxs := make([]*Transaction, 0) + err := marshaller.Unmarshal(&innerTxs, tx.InnerTransactions) + if err != nil { + return nil, err + } -// HasOptionHashSignSet returns true if the signed with hash option is set -func (tx *Transaction) HasOptionHashSignSet() bool { - return tx.Options&MaskSignedWithHash > 0 -} + innerFtxs := make([]*FrontendTransaction, 0, len(innerTxs)) + for _, innerTx := range innerTxs { + innerFtx, innerErr := innerTx.prepareTx(encoder) + if innerErr != nil { + return nil, err + } -// CheckIntegrity checks for not nil fields and negative value -func (tx *Transaction) CheckIntegrity() error { - if tx.Signature == nil { - return data.ErrNilSignature - } - if tx.Value == nil { - return data.ErrNilValue - } - if tx.Value.Sign() < 0 { - return data.ErrNegativeValue - } - if len(tx.RcvUserName) > core.MaxUserNameLength { - return data.ErrInvalidUserNameLength - } - if len(tx.SndUserName) > core.MaxUserNameLength { - return data.ErrInvalidUserNameLength + innerFtx.Signature = hex.EncodeToString(innerTx.Signature) + innerFtx.GuardianSignature = hex.EncodeToString(innerTx.GuardianSignature) + + innerFtxs = append(innerFtxs, innerFtx) } - return nil + return innerFtxs, nil } diff --git a/data/transaction/transaction_test.go b/data/transaction/transaction_test.go index ff4221254..79314f833 100644 --- a/data/transaction/transaction_test.go +++ b/data/transaction/transaction_test.go @@ -228,7 +228,6 @@ func TestTransaction_GetDataForSigningShouldWork(t *testing.T) { numEncodeCalled := 0 marshallWasCalled := false - unmarshallWasCalled := false hasherWasCalled := false buff, err := tx.GetDataForSigning( &mock.PubkeyConverterStub{ @@ -243,11 +242,6 @@ func TestTransaction_GetDataForSigningShouldWork(t *testing.T) { return make([]byte, 0), nil }, - UnmarshalCalled: func(obj interface{}, buff []byte) error { - unmarshallWasCalled = true - - return nil - }, }, &mock.HasherStub{ ComputeCalled: func(s string) []byte { @@ -261,7 +255,6 @@ func TestTransaction_GetDataForSigningShouldWork(t *testing.T) { assert.Equal(t, 0, len(buff)) assert.Nil(t, err) assert.True(t, marshallWasCalled) - assert.True(t, unmarshallWasCalled) assert.False(t, hasherWasCalled) assert.Equal(t, 2, numEncodeCalled) }) @@ -336,7 +329,6 @@ func TestTransaction_GetDataForSigningShouldWork(t *testing.T) { numEncodeCalled := 0 marshallWasCalled := false - unmarshallWasCalled := false hasherWasCalled := false expectedHash := []byte("expectedHash") buff, err := tx.GetDataForSigning( @@ -352,11 +344,6 @@ func TestTransaction_GetDataForSigningShouldWork(t *testing.T) { return make([]byte, 0), nil }, - UnmarshalCalled: func(obj interface{}, buff []byte) error { - unmarshallWasCalled = true - - return nil - }, }, &mock.HasherStub{ ComputeCalled: func(s string) []byte { @@ -369,7 +356,6 @@ func TestTransaction_GetDataForSigningShouldWork(t *testing.T) { assert.Nil(t, err) assert.True(t, marshallWasCalled) - assert.True(t, unmarshallWasCalled) assert.True(t, hasherWasCalled) assert.Equal(t, expectedHash, buff) assert.Equal(t, 2, numEncodeCalled) From 132204ad0b6c286d390f10e2555ca7959a6a5cc3 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 8 Sep 2023 16:43:37 +0300 Subject: [PATCH 04/22] added RelayedV3TransactionHandler --- data/interface.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/data/interface.go b/data/interface.go index 748868fe7..169c39543 100644 --- a/data/interface.go +++ b/data/interface.go @@ -408,3 +408,8 @@ type UserAccountHandler interface { AddressBytes() []byte IsInterfaceNil() bool } + +// RelayedV3TransactionHandler defines functionality for relayed v3 transaction +type RelayedV3TransactionHandler interface { + GetInnerTransactions() []byte +} From 8f1a3790459a7709d2db6efefde93f511f27eb7f Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 20 Sep 2023 09:42:55 +0300 Subject: [PATCH 05/22] only one inner tx --- data/interface.go | 2 +- data/transaction/apiTransactionResult.go | 2 +- data/transaction/frontendTransaction.go | 32 +++---- data/transaction/transaction.go | 35 ++++---- data/transaction/transaction.pb.go | 106 +++++++++++------------ data/transaction/transaction.proto | 2 +- data/transaction/transaction_test.go | 36 ++++---- 7 files changed, 103 insertions(+), 112 deletions(-) diff --git a/data/interface.go b/data/interface.go index 169c39543..a554675cd 100644 --- a/data/interface.go +++ b/data/interface.go @@ -411,5 +411,5 @@ type UserAccountHandler interface { // RelayedV3TransactionHandler defines functionality for relayed v3 transaction type RelayedV3TransactionHandler interface { - GetInnerTransactions() []byte + GetInnerTransaction() []byte } diff --git a/data/transaction/apiTransactionResult.go b/data/transaction/apiTransactionResult.go index 8f619d064..20e86eb1d 100644 --- a/data/transaction/apiTransactionResult.go +++ b/data/transaction/apiTransactionResult.go @@ -69,7 +69,7 @@ type ApiTransactionResult struct { Options uint32 `json:"options"` GuardianAddr string `json:"guardian,omitempty"` GuardianSignature string `json:"guardianSignature,omitempty"` - InnerTransactions []data.TransactionHandler `json:"innerTransactions,omitempty"` + InnerTransaction data.TransactionHandler `json:"innerTransaction,omitempty"` } // ApiSmartContractResult represents a smart contract result with changed fields' types in order to make it friendly for API's json diff --git a/data/transaction/frontendTransaction.go b/data/transaction/frontendTransaction.go index 8b706e767..c627a5164 100644 --- a/data/transaction/frontendTransaction.go +++ b/data/transaction/frontendTransaction.go @@ -2,20 +2,20 @@ 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"` - 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"` + InnerTransaction *FrontendTransaction `json:"innerTransaction,omitempty"` } diff --git a/data/transaction/transaction.go b/data/transaction/transaction.go index 4851ff6f1..6dc9d14ea 100644 --- a/data/transaction/transaction.go +++ b/data/transaction/transaction.go @@ -37,9 +37,9 @@ func (tx *Transaction) SetSndAddr(addr []byte) { tx.SndAddr = addr } -// SetInnerTransactions sets the inner transactions of the transaction -func (tx *Transaction) SetInnerTransactions(innerTransactions []byte) { - tx.InnerTransactions = innerTransactions +// SetInnerTransaction sets the inner transaction of the transaction +func (tx *Transaction) SetInnerTransaction(innerTransaction []byte) { + tx.InnerTransaction = innerTransaction } // TrimSlicePtr creates a copy of the provided slice without the excess capacity @@ -79,8 +79,8 @@ func (tx *Transaction) GetDataForSigning(encoder data.Encoder, marshaller data.M return nil, err } - if len(tx.InnerTransactions) > 0 { - ftx.InnerTransactions, err = tx.prepareInnerTxs(encoder, marshaller) + if len(tx.InnerTransaction) > 0 { + ftx.InnerTransaction, err = tx.prepareInnerTx(encoder, marshaller) if err != nil { return nil, err } @@ -170,25 +170,20 @@ func (tx *Transaction) prepareTx(encoder data.Encoder) (*FrontendTransaction, er return ftx, nil } -func (tx *Transaction) prepareInnerTxs(encoder data.Encoder, marshaller data.Marshaller) ([]*FrontendTransaction, error) { - innerTxs := make([]*Transaction, 0) - err := marshaller.Unmarshal(&innerTxs, tx.InnerTransactions) +func (tx *Transaction) prepareInnerTx(encoder data.Encoder, marshaller data.Marshaller) (*FrontendTransaction, error) { + var innerTx Transaction + err := marshaller.Unmarshal(&innerTx, tx.InnerTransaction) if err != nil { return nil, err } - innerFtxs := make([]*FrontendTransaction, 0, len(innerTxs)) - for _, innerTx := range innerTxs { - innerFtx, innerErr := innerTx.prepareTx(encoder) - if innerErr != nil { - return nil, err - } - - innerFtx.Signature = hex.EncodeToString(innerTx.Signature) - innerFtx.GuardianSignature = hex.EncodeToString(innerTx.GuardianSignature) - - innerFtxs = append(innerFtxs, innerFtx) + ftx, err := tx.prepareTx(encoder) + if err != nil { + return nil, err } - return innerFtxs, nil + ftx.Signature = hex.EncodeToString(innerTx.Signature) + ftx.GuardianSignature = hex.EncodeToString(innerTx.GuardianSignature) + + return ftx, nil } diff --git a/data/transaction/transaction.pb.go b/data/transaction/transaction.pb.go index c6dfba036..389b7526e 100644 --- a/data/transaction/transaction.pb.go +++ b/data/transaction/transaction.pb.go @@ -45,7 +45,7 @@ type Transaction struct { Options uint32 `protobuf:"varint,13,opt,name=Options,proto3" json:"options,omitempty"` GuardianAddr []byte `protobuf:"bytes,14,opt,name=GuardianAddr,proto3" json:"guardian,omitempty"` GuardianSignature []byte `protobuf:"bytes,15,opt,name=GuardianSignature,proto3" json:"guardianSignature,omitempty"` - InnerTransactions []byte `protobuf:"bytes,16,opt,name=InnerTransactions,proto3" json:"innerTransactions,omitempty"` + InnerTransaction []byte `protobuf:"bytes,16,opt,name=InnerTransaction,proto3" json:"innerTransaction,omitempty"` } func (m *Transaction) Reset() { *m = Transaction{} } @@ -181,9 +181,9 @@ func (m *Transaction) GetGuardianSignature() []byte { return nil } -func (m *Transaction) GetInnerTransactions() []byte { +func (m *Transaction) GetInnerTransaction() []byte { if m != nil { - return m.InnerTransactions + return m.InnerTransaction } return nil } @@ -195,44 +195,44 @@ func init() { func init() { proto.RegisterFile("transaction.proto", fileDescriptor_2cc4e03d2c28c490) } var fileDescriptor_2cc4e03d2c28c490 = []byte{ - // 587 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x54, 0xcf, 0x4e, 0x14, 0x3d, - 0x00, 0xdf, 0x7e, 0x1f, 0xcb, 0x40, 0x77, 0x41, 0xa9, 0x41, 0xab, 0x26, 0x2d, 0x31, 0x4a, 0x38, - 0xb8, 0x3b, 0x89, 0xc6, 0x8b, 0x9c, 0x5c, 0x30, 0x64, 0x13, 0x45, 0x33, 0x28, 0x07, 0x6f, 0xdd, - 0x99, 0x3a, 0xdb, 0x84, 0x69, 0x49, 0xa7, 0xbb, 0xc1, 0x83, 0x09, 0x8f, 0xe0, 0x63, 0x18, 0x9f, - 0xc4, 0x23, 0x47, 0x4e, 0xa3, 0x0c, 0x17, 0x33, 0x27, 0x1e, 0xc1, 0x4c, 0x67, 0x87, 0x29, 0x70, - 0xf2, 0x34, 0xed, 0xef, 0x6f, 0xd3, 0x4e, 0x0b, 0x57, 0x8c, 0x66, 0x32, 0x65, 0xa1, 0x11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, 0x3d, 0xad, 0x65, 0x5b, 0x55, - 0xed, 0xca, 0x0c, 0x77, 0x6c, 0x57, 0xb4, 0xe8, 0x2d, 0x5c, 0xa9, 0xe7, 0xcd, 0x5a, 0x6f, 0xd9, - 0x00, 0x5a, 0x64, 0xf4, 0x61, 0x7c, 0x9d, 0x74, 0x92, 0x6e, 0x3a, 0xcb, 0xb8, 0xa1, 0x94, 0x5c, - 0x3b, 0xf7, 0x26, 0xc5, 0xb7, 0x9b, 0x38, 0x71, 0x9d, 0x74, 0xe3, 0x6e, 0x38, 0x07, 0x5f, 0x4f, - 0xce, 0x48, 0xeb, 0xf4, 0x8c, 0xb4, 0x2e, 0xce, 0x08, 0x38, 0xce, 0x09, 0xf8, 0x9e, 0x13, 0xf0, - 0x33, 0x27, 0xe0, 0x24, 0x27, 0xe0, 0x34, 0x27, 0xe0, 0x77, 0x4e, 0xc0, 0x9f, 0x9c, 0xb4, 0x2e, - 0x72, 0x02, 0xbe, 0x9d, 0x93, 0xd6, 0xc9, 0x39, 0x69, 0x9d, 0x9e, 0x93, 0xd6, 0xa7, 0xad, 0x7f, - 0xb8, 0x62, 0xbe, 0xf3, 0x62, 0x6c, 0x3a, 0xe3, 0xd1, 0xbc, 0x7d, 0x08, 0x9e, 0xff, 0x0d, 0x00, - 0x00, 0xff, 0xff, 0x89, 0xbf, 0x61, 0x05, 0x53, 0x04, 0x00, 0x00, + // 592 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x54, 0xcd, 0x6e, 0xd3, 0x30, + 0x00, 0xae, 0x61, 0x6d, 0x37, 0xb7, 0x1b, 0x9b, 0xd1, 0xc0, 0x0c, 0xc9, 0x9e, 0x10, 0x4c, 0x3b, + 0xd0, 0x46, 0x02, 0x71, 0x61, 0x27, 0xba, 0xa1, 0xa9, 0x08, 0x06, 0xca, 0x60, 0x07, 0x6e, 0x6e, + 0x62, 0x52, 0x4b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cd, + 0x71, 0xdb, 0xe6, 0xdd, 0xcd, 0x53, 0x7a, 0x3b, 0x99, 0x82, 0x4e, 0x7f, 0xa5, 0x44, 0x1e, 0x6c, + 0xbe, 0x3d, 0x2a, 0xfe, 0xb8, 0x04, 0x2f, 0xda, 0xf4, 0xd5, 0x3c, 0xa5, 0x2b, 0xaa, 0x84, 0x1c, + 0xcb, 0x54, 0x85, 0x9e, 0xc3, 0xf6, 0xee, 0x88, 0xe9, 0x50, 0x30, 0x69, 0x4f, 0x6b, 0xc9, 0x56, + 0x95, 0xbb, 0x32, 0xc1, 0x1d, 0xdb, 0x15, 0x2d, 0x7a, 0x03, 0x57, 0xa6, 0xf3, 0x6a, 0xad, 0xb7, + 0x6c, 0x00, 0xcd, 0x53, 0x7a, 0x3f, 0x9a, 0x25, 0x9d, 0xa4, 0xeb, 0x4e, 0xf4, 0x0a, 0x2e, 0xf7, + 0xa5, 0xe4, 0xda, 0xb9, 0x37, 0x78, 0xd9, 0xa6, 0x91, 0x3c, 0xa5, 0x6b, 0x62, 0x86, 0x73, 0xc2, + 0xae, 0xf9, 0x7a, 0x5f, 0x4e, 0xce, 0x48, 0xed, 0xf4, 0x8c, 0xd4, 0x2e, 0xce, 0x08, 0xf8, 0x9a, + 0x11, 0xf0, 0x3d, 0x23, 0xe0, 0x67, 0x46, 0xc0, 0x49, 0x46, 0xc0, 0x69, 0x46, 0xc0, 0xef, 0x8c, + 0x80, 0x3f, 0x19, 0xa9, 0x5d, 0x64, 0x04, 0x7c, 0x3b, 0x27, 0xb5, 0x93, 0x73, 0x52, 0x3b, 0x3d, + 0x27, 0xb5, 0x8f, 0xdb, 0xff, 0x71, 0xbf, 0x3c, 0xe7, 0xb9, 0xd8, 0x72, 0xc6, 0x83, 0x86, 0x7d, + 0x05, 0x9e, 0xfe, 0x0b, 0x00, 0x00, 0xff, 0xff, 0xe8, 0x47, 0x21, 0xb0, 0x50, 0x04, 0x00, 0x00, } func (this *Transaction) Equal(that interface{}) bool { @@ -302,7 +302,7 @@ func (this *Transaction) Equal(that interface{}) bool { if !bytes.Equal(this.GuardianSignature, that1.GuardianSignature) { return false } - if !bytes.Equal(this.InnerTransactions, that1.InnerTransactions) { + if !bytes.Equal(this.InnerTransaction, that1.InnerTransaction) { return false } return true @@ -328,7 +328,7 @@ func (this *Transaction) GoString() string { s = append(s, "Options: "+fmt.Sprintf("%#v", this.Options)+",\n") s = append(s, "GuardianAddr: "+fmt.Sprintf("%#v", this.GuardianAddr)+",\n") s = append(s, "GuardianSignature: "+fmt.Sprintf("%#v", this.GuardianSignature)+",\n") - s = append(s, "InnerTransactions: "+fmt.Sprintf("%#v", this.InnerTransactions)+",\n") + s = append(s, "InnerTransaction: "+fmt.Sprintf("%#v", this.InnerTransaction)+",\n") s = append(s, "}") return strings.Join(s, "") } @@ -360,10 +360,10 @@ func (m *Transaction) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.InnerTransactions) > 0 { - i -= len(m.InnerTransactions) - copy(dAtA[i:], m.InnerTransactions) - i = encodeVarintTransaction(dAtA, i, uint64(len(m.InnerTransactions))) + if len(m.InnerTransaction) > 0 { + i -= len(m.InnerTransaction) + copy(dAtA[i:], m.InnerTransaction) + i = encodeVarintTransaction(dAtA, i, uint64(len(m.InnerTransaction))) i-- dAtA[i] = 0x1 i-- @@ -544,7 +544,7 @@ func (m *Transaction) Size() (n int) { if l > 0 { n += 1 + l + sovTransaction(uint64(l)) } - l = len(m.InnerTransactions) + l = len(m.InnerTransaction) if l > 0 { n += 2 + l + sovTransaction(uint64(l)) } @@ -577,7 +577,7 @@ func (this *Transaction) String() string { `Options:` + fmt.Sprintf("%v", this.Options) + `,`, `GuardianAddr:` + fmt.Sprintf("%v", this.GuardianAddr) + `,`, `GuardianSignature:` + fmt.Sprintf("%v", this.GuardianSignature) + `,`, - `InnerTransactions:` + fmt.Sprintf("%v", this.InnerTransactions) + `,`, + `InnerTransaction:` + fmt.Sprintf("%v", this.InnerTransaction) + `,`, `}`, }, "") return s @@ -1060,7 +1060,7 @@ func (m *Transaction) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 16: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field InnerTransactions", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field InnerTransaction", wireType) } var byteLen int for shift := uint(0); ; shift += 7 { @@ -1087,9 +1087,9 @@ func (m *Transaction) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.InnerTransactions = append(m.InnerTransactions[:0], dAtA[iNdEx:postIndex]...) - if m.InnerTransactions == nil { - m.InnerTransactions = []byte{} + m.InnerTransaction = append(m.InnerTransaction[:0], dAtA[iNdEx:postIndex]...) + if m.InnerTransaction == nil { + m.InnerTransaction = []byte{} } iNdEx = postIndex default: diff --git a/data/transaction/transaction.proto b/data/transaction/transaction.proto index d1a156ae2..39180eefb 100644 --- a/data/transaction/transaction.proto +++ b/data/transaction/transaction.proto @@ -30,5 +30,5 @@ message Transaction { uint32 Options = 13 [(gogoproto.jsontag) = "options,omitempty"]; bytes GuardianAddr = 14 [(gogoproto.jsontag) = "guardian,omitempty"]; bytes GuardianSignature = 15 [(gogoproto.jsontag) = "guardianSignature,omitempty"]; - bytes InnerTransactions = 16 [(gogoproto.jsontag) = "innerTransactions,omitempty"]; + bytes InnerTransaction = 16 [(gogoproto.jsontag) = "innerTransaction,omitempty"]; } diff --git a/data/transaction/transaction_test.go b/data/transaction/transaction_test.go index 79314f833..f3adf5dad 100644 --- a/data/transaction/transaction_test.go +++ b/data/transaction/transaction_test.go @@ -23,7 +23,7 @@ func TestTransaction_SettersAndGetters(t *testing.T) { gasLimit := uint64(5) sender := []byte("sndr") receiver := []byte("receiver") - innerTxs := []byte("inner txs") + innerTx := []byte("inner tx") tx := &transaction.Transaction{ Nonce: nonce, @@ -36,7 +36,7 @@ func TestTransaction_SettersAndGetters(t *testing.T) { tx.SetData(txData) tx.SetValue(value) tx.SetRcvAddr(receiver) - tx.SetInnerTransactions(innerTxs) + tx.SetInnerTransaction(innerTx) assert.Equal(t, nonce, tx.GetNonce()) assert.Equal(t, value, tx.GetValue()) @@ -45,7 +45,7 @@ func TestTransaction_SettersAndGetters(t *testing.T) { assert.Equal(t, gasLimit, tx.GetGasLimit()) assert.Equal(t, sender, tx.GetSndAddr()) assert.Equal(t, receiver, tx.GetRcvAddr()) - assert.Equal(t, innerTxs, tx.GetInnerTransactions()) + assert.Equal(t, innerTx, tx.GetInnerTransaction()) } func TestTransaction_MarshalUnmarshalJsonShouldWork(t *testing.T) { @@ -53,15 +53,15 @@ func TestTransaction_MarshalUnmarshalJsonShouldWork(t *testing.T) { value := big.NewInt(445566) tx := &transaction.Transaction{ - Nonce: 112233, - Value: new(big.Int).Set(value), - RcvAddr: []byte("receiver"), - SndAddr: []byte("sender"), - GasPrice: 1234, - GasLimit: 5678, - Data: []byte("data"), - Signature: []byte("signature"), - InnerTransactions: []byte("inner txs"), + Nonce: 112233, + Value: new(big.Int).Set(value), + RcvAddr: []byte("receiver"), + SndAddr: []byte("sender"), + GasPrice: 1234, + GasLimit: 5678, + Data: []byte("data"), + Signature: []byte("signature"), + InnerTransaction: []byte("inner tx"), } buff, err := json.Marshal(tx) @@ -265,14 +265,11 @@ func TestTransaction_GetDataForSigningShouldWork(t *testing.T) { tx1 := &transaction.Transaction{ Nonce: 1, } - tx2 := &transaction.Transaction{ - Nonce: 2, - } - innerTxsBuff, err := json.Marshal([]*transaction.Transaction{tx1, tx2}) + innerTxBuff, err := json.Marshal(tx1) assert.NoError(t, err) tx := &transaction.Transaction{ - Nonce: 3, - InnerTransactions: innerTxsBuff, + Nonce: 3, + InnerTransaction: innerTxBuff, } numEncodeCalled := 0 @@ -312,12 +309,11 @@ func TestTransaction_GetDataForSigningShouldWork(t *testing.T) { var ftx transaction.FrontendTransaction err = json.Unmarshal(buff, &ftx) assert.Nil(t, err) - assert.Equal(t, 2, len(ftx.InnerTransactions)) assert.True(t, marshallWasCalled) assert.True(t, unmarshallWasCalled) assert.False(t, hasherWasCalled) - assert.Equal(t, 6, numEncodeCalled) + assert.Equal(t, 4, numEncodeCalled) }) t.Run("with hash sign option set", func(t *testing.T) { From 6724a647cd71dc03bc17e46dbb7e8510a4a9d158 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 20 Sep 2023 12:47:28 +0300 Subject: [PATCH 06/22] added missing pointer --- data/transaction/transaction.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/transaction/transaction.go b/data/transaction/transaction.go index 6dc9d14ea..2f550fd80 100644 --- a/data/transaction/transaction.go +++ b/data/transaction/transaction.go @@ -171,7 +171,7 @@ func (tx *Transaction) prepareTx(encoder data.Encoder) (*FrontendTransaction, er } func (tx *Transaction) prepareInnerTx(encoder data.Encoder, marshaller data.Marshaller) (*FrontendTransaction, error) { - var innerTx Transaction + var innerTx *Transaction err := marshaller.Unmarshal(&innerTx, tx.InnerTransaction) if err != nil { return nil, err From 978c5de1b9196faabcb8faa0653f3f7cec3b1fdc Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 20 Sep 2023 12:50:32 +0300 Subject: [PATCH 07/22] prepare proper inner tx --- data/transaction/transaction.go | 2 +- data/transaction/transaction_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/data/transaction/transaction.go b/data/transaction/transaction.go index 2f550fd80..5f1a0eb4b 100644 --- a/data/transaction/transaction.go +++ b/data/transaction/transaction.go @@ -177,7 +177,7 @@ func (tx *Transaction) prepareInnerTx(encoder data.Encoder, marshaller data.Mars return nil, err } - ftx, err := tx.prepareTx(encoder) + ftx, err := innerTx.prepareTx(encoder) if err != nil { return nil, err } diff --git a/data/transaction/transaction_test.go b/data/transaction/transaction_test.go index f3adf5dad..bcc78e180 100644 --- a/data/transaction/transaction_test.go +++ b/data/transaction/transaction_test.go @@ -259,7 +259,7 @@ func TestTransaction_GetDataForSigningShouldWork(t *testing.T) { assert.Equal(t, 2, numEncodeCalled) }) - t.Run("inner txs, without hash sign option set", func(t *testing.T) { + t.Run("inner tx, without hash sign option set", func(t *testing.T) { t.Parallel() tx1 := &transaction.Transaction{ From d7df5756e9e9fb304bdb093c0e48f2c29ab142a7 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 20 Sep 2023 13:01:04 +0300 Subject: [PATCH 08/22] fix unmarshal of inner --- data/transaction/transaction.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/data/transaction/transaction.go b/data/transaction/transaction.go index 5f1a0eb4b..683998bf9 100644 --- a/data/transaction/transaction.go +++ b/data/transaction/transaction.go @@ -171,8 +171,8 @@ func (tx *Transaction) prepareTx(encoder data.Encoder) (*FrontendTransaction, er } func (tx *Transaction) prepareInnerTx(encoder data.Encoder, marshaller data.Marshaller) (*FrontendTransaction, error) { - var innerTx *Transaction - err := marshaller.Unmarshal(&innerTx, tx.InnerTransaction) + innerTx := &Transaction{} + err := marshaller.Unmarshal(innerTx, tx.InnerTransaction) if err != nil { return nil, err } From 2791fda6508712015566597e0434fac11f8eecf4 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 20 Sep 2023 16:55:40 +0300 Subject: [PATCH 09/22] proper implementation --- data/interface.go | 5 -- data/transaction/transaction.go | 25 +----- data/transaction/transaction.pb.go | 120 +++++++++++++++------------ data/transaction/transaction.proto | 32 +++---- data/transaction/transaction_test.go | 35 ++++---- 5 files changed, 99 insertions(+), 118 deletions(-) diff --git a/data/interface.go b/data/interface.go index a554675cd..748868fe7 100644 --- a/data/interface.go +++ b/data/interface.go @@ -408,8 +408,3 @@ type UserAccountHandler interface { AddressBytes() []byte IsInterfaceNil() bool } - -// RelayedV3TransactionHandler defines functionality for relayed v3 transaction -type RelayedV3TransactionHandler interface { - GetInnerTransaction() []byte -} diff --git a/data/transaction/transaction.go b/data/transaction/transaction.go index 683998bf9..7c5040c40 100644 --- a/data/transaction/transaction.go +++ b/data/transaction/transaction.go @@ -2,7 +2,6 @@ package transaction import ( - "encoding/hex" "math/big" "github.com/multiversx/mx-chain-core-go/core" @@ -38,7 +37,7 @@ func (tx *Transaction) SetSndAddr(addr []byte) { } // SetInnerTransaction sets the inner transaction of the transaction -func (tx *Transaction) SetInnerTransaction(innerTransaction []byte) { +func (tx *Transaction) SetInnerTransaction(innerTransaction *Transaction) { tx.InnerTransaction = innerTransaction } @@ -79,8 +78,8 @@ func (tx *Transaction) GetDataForSigning(encoder data.Encoder, marshaller data.M return nil, err } - if len(tx.InnerTransaction) > 0 { - ftx.InnerTransaction, err = tx.prepareInnerTx(encoder, marshaller) + if tx.InnerTransaction != nil { + ftx.InnerTransaction, err = tx.prepareTx(encoder) if err != nil { return nil, err } @@ -169,21 +168,3 @@ func (tx *Transaction) prepareTx(encoder data.Encoder) (*FrontendTransaction, er return ftx, nil } - -func (tx *Transaction) prepareInnerTx(encoder data.Encoder, marshaller data.Marshaller) (*FrontendTransaction, error) { - innerTx := &Transaction{} - err := marshaller.Unmarshal(innerTx, tx.InnerTransaction) - if err != nil { - return nil, err - } - - ftx, err := innerTx.prepareTx(encoder) - if err != nil { - return nil, err - } - - ftx.Signature = hex.EncodeToString(innerTx.Signature) - ftx.GuardianSignature = hex.EncodeToString(innerTx.GuardianSignature) - - return ftx, nil -} diff --git a/data/transaction/transaction.pb.go b/data/transaction/transaction.pb.go index 389b7526e..95f6b9597 100644 --- a/data/transaction/transaction.pb.go +++ b/data/transaction/transaction.pb.go @@ -45,7 +45,7 @@ type Transaction struct { Options uint32 `protobuf:"varint,13,opt,name=Options,proto3" json:"options,omitempty"` GuardianAddr []byte `protobuf:"bytes,14,opt,name=GuardianAddr,proto3" json:"guardian,omitempty"` GuardianSignature []byte `protobuf:"bytes,15,opt,name=GuardianSignature,proto3" json:"guardianSignature,omitempty"` - InnerTransaction []byte `protobuf:"bytes,16,opt,name=InnerTransaction,proto3" json:"innerTransaction,omitempty"` + InnerTransaction *Transaction `protobuf:"bytes,16,opt,name=InnerTransaction,proto3" json:"innerTransaction,omitempty"` } func (m *Transaction) Reset() { *m = Transaction{} } @@ -181,7 +181,7 @@ func (m *Transaction) GetGuardianSignature() []byte { return nil } -func (m *Transaction) GetInnerTransaction() []byte { +func (m *Transaction) GetInnerTransaction() *Transaction { if m != nil { return m.InnerTransaction } @@ -195,44 +195,45 @@ func init() { func init() { proto.RegisterFile("transaction.proto", fileDescriptor_2cc4e03d2c28c490) } var fileDescriptor_2cc4e03d2c28c490 = []byte{ - // 592 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x54, 0xcd, 0x6e, 0xd3, 0x30, - 0x00, 0xae, 0x61, 0x6d, 0x37, 0xb7, 0x1b, 0x9b, 0xd1, 0xc0, 0x0c, 0xc9, 0x9e, 0x10, 0x4c, 0x3b, - 0xd0, 0x46, 0x02, 0x71, 0x61, 0x27, 0xba, 0xa1, 0xa9, 0x08, 0x06, 0xca, 0x60, 0x07, 0x6e, 0x6e, - 0x62, 0x52, 0x4b, 0x8b, 0x3d, 0x39, 0x6e, 0x35, 0x0e, 0x48, 0x3c, 0x02, 0x8f, 0x81, 0x78, 0x12, - 0x8e, 0x3b, 0xee, 0x14, 0x58, 0x76, 0x41, 0x39, 0xed, 0x05, 0x90, 0x50, 0x9c, 0x76, 0xf1, 0xba, - 0x13, 0xa7, 0xd8, 0xdf, 0xaf, 0x65, 0xc7, 0x86, 0x2b, 0x46, 0x33, 0x99, 0xb0, 0xc0, 0x08, 0x25, - 0xbb, 0x47, 0x5a, 0x19, 0x85, 0xea, 0xf6, 0xb3, 0xd6, 0x89, 0x84, 0x19, 0x8e, 0x06, 0xdd, 0x40, - 0xc5, 0x5e, 0xa4, 0x22, 0xe5, 0x59, 0x78, 0x30, 0xfa, 0x64, 0x67, 0x76, 0x62, 0x47, 0xa5, 0xeb, - 0xc1, 0xdf, 0x06, 0x6c, 0xbd, 0xaf, 0xb2, 0x10, 0x85, 0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 0xda, 0xb9, 0x37, 0x78, 0xd9, 0xa6, 0x91, 0x3c, 0xa5, 0x6b, 0x62, 0x86, 0x73, 0xc2, - 0xae, 0xf9, 0x7a, 0x5f, 0x4e, 0xce, 0x48, 0xed, 0xf4, 0x8c, 0xd4, 0x2e, 0xce, 0x08, 0xf8, 0x9a, - 0x11, 0xf0, 0x3d, 0x23, 0xe0, 0x67, 0x46, 0xc0, 0x49, 0x46, 0xc0, 0x69, 0x46, 0xc0, 0xef, 0x8c, - 0x80, 0x3f, 0x19, 0xa9, 0x5d, 0x64, 0x04, 0x7c, 0x3b, 0x27, 0xb5, 0x93, 0x73, 0x52, 0x3b, 0x3d, - 0x27, 0xb5, 0x8f, 0xdb, 0xff, 0x71, 0xbf, 0x3c, 0xe7, 0xb9, 0xd8, 0x72, 0xc6, 0x83, 0x86, 0x7d, - 0x05, 0x9e, 0xfe, 0x0b, 0x00, 0x00, 0xff, 0xff, 0xe8, 0x47, 0x21, 0xb0, 0x50, 0x04, 0x00, 0x00, + // 607 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x94, 0x41, 0x6f, 0xd3, 0x3c, + 0x1c, 0xc6, 0xeb, 0xf7, 0x5d, 0x97, 0xcd, 0xed, 0xc6, 0x66, 0x34, 0x30, 0x43, 0xb2, 0x2b, 0x04, + 0x53, 0x0f, 0xb4, 0x91, 0x86, 0xb8, 0xb0, 0x13, 0xdd, 0xd0, 0x54, 0x09, 0x06, 0xca, 0x60, 0x07, + 0x0e, 0x48, 0x6e, 0x62, 0x52, 0x4b, 0x8b, 0x3d, 0x39, 0x6e, 0x35, 0x0e, 0x48, 0x7c, 0x04, 0xf8, + 0x16, 0x88, 0x4f, 0xc2, 0x71, 0xc7, 0x9d, 0x02, 0xcb, 0x2e, 0x28, 0xa7, 0x7d, 0x04, 0x14, 0xa7, + 0x5d, 0xbd, 0xed, 0xc4, 0x29, 0xf6, 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 0x42, 0x8e, 0x65, 0xaa, 0x42, 0xcf, 0x60, 0x73, 0x77, 0xc4, 0x74, 0x24, 0x98, + 0xb4, 0xa7, 0xb5, 0x6c, 0xa3, 0xaa, 0x5d, 0x99, 0x70, 0xc7, 0x76, 0x45, 0x8b, 0x5e, 0xc1, 0xd5, + 0xe9, 0x7c, 0xb6, 0xd6, 0x5b, 0xb6, 0x01, 0x2d, 0x32, 0x7a, 0x3f, 0xbe, 0x5e, 0x74, 0x3a, 0xdd, + 0x74, 0xa2, 0x0f, 0x70, 0xa5, 0x2f, 0x25, 0xd7, 0xce, 0xbd, 0xc1, 0x2b, 0x2d, 0xd0, 0x6e, 0x6c, + 0xa2, 0xea, 0x56, 0x75, 0x9d, 0x4a, 0x8f, 0x14, 0x19, 0x5d, 0x17, 0xd7, 0xf4, 0x4e, 0xc0, 0x8d, + 0x5e, 0xbd, 0xcf, 0x27, 0x67, 0xa4, 0x76, 0x7a, 0x46, 0x6a, 0x17, 0x67, 0x04, 0x7c, 0xc9, 0x09, + 0xf8, 0x9e, 0x13, 0xf0, 0x33, 0x27, 0xe0, 0x24, 0x27, 0xe0, 0x34, 0x27, 0xe0, 0x77, 0x4e, 0xc0, + 0x9f, 0x9c, 0xd4, 0x2e, 0x72, 0x02, 0xbe, 0x9e, 0x93, 0xda, 0xc9, 0x39, 0xa9, 0x9d, 0x9e, 0x93, + 0xda, 0xfb, 0xed, 0x7f, 0xb8, 0x73, 0xbe, 0xf3, 0x0b, 0xd9, 0x72, 0xc6, 0x83, 0x79, 0xfb, 0x0e, + 0x4f, 0xfe, 0x06, 0x00, 0x00, 0xff, 0xff, 0xd6, 0x91, 0x2c, 0x8b, 0x64, 0x04, 0x00, 0x00, } func (this *Transaction) Equal(that interface{}) bool { @@ -302,7 +303,7 @@ func (this *Transaction) Equal(that interface{}) bool { if !bytes.Equal(this.GuardianSignature, that1.GuardianSignature) { return false } - if !bytes.Equal(this.InnerTransaction, that1.InnerTransaction) { + if !this.InnerTransaction.Equal(that1.InnerTransaction) { return false } return true @@ -328,7 +329,9 @@ func (this *Transaction) GoString() string { s = append(s, "Options: "+fmt.Sprintf("%#v", this.Options)+",\n") s = append(s, "GuardianAddr: "+fmt.Sprintf("%#v", this.GuardianAddr)+",\n") s = append(s, "GuardianSignature: "+fmt.Sprintf("%#v", this.GuardianSignature)+",\n") - s = append(s, "InnerTransaction: "+fmt.Sprintf("%#v", this.InnerTransaction)+",\n") + if this.InnerTransaction != nil { + s = append(s, "InnerTransaction: "+fmt.Sprintf("%#v", this.InnerTransaction)+",\n") + } s = append(s, "}") return strings.Join(s, "") } @@ -360,10 +363,15 @@ func (m *Transaction) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.InnerTransaction) > 0 { - i -= len(m.InnerTransaction) - copy(dAtA[i:], m.InnerTransaction) - i = encodeVarintTransaction(dAtA, i, uint64(len(m.InnerTransaction))) + if m.InnerTransaction != nil { + { + size, err := m.InnerTransaction.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTransaction(dAtA, i, uint64(size)) + } i-- dAtA[i] = 0x1 i-- @@ -544,8 +552,8 @@ func (m *Transaction) Size() (n int) { if l > 0 { n += 1 + l + sovTransaction(uint64(l)) } - l = len(m.InnerTransaction) - if l > 0 { + if m.InnerTransaction != nil { + l = m.InnerTransaction.Size() n += 2 + l + sovTransaction(uint64(l)) } return n @@ -577,7 +585,7 @@ func (this *Transaction) String() string { `Options:` + fmt.Sprintf("%v", this.Options) + `,`, `GuardianAddr:` + fmt.Sprintf("%v", this.GuardianAddr) + `,`, `GuardianSignature:` + fmt.Sprintf("%v", this.GuardianSignature) + `,`, - `InnerTransaction:` + fmt.Sprintf("%v", this.InnerTransaction) + `,`, + `InnerTransaction:` + strings.Replace(this.InnerTransaction.String(), "Transaction", "Transaction", 1) + `,`, `}`, }, "") return s @@ -1062,7 +1070,7 @@ func (m *Transaction) Unmarshal(dAtA []byte) error { if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field InnerTransaction", wireType) } - var byteLen int + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTransaction @@ -1072,24 +1080,26 @@ func (m *Transaction) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - byteLen |= int(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - if byteLen < 0 { + if msglen < 0 { return ErrInvalidLengthTransaction } - postIndex := iNdEx + byteLen + postIndex := iNdEx + msglen if postIndex < 0 { return ErrInvalidLengthTransaction } if postIndex > l { return io.ErrUnexpectedEOF } - m.InnerTransaction = append(m.InnerTransaction[:0], dAtA[iNdEx:postIndex]...) if m.InnerTransaction == nil { - m.InnerTransaction = []byte{} + m.InnerTransaction = &Transaction{} + } + if err := m.InnerTransaction.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err } iNdEx = postIndex default: diff --git a/data/transaction/transaction.proto b/data/transaction/transaction.proto index 39180eefb..584d0a17d 100644 --- a/data/transaction/transaction.proto +++ b/data/transaction/transaction.proto @@ -15,20 +15,20 @@ import "github.com/gogo/protobuf/gogoproto/gogo.proto"; // Transaction holds all the data needed for a value transfer or SC call message Transaction { - uint64 Nonce = 1 [(gogoproto.jsontag) = "nonce"]; - bytes Value = 2 [(gogoproto.jsontag) = "value", (gogoproto.casttypewith) = "math/big.Int;github.com/multiversx/mx-chain-core-go/data.BigIntCaster"]; - bytes RcvAddr = 3 [(gogoproto.jsontag) = "receiver"]; - bytes RcvUserName = 4 [(gogoproto.jsontag) = "rcvUserName,omitempty"]; - bytes SndAddr = 5 [(gogoproto.jsontag) = "sender"]; - bytes SndUserName = 6 [(gogoproto.jsontag) = "sndUserName,omitempty"]; - uint64 GasPrice = 7 [(gogoproto.jsontag) = "gasPrice,omitempty"]; - uint64 GasLimit = 8 [(gogoproto.jsontag) = "gasLimit,omitempty"]; - bytes Data = 9 [(gogoproto.jsontag) = "data,omitempty"]; - bytes ChainID = 10 [(gogoproto.jsontag) = "chainID"]; - uint32 Version = 11 [(gogoproto.jsontag) = "version"]; - bytes Signature = 12 [(gogoproto.jsontag) = "signature,omitempty"]; - uint32 Options = 13 [(gogoproto.jsontag) = "options,omitempty"]; - bytes GuardianAddr = 14 [(gogoproto.jsontag) = "guardian,omitempty"]; - bytes GuardianSignature = 15 [(gogoproto.jsontag) = "guardianSignature,omitempty"]; - bytes InnerTransaction = 16 [(gogoproto.jsontag) = "innerTransaction,omitempty"]; + uint64 Nonce = 1 [(gogoproto.jsontag) = "nonce"]; + bytes Value = 2 [(gogoproto.jsontag) = "value", (gogoproto.casttypewith) = "math/big.Int;github.com/multiversx/mx-chain-core-go/data.BigIntCaster"]; + bytes RcvAddr = 3 [(gogoproto.jsontag) = "receiver"]; + bytes RcvUserName = 4 [(gogoproto.jsontag) = "rcvUserName,omitempty"]; + bytes SndAddr = 5 [(gogoproto.jsontag) = "sender"]; + bytes SndUserName = 6 [(gogoproto.jsontag) = "sndUserName,omitempty"]; + uint64 GasPrice = 7 [(gogoproto.jsontag) = "gasPrice,omitempty"]; + uint64 GasLimit = 8 [(gogoproto.jsontag) = "gasLimit,omitempty"]; + bytes Data = 9 [(gogoproto.jsontag) = "data,omitempty"]; + bytes ChainID = 10 [(gogoproto.jsontag) = "chainID"]; + uint32 Version = 11 [(gogoproto.jsontag) = "version"]; + bytes Signature = 12 [(gogoproto.jsontag) = "signature,omitempty"]; + uint32 Options = 13 [(gogoproto.jsontag) = "options,omitempty"]; + bytes GuardianAddr = 14 [(gogoproto.jsontag) = "guardian,omitempty"]; + bytes GuardianSignature = 15 [(gogoproto.jsontag) = "guardianSignature,omitempty"]; + Transaction InnerTransaction = 16 [(gogoproto.jsontag) = "innerTransaction,omitempty"]; } diff --git a/data/transaction/transaction_test.go b/data/transaction/transaction_test.go index bcc78e180..8c89fac5d 100644 --- a/data/transaction/transaction_test.go +++ b/data/transaction/transaction_test.go @@ -23,7 +23,9 @@ func TestTransaction_SettersAndGetters(t *testing.T) { gasLimit := uint64(5) sender := []byte("sndr") receiver := []byte("receiver") - innerTx := []byte("inner tx") + innerTx := &transaction.Transaction{ + Nonce: 123, + } tx := &transaction.Transaction{ Nonce: nonce, @@ -53,15 +55,17 @@ func TestTransaction_MarshalUnmarshalJsonShouldWork(t *testing.T) { value := big.NewInt(445566) tx := &transaction.Transaction{ - Nonce: 112233, - Value: new(big.Int).Set(value), - RcvAddr: []byte("receiver"), - SndAddr: []byte("sender"), - GasPrice: 1234, - GasLimit: 5678, - Data: []byte("data"), - Signature: []byte("signature"), - InnerTransaction: []byte("inner tx"), + Nonce: 112233, + Value: new(big.Int).Set(value), + RcvAddr: []byte("receiver"), + SndAddr: []byte("sender"), + GasPrice: 1234, + GasLimit: 5678, + Data: []byte("data"), + Signature: []byte("signature"), + InnerTransaction: &transaction.Transaction{ + Nonce: 123, + }, } buff, err := json.Marshal(tx) @@ -265,16 +269,13 @@ func TestTransaction_GetDataForSigningShouldWork(t *testing.T) { tx1 := &transaction.Transaction{ Nonce: 1, } - innerTxBuff, err := json.Marshal(tx1) - assert.NoError(t, err) tx := &transaction.Transaction{ Nonce: 3, - InnerTransaction: innerTxBuff, + InnerTransaction: tx1, } numEncodeCalled := 0 marshallWasCalled := false - unmarshallWasCalled := false hasherWasCalled := false buff, err := tx.GetDataForSigning( &mock.PubkeyConverterStub{ @@ -289,11 +290,6 @@ func TestTransaction_GetDataForSigningShouldWork(t *testing.T) { return json.Marshal(obj) }, - UnmarshalCalled: func(obj interface{}, buff []byte) error { - unmarshallWasCalled = true - - return json.Unmarshal(buff, obj) - }, }, &mock.HasherStub{ ComputeCalled: func(s string) []byte { @@ -311,7 +307,6 @@ func TestTransaction_GetDataForSigningShouldWork(t *testing.T) { assert.Nil(t, err) assert.True(t, marshallWasCalled) - assert.True(t, unmarshallWasCalled) assert.False(t, hasherWasCalled) assert.Equal(t, 4, numEncodeCalled) }) From 4b6ee196f511b20e82fcefb223593c9d1fdcd801 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 20 Sep 2023 17:47:52 +0300 Subject: [PATCH 10/22] fixed inner tx preparation --- data/transaction/transaction.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/transaction/transaction.go b/data/transaction/transaction.go index 7c5040c40..192fd640c 100644 --- a/data/transaction/transaction.go +++ b/data/transaction/transaction.go @@ -79,7 +79,7 @@ func (tx *Transaction) GetDataForSigning(encoder data.Encoder, marshaller data.M } if tx.InnerTransaction != nil { - ftx.InnerTransaction, err = tx.prepareTx(encoder) + ftx.InnerTransaction, err = tx.InnerTransaction.prepareTx(encoder) if err != nil { return nil, err } From 7aa5258279f742238ff1e2a3561b96ecd9ef1ad1 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 20 Sep 2023 18:20:19 +0300 Subject: [PATCH 11/22] use inner tx signature when returning data for signing --- data/transaction/transaction.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/data/transaction/transaction.go b/data/transaction/transaction.go index 192fd640c..6b9e4debb 100644 --- a/data/transaction/transaction.go +++ b/data/transaction/transaction.go @@ -2,6 +2,7 @@ package transaction import ( + "encoding/hex" "math/big" "github.com/multiversx/mx-chain-core-go/core" @@ -83,6 +84,9 @@ func (tx *Transaction) GetDataForSigning(encoder data.Encoder, marshaller data.M if err != nil { return nil, err } + + ftx.InnerTransaction.Signature = hex.EncodeToString(tx.InnerTransaction.Signature) + ftx.InnerTransaction.GuardianSignature = hex.EncodeToString(tx.InnerTransaction.GuardianSignature) } ftxBytes, err := marshaller.Marshal(ftx) From afd6941049cf79499ec2375923dc8027bedb7272 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Thu, 21 Sep 2023 11:17:23 +0300 Subject: [PATCH 12/22] added optional relayer address on tx --- data/transaction/frontendTransaction.go | 1 + data/transaction/transaction.go | 14 ++- data/transaction/transaction.pb.go | 144 +++++++++++++++++------- data/transaction/transaction.proto | 3 +- data/transaction/transaction_test.go | 12 +- 5 files changed, 122 insertions(+), 52 deletions(-) diff --git a/data/transaction/frontendTransaction.go b/data/transaction/frontendTransaction.go index c627a5164..820014f73 100644 --- a/data/transaction/frontendTransaction.go +++ b/data/transaction/frontendTransaction.go @@ -17,5 +17,6 @@ type FrontendTransaction struct { Options uint32 `json:"options,omitempty"` GuardianAddr string `json:"guardian,omitempty"` GuardianSignature string `json:"guardianSignature,omitempty"` + Relayer string `json:"relayer,omitempty"` InnerTransaction *FrontendTransaction `json:"innerTransaction,omitempty"` } diff --git a/data/transaction/transaction.go b/data/transaction/transaction.go index 6b9e4debb..575f3b80f 100644 --- a/data/transaction/transaction.go +++ b/data/transaction/transaction.go @@ -37,11 +37,6 @@ func (tx *Transaction) SetSndAddr(addr []byte) { tx.SndAddr = addr } -// SetInnerTransaction sets the inner transaction of the transaction -func (tx *Transaction) SetInnerTransaction(innerTransaction *Transaction) { - tx.InnerTransaction = innerTransaction -} - // TrimSlicePtr creates a copy of the provided slice without the excess capacity func TrimSlicePtr(in []*Transaction) []*Transaction { if len(in) == 0 { @@ -161,6 +156,15 @@ func (tx *Transaction) prepareTx(encoder data.Encoder) (*FrontendTransaction, er Options: tx.Options, } + if len(tx.RelayedAddr) > 0 { + relayerAddr, errRelayer := encoder.Encode(tx.RelayedAddr) + if errRelayer != nil { + return nil, errRelayer + } + + ftx.Relayer = relayerAddr + } + if len(tx.GuardianAddr) > 0 { guardianAddr, errGuardian := encoder.Encode(tx.GuardianAddr) if errGuardian != nil { diff --git a/data/transaction/transaction.pb.go b/data/transaction/transaction.pb.go index 95f6b9597..48783a2b4 100644 --- a/data/transaction/transaction.pb.go +++ b/data/transaction/transaction.pb.go @@ -45,7 +45,8 @@ type Transaction struct { Options uint32 `protobuf:"varint,13,opt,name=Options,proto3" json:"options,omitempty"` GuardianAddr []byte `protobuf:"bytes,14,opt,name=GuardianAddr,proto3" json:"guardian,omitempty"` GuardianSignature []byte `protobuf:"bytes,15,opt,name=GuardianSignature,proto3" json:"guardianSignature,omitempty"` - InnerTransaction *Transaction `protobuf:"bytes,16,opt,name=InnerTransaction,proto3" json:"innerTransaction,omitempty"` + RelayedAddr []byte `protobuf:"bytes,16,opt,name=RelayedAddr,proto3" json:"relayer,omitempty"` + InnerTransaction *Transaction `protobuf:"bytes,17,opt,name=InnerTransaction,proto3" json:"innerTransaction,omitempty"` } func (m *Transaction) Reset() { *m = Transaction{} } @@ -181,6 +182,13 @@ func (m *Transaction) GetGuardianSignature() []byte { return nil } +func (m *Transaction) GetRelayedAddr() []byte { + if m != nil { + return m.RelayedAddr + } + return nil +} + func (m *Transaction) GetInnerTransaction() *Transaction { if m != nil { return m.InnerTransaction @@ -195,45 +203,47 @@ func init() { func init() { proto.RegisterFile("transaction.proto", fileDescriptor_2cc4e03d2c28c490) } var fileDescriptor_2cc4e03d2c28c490 = []byte{ - // 607 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x94, 0x41, 0x6f, 0xd3, 0x3c, - 0x1c, 0xc6, 0xeb, 0xf7, 0x5d, 0x97, 0xcd, 0xed, 0xc6, 0x66, 0x34, 0x30, 0x43, 0xb2, 0x2b, 0x04, - 0x53, 0x0f, 0xb4, 0x91, 0x86, 0xb8, 0xb0, 0x13, 0xdd, 0xd0, 0x54, 0x09, 0x06, 0xca, 0x60, 0x07, - 0x0e, 0x48, 0x6e, 0x62, 0x52, 0x4b, 0x8b, 0x3d, 0x39, 0x6e, 0x35, 0x0e, 0x48, 0x7c, 0x04, 0xf8, - 0x16, 0x88, 0x4f, 0xc2, 0x71, 0xc7, 0x9d, 0x02, 0xcb, 0x2e, 0x28, 0xa7, 0x7d, 0x04, 0x14, 0xa7, - 0x5d, 0xbd, 0xed, 0xc4, 0x29, 0xf6, 0xef, 0xff, 0x3c, 0xff, 0xc7, 0xb1, 0xe3, 0xc0, 0x55, 0xa3, - 0x99, 0x4c, 0x59, 0x68, 0x84, 0x92, 0xdd, 0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0xa3, 0xaa, 0x5d, 0x99, 0x70, 0xc7, 0x76, 0x45, 0x8b, 0x5e, 0xc1, 0xd5, - 0xe9, 0x7c, 0xb6, 0xd6, 0x5b, 0xb6, 0x01, 0x2d, 0x32, 0x7a, 0x3f, 0xbe, 0x5e, 0x74, 0x3a, 0xdd, - 0x74, 0xa2, 0x0f, 0x70, 0xa5, 0x2f, 0x25, 0xd7, 0xce, 0xbd, 0xc1, 0x2b, 0x2d, 0xd0, 0x6e, 0x6c, - 0xa2, 0xea, 0x56, 0x75, 0x9d, 0x4a, 0x8f, 0x14, 0x19, 0x5d, 0x17, 0xd7, 0xf4, 0x4e, 0xc0, 0x8d, - 0x5e, 0xbd, 0xcf, 0x27, 0x67, 0xa4, 0x76, 0x7a, 0x46, 0x6a, 0x17, 0x67, 0x04, 0x7c, 0xc9, 0x09, - 0xf8, 0x9e, 0x13, 0xf0, 0x33, 0x27, 0xe0, 0x24, 0x27, 0xe0, 0x34, 0x27, 0xe0, 0x77, 0x4e, 0xc0, - 0x9f, 0x9c, 0xd4, 0x2e, 0x72, 0x02, 0xbe, 0x9e, 0x93, 0xda, 0xc9, 0x39, 0xa9, 0x9d, 0x9e, 0x93, - 0xda, 0xfb, 0xed, 0x7f, 0xb8, 0x73, 0xbe, 0xf3, 0x0b, 0xd9, 0x72, 0xc6, 0x83, 0x79, 0xfb, 0x0e, - 0x4f, 0xfe, 0x06, 0x00, 0x00, 0xff, 0xff, 0xd6, 0x91, 0x2c, 0x8b, 0x64, 0x04, 0x00, 0x00, + // 627 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x54, 0xcf, 0x6e, 0xd3, 0x3e, + 0x1c, 0xaf, 0x7f, 0xbf, 0x75, 0xd9, 0xdc, 0x6e, 0xac, 0x46, 0x83, 0x30, 0x24, 0xbb, 0x42, 0x30, + 0xf5, 0x40, 0x1b, 0x69, 0x08, 0x21, 0xb1,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0, 0xeb, 0x39, 0xae, 0x9d, 0x9c, 0xe3, + 0xda, 0xe9, 0x39, 0xae, 0x7d, 0xd8, 0xfa, 0x87, 0xcb, 0xea, 0x59, 0xdf, 0x9e, 0x4d, 0xeb, 0x79, + 0x38, 0x6f, 0xfe, 0xc3, 0x93, 0xbf, 0x01, 0x00, 0x00, 0xff, 0xff, 0xee, 0x17, 0x8f, 0x8e, 0x9d, + 0x04, 0x00, 0x00, } func (this *Transaction) Equal(that interface{}) bool { @@ -303,6 +313,9 @@ func (this *Transaction) Equal(that interface{}) bool { if !bytes.Equal(this.GuardianSignature, that1.GuardianSignature) { return false } + if !bytes.Equal(this.RelayedAddr, that1.RelayedAddr) { + return false + } if !this.InnerTransaction.Equal(that1.InnerTransaction) { return false } @@ -312,7 +325,7 @@ func (this *Transaction) GoString() string { if this == nil { return "nil" } - s := make([]string, 0, 20) + s := make([]string, 0, 21) s = append(s, "&transaction.Transaction{") s = append(s, "Nonce: "+fmt.Sprintf("%#v", this.Nonce)+",\n") s = append(s, "Value: "+fmt.Sprintf("%#v", this.Value)+",\n") @@ -329,6 +342,7 @@ func (this *Transaction) GoString() string { s = append(s, "Options: "+fmt.Sprintf("%#v", this.Options)+",\n") s = append(s, "GuardianAddr: "+fmt.Sprintf("%#v", this.GuardianAddr)+",\n") s = append(s, "GuardianSignature: "+fmt.Sprintf("%#v", this.GuardianSignature)+",\n") + s = append(s, "RelayedAddr: "+fmt.Sprintf("%#v", this.RelayedAddr)+",\n") if this.InnerTransaction != nil { s = append(s, "InnerTransaction: "+fmt.Sprintf("%#v", this.InnerTransaction)+",\n") } @@ -375,6 +389,15 @@ func (m *Transaction) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x1 i-- + dAtA[i] = 0x8a + } + if len(m.RelayedAddr) > 0 { + i -= len(m.RelayedAddr) + copy(dAtA[i:], m.RelayedAddr) + i = encodeVarintTransaction(dAtA, i, uint64(len(m.RelayedAddr))) + i-- + dAtA[i] = 0x1 + i-- dAtA[i] = 0x82 } if len(m.GuardianSignature) > 0 { @@ -552,6 +575,10 @@ func (m *Transaction) Size() (n int) { if l > 0 { n += 1 + l + sovTransaction(uint64(l)) } + l = len(m.RelayedAddr) + if l > 0 { + n += 2 + l + sovTransaction(uint64(l)) + } if m.InnerTransaction != nil { l = m.InnerTransaction.Size() n += 2 + l + sovTransaction(uint64(l)) @@ -585,6 +612,7 @@ func (this *Transaction) String() string { `Options:` + fmt.Sprintf("%v", this.Options) + `,`, `GuardianAddr:` + fmt.Sprintf("%v", this.GuardianAddr) + `,`, `GuardianSignature:` + fmt.Sprintf("%v", this.GuardianSignature) + `,`, + `RelayedAddr:` + fmt.Sprintf("%v", this.RelayedAddr) + `,`, `InnerTransaction:` + strings.Replace(this.InnerTransaction.String(), "Transaction", "Transaction", 1) + `,`, `}`, }, "") @@ -1067,6 +1095,40 @@ func (m *Transaction) Unmarshal(dAtA []byte) error { } iNdEx = postIndex case 16: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field RelayedAddr", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTransaction + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTransaction + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTransaction + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.RelayedAddr = append(m.RelayedAddr[:0], dAtA[iNdEx:postIndex]...) + if m.RelayedAddr == nil { + m.RelayedAddr = []byte{} + } + iNdEx = postIndex + case 17: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field InnerTransaction", wireType) } diff --git a/data/transaction/transaction.proto b/data/transaction/transaction.proto index 584d0a17d..f727b853f 100644 --- a/data/transaction/transaction.proto +++ b/data/transaction/transaction.proto @@ -30,5 +30,6 @@ message Transaction { uint32 Options = 13 [(gogoproto.jsontag) = "options,omitempty"]; bytes GuardianAddr = 14 [(gogoproto.jsontag) = "guardian,omitempty"]; bytes GuardianSignature = 15 [(gogoproto.jsontag) = "guardianSignature,omitempty"]; - Transaction InnerTransaction = 16 [(gogoproto.jsontag) = "innerTransaction,omitempty"]; + bytes RelayedAddr = 16 [(gogoproto.jsontag) = "relayer,omitempty"]; + Transaction InnerTransaction = 17 [(gogoproto.jsontag) = "innerTransaction,omitempty"]; } diff --git a/data/transaction/transaction_test.go b/data/transaction/transaction_test.go index 8c89fac5d..38be7fbed 100644 --- a/data/transaction/transaction_test.go +++ b/data/transaction/transaction_test.go @@ -24,13 +24,15 @@ func TestTransaction_SettersAndGetters(t *testing.T) { sender := []byte("sndr") receiver := []byte("receiver") innerTx := &transaction.Transaction{ - Nonce: 123, + Nonce: 123, + RelayedAddr: sender, } tx := &transaction.Transaction{ - Nonce: nonce, - GasPrice: gasPrice, - GasLimit: gasLimit, + Nonce: nonce, + GasPrice: gasPrice, + GasLimit: gasLimit, + InnerTransaction: innerTx, } assert.False(t, check.IfNil(tx)) @@ -38,7 +40,6 @@ func TestTransaction_SettersAndGetters(t *testing.T) { tx.SetData(txData) tx.SetValue(value) tx.SetRcvAddr(receiver) - tx.SetInnerTransaction(innerTx) assert.Equal(t, nonce, tx.GetNonce()) assert.Equal(t, value, tx.GetValue()) @@ -48,6 +49,7 @@ func TestTransaction_SettersAndGetters(t *testing.T) { assert.Equal(t, sender, tx.GetSndAddr()) assert.Equal(t, receiver, tx.GetRcvAddr()) assert.Equal(t, innerTx, tx.GetInnerTransaction()) + assert.Equal(t, sender, tx.GetInnerTransaction().GetRelayedAddr()) } func TestTransaction_MarshalUnmarshalJsonShouldWork(t *testing.T) { From 48fd7cc48186c18c1814086b634bf11d3e30f92c Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Thu, 21 Sep 2023 11:20:11 +0300 Subject: [PATCH 13/22] removed previously added method from interface --- data/interface.go | 1 - 1 file changed, 1 deletion(-) diff --git a/data/interface.go b/data/interface.go index 748868fe7..80b039da2 100644 --- a/data/interface.go +++ b/data/interface.go @@ -296,7 +296,6 @@ type Encoder interface { // Marshaller is able to encode an object to its byte slice representation type Marshaller interface { Marshal(obj interface{}) ([]byte, error) - Unmarshal(obj interface{}, buff []byte) error IsInterfaceNil() bool } From 1e73b4f43019546bef32ca0f91d5577b9709157a Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Mon, 25 Sep 2023 12:19:36 +0300 Subject: [PATCH 14/22] fix typo after self review --- data/transaction/transaction.go | 4 +-- data/transaction/transaction.pb.go | 50 ++++++++++++++-------------- data/transaction/transaction.proto | 2 +- data/transaction/transaction_test.go | 4 +-- 4 files changed, 30 insertions(+), 30 deletions(-) diff --git a/data/transaction/transaction.go b/data/transaction/transaction.go index 575f3b80f..1c62c7f7e 100644 --- a/data/transaction/transaction.go +++ b/data/transaction/transaction.go @@ -156,8 +156,8 @@ func (tx *Transaction) prepareTx(encoder data.Encoder) (*FrontendTransaction, er Options: tx.Options, } - if len(tx.RelayedAddr) > 0 { - relayerAddr, errRelayer := encoder.Encode(tx.RelayedAddr) + if len(tx.RelayerAddr) > 0 { + relayerAddr, errRelayer := encoder.Encode(tx.RelayerAddr) if errRelayer != nil { return nil, errRelayer } diff --git a/data/transaction/transaction.pb.go b/data/transaction/transaction.pb.go index 48783a2b4..b19e9438f 100644 --- a/data/transaction/transaction.pb.go +++ b/data/transaction/transaction.pb.go @@ -45,7 +45,7 @@ type Transaction struct { Options uint32 `protobuf:"varint,13,opt,name=Options,proto3" json:"options,omitempty"` GuardianAddr []byte `protobuf:"bytes,14,opt,name=GuardianAddr,proto3" json:"guardian,omitempty"` GuardianSignature []byte `protobuf:"bytes,15,opt,name=GuardianSignature,proto3" json:"guardianSignature,omitempty"` - RelayedAddr []byte `protobuf:"bytes,16,opt,name=RelayedAddr,proto3" json:"relayer,omitempty"` + RelayerAddr []byte `protobuf:"bytes,16,opt,name=RelayerAddr,proto3" json:"relayer,omitempty"` InnerTransaction *Transaction `protobuf:"bytes,17,opt,name=InnerTransaction,proto3" json:"innerTransaction,omitempty"` } @@ -182,9 +182,9 @@ func (m *Transaction) GetGuardianSignature() []byte { return nil } -func (m *Transaction) GetRelayedAddr() []byte { +func (m *Transaction) GetRelayerAddr() []byte { if m != nil { - return m.RelayedAddr + return m.RelayerAddr } return nil } @@ -203,7 +203,7 @@ func init() { func init() { proto.RegisterFile("transaction.proto", fileDescriptor_2cc4e03d2c28c490) } var fileDescriptor_2cc4e03d2c28c490 = []byte{ - // 627 bytes of a gzipped FileDescriptorProto + // 626 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x54, 0xcf, 0x6e, 0xd3, 0x3e, 0x1c, 0xaf, 0x7f, 0xbf, 0x75, 0xd9, 0xdc, 0x6e, 0xac, 0x46, 0x83, 0x30, 0x24, 0xbb, 0x42, 0x30, 0xf5, 0x40, 0x1b, 0x69, 0x08, 0x21, 0xb1, 0x13, 0xdd, 0xd0, 0x54, 0x09, 0x06, 0xca, 0x60, 0x07, @@ -235,15 +235,15 @@ var fileDescriptor_2cc4e03d2c28c490 = []byte{ 0x92, 0x25, 0x64, 0x59, 0x66, 0x2a, 0xf4, 0x1c, 0x36, 0x77, 0xc6, 0x54, 0x85, 0x9c, 0x0a, 0xf3, 0xb6, 0x96, 0x4d, 0x55, 0xb9, 0x2b, 0x53, 0xdc, 0xb2, 0x5d, 0xd1, 0xa2, 0xd7, 0xb0, 0x35, 0x5b, 0x57, 0xb3, 0xde, 0x32, 0x01, 0x24, 0x4f, 0xc9, 0xfd, 0xe8, 0x3a, 0x69, 0x25, 0xdd, 0x74, 0xa2, - 0x67, 0xb0, 0xe1, 0xb3, 0x03, 0x7a, 0xcc, 0xca, 0x73, 0xb3, 0x62, 0x82, 0xcc, 0xfc, 0xca, 0xc0, - 0xea, 0xca, 0x61, 0x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 0x47, 0x86, 0xc1, 0x49, 0x86, 0xc1, 0x69, 0x86, 0xc1, + 0xef, 0x0c, 0x83, 0x3f, 0x19, 0xae, 0x5d, 0x64, 0x18, 0x7c, 0x3d, 0xc7, 0xb5, 0x93, 0x73, 0x5c, + 0x3b, 0x3d, 0xc7, 0xb5, 0x0f, 0x5b, 0xff, 0x70, 0x59, 0x3d, 0xeb, 0xdb, 0xb3, 0x69, 0x3d, 0x0f, + 0xe7, 0xcd, 0x7f, 0x78, 0xf2, 0x37, 0x00, 0x00, 0xff, 0xff, 0x2a, 0xdc, 0x62, 0xaa, 0x9d, 0x04, + 0x00, 0x00, } func (this *Transaction) Equal(that interface{}) bool { @@ -313,7 +313,7 @@ func (this *Transaction) Equal(that interface{}) bool { if !bytes.Equal(this.GuardianSignature, that1.GuardianSignature) { return false } - if !bytes.Equal(this.RelayedAddr, that1.RelayedAddr) { + if !bytes.Equal(this.RelayerAddr, that1.RelayerAddr) { return false } if !this.InnerTransaction.Equal(that1.InnerTransaction) { @@ -342,7 +342,7 @@ func (this *Transaction) GoString() string { s = append(s, "Options: "+fmt.Sprintf("%#v", this.Options)+",\n") s = append(s, "GuardianAddr: "+fmt.Sprintf("%#v", this.GuardianAddr)+",\n") s = append(s, "GuardianSignature: "+fmt.Sprintf("%#v", this.GuardianSignature)+",\n") - s = append(s, "RelayedAddr: "+fmt.Sprintf("%#v", this.RelayedAddr)+",\n") + s = append(s, "RelayerAddr: "+fmt.Sprintf("%#v", this.RelayerAddr)+",\n") if this.InnerTransaction != nil { s = append(s, "InnerTransaction: "+fmt.Sprintf("%#v", this.InnerTransaction)+",\n") } @@ -391,10 +391,10 @@ func (m *Transaction) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x8a } - if len(m.RelayedAddr) > 0 { - i -= len(m.RelayedAddr) - copy(dAtA[i:], m.RelayedAddr) - i = encodeVarintTransaction(dAtA, i, uint64(len(m.RelayedAddr))) + if len(m.RelayerAddr) > 0 { + i -= len(m.RelayerAddr) + copy(dAtA[i:], m.RelayerAddr) + i = encodeVarintTransaction(dAtA, i, uint64(len(m.RelayerAddr))) i-- dAtA[i] = 0x1 i-- @@ -575,7 +575,7 @@ func (m *Transaction) Size() (n int) { if l > 0 { n += 1 + l + sovTransaction(uint64(l)) } - l = len(m.RelayedAddr) + l = len(m.RelayerAddr) if l > 0 { n += 2 + l + sovTransaction(uint64(l)) } @@ -612,7 +612,7 @@ func (this *Transaction) String() string { `Options:` + fmt.Sprintf("%v", this.Options) + `,`, `GuardianAddr:` + fmt.Sprintf("%v", this.GuardianAddr) + `,`, `GuardianSignature:` + fmt.Sprintf("%v", this.GuardianSignature) + `,`, - `RelayedAddr:` + fmt.Sprintf("%v", this.RelayedAddr) + `,`, + `RelayerAddr:` + fmt.Sprintf("%v", this.RelayerAddr) + `,`, `InnerTransaction:` + strings.Replace(this.InnerTransaction.String(), "Transaction", "Transaction", 1) + `,`, `}`, }, "") @@ -1096,7 +1096,7 @@ func (m *Transaction) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 16: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field RelayedAddr", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field RelayerAddr", wireType) } var byteLen int for shift := uint(0); ; shift += 7 { @@ -1123,9 +1123,9 @@ func (m *Transaction) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.RelayedAddr = append(m.RelayedAddr[:0], dAtA[iNdEx:postIndex]...) - if m.RelayedAddr == nil { - m.RelayedAddr = []byte{} + m.RelayerAddr = append(m.RelayerAddr[:0], dAtA[iNdEx:postIndex]...) + if m.RelayerAddr == nil { + m.RelayerAddr = []byte{} } iNdEx = postIndex case 17: diff --git a/data/transaction/transaction.proto b/data/transaction/transaction.proto index f727b853f..626e6e432 100644 --- a/data/transaction/transaction.proto +++ b/data/transaction/transaction.proto @@ -30,6 +30,6 @@ message Transaction { uint32 Options = 13 [(gogoproto.jsontag) = "options,omitempty"]; bytes GuardianAddr = 14 [(gogoproto.jsontag) = "guardian,omitempty"]; bytes GuardianSignature = 15 [(gogoproto.jsontag) = "guardianSignature,omitempty"]; - bytes RelayedAddr = 16 [(gogoproto.jsontag) = "relayer,omitempty"]; + bytes RelayerAddr = 16 [(gogoproto.jsontag) = "relayer,omitempty"]; Transaction InnerTransaction = 17 [(gogoproto.jsontag) = "innerTransaction,omitempty"]; } diff --git a/data/transaction/transaction_test.go b/data/transaction/transaction_test.go index 38be7fbed..15ceb09ba 100644 --- a/data/transaction/transaction_test.go +++ b/data/transaction/transaction_test.go @@ -25,7 +25,7 @@ func TestTransaction_SettersAndGetters(t *testing.T) { receiver := []byte("receiver") innerTx := &transaction.Transaction{ Nonce: 123, - RelayedAddr: sender, + RelayerAddr: sender, } tx := &transaction.Transaction{ @@ -49,7 +49,7 @@ func TestTransaction_SettersAndGetters(t *testing.T) { assert.Equal(t, sender, tx.GetSndAddr()) assert.Equal(t, receiver, tx.GetRcvAddr()) assert.Equal(t, innerTx, tx.GetInnerTransaction()) - assert.Equal(t, sender, tx.GetInnerTransaction().GetRelayedAddr()) + assert.Equal(t, sender, tx.GetInnerTransaction().GetRelayerAddr()) } func TestTransaction_MarshalUnmarshalJsonShouldWork(t *testing.T) { From ab2114ef6c2826a3cd1cd8280ddb4cedba49e497 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Tue, 26 Sep 2023 12:40:53 +0300 Subject: [PATCH 15/22] fixes after first review --- data/interface.go | 1 + data/receipt/receipt.go | 5 +++++ data/receipt/receipt_test.go | 1 + data/rewardTx/rewardTx.go | 5 +++++ data/rewardTx/rewardTx_test.go | 1 + data/smartContractResult/smartContractResult.go | 5 +++++ data/smartContractResult/smartContractResult_test.go | 1 + data/transaction/transaction.go | 5 +++++ data/transaction/transaction_test.go | 2 +- 9 files changed, 25 insertions(+), 1 deletion(-) diff --git a/data/interface.go b/data/interface.go index 80b039da2..259277e48 100644 --- a/data/interface.go +++ b/data/interface.go @@ -271,6 +271,7 @@ type TransactionHandler interface { GetSndAddr() []byte GetGasLimit() uint64 GetGasPrice() uint64 + GetUserTransaction() TransactionHandler SetValue(*big.Int) SetData([]byte) diff --git a/data/receipt/receipt.go b/data/receipt/receipt.go index 992e49322..acff06aae 100644 --- a/data/receipt/receipt.go +++ b/data/receipt/receipt.go @@ -58,6 +58,11 @@ func (_ *Receipt) GetRcvUserName() []byte { return nil } +// GetUserTransaction returns nil as Receipt does not have user transaction +func (rpt *Receipt) GetUserTransaction() data.TransactionHandler { + return nil +} + // CheckIntegrity checks for not nil fields and negative value func (rpt *Receipt) CheckIntegrity() error { return nil diff --git a/data/receipt/receipt_test.go b/data/receipt/receipt_test.go index 84f689413..5621c968c 100644 --- a/data/receipt/receipt_test.go +++ b/data/receipt/receipt_test.go @@ -29,6 +29,7 @@ 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.GetUserTransaction()) } func TestReceipt_CheckIntegrityReturnsNil(t *testing.T) { diff --git a/data/rewardTx/rewardTx.go b/data/rewardTx/rewardTx.go index 0ccb44a5e..35ec718ba 100644 --- a/data/rewardTx/rewardTx.go +++ b/data/rewardTx/rewardTx.go @@ -62,6 +62,11 @@ func (rtx *RewardTx) GetRcvUserName() []byte { return nil } +// GetUserTransaction returns nil as RewardTx does not have user transaction +func (rtx *RewardTx) GetUserTransaction() data.TransactionHandler { + return nil +} + // CheckIntegrity checks for not nil fields and negative value func (rtx *RewardTx) CheckIntegrity() error { if len(rtx.RcvAddr) == 0 { diff --git a/data/rewardTx/rewardTx_test.go b/data/rewardTx/rewardTx_test.go index 2f8680e26..70d24bf63 100644 --- a/data/rewardTx/rewardTx_test.go +++ b/data/rewardTx/rewardTx_test.go @@ -27,6 +27,7 @@ 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.GetUserTransaction()) } func TestRewardTx_CheckIntegrityShouldWork(t *testing.T) { diff --git a/data/smartContractResult/smartContractResult.go b/data/smartContractResult/smartContractResult.go index 2c2481761..198aac81f 100644 --- a/data/smartContractResult/smartContractResult.go +++ b/data/smartContractResult/smartContractResult.go @@ -39,6 +39,11 @@ func (_ *SmartContractResult) GetRcvUserName() []byte { return nil } +// GetUserTransaction returns nil as SmartContractResult does not have user transaction +func (scr *SmartContractResult) GetUserTransaction() 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 { diff --git a/data/smartContractResult/smartContractResult_test.go b/data/smartContractResult/smartContractResult_test.go index 75eba8287..d477b6309 100644 --- a/data/smartContractResult/smartContractResult_test.go +++ b/data/smartContractResult/smartContractResult_test.go @@ -38,6 +38,7 @@ 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.GetUserTransaction()) } func TestTrimSlicePtr(t *testing.T) { diff --git a/data/transaction/transaction.go b/data/transaction/transaction.go index 1c62c7f7e..b261a7fa3 100644 --- a/data/transaction/transaction.go +++ b/data/transaction/transaction.go @@ -37,6 +37,11 @@ func (tx *Transaction) SetSndAddr(addr []byte) { tx.SndAddr = addr } +// GetUserTransaction returns the inner transaction +func (tx *Transaction) GetUserTransaction() data.TransactionHandler { + return tx.GetInnerTransaction() +} + // TrimSlicePtr creates a copy of the provided slice without the excess capacity func TrimSlicePtr(in []*Transaction) []*Transaction { if len(in) == 0 { diff --git a/data/transaction/transaction_test.go b/data/transaction/transaction_test.go index 15ceb09ba..ce8e70aea 100644 --- a/data/transaction/transaction_test.go +++ b/data/transaction/transaction_test.go @@ -48,7 +48,7 @@ func TestTransaction_SettersAndGetters(t *testing.T) { assert.Equal(t, gasLimit, tx.GetGasLimit()) assert.Equal(t, sender, tx.GetSndAddr()) assert.Equal(t, receiver, tx.GetRcvAddr()) - assert.Equal(t, innerTx, tx.GetInnerTransaction()) + assert.Equal(t, innerTx, tx.GetUserTransaction()) assert.Equal(t, sender, tx.GetInnerTransaction().GetRelayerAddr()) } From 61487cb5f8ad4f725b6ad5cac923e7eda9c6406e Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Thu, 5 Oct 2023 13:01:18 +0300 Subject: [PATCH 16/22] switched the innerTransaction field to a slice of transactions --- data/interface.go | 2 +- data/receipt/receipt.go | 4 +- data/receipt/receipt_test.go | 2 +- data/rewardTx/rewardTx.go | 4 +- data/rewardTx/rewardTx_test.go | 2 +- .../smartContractResult.go | 4 +- .../smartContractResult_test.go | 2 +- data/transaction/frontendTransaction.go | 34 ++-- data/transaction/transaction.go | 31 ++- data/transaction/transaction.pb.go | 178 ++++++++++-------- data/transaction/transaction.proto | 34 ++-- data/transaction/transaction_test.go | 32 ++-- 12 files changed, 179 insertions(+), 150 deletions(-) diff --git a/data/interface.go b/data/interface.go index 259277e48..d91079d60 100644 --- a/data/interface.go +++ b/data/interface.go @@ -271,7 +271,7 @@ type TransactionHandler interface { GetSndAddr() []byte GetGasLimit() uint64 GetGasPrice() uint64 - GetUserTransaction() TransactionHandler + GetUserTransactions() []TransactionHandler SetValue(*big.Int) SetData([]byte) diff --git a/data/receipt/receipt.go b/data/receipt/receipt.go index acff06aae..d19933df8 100644 --- a/data/receipt/receipt.go +++ b/data/receipt/receipt.go @@ -58,8 +58,8 @@ func (_ *Receipt) GetRcvUserName() []byte { return nil } -// GetUserTransaction returns nil as Receipt does not have user transaction -func (rpt *Receipt) GetUserTransaction() data.TransactionHandler { +// GetUserTransactions returns nil as Receipt does not have user transactions +func (rpt *Receipt) GetUserTransactions() []data.TransactionHandler { return nil } diff --git a/data/receipt/receipt_test.go b/data/receipt/receipt_test.go index 5621c968c..eda8ebc78 100644 --- a/data/receipt/receipt_test.go +++ b/data/receipt/receipt_test.go @@ -29,7 +29,7 @@ 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.GetUserTransaction()) + assert.Nil(t, r.GetUserTransactions()) } func TestReceipt_CheckIntegrityReturnsNil(t *testing.T) { diff --git a/data/rewardTx/rewardTx.go b/data/rewardTx/rewardTx.go index 35ec718ba..c9b140743 100644 --- a/data/rewardTx/rewardTx.go +++ b/data/rewardTx/rewardTx.go @@ -62,8 +62,8 @@ func (rtx *RewardTx) GetRcvUserName() []byte { return nil } -// GetUserTransaction returns nil as RewardTx does not have user transaction -func (rtx *RewardTx) GetUserTransaction() data.TransactionHandler { +// GetUserTransactions returns nil as RewardTx does not have user transactions +func (rtx *RewardTx) GetUserTransactions() []data.TransactionHandler { return nil } diff --git a/data/rewardTx/rewardTx_test.go b/data/rewardTx/rewardTx_test.go index 70d24bf63..043d10586 100644 --- a/data/rewardTx/rewardTx_test.go +++ b/data/rewardTx/rewardTx_test.go @@ -27,7 +27,7 @@ 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.GetUserTransaction()) + assert.Nil(t, rwdTx.GetUserTransactions()) } func TestRewardTx_CheckIntegrityShouldWork(t *testing.T) { diff --git a/data/smartContractResult/smartContractResult.go b/data/smartContractResult/smartContractResult.go index 198aac81f..f8ea3324e 100644 --- a/data/smartContractResult/smartContractResult.go +++ b/data/smartContractResult/smartContractResult.go @@ -39,8 +39,8 @@ func (_ *SmartContractResult) GetRcvUserName() []byte { return nil } -// GetUserTransaction returns nil as SmartContractResult does not have user transaction -func (scr *SmartContractResult) GetUserTransaction() data.TransactionHandler { +// GetUserTransactions returns nil as SmartContractResult does not have user transactions +func (scr *SmartContractResult) GetUserTransactions() []data.TransactionHandler { return nil } diff --git a/data/smartContractResult/smartContractResult_test.go b/data/smartContractResult/smartContractResult_test.go index d477b6309..50e261431 100644 --- a/data/smartContractResult/smartContractResult_test.go +++ b/data/smartContractResult/smartContractResult_test.go @@ -38,7 +38,7 @@ 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.GetUserTransaction()) + assert.Nil(t, scr.GetUserTransactions()) } func TestTrimSlicePtr(t *testing.T) { diff --git a/data/transaction/frontendTransaction.go b/data/transaction/frontendTransaction.go index 820014f73..267d7e9c6 100644 --- a/data/transaction/frontendTransaction.go +++ b/data/transaction/frontendTransaction.go @@ -2,21 +2,21 @@ 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"` - InnerTransaction *FrontendTransaction `json:"innerTransaction,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"` + Relayer string `json:"relayer,omitempty"` + InnerTransactions []*FrontendTransaction `json:"innerTransactions,omitempty"` } diff --git a/data/transaction/transaction.go b/data/transaction/transaction.go index b261a7fa3..5680523aa 100644 --- a/data/transaction/transaction.go +++ b/data/transaction/transaction.go @@ -37,9 +37,15 @@ func (tx *Transaction) SetSndAddr(addr []byte) { tx.SndAddr = addr } -// GetUserTransaction returns the inner transaction -func (tx *Transaction) GetUserTransaction() data.TransactionHandler { - return tx.GetInnerTransaction() +// 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 @@ -79,14 +85,21 @@ func (tx *Transaction) GetDataForSigning(encoder data.Encoder, marshaller data.M return nil, err } - if tx.InnerTransaction != nil { - ftx.InnerTransaction, err = tx.InnerTransaction.prepareTx(encoder) - if err != nil { - return nil, err + numInnerTxs := len(tx.InnerTransactions) + if numInnerTxs > 0 { + ftx.InnerTransactions = make([]*FrontendTransaction, numInnerTxs) + for i := 0; i < numInnerTxs; i++ { + innerFtx, errPrepare := tx.InnerTransactions[i].prepareTx(encoder) + if errPrepare != nil { + return nil, errPrepare + } + + innerFtx.Signature = hex.EncodeToString(tx.InnerTransactions[i].Signature) + innerFtx.GuardianSignature = hex.EncodeToString(tx.InnerTransactions[i].GuardianSignature) + + ftx.InnerTransactions[i] = innerFtx } - ftx.InnerTransaction.Signature = hex.EncodeToString(tx.InnerTransaction.Signature) - ftx.InnerTransaction.GuardianSignature = hex.EncodeToString(tx.InnerTransaction.GuardianSignature) } ftxBytes, err := marshaller.Marshal(ftx) diff --git a/data/transaction/transaction.pb.go b/data/transaction/transaction.pb.go index b19e9438f..90e14b7fd 100644 --- a/data/transaction/transaction.pb.go +++ b/data/transaction/transaction.pb.go @@ -30,23 +30,23 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // Transaction holds all the data needed for a value transfer or SC call type Transaction struct { - Nonce uint64 `protobuf:"varint,1,opt,name=Nonce,proto3" json:"nonce"` - Value *math_big.Int `protobuf:"bytes,2,opt,name=Value,proto3,casttypewith=math/big.Int;github.com/multiversx/mx-chain-core-go/data.BigIntCaster" json:"value"` - RcvAddr []byte `protobuf:"bytes,3,opt,name=RcvAddr,proto3" json:"receiver"` - RcvUserName []byte `protobuf:"bytes,4,opt,name=RcvUserName,proto3" json:"rcvUserName,omitempty"` - SndAddr []byte `protobuf:"bytes,5,opt,name=SndAddr,proto3" json:"sender"` - SndUserName []byte `protobuf:"bytes,6,opt,name=SndUserName,proto3" json:"sndUserName,omitempty"` - GasPrice uint64 `protobuf:"varint,7,opt,name=GasPrice,proto3" json:"gasPrice,omitempty"` - GasLimit uint64 `protobuf:"varint,8,opt,name=GasLimit,proto3" json:"gasLimit,omitempty"` - Data []byte `protobuf:"bytes,9,opt,name=Data,proto3" json:"data,omitempty"` - ChainID []byte `protobuf:"bytes,10,opt,name=ChainID,proto3" json:"chainID"` - Version uint32 `protobuf:"varint,11,opt,name=Version,proto3" json:"version"` - Signature []byte `protobuf:"bytes,12,opt,name=Signature,proto3" json:"signature,omitempty"` - Options uint32 `protobuf:"varint,13,opt,name=Options,proto3" json:"options,omitempty"` - GuardianAddr []byte `protobuf:"bytes,14,opt,name=GuardianAddr,proto3" json:"guardian,omitempty"` - GuardianSignature []byte `protobuf:"bytes,15,opt,name=GuardianSignature,proto3" json:"guardianSignature,omitempty"` - RelayerAddr []byte `protobuf:"bytes,16,opt,name=RelayerAddr,proto3" json:"relayer,omitempty"` - InnerTransaction *Transaction `protobuf:"bytes,17,opt,name=InnerTransaction,proto3" json:"innerTransaction,omitempty"` + Nonce uint64 `protobuf:"varint,1,opt,name=Nonce,proto3" json:"nonce"` + Value *math_big.Int `protobuf:"bytes,2,opt,name=Value,proto3,casttypewith=math/big.Int;github.com/multiversx/mx-chain-core-go/data.BigIntCaster" json:"value"` + RcvAddr []byte `protobuf:"bytes,3,opt,name=RcvAddr,proto3" json:"receiver"` + RcvUserName []byte `protobuf:"bytes,4,opt,name=RcvUserName,proto3" json:"rcvUserName,omitempty"` + SndAddr []byte `protobuf:"bytes,5,opt,name=SndAddr,proto3" json:"sender"` + SndUserName []byte `protobuf:"bytes,6,opt,name=SndUserName,proto3" json:"sndUserName,omitempty"` + GasPrice uint64 `protobuf:"varint,7,opt,name=GasPrice,proto3" json:"gasPrice,omitempty"` + GasLimit uint64 `protobuf:"varint,8,opt,name=GasLimit,proto3" json:"gasLimit,omitempty"` + Data []byte `protobuf:"bytes,9,opt,name=Data,proto3" json:"data,omitempty"` + ChainID []byte `protobuf:"bytes,10,opt,name=ChainID,proto3" json:"chainID"` + Version uint32 `protobuf:"varint,11,opt,name=Version,proto3" json:"version"` + Signature []byte `protobuf:"bytes,12,opt,name=Signature,proto3" json:"signature,omitempty"` + Options uint32 `protobuf:"varint,13,opt,name=Options,proto3" json:"options,omitempty"` + GuardianAddr []byte `protobuf:"bytes,14,opt,name=GuardianAddr,proto3" json:"guardian,omitempty"` + GuardianSignature []byte `protobuf:"bytes,15,opt,name=GuardianSignature,proto3" json:"guardianSignature,omitempty"` + RelayerAddr []byte `protobuf:"bytes,16,opt,name=RelayerAddr,proto3" json:"relayer,omitempty"` + InnerTransactions []*Transaction `protobuf:"bytes,17,rep,name=InnerTransactions,proto3" json:"innerTransactions,omitempty"` } func (m *Transaction) Reset() { *m = Transaction{} } @@ -189,9 +189,9 @@ func (m *Transaction) GetRelayerAddr() []byte { return nil } -func (m *Transaction) GetInnerTransaction() *Transaction { +func (m *Transaction) GetInnerTransactions() []*Transaction { if m != nil { - return m.InnerTransaction + return m.InnerTransactions } return nil } @@ -203,47 +203,47 @@ func init() { func init() { proto.RegisterFile("transaction.proto", fileDescriptor_2cc4e03d2c28c490) } var fileDescriptor_2cc4e03d2c28c490 = []byte{ - // 626 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x54, 0xcf, 0x6e, 0xd3, 0x3e, - 0x1c, 0xaf, 0x7f, 0xbf, 0x75, 0xd9, 0xdc, 0x6e, 0xac, 0x46, 0x83, 0x30, 0x24, 0xbb, 0x42, 0x30, - 0xf5, 0x40, 0x1b, 0x69, 0x08, 0x21, 0xb1, 0x13, 0xdd, 0xd0, 0x54, 0x09, 0x06, 0xca, 0x60, 0x07, - 0x0e, 0x48, 0x6e, 0x62, 0x52, 0x4b, 0x8b, 0x3d, 0x39, 0x6e, 0xb5, 0x1d, 0x90, 0x78, 0x04, 0x1e, - 0x03, 0xf1, 0x24, 0x88, 0xd3, 0x8e, 0x3b, 0x05, 0x96, 0x5d, 0x50, 0x4e, 0x7b, 0x04, 0x14, 0xa7, - 0x5d, 0xbc, 0xed, 0xc4, 0xa9, 0xf1, 0xe7, 0xef, 0xb7, 0x8e, 0x1d, 0xd8, 0xd2, 0x8a, 0x8a, 0x84, - 0x06, 0x9a, 0x4b, 0xd1, 0x3b, 0x54, 0x52, 0x4b, 0x54, 0x37, 0x3f, 0x6b, 0xdd, 0x88, 0xeb, 0xd1, - 0x78, 0xd8, 0x0b, 0x64, 0xec, 0x45, 0x32, 0x92, 0x9e, 0x81, 0x87, 0xe3, 0x4f, 0x66, 0x65, 0x16, - 0xe6, 0xa9, 0x74, 0x3d, 0xf8, 0xe9, 0xc0, 0xc6, 0xbb, 0x2a, 0x0b, 0x11, 0x58, 0xdf, 0x95, 0x22, - 0x60, 0x2e, 0x68, 0x83, 0xce, 0x5c, 0x7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, 0x95, 0x12, 0x7d, 0x84, 0x2b, 0x03, 0x21, 0x98, 0xb2, 0x2e, 0x9c, 0xdb, 0x6a, - 0x83, 0x4e, 0x63, 0x03, 0x95, 0xd7, 0xb1, 0x67, 0x31, 0x7d, 0x9c, 0xa7, 0x64, 0x8d, 0x5f, 0xd3, - 0x5b, 0xd1, 0x37, 0xb2, 0xfa, 0x9f, 0x4f, 0xce, 0x70, 0xed, 0xf4, 0x0c, 0xd7, 0x2e, 0xce, 0x30, - 0xf8, 0x92, 0x61, 0xf0, 0x2d, 0xc3, 0xe0, 0x47, 0x86, 0xc1, 0x49, 0x86, 0xc1, 0x69, 0x86, 0xc1, - 0xef, 0x0c, 0x83, 0x3f, 0x19, 0xae, 0x5d, 0x64, 0x18, 0x7c, 0x3d, 0xc7, 0xb5, 0x93, 0x73, 0x5c, - 0x3b, 0x3d, 0xc7, 0xb5, 0x0f, 0x5b, 0xff, 0x70, 0x59, 0x3d, 0xeb, 0xdb, 0xb3, 0x69, 0x3d, 0x0f, - 0xe7, 0xcd, 0x7f, 0x78, 0xf2, 0x37, 0x00, 0x00, 0xff, 0xff, 0x2a, 0xdc, 0x62, 0xaa, 0x9d, 0x04, - 0x00, 0x00, + // 628 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x94, 0x41, 0x6f, 0xd3, 0x3e, + 0x18, 0xc6, 0x9b, 0xff, 0xd6, 0x65, 0x73, 0xbb, 0xfd, 0xa9, 0xd1, 0x20, 0x80, 0x64, 0x57, 0x08, + 0xa6, 0x1e, 0x68, 0x23, 0x0d, 0x21, 0x24, 0x76, 0xa2, 0x1b, 0x9a, 0x2a, 0xc1, 0x40, 0x19, 0xec, + 0xc0, 0xcd, 0x4d, 0x4c, 0x6a, 0x69, 0x71, 0x26, 0xc7, 0xad, 0xb6, 0x03, 0x12, 0x1f, 0x81, 0x8f, + 0x81, 0xf8, 0x24, 0x5c,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, 0x00, 0x00, 0x00, 0xff, 0xff, 0xee, 0xb2, 0x15, 0x7c, + 0xa0, 0x04, 0x00, 0x00, } func (this *Transaction) Equal(that interface{}) bool { @@ -316,9 +316,14 @@ func (this *Transaction) Equal(that interface{}) bool { if !bytes.Equal(this.RelayerAddr, that1.RelayerAddr) { return false } - if !this.InnerTransaction.Equal(that1.InnerTransaction) { + if len(this.InnerTransactions) != len(that1.InnerTransactions) { return false } + for i := range this.InnerTransactions { + if !this.InnerTransactions[i].Equal(that1.InnerTransactions[i]) { + return false + } + } return true } func (this *Transaction) GoString() string { @@ -343,8 +348,8 @@ func (this *Transaction) GoString() string { s = append(s, "GuardianAddr: "+fmt.Sprintf("%#v", this.GuardianAddr)+",\n") s = append(s, "GuardianSignature: "+fmt.Sprintf("%#v", this.GuardianSignature)+",\n") s = append(s, "RelayerAddr: "+fmt.Sprintf("%#v", this.RelayerAddr)+",\n") - if this.InnerTransaction != nil { - s = append(s, "InnerTransaction: "+fmt.Sprintf("%#v", this.InnerTransaction)+",\n") + if this.InnerTransactions != nil { + s = append(s, "InnerTransactions: "+fmt.Sprintf("%#v", this.InnerTransactions)+",\n") } s = append(s, "}") return strings.Join(s, "") @@ -377,19 +382,21 @@ func (m *Transaction) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if m.InnerTransaction != nil { - { - size, err := m.InnerTransaction.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err + if len(m.InnerTransactions) > 0 { + for iNdEx := len(m.InnerTransactions) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.InnerTransactions[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTransaction(dAtA, i, uint64(size)) } - i -= size - i = encodeVarintTransaction(dAtA, i, uint64(size)) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0x8a } - i-- - dAtA[i] = 0x1 - i-- - dAtA[i] = 0x8a } if len(m.RelayerAddr) > 0 { i -= len(m.RelayerAddr) @@ -579,9 +586,11 @@ func (m *Transaction) Size() (n int) { if l > 0 { n += 2 + l + sovTransaction(uint64(l)) } - if m.InnerTransaction != nil { - l = m.InnerTransaction.Size() - n += 2 + l + sovTransaction(uint64(l)) + if len(m.InnerTransactions) > 0 { + for _, e := range m.InnerTransactions { + l = e.Size() + n += 2 + l + sovTransaction(uint64(l)) + } } return n } @@ -596,6 +605,11 @@ func (this *Transaction) String() string { if this == nil { return "nil" } + repeatedStringForInnerTransactions := "[]*Transaction{" + for _, f := range this.InnerTransactions { + repeatedStringForInnerTransactions += strings.Replace(f.String(), "Transaction", "Transaction", 1) + "," + } + repeatedStringForInnerTransactions += "}" s := strings.Join([]string{`&Transaction{`, `Nonce:` + fmt.Sprintf("%v", this.Nonce) + `,`, `Value:` + fmt.Sprintf("%v", this.Value) + `,`, @@ -613,7 +627,7 @@ func (this *Transaction) String() string { `GuardianAddr:` + fmt.Sprintf("%v", this.GuardianAddr) + `,`, `GuardianSignature:` + fmt.Sprintf("%v", this.GuardianSignature) + `,`, `RelayerAddr:` + fmt.Sprintf("%v", this.RelayerAddr) + `,`, - `InnerTransaction:` + strings.Replace(this.InnerTransaction.String(), "Transaction", "Transaction", 1) + `,`, + `InnerTransactions:` + repeatedStringForInnerTransactions + `,`, `}`, }, "") return s @@ -1130,7 +1144,7 @@ func (m *Transaction) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 17: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field InnerTransaction", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field InnerTransactions", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -1157,10 +1171,8 @@ func (m *Transaction) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if m.InnerTransaction == nil { - m.InnerTransaction = &Transaction{} - } - if err := m.InnerTransaction.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + m.InnerTransactions = append(m.InnerTransactions, &Transaction{}) + if err := m.InnerTransactions[len(m.InnerTransactions)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex diff --git a/data/transaction/transaction.proto b/data/transaction/transaction.proto index 626e6e432..5912769de 100644 --- a/data/transaction/transaction.proto +++ b/data/transaction/transaction.proto @@ -15,21 +15,21 @@ import "github.com/gogo/protobuf/gogoproto/gogo.proto"; // Transaction holds all the data needed for a value transfer or SC call message Transaction { - uint64 Nonce = 1 [(gogoproto.jsontag) = "nonce"]; - bytes Value = 2 [(gogoproto.jsontag) = "value", (gogoproto.casttypewith) = "math/big.Int;github.com/multiversx/mx-chain-core-go/data.BigIntCaster"]; - bytes RcvAddr = 3 [(gogoproto.jsontag) = "receiver"]; - bytes RcvUserName = 4 [(gogoproto.jsontag) = "rcvUserName,omitempty"]; - bytes SndAddr = 5 [(gogoproto.jsontag) = "sender"]; - bytes SndUserName = 6 [(gogoproto.jsontag) = "sndUserName,omitempty"]; - uint64 GasPrice = 7 [(gogoproto.jsontag) = "gasPrice,omitempty"]; - uint64 GasLimit = 8 [(gogoproto.jsontag) = "gasLimit,omitempty"]; - bytes Data = 9 [(gogoproto.jsontag) = "data,omitempty"]; - bytes ChainID = 10 [(gogoproto.jsontag) = "chainID"]; - uint32 Version = 11 [(gogoproto.jsontag) = "version"]; - bytes Signature = 12 [(gogoproto.jsontag) = "signature,omitempty"]; - uint32 Options = 13 [(gogoproto.jsontag) = "options,omitempty"]; - bytes GuardianAddr = 14 [(gogoproto.jsontag) = "guardian,omitempty"]; - bytes GuardianSignature = 15 [(gogoproto.jsontag) = "guardianSignature,omitempty"]; - bytes RelayerAddr = 16 [(gogoproto.jsontag) = "relayer,omitempty"]; - Transaction InnerTransaction = 17 [(gogoproto.jsontag) = "innerTransaction,omitempty"]; + uint64 Nonce = 1 [(gogoproto.jsontag) = "nonce"]; + bytes Value = 2 [(gogoproto.jsontag) = "value", (gogoproto.casttypewith) = "math/big.Int;github.com/multiversx/mx-chain-core-go/data.BigIntCaster"]; + bytes RcvAddr = 3 [(gogoproto.jsontag) = "receiver"]; + bytes RcvUserName = 4 [(gogoproto.jsontag) = "rcvUserName,omitempty"]; + bytes SndAddr = 5 [(gogoproto.jsontag) = "sender"]; + bytes SndUserName = 6 [(gogoproto.jsontag) = "sndUserName,omitempty"]; + uint64 GasPrice = 7 [(gogoproto.jsontag) = "gasPrice,omitempty"]; + uint64 GasLimit = 8 [(gogoproto.jsontag) = "gasLimit,omitempty"]; + bytes Data = 9 [(gogoproto.jsontag) = "data,omitempty"]; + bytes ChainID = 10 [(gogoproto.jsontag) = "chainID"]; + uint32 Version = 11 [(gogoproto.jsontag) = "version"]; + bytes Signature = 12 [(gogoproto.jsontag) = "signature,omitempty"]; + uint32 Options = 13 [(gogoproto.jsontag) = "options,omitempty"]; + bytes GuardianAddr = 14 [(gogoproto.jsontag) = "guardian,omitempty"]; + bytes GuardianSignature = 15 [(gogoproto.jsontag) = "guardianSignature,omitempty"]; + bytes RelayerAddr = 16 [(gogoproto.jsontag) = "relayer,omitempty"]; + repeated Transaction InnerTransactions = 17 [(gogoproto.jsontag) = "innerTransactions,omitempty"]; } diff --git a/data/transaction/transaction_test.go b/data/transaction/transaction_test.go index ce8e70aea..792eacc89 100644 --- a/data/transaction/transaction_test.go +++ b/data/transaction/transaction_test.go @@ -23,16 +23,18 @@ func TestTransaction_SettersAndGetters(t *testing.T) { gasLimit := uint64(5) sender := []byte("sndr") receiver := []byte("receiver") - innerTx := &transaction.Transaction{ - Nonce: 123, - RelayerAddr: sender, + innerTxs := []*transaction.Transaction{ + { + Nonce: 123, + RelayerAddr: sender, + }, } tx := &transaction.Transaction{ - Nonce: nonce, - GasPrice: gasPrice, - GasLimit: gasLimit, - InnerTransaction: innerTx, + Nonce: nonce, + GasPrice: gasPrice, + GasLimit: gasLimit, + InnerTransactions: innerTxs, } assert.False(t, check.IfNil(tx)) @@ -48,8 +50,8 @@ func TestTransaction_SettersAndGetters(t *testing.T) { assert.Equal(t, gasLimit, tx.GetGasLimit()) assert.Equal(t, sender, tx.GetSndAddr()) assert.Equal(t, receiver, tx.GetRcvAddr()) - assert.Equal(t, innerTx, tx.GetUserTransaction()) - assert.Equal(t, sender, tx.GetInnerTransaction().GetRelayerAddr()) + assert.Equal(t, innerTxs[0], tx.GetUserTransactions()[0]) + assert.Equal(t, sender, tx.GetInnerTransactions()[0].GetRelayerAddr()) } func TestTransaction_MarshalUnmarshalJsonShouldWork(t *testing.T) { @@ -65,8 +67,10 @@ func TestTransaction_MarshalUnmarshalJsonShouldWork(t *testing.T) { GasLimit: 5678, Data: []byte("data"), Signature: []byte("signature"), - InnerTransaction: &transaction.Transaction{ - Nonce: 123, + InnerTransactions: []*transaction.Transaction{ + { + Nonce: 123, + }, }, } @@ -265,15 +269,15 @@ func TestTransaction_GetDataForSigningShouldWork(t *testing.T) { assert.Equal(t, 2, numEncodeCalled) }) - t.Run("inner tx, without hash sign option set", func(t *testing.T) { + t.Run("inner txs, without hash sign option set", func(t *testing.T) { t.Parallel() tx1 := &transaction.Transaction{ Nonce: 1, } tx := &transaction.Transaction{ - Nonce: 3, - InnerTransaction: tx1, + Nonce: 3, + InnerTransactions: []*transaction.Transaction{tx1}, } numEncodeCalled := 0 From 48e2da52259e97a818d9a1335cbccd1863ef10d1 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Thu, 4 Apr 2024 21:13:42 +0300 Subject: [PATCH 17/22] update ApiTransactionResult as well --- data/transaction/apiTransactionResult.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/transaction/apiTransactionResult.go b/data/transaction/apiTransactionResult.go index 20e86eb1d..8f619d064 100644 --- a/data/transaction/apiTransactionResult.go +++ b/data/transaction/apiTransactionResult.go @@ -69,7 +69,7 @@ type ApiTransactionResult struct { Options uint32 `json:"options"` GuardianAddr string `json:"guardian,omitempty"` GuardianSignature string `json:"guardianSignature,omitempty"` - InnerTransaction data.TransactionHandler `json:"innerTransaction,omitempty"` + InnerTransactions []data.TransactionHandler `json:"innerTransactions,omitempty"` } // ApiSmartContractResult represents a smart contract result with changed fields' types in order to make it friendly for API's json From 8b6faa711b232f24a9bcdc5e319f544056e8de61 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Tue, 28 May 2024 16:27:12 +0300 Subject: [PATCH 18/22] update ApiTransactionResult to use FrontEndTransaction for better visibility --- data/transaction/apiTransactionResult.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/transaction/apiTransactionResult.go b/data/transaction/apiTransactionResult.go index 8f619d064..1dd23f4c9 100644 --- a/data/transaction/apiTransactionResult.go +++ b/data/transaction/apiTransactionResult.go @@ -69,7 +69,7 @@ type ApiTransactionResult struct { Options uint32 `json:"options"` GuardianAddr string `json:"guardian,omitempty"` GuardianSignature string `json:"guardianSignature,omitempty"` - InnerTransactions []data.TransactionHandler `json:"innerTransactions,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 From 1559f923a59de7daa315a64130e1afe6392b71dd Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 29 May 2024 11:54:08 +0300 Subject: [PATCH 19/22] added RelayedTransactionV3 constant --- core/constants.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/constants.go b/core/constants.go index e022eea34..839f3ce1c 100644 --- a/core/constants.go +++ b/core/constants.go @@ -250,6 +250,9 @@ const RelayedTransaction = "relayedTx" // RelayedTransactionV2 is the key for the optimized electronic meta/gassless/relayed transaction standard const RelayedTransactionV2 = "relayedTxV2" +// RelayedTransactionV3 is the key for the optimized electronic meta/gassless/relayed transaction standard +const RelayedTransactionV3 = "relayedTxV3" + // SCDeployInitFunctionName is the key for the function which is called at smart contract deploy time const SCDeployInitFunctionName = "_init" From 139a833706a1ce6ebeddd46ab32d8a4545db8efc Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 29 May 2024 13:00:34 +0300 Subject: [PATCH 20/22] reverted last commit --- core/constants.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/core/constants.go b/core/constants.go index 839f3ce1c..e022eea34 100644 --- a/core/constants.go +++ b/core/constants.go @@ -250,9 +250,6 @@ const RelayedTransaction = "relayedTx" // RelayedTransactionV2 is the key for the optimized electronic meta/gassless/relayed transaction standard const RelayedTransactionV2 = "relayedTxV2" -// RelayedTransactionV3 is the key for the optimized electronic meta/gassless/relayed transaction standard -const RelayedTransactionV3 = "relayedTxV3" - // SCDeployInitFunctionName is the key for the function which is called at smart contract deploy time const SCDeployInitFunctionName = "_init" From 88bd243c9240132ebfd78daca26d717b8fbf874d Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Tue, 4 Jun 2024 10:53:37 +0300 Subject: [PATCH 21/22] fixes after review --- data/transaction/transaction.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/data/transaction/transaction.go b/data/transaction/transaction.go index 5680523aa..d7fd3843c 100644 --- a/data/transaction/transaction.go +++ b/data/transaction/transaction.go @@ -88,16 +88,15 @@ func (tx *Transaction) GetDataForSigning(encoder data.Encoder, marshaller data.M numInnerTxs := len(tx.InnerTransactions) if numInnerTxs > 0 { ftx.InnerTransactions = make([]*FrontendTransaction, numInnerTxs) + var errPrepare error for i := 0; i < numInnerTxs; i++ { - innerFtx, errPrepare := tx.InnerTransactions[i].prepareTx(encoder) + ftx.InnerTransactions[i], errPrepare = tx.InnerTransactions[i].prepareTx(encoder) if errPrepare != nil { return nil, errPrepare } - innerFtx.Signature = hex.EncodeToString(tx.InnerTransactions[i].Signature) - innerFtx.GuardianSignature = hex.EncodeToString(tx.InnerTransactions[i].GuardianSignature) - - ftx.InnerTransactions[i] = innerFtx + ftx.InnerTransactions[i].Signature = hex.EncodeToString(tx.InnerTransactions[i].Signature) + ftx.InnerTransactions[i].GuardianSignature = hex.EncodeToString(tx.InnerTransactions[i].GuardianSignature) } } From 86ff8cd5798bbc167e7ae54f6b9983f0a21bf176 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Tue, 11 Jun 2024 14:14:33 +0300 Subject: [PATCH 22/22] added GetUserTransactions on TransactionWithFeeHandler --- data/interface.go | 1 + 1 file changed, 1 insertion(+) diff --git a/data/interface.go b/data/interface.go index 0a694b469..cbfd50c80 100644 --- a/data/interface.go +++ b/data/interface.go @@ -399,6 +399,7 @@ type TransactionWithFeeHandler interface { GetData() []byte GetRcvAddr() []byte GetValue() *big.Int + GetUserTransactions() []TransactionHandler } // UserAccountHandler models a user account