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

Add accounts endpoint #226

Merged
merged 1 commit into from
Jan 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions stellar-dotnet-sdk-test/requests/AccountsRequestBuilderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,48 @@ public async Task TestAccountsData()
Assert.AreEqual("TestValue", accountData.ValueDecoded);
}
}

[TestMethod]
public async Task TestAccountsWithSigner()
{
var jsonResponse = File.ReadAllText(Path.Combine("testdata", "accountsWithSigner.json"));
var fakeHttpClient = FakeHttpClient.CreateFakeHttpClient(jsonResponse);

using (var server = new Server("https://horizon-testnet.stellar.org", fakeHttpClient))
{
var req = server.Accounts
.WithSigner("GBPOFUJUHOFTZHMZ63H5GE6NX5KVKQRD6N3I2E5AL3T2UG7HSLPLXN2K");

Assert.AreEqual(
"https://horizon-testnet.stellar.org/accounts?signer=GBPOFUJUHOFTZHMZ63H5GE6NX5KVKQRD6N3I2E5AL3T2UG7HSLPLXN2K",
req.BuildUri().ToString());
var accounts = await req.Execute();

Assert.AreEqual(1, accounts.Records.Count);
}
}


[TestMethod]
public async Task TestAccountsWithTrustline()
{
var jsonResponse = File.ReadAllText(Path.Combine("testdata", "accountsWithTrustline.json"));
var fakeHttpClient = FakeHttpClient.CreateFakeHttpClient(jsonResponse);

using (var server = new Server("https://horizon-testnet.stellar.org", fakeHttpClient))
{
var asset = Asset.CreateNonNativeAsset("FOO",
"GAGLYFZJMN5HEULSTH5CIGPOPAVUYPG5YSWIYDJMAPIECYEBPM2TA3QR");
var req = server.Accounts.WithTrustline(asset);

Assert.AreEqual(
"https://horizon-testnet.stellar.org/accounts?asset=FOO:GAGLYFZJMN5HEULSTH5CIGPOPAVUYPG5YSWIYDJMAPIECYEBPM2TA3QR",
req.BuildUri().ToString());
var accounts = await req.Execute();

Assert.AreEqual(1, accounts.Records.Count);
}
}

}
}
8 changes: 7 additions & 1 deletion stellar-dotnet-sdk-test/stellar-dotnet-sdk-test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="coveralls.io" Version="1.4.2"/>
<PackageReference Include="coveralls.io" Version="1.4.2" />
<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 Expand Up @@ -242,5 +242,11 @@
<None Update="testdata\transactionTransactionPre020.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="testdata\accountsWithSigner.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="testdata\accountsWithTrustline.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
115 changes: 115 additions & 0 deletions stellar-dotnet-sdk-test/testdata/accountsWithSigner.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
{
"_links": {
"self": {
"href": "https://horizon-testnet.stellar.org/accounts?cursor=\u0026limit=10\u0026order=asc\u0026signer=GBPOFUJUHOFTZHMZ63H5GE6NX5KVKQRD6N3I2E5AL3T2UG7HSLPLXN2K"
},
"next": {
"href": "https://horizon-testnet.stellar.org/accounts?cursor=GDRREYWHQWJDICNH4SAH4TT2JRBYRPTDYIMLK4UWBDT3X3ZVVYT6I4UQ\u0026limit=10\u0026order=asc\u0026signer=GBPOFUJUHOFTZHMZ63H5GE6NX5KVKQRD6N3I2E5AL3T2UG7HSLPLXN2K"
},
"prev": {
"href": "https://horizon-testnet.stellar.org/accounts?cursor=GDRREYWHQWJDICNH4SAH4TT2JRBYRPTDYIMLK4UWBDT3X3ZVVYT6I4UQ\u0026limit=10\u0026order=desc\u0026signer=GBPOFUJUHOFTZHMZ63H5GE6NX5KVKQRD6N3I2E5AL3T2UG7HSLPLXN2K"
}
},
"_embedded": {
"records": [
{
"_links": {
"self": {
"href": "https://horizon-testnet.stellar.org/accounts/GD42RQNXTRIW6YR3E2HXV5T2AI27LBRHOERV2JIYNFMXOBA234SWLQQB"
},
"transactions": {
"href": "https://horizon-testnet.stellar.org/accounts/GD42RQNXTRIW6YR3E2HXV5T2AI27LBRHOERV2JIYNFMXOBA234SWLQQB/transactions{?cursor,limit,order}",
"templated": true
},
"operations": {
"href": "https://horizon-testnet.stellar.org/accounts/GD42RQNXTRIW6YR3E2HXV5T2AI27LBRHOERV2JIYNFMXOBA234SWLQQB/operations{?cursor,limit,order}",
"templated": true
},
"payments": {
"href": "https://horizon-testnet.stellar.org/accounts/GD42RQNXTRIW6YR3E2HXV5T2AI27LBRHOERV2JIYNFMXOBA234SWLQQB/payments{?cursor,limit,order}",
"templated": true
},
"effects": {
"href": "https://horizon-testnet.stellar.org/accounts/GD42RQNXTRIW6YR3E2HXV5T2AI27LBRHOERV2JIYNFMXOBA234SWLQQB/effects{?cursor,limit,order}",
"templated": true
},
"offers": {
"href": "https://horizon-testnet.stellar.org/accounts/GD42RQNXTRIW6YR3E2HXV5T2AI27LBRHOERV2JIYNFMXOBA234SWLQQB/offers{?cursor,limit,order}",
"templated": true
},
"trades": {
"href": "https://horizon-testnet.stellar.org/accounts/GD42RQNXTRIW6YR3E2HXV5T2AI27LBRHOERV2JIYNFMXOBA234SWLQQB/trades{?cursor,limit,order}",
"templated": true
},
"data": {
"href": "https://horizon-testnet.stellar.org/accounts/GD42RQNXTRIW6YR3E2HXV5T2AI27LBRHOERV2JIYNFMXOBA234SWLQQB/data/{key}",
"templated": true
}
},
"id": "GD42RQNXTRIW6YR3E2HXV5T2AI27LBRHOERV2JIYNFMXOBA234SWLQQB",
"paging_token": "",
"account_id": "GD42RQNXTRIW6YR3E2HXV5T2AI27LBRHOERV2JIYNFMXOBA234SWLQQB",
"sequence": 7275146318446606,
"last_modified_ledger": 22379074,
"subentry_count": 4,
"thresholds": {
"low_threshold": 0,
"med_threshold": 0,
"high_threshold": 0
},
"flags": {
"auth_required": false,
"auth_revocable": false,
"auth_immutable": false
},
"balances": [
{
"balance": "1000000.0000000",
"limit": "922337203685.4775807",
"buying_liabilities": "0.0000000",
"selling_liabilities": "0.0000000",
"last_modified_ledger": 632070,
"asset_type": "credit_alphanum4",
"asset_code": "FOO",
"asset_issuer": "GAGLYFZJMN5HEULSTH5CIGPOPAVUYPG5YSWIYDJMAPIECYEBPM2TA3QR"
},
{
"balance": "10000.0000000",
"buying_liabilities": "0.0000000",
"selling_liabilities": "0.0000000",
"asset_type": "native"
}
],
"signers": [
{
"public_key": "GDLEPBJBC2VSKJCLJB264F2WDK63X4NKOG774A3QWVH2U6PERGDPUCS4",
"weight": 1,
"key": "GDLEPBJBC2VSKJCLJB264F2WDK63X4NKOG774A3QWVH2U6PERGDPUCS4",
"type": "ed25519_public_key"
},
{
"public_key": "GBPOFUJUHOFTZHMZ63H5GE6NX5KVKQRD6N3I2E5AL3T2UG7HSLPLXN2K",
"weight": 1,
"key": "GBPOFUJUHOFTZHMZ63H5GE6NX5KVKQRD6N3I2E5AL3T2UG7HSLPLXN2K",
"type": "sha256_hash"
},
{
"public_key": "GDUDIN23QQTB23Q3Q6GUL6I7CEAQY4CWCFVRXFWPF4UJAQO47SPUFCXG",
"weight": 1,
"key": "GDUDIN23QQTB23Q3Q6GUL6I7CEAQY4CWCFVRXFWPF4UJAQO47SPUFCXG",
"type": "preauth_tx"
},
{
"public_key": "GD42RQNXTRIW6YR3E2HXV5T2AI27LBRHOERV2JIYNFMXOBA234SWLQQB",
"weight": 1,
"key": "GD42RQNXTRIW6YR3E2HXV5T2AI27LBRHOERV2JIYNFMXOBA234SWLQQB",
"type": "ed25519_public_key"
}
],
"data": {
"best_friend": "c3Ryb29weQ=="
}
}
]
}
}
115 changes: 115 additions & 0 deletions stellar-dotnet-sdk-test/testdata/accountsWithTrustline.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
{
"_links": {
"self": {
"href": "https://horizon-testnet.stellar.org/accounts?cursor=\u0026limit=10\u0026order=asc\u0026signer=GBPOFUJUHOFTZHMZ63H5GE6NX5KVKQRD6N3I2E5AL3T2UG7HSLPLXN2K"
},
"next": {
"href": "https://horizon-testnet.stellar.org/accounts?cursor=GDRREYWHQWJDICNH4SAH4TT2JRBYRPTDYIMLK4UWBDT3X3ZVVYT6I4UQ\u0026limit=10\u0026order=asc\u0026signer=GBPOFUJUHOFTZHMZ63H5GE6NX5KVKQRD6N3I2E5AL3T2UG7HSLPLXN2K"
},
"prev": {
"href": "https://horizon-testnet.stellar.org/accounts?cursor=GDRREYWHQWJDICNH4SAH4TT2JRBYRPTDYIMLK4UWBDT3X3ZVVYT6I4UQ\u0026limit=10\u0026order=desc\u0026signer=GBPOFUJUHOFTZHMZ63H5GE6NX5KVKQRD6N3I2E5AL3T2UG7HSLPLXN2K"
}
},
"_embedded": {
"records": [
{
"_links": {
"self": {
"href": "https://horizon-testnet.stellar.org/accounts/GD42RQNXTRIW6YR3E2HXV5T2AI27LBRHOERV2JIYNFMXOBA234SWLQQB"
},
"transactions": {
"href": "https://horizon-testnet.stellar.org/accounts/GD42RQNXTRIW6YR3E2HXV5T2AI27LBRHOERV2JIYNFMXOBA234SWLQQB/transactions{?cursor,limit,order}",
"templated": true
},
"operations": {
"href": "https://horizon-testnet.stellar.org/accounts/GD42RQNXTRIW6YR3E2HXV5T2AI27LBRHOERV2JIYNFMXOBA234SWLQQB/operations{?cursor,limit,order}",
"templated": true
},
"payments": {
"href": "https://horizon-testnet.stellar.org/accounts/GD42RQNXTRIW6YR3E2HXV5T2AI27LBRHOERV2JIYNFMXOBA234SWLQQB/payments{?cursor,limit,order}",
"templated": true
},
"effects": {
"href": "https://horizon-testnet.stellar.org/accounts/GD42RQNXTRIW6YR3E2HXV5T2AI27LBRHOERV2JIYNFMXOBA234SWLQQB/effects{?cursor,limit,order}",
"templated": true
},
"offers": {
"href": "https://horizon-testnet.stellar.org/accounts/GD42RQNXTRIW6YR3E2HXV5T2AI27LBRHOERV2JIYNFMXOBA234SWLQQB/offers{?cursor,limit,order}",
"templated": true
},
"trades": {
"href": "https://horizon-testnet.stellar.org/accounts/GD42RQNXTRIW6YR3E2HXV5T2AI27LBRHOERV2JIYNFMXOBA234SWLQQB/trades{?cursor,limit,order}",
"templated": true
},
"data": {
"href": "https://horizon-testnet.stellar.org/accounts/GD42RQNXTRIW6YR3E2HXV5T2AI27LBRHOERV2JIYNFMXOBA234SWLQQB/data/{key}",
"templated": true
}
},
"id": "GD42RQNXTRIW6YR3E2HXV5T2AI27LBRHOERV2JIYNFMXOBA234SWLQQB",
"paging_token": "",
"account_id": "GD42RQNXTRIW6YR3E2HXV5T2AI27LBRHOERV2JIYNFMXOBA234SWLQQB",
"sequence": 7275146318446606,
"last_modified_ledger": 22379074,
"subentry_count": 4,
"thresholds": {
"low_threshold": 0,
"med_threshold": 0,
"high_threshold": 0
},
"flags": {
"auth_required": false,
"auth_revocable": false,
"auth_immutable": false
},
"balances": [
{
"balance": "1000000.0000000",
"limit": "922337203685.4775807",
"buying_liabilities": "0.0000000",
"selling_liabilities": "0.0000000",
"last_modified_ledger": 632070,
"asset_type": "credit_alphanum4",
"asset_code": "FOO",
"asset_issuer": "GAGLYFZJMN5HEULSTH5CIGPOPAVUYPG5YSWIYDJMAPIECYEBPM2TA3QR"
},
{
"balance": "10000.0000000",
"buying_liabilities": "0.0000000",
"selling_liabilities": "0.0000000",
"asset_type": "native"
}
],
"signers": [
{
"public_key": "GDLEPBJBC2VSKJCLJB264F2WDK63X4NKOG774A3QWVH2U6PERGDPUCS4",
"weight": 1,
"key": "GDLEPBJBC2VSKJCLJB264F2WDK63X4NKOG774A3QWVH2U6PERGDPUCS4",
"type": "ed25519_public_key"
},
{
"public_key": "GBPOFUJUHOFTZHMZ63H5GE6NX5KVKQRD6N3I2E5AL3T2UG7HSLPLXN2K",
"weight": 1,
"key": "GBPOFUJUHOFTZHMZ63H5GE6NX5KVKQRD6N3I2E5AL3T2UG7HSLPLXN2K",
"type": "sha256_hash"
},
{
"public_key": "GDUDIN23QQTB23Q3Q6GUL6I7CEAQY4CWCFVRXFWPF4UJAQO47SPUFCXG",
"weight": 1,
"key": "GDUDIN23QQTB23Q3Q6GUL6I7CEAQY4CWCFVRXFWPF4UJAQO47SPUFCXG",
"type": "preauth_tx"
},
{
"public_key": "GD42RQNXTRIW6YR3E2HXV5T2AI27LBRHOERV2JIYNFMXOBA234SWLQQB",
"weight": 1,
"key": "GD42RQNXTRIW6YR3E2HXV5T2AI27LBRHOERV2JIYNFMXOBA234SWLQQB",
"type": "ed25519_public_key"
}
],
"data": {
"best_friend": "c3Ryb29weQ=="
}
}
]
}
}
81 changes: 81 additions & 0 deletions stellar-dotnet-sdk/requests/AccountsRequestBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,86 @@ public async Task<AccountDataResponse> AccountData(string accountId, string key)
SetSegments("accounts", accountId, "data", key);
return await AccountData(BuildUri());
}

/// <summary>
/// Filter accounts that have the given signer or have a trustline to the given asset.
/// https://www.stellar.org/developers/horizon/reference/endpoints/accounts.html
/// </summary>
/// <param name="options">The filtering options</param>
public AccountsRequestBuilder Accounts(AccountsRequestOptions options)
{
if (options == null) throw new ArgumentNullException(nameof(options));

if (options.Signer != null)
{
UriBuilder.SetQueryParam("signer", options.Signer);
}

if (options.Asset != null)
{
UriBuilder.SetQueryParam("asset", AssetToQueryParam(options.Asset));
}

return this;
}

/// <summary>
/// Filter accounts that have the given signer or have a trustline to the given asset.
/// https://www.stellar.org/developers/horizon/reference/endpoints/accounts.html
/// </summary>
/// <param name="optionsAction"></param>
public AccountsRequestBuilder Accounts(Action<AccountsRequestOptions> optionsAction)
{
if (optionsAction == null) throw new ArgumentNullException(nameof(optionsAction));
var options = new AccountsRequestOptions();
optionsAction.Invoke(options);
return Accounts(options);
}

/// <summary>
/// Filter accounts that have the given signer.
/// </summary>
/// <param name="signer">The signer.</param>
/// <returns></returns>
public AccountsRequestBuilder WithSigner(string signer)
{
return Accounts(options => options.Signer = signer);
}

/// <summary>
/// Filter accounts that have a trustline to the given asset.
/// </summary>
/// <param name="asset"></param>
/// <returns></returns>
public AccountsRequestBuilder WithTrustline(Asset asset)
{
return Accounts(options => options.Asset = asset);
}

private string AssetToQueryParam(Asset asset)
{
switch (asset)
{
case AssetTypeNative _:
return "native";
case AssetTypeCreditAlphaNum credit:
return $"{credit.Code}:{credit.Issuer}";
default:
throw new ArgumentException($"Unknown Asset type {asset.GetType()}");
}
}

public class AccountsRequestOptions
{
/// <summary>
/// Filter accounts that have the given Signer.
/// </summary>
public string Signer { get; set; }

/// <summary>
/// Filter accounts that trust the given Asset.
/// </summary>
public Asset Asset { get; set; }
}
}
}