Skip to content
This repository has been archived by the owner on May 24, 2024. It is now read-only.

Commit

Permalink
Merge pull request #345 from RivalCoins/LiquidityPoolBalanceFix
Browse files Browse the repository at this point in the history
Fix liquidity pool balance deserialization.
  • Loading branch information
elucidsoft authored Nov 15, 2021
2 parents 3525e0d + 01eac83 commit 4a50bb5
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 9 deletions.
1 change: 1 addition & 0 deletions stellar-dotnet-sdk-test/AccountFlagTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public void TestValues()
Assert.AreEqual(1, (int)AccountFlag.AuthRequiredFlag);
Assert.AreEqual(2, (int)AccountFlag.AuthRevocableFlag);
Assert.AreEqual(4, (int)AccountFlag.AuthImmutableFlag);
Assert.AreEqual(8, (int)AccountFlag.AuthClawbackFlag);
}
}
}
4 changes: 2 additions & 2 deletions stellar-dotnet-sdk-test/ServerCheckMemoRequiredTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,10 @@ private string BuildAccountResponse(string accountId, Dictionary<string, string>
{
Balances = new[]
{
new Balance("native", null, null, "12345.6789", null, "0.0", "0.0", false, true),
new Balance("native", null, null, "12345.6789", null, "0.0", "0.0", false, true, "1c80ecd9cc567ef5301683af3ca7c2deeba7d519275325549f22514076396469"),
},
Data = accountData,
Flags = new Flags(false, false, false),
Flags = new Flags(false, false, false, false),
HomeDomain = null,
InflationDestination = null,
Signers = new[]
Expand Down
24 changes: 24 additions & 0 deletions stellar-dotnet-sdk-test/responses/AccountDeserializerTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.IO;
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;
using stellar_dotnet_sdk;
Expand Down Expand Up @@ -74,6 +75,7 @@ public static void AssertTestData(AccountResponse account)
Assert.AreEqual(account.Flags.AuthRequired, false);
Assert.AreEqual(account.Flags.AuthRevocable, true);
Assert.AreEqual(account.Flags.AuthImmutable, true);
Assert.AreEqual(account.Flags.AuthClawback, true);

Assert.AreEqual(account.Balances[0].AssetType, "credit_alphanum4");
Assert.AreEqual(account.Balances[0].AssetCode, "ABC");
Expand All @@ -83,6 +85,9 @@ public static void AssertTestData(AccountResponse account)
Assert.AreEqual(asset.Code, "ABC");
Assert.AreEqual(asset.Issuer, "GCRA6COW27CY5MTKIA7POQ2326C5ABYCXODBN4TFF5VL4FMBRHOT3YHU");

account.Balances
.Should().HaveCount(3);

Assert.AreEqual(account.Balances[0].BalanceString, "1001.0000000");
Assert.AreEqual(account.Balances[0].Limit, "12000.4775807");
Assert.AreEqual(account.Balances[0].BuyingLiabilities, "100.1234567");
Expand All @@ -98,6 +103,25 @@ public static void AssertTestData(AccountResponse account)
Assert.AreEqual(account.Balances[1].SellingLiabilities, "1.7654321");
Assert.AreEqual(account.Balances[1].Limit, null);

// liquidity pool balance
account.Balances[2].AssetType
.Should().Be("liquidity_pool_shares");

account.Balances[2].BalanceString
.Should().Be("500.0000400");

account.Balances[2].Limit
.Should().Be("922337203685.4775807");

account.Balances[2].IsAuthorized
.Should().BeFalse();

account.Balances[2].IsAuthorizedToMaintainLiabilities
.Should().BeFalse();

account.Balances[2].LiquidityPoolId
.Should().Be("1c80ecd9cc567ef5301683af3ca7c2deeba7d519275325549f22514076396469");

Assert.AreEqual(account.Signers[0].Key, "GAAZI4TCR3TY5OJHCTJC2A4QSY6CJWJH5IAJTGKIN2ER7LBNVKOCCWN7");
Assert.AreEqual(account.Signers[0].Weight, 0);
Assert.AreEqual(account.Signers[0].Type, "ed25519_public_key");
Expand Down
1 change: 1 addition & 0 deletions stellar-dotnet-sdk-test/stellar-dotnet-sdk-test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="coveralls.io" Version="1.4.2" />
<PackageReference Include="FluentAssertions" Version="5.10.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="Moq" Version="4.10.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.4.0" />
Expand Down
12 changes: 11 additions & 1 deletion stellar-dotnet-sdk-test/testdata/account.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
"flags": {
"auth_required": false,
"auth_revocable": true,
"auth_immutable": true
"auth_immutable": true,
"auth_clawback_enabled": true
},
"balances": [
{
Expand All @@ -53,6 +54,15 @@
"balance": "20.0000300",
"buying_liabilities": "5.1234567",
"selling_liabilities": "1.7654321"
},
{
"balance": "500.0000400",
"liquidity_pool_id": "1c80ecd9cc567ef5301683af3ca7c2deeba7d519275325549f22514076396469",
"limit": "922337203685.4775807",
"last_modified_ledger": 975243,
"is_authorized": false,
"is_authorized_to_maintain_liabilities": false,
"asset_type": "liquidity_pool_shares"
}
],
"signers": [
Expand Down
9 changes: 7 additions & 2 deletions stellar-dotnet-sdk/AccountFlag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@ public enum AccountFlag
AuthRevocableFlag = AccountFlags.AccountFlagsEnum.AUTH_REVOCABLE_FLAG,

/// <summary>
/// With this setting, none of the following authorization flags can be changed.
/// With this setting, none of the other authorization flags can be changed.
/// </summary>
AuthImmutableFlag = AccountFlags.AccountFlagsEnum.AUTH_IMMUTABLE_FLAG
AuthImmutableFlag = AccountFlags.AccountFlagsEnum.AUTH_IMMUTABLE_FLAG,

/// <summary>
/// With this setting, an anchor can unilaterally take away any portion of its issued asset(s) from any asset holder.
/// </summary>
AuthClawbackFlag = AccountFlags.AccountFlagsEnum.AUTH_CLAWBACK_ENABLED_FLAG
}
}
19 changes: 16 additions & 3 deletions stellar-dotnet-sdk/responses/Balance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,27 @@ namespace stellar_dotnet_sdk.responses
/// </summary>
public class Balance
{
public Balance(string assetType, string assetCode, string assetIssuer, string balance, string limit, string buyingLiabilities, string sellingLiabilities, bool isAuthorized, bool isAuthorizedToMaintainLiabilities)
public Balance(string assetType, string assetCode, string assetIssuer, string balance, string limit, string buyingLiabilities, string sellingLiabilities, bool isAuthorized, bool isAuthorizedToMaintainLiabilities, string liquidityPoolId)
{
AssetType = assetType ?? throw new ArgumentNullException(nameof(assetType), "assertType cannot be null");
BalanceString = balance ?? throw new ArgumentNullException(nameof(balance), "balance cannot be null");
Limit = limit;
AssetCode = assetCode;
AssetIssuer = assetIssuer;
BuyingLiabilities = buyingLiabilities ?? throw new ArgumentNullException(nameof(buyingLiabilities), "buyingLiabilities cannot be null");
SellingLiabilities = sellingLiabilities ?? throw new ArgumentNullException(nameof(sellingLiabilities), "sellingLiabilities cannot be null");

if (assetType != "liquidity_pool_shares")
{
BuyingLiabilities = buyingLiabilities ?? throw new ArgumentNullException(nameof(buyingLiabilities), "buyingLiabilities cannot be null");
SellingLiabilities = sellingLiabilities ?? throw new ArgumentNullException(nameof(sellingLiabilities), "sellingLiabilities cannot be null");
}

IsAuthorized = isAuthorized;
IsAuthorizedToMaintainLiabilities = isAuthorizedToMaintainLiabilities;

if (assetType == "liquidity_pool_shares")
{
LiquidityPoolId = liquidityPoolId ?? throw new ArgumentNullException(nameof(liquidityPoolId));
}
}

[JsonProperty(PropertyName = "asset_type")]
Expand Down Expand Up @@ -50,5 +60,8 @@ public Balance(string assetType, string assetCode, string assetIssuer, string ba

[JsonProperty(PropertyName = "is_authorized_to_maintain_liabilities")]
public bool IsAuthorizedToMaintainLiabilities { get; private set; }

[JsonProperty(PropertyName = "liquidity_pool_id")]
public string LiquidityPoolId { get; private set; }
}
}
18 changes: 17 additions & 1 deletion stellar-dotnet-sdk/responses/Flags.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,36 @@ namespace stellar_dotnet_sdk.responses
/// </summary>
public class Flags
{
public Flags(bool authRequired, bool authRevocable, bool authImmutable)
public Flags(bool authRequired, bool authRevocable, bool authImmutable, bool authClawback)
{
AuthRequired = authRequired;
AuthRevocable = authRevocable;
AuthImmutable = authImmutable;
AuthClawback = authClawback;
}

/// <summary>
/// This account must approve anyone who wants to hold its asset.
/// </summary>
[JsonProperty(PropertyName = "auth_required")]
public bool AuthRequired { get; private set; }

/// <summary>
/// This account can set the authorize flag of an existing trustline to freeze the assets held by an asset holder.
/// </summary>
[JsonProperty(PropertyName = "auth_revocable")]
public bool AuthRevocable { get; private set; }

/// <summary>
/// This account cannot change any of the authorization flags.
/// </summary>
[JsonProperty(PropertyName = "auth_immutable")]
public bool AuthImmutable { get; private set; }

/// <summary>
/// This account can unilaterally take away any portion of its issued asset(s) from any asset holders.
/// </summary>
[JsonProperty(PropertyName = "auth_clawback_enabled")]
public bool AuthClawback { get; private set; }
}
}

0 comments on commit 4a50bb5

Please sign in to comment.