Skip to content

Commit

Permalink
Added a check inside 'account_create_transaction' for stakedNodeID
Browse files Browse the repository at this point in the history
Signed-off-by: NikolaMirchev <nikola.mirchev@limechain.tech>
  • Loading branch information
NikolaMirchev committed Jan 23, 2024
1 parent 48d881a commit f14940a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
14 changes: 9 additions & 5 deletions account_create_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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(),
}

Expand Down
10 changes: 3 additions & 7 deletions serialize_deserialize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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) {
Expand Down

0 comments on commit f14940a

Please sign in to comment.