elucidsoft / dotnet-stellar-sdk

Stellar API SDK for .NET 6.x
Apache License 2.0
116 stars 54 forks source link

TransactionResponse constructor fails for text memo #263

Closed OttoVT closed 4 years ago

OttoVT commented 4 years ago

Problem In the class stellar_dotnet_sdk.responses.TransactionResponse processing of MemoText currently is not possible. For example, this text memo cad98atrnpbwtn9qiozjpd5m6o is used as a deposit address for a user.

This code should work with text memo: https://github.com/elucidsoft/dotnet-stellar-sdk/blob/master/stellar-dotnet-sdk/responses/TransactionResponse.cs#L78

Solution Update getter and setter of MemoValue property

public Memo Memo
        {
            get
            {
                switch (MemoType)
                {
                    case "none":
                        return Memo.None();
                    case "id":
                        return Memo.Id(ulong.Parse(MemoValue));
                    case "hash":
                        return Memo.Hash(Convert.FromBase64String(MemoValue));
                    case "return":
                        return Memo.ReturnHash(Convert.FromBase64String(MemoValue));
                   // Code below should be added
                    case "text":
                        return Memo.Text(MemoValue);
                    default:
                        throw new ArgumentException(nameof(MemoType));
                }
            }
            private set
            {
                switch (value)
                {
                    case MemoNone _:
                        MemoType = "none";
                        MemoValue = null;
                        return;
                    case MemoId id:
                        MemoType = "id";
                        MemoValue = id.IdValue.ToString();
                        return;
                    case MemoHash h:
                        MemoType = "hash";
                        MemoValue = Convert.ToBase64String(h.MemoBytes);
                        return;
                    case MemoReturnHash r:
                        MemoType = "return";
                        MemoValue = Convert.ToBase64String(r.MemoBytes);
                        return;
                   // Code below should be added
                   case MemoText r:
                        MemoType = "text";
                        MemoValue = value;
                        return;
                    default:
                        throw new ArgumentException(nameof(value));
                }
            }
        }
Kirbyrawr commented 4 years ago

Checking!

Kirbyrawr commented 4 years ago

Yup totally right that case is missing as far as i'm seeing, thanks for the report i will fix it

Kirbyrawr commented 4 years ago

https://github.com/elucidsoft/dotnet-stellar-sdk/pull/264

fracek commented 4 years ago

The fix was merged in master. I will close once we release a new version.

OttoVT commented 4 years ago

Thank you! =)

fracek commented 4 years ago

Version 4.2.24 was published on nuget. The bug should be fixed now.