From f14940a3ef3912a5360c99db6ffb6640a79f32b8 Mon Sep 17 00:00:00 2001 From: NikolaMirchev Date: Tue, 23 Jan 2024 15:26:25 +0200 Subject: [PATCH] Added a check inside 'account_create_transaction' for stakedNodeID Signed-off-by: NikolaMirchev --- account_create_transaction.go | 14 +++++++++----- serialize_deserialize_test.go | 10 +++------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/account_create_transaction.go b/account_create_transaction.go index 40d6523ee..5cc1ed4fc 100644 --- a/account_create_transaction.go +++ b/account_create_transaction.go @@ -67,11 +67,15 @@ func NewAccountCreateTransaction() *AccountCreateTransaction { func _AccountCreateTransactionFromProtobuf(tx Transaction, pb *services.TransactionBody) *AccountCreateTransaction { key, _ := _KeyFromProtobuf(pb.GetCryptoCreateAccount().GetKey()) renew := _DurationFromProtobuf(pb.GetCryptoCreateAccount().GetAutoRenewPeriod()) - stakedNodeID := pb.GetCryptoCreateAccount().GetStakedNodeId() - var stakeNodeAccountID *AccountID + var stakedNodeID *int64 + if pb.GetCryptoCreateAccount().GetStakedNodeId() != 0 { + nodeId := pb.GetCryptoCreateAccount().GetStakedNodeId() + stakedNodeID = &nodeId + } + var stakeAccountID *AccountID if pb.GetCryptoCreateAccount().GetStakedAccountId() != nil { - stakeNodeAccountID = _AccountIDFromProtobuf(pb.GetCryptoCreateAccount().GetStakedAccountId()) + stakeAccountID = _AccountIDFromProtobuf(pb.GetCryptoCreateAccount().GetStakedAccountId()) } body := AccountCreateTransaction{ @@ -82,8 +86,8 @@ func _AccountCreateTransactionFromProtobuf(tx Transaction, pb *services.Transact memo: pb.GetCryptoCreateAccount().GetMemo(), receiverSignatureRequired: pb.GetCryptoCreateAccount().ReceiverSigRequired, maxAutomaticTokenAssociations: uint32(pb.GetCryptoCreateAccount().MaxAutomaticTokenAssociations), - stakedAccountID: stakeNodeAccountID, - stakedNodeID: &stakedNodeID, + stakedAccountID: stakeAccountID, + stakedNodeID: stakedNodeID, declineReward: pb.GetCryptoCreateAccount().GetDeclineReward(), } diff --git a/serialize_deserialize_test.go b/serialize_deserialize_test.go index fe0718838..c93089cbb 100644 --- a/serialize_deserialize_test.go +++ b/serialize_deserialize_test.go @@ -34,6 +34,8 @@ func TestIntegrationSerializeTransactionDeserializeAndAgainSerializeHasTheSameBy transaction := txFromBytes.(AccountCreateTransaction) secondBytes, err := transaction.ToBytes() + fmt.Println(len(secondBytes)) + fmt.Println(secondBytes) require.NoError(t, err) assert.Equal(t, firstBytes, secondBytes) @@ -53,7 +55,6 @@ func TestIntegrationSerializeTransactionDeserializeAndAgainSerializeHasTheSameBy SetInitialBalance(newBalance) firstBytes, err := originalTransaction.ToBytes() require.NoError(t, err) - fmt.Println("First Bytes: ", firstBytes) txFromBytes, err := TransactionFromBytes(firstBytes) require.NoError(t, err) @@ -62,12 +63,7 @@ func TestIntegrationSerializeTransactionDeserializeAndAgainSerializeHasTheSameBy secondBytes, err := transaction.ToBytes() require.NoError(t, err) - fmt.Println("Second Bytes: ", secondBytes) - - txFromBytes2, err := TransactionFromBytes(secondBytes) - transaction2 := txFromBytes2.(AccountCreateTransaction) - - // assert.Equal(t, firstBytes, secondBytes) + assert.Equal(t, firstBytes, secondBytes) } func TestIntegrationSerializeTransactionWithoutNodeAccountIdDeserialiseAndExecute(t *testing.T) {