Skip to content

Commit

Permalink
GraphQl query cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
michielpost committed Apr 11, 2024
1 parent 98e3839 commit 913220d
Show file tree
Hide file tree
Showing 2 changed files with 179 additions and 9 deletions.
184 changes: 177 additions & 7 deletions src/aoWebWallet/Services/GraphqlClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,39 @@ public async Task<List<TokenTransfer>> GetTransactionsIn(string adddress, string
return processInfo;
}

public async Task<List<TokenTransfer>> GetTransactionsOut(string adddress, string? fromTxId = null)
public async Task<List<TokenTransfer>> GetTransactionsOut(string address, string? fromTxId = null)
{
string query = "query {\r\n transactions(\r\n first: 100\r\n sort: HEIGHT_DESC\r\n owners: [\"" + adddress + "\"]\r\n tags: [\r\n { name: \"Data-Protocol\", values: [\"ao\"] }\r\n { name: \"Action\", values: [\"Transfer\"] }\r\n ]\r\n ) {\r\n edges {\r\n node {\r\n id\r\n recipient\r\n owner {\r\n address\r\n }\r\n block {\r\n timestamp\r\n height\r\n }\r\n tags {\r\n name\r\n value\r\n }\r\n }\r\n }\r\n }\r\n}\r\n";
string query = $$"""
query {
transactions(
first: 100
sort: HEIGHT_DESC
owners: ["{{address}}"]
tags: [
{ name: "Data-Protocol", values: ["ao"] }
{ name: "Action", values: ["Transfer"] }
]
) {
edges {
node {
id
recipient
owner {
address
}
block {
timestamp
height
}
tags {
name
value
}
}
}
}
}
""";
var queryResult = await PostQueryAsync(query);

var result = new List<TokenTransfer>();
Expand All @@ -116,7 +146,38 @@ public async Task<List<TokenTransfer>> GetTransactionsOut(string adddress, strin

public async Task<List<TokenTransfer>> GetTransactionsOutFromProcess(string address, string? fromTxId = null)
{
string query = "query {\r\n transactions(\r\n first: 100\r\n sort: HEIGHT_DESC\r\n tags: [\r\n { name: \"From-Process\", values: [\"" + address + "\"] }\r\n { name: \"Data-Protocol\", values: [\"ao\"] }\r\n { name: \"Action\", values: [\"Transfer\"] }\r\n ]\r\n ) {\r\n edges {\r\n node {\r\n id\r\n recipient\r\n owner {\r\n address\r\n }\r\n block {\r\n timestamp\r\n height\r\n }\r\n tags {\r\n name\r\n value\r\n }\r\n }\r\n }\r\n }\r\n}\r\n";
string query = $$"""
query {
transactions(
first: 100
sort: HEIGHT_DESC
tags: [
{ name: "From-Process", values: ["{{address}}"] }
{ name: "Data-Protocol", values: ["ao"] }
{ name: "Action", values: ["Transfer"] }
]
) {
edges {
node {
id
recipient
owner {
address
}
block {
timestamp
height
}
tags {
name
value
}
}
}
}
}

""";
var queryResult = await PostQueryAsync(query);

var result = new List<TokenTransfer>();
Expand All @@ -134,7 +195,37 @@ public async Task<List<TokenTransfer>> GetTransactionsOutFromProcess(string addr

public async Task<TokenTransfer?> GetTransactionsById(string txId)
{
string query = "query {\r\n transactions(\r\n first: 1\r\n sort: HEIGHT_DESC\r\n ids: [\"" + txId + "\"]\r\n tags: [\r\n { name: \"Data-Protocol\", values: [\"ao\"] }\r\n { name: \"Action\", values: [\"Transfer\"] }\r\n ]\r\n ) {\r\n edges {\r\n node {\r\n id\r\n recipient\r\n owner {\r\n address\r\n }\r\n block {\r\n timestamp\r\n height\r\n }\r\n tags {\r\n name\r\n value\r\n }\r\n }\r\n }\r\n }\r\n}\r\n";
string query = $$"""
query {
transactions(
first: 1
sort: HEIGHT_DESC
ids: ["{{txId}}"]
tags: [
{ name: "Data-Protocol", values: ["ao"] }
{ name: "Action", values: ["Transfer"] }
]
) {
edges {
node {
id
recipient
owner {
address
}
block {
timestamp
height
}
tags {
name
value
}
}
}
}
}
""";
var queryResult = await PostQueryAsync(query);

var result = new List<TokenTransfer>();
Expand All @@ -152,7 +243,37 @@ public async Task<List<TokenTransfer>> GetTransactionsOutFromProcess(string addr

public async Task<List<TokenTransfer>> GetTransactionsForToken(string tokenId, string? fromTxId = null)
{
string query = "query {\r\n transactions(\r\n first: 50\r\n sort: HEIGHT_DESC\r\n recipients: [\"" + tokenId + "\"]\r\n tags: [\r\n { name: \"Data-Protocol\", values: [\"ao\"] }\r\n { name: \"Action\", values: [\"Transfer\"] }\r\n ]\r\n ) {\r\n edges {\r\n node {\r\n id\r\n recipient\r\n owner {\r\n address\r\n }\r\n block {\r\n timestamp\r\n height\r\n }\r\n tags {\r\n name\r\n value\r\n }\r\n }\r\n }\r\n }\r\n}\r\n";
string query = $$"""
query {
transactions(
first: 50
sort: HEIGHT_DESC
recipients: ["{{tokenId}}"]
tags: [
{ name: "Data-Protocol", values: ["ao"] }
{ name: "Action", values: ["Transfer"] }
]
) {
edges {
node {
id
recipient
owner {
address
}
block {
timestamp
height
}
tags {
name
value
}
}
}
}
}
""";
var queryResult = await PostQueryAsync(query);

var result = new List<TokenTransfer>();
Expand All @@ -170,11 +291,35 @@ public async Task<List<TokenTransfer>> GetTransactionsForToken(string tokenId, s

public async Task<List<AoProcessInfo>> GetAoProcessesForAddress(string address)
{
string query = "query {\r\n transactions(\r\n first: 100,\r\n owners: [\"" + address + "\"],\r\n tags: [\r\n { name: \"Data-Protocol\", values: [\"ao\"] },\r\n { name: \"Type\", values: [\"Process\"]},\r\n { name: \"App-Name\", values: [\"aos\"]},\r\n \r\n ]\r\n ) {\r\n edges {\r\n node {\r\n id\r\n tags {\r\n name\r\n value\r\n }\r\n }\r\n }\r\n }\r\n }";
string query = $$"""
query {
transactions(
first: 100
owners: ["{{address}}"]
tags: [
{ name: "Data-Protocol", values: ["ao"] }
{ name: "Type", values: ["Process"] }
{ name: "App-Name", values: ["aos"] }
]
) {
edges {
node {
id
tags {
name
value
}
}
}
}
}
""";
var queryResult = await PostQueryAsync(query);

var result = new List<AoProcessInfo>();

Console.WriteLine("AOresult:" + (queryResult?.Data?.Transactions?.Edges.Count ?? 0).ToString());

foreach (var edge in queryResult?.Data?.Transactions?.Edges ?? new())
{
AoProcessInfo? processInfo = GetAoProcessInfo(edge);
Expand All @@ -188,7 +333,32 @@ public async Task<List<AoProcessInfo>> GetAoProcessesForAddress(string address)

public async Task<AoProcessInfo?> GetOwnerForAoProcessAddress(string address)
{
string query = "query {\r\n transactions(\r\n first: 50,\r\n ids: [\"" + address + "\"],\r\n tags: [\r\n { name: \"Data-Protocol\", values: [\"ao\"] },\r\n { name: \"Type\", values: [\"Process\"]},\r\n { name: \"App-Name\", values: [\"aos\"]},\r\n \r\n ]\r\n ) {\r\n edges {\r\n node {\r\n id\r\n \towner {\r\n \t address\r\n \t}\r\n tags {\r\n name\r\n value\r\n }\r\n }\r\n }\r\n }\r\n }";
string query = $$"""
query {
transactions(
first: 50
ids: ["{{address}}"]
tags: [
{ name: "Data-Protocol", values: ["ao"] }
{ name: "Type", values: ["Process"] }
{ name: "App-Name", values: ["aos"] }
]
) {
edges {
node {
id
owner {
address
}
tags {
name
value
}
}
}
}
}
""";
var queryResult = await PostQueryAsync(query);

var result = new List<AoProcessInfo>();
Expand Down
4 changes: 2 additions & 2 deletions src/aoWebWallet/aoWebWallet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
<PackageReference Include="Blazored.LocalStorage" Version="4.5.0" />
<PackageReference Include="BlazorWasmPreRendering.Build" Version="3.1.0-preview.4" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.3" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.3" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.4" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.4" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit 913220d

Please sign in to comment.