Skip to content

Commit

Permalink
Issue_191
Browse files Browse the repository at this point in the history
  • Loading branch information
xactant committed Oct 7, 2022
1 parent 4fcf456 commit de9ff9f
Show file tree
Hide file tree
Showing 26 changed files with 303 additions and 112 deletions.
Binary file modified .vs/MoralisDotNetSdk/DesignTimeBuild/.dtbcache.v2
Binary file not shown.
Binary file modified .vs/MoralisDotNetSdk/v17/.futdcache.v1
Binary file not shown.
61 changes: 41 additions & 20 deletions Moralis.StreamsApi.Integrated.Tests/StreamsTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Moralis.Abi;
using Moralis.StreamsApi.Interfaces;
using Moralis.StreamsApi.Interfaces;
using Moralis.StreamsApi.Models;

namespace Moralis.StreamsApi.Integrated.Tests
Expand Down Expand Up @@ -97,18 +96,25 @@ private async Task<string> BindStream(IStreamsApiClient streamsApi)

try
{
List<AbiItem> functionAbis = new List<AbiItem>();
functionAbis.Add(AbiTools.FunctionAbiFromJson("grantRole", GetAbiJson()));

StreamBindingDto dto = new StreamBindingDto()
{
Address = "0x35ba4825204dcE15C7147eA89b31178a00750f81",
ChainIds = new List<string>(new string[] { "0x1" }),
IncludeNativeTxs = true,
Abi = AbiTools.FunctionAbiFromJson("grantRole", GetAbiJson()),
WebHookUrl = "https://davesmoralisazurefunctions.azurewebsites.net/api/RawStreamsHandler?code=BT-PQKI8vc4hA_EieKWuKgVq_GSLgo9y2cqWD6K0g_jOAzFu46pOTA==",
Description = "Bob wuz ere",
TokenAddress = "0x62441037E626D6EdeC892838a06DF3C9D43ED482",
Topic = "grantRole",
Type = "contract",
Tag = "my first stream",
WebHookUrl = "https://davesmoralisazurefunctions.azurewebsites.net/api/RawStreamsHandler?code=BT-PQKI8vc4hA_EieKWuKgVq_GSLgo9y2cqWD6K0g_jOAzFu46pOTA=="
Topic = new List<string>( new string[]{ "grantRole" }),
//Address = "0x35ba4825204dcE15C7147eA89b31178a00750f81",
AllAddresses = true,
IncludeNativeTxs = true,
IncludeContractLogs = true,
IncludeInternalTxs = true,
Abi = functionAbis,
//ChainIds = new List<string>(new string[] { "0x1" }),
//TokenAddress = "0x62441037E626D6EdeC892838a06DF3C9D43ED482",
//Type = "contract",

};

StreamBindingDto resp = await streamsApi.StreamsEndpoint.BindStream(dto);
Expand Down Expand Up @@ -187,19 +193,34 @@ private async Task<bool> UpdateStream(IStreamsApiClient streamsApi, string strea

try
{
List<AbiItem> functionAbis = new List<AbiItem>();
functionAbis.Add(AbiTools.FunctionAbiFromJson("grantRole", GetAbiJson()));

StreamBindingDto dto = new StreamBindingDto()
{
Address = "0x35ba4825204dcE15C7147eA89b31178a00750f81",
ChainIds = new List<string>(new string[] { "0x1" }),
IncludeNativeTxs = true,
Abi = AbiTools.FunctionAbiFromJson("grantRole", GetAbiJson()),
Description = "OOP",
TokenAddress = "0x62441037E626D6EdeC892838a06DF3C9D43ED482",
Topic = "grantRole",
Type = "contract",
Tag = "my first stream",
WebHookUrl = "https://davesmoralisazurefunctions.azurewebsites.net/api/RawStreamsHandler?code=BT-PQKI8vc4hA_EieKWuKgVq_GSLgo9y2cqWD6K0g_jOAzFu46pOTA==",
StreamId = streamId
Description = "Bob wuz ere",
Tag = "oop",
Topic = new List<string>(new string[] { "grantRole" }),
//Address = "0x35ba4825204dcE15C7147eA89b31178a00750f81",
AllAddresses = true,
IncludeNativeTxs = true,
IncludeContractLogs = true,
IncludeInternalTxs = true,
Abi = functionAbis,
ChainIds = new List<string>(new string[] { "0x1" })

//Address = "0x35ba4825204dcE15C7147eA89b31178a00750f81",
//ChainIds = new List<string>(new string[] { "0x1" }),
//IncludeNativeTxs = true,
//Abi = AbiTools.FunctionAbiFromJson("grantRole", GetAbiJson()),
//Description = "OOP",
//TokenAddress = "0x62441037E626D6EdeC892838a06DF3C9D43ED482",
//Topic = "grantRole",
//Type = "contract",
//Tag = "my first stream",
//WebHookUrl = "https://davesmoralisazurefunctions.azurewebsites.net/api/RawStreamsHandler?code=BT-PQKI8vc4hA_EieKWuKgVq_GSLgo9y2cqWD6K0g_jOAzFu46pOTA==",
//StreamId = streamId
};

StreamBindingDto resp = await streamsApi.StreamsEndpoint.UpdateStream(dto);
Expand Down
35 changes: 35 additions & 0 deletions MoralisDotNet/Moralis.StreamsApi/AbiTools.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Moralis.StreamsApi.Models;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;

namespace Moralis.StreamsApi
{
public class AbiTools
{
public static List<AbiItem> JsonToStreamsAbi(string json)
{
List<AbiItem> abi = JsonConvert.DeserializeObject<List<AbiItem>>(json);

return abi;
}

public static AbiItem FunctionAbiFromJson(string functionaName, string json)
{
AbiItem func = null;
List<AbiItem> abi = JsonToStreamsAbi(json);

foreach (AbiItem item in abi)
{
if (!String.IsNullOrEmpty(item.Name) && functionaName.ToLower().Equals(item.Name.ToLower()))
{
func = item;
break;
}
}

return func;
}
}
}
4 changes: 2 additions & 2 deletions MoralisDotNet/Moralis.StreamsApi/Api/StreamsApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ public async Task<AddressResponse> AddAddressToStream(string streamId, StreamsAd
/// <param name="streamId"></param>
/// <param name="address"></param>
/// <returns>AddressResponse</returns>
public async Task<AddressResponse> RemoveAddressFromStream(string streamId, StreamsAddressRequest address)
public async Task<DeleteAddressResponse> RemoveAddressFromStream(string streamId, StreamsAddressRequest address)
{
// Verify stream Id is set.
if (string.IsNullOrEmpty(streamId)) throw new ApiException(400, "Missing required parameter 'streamId' when calling RemoveAddressFromStream");
Expand All @@ -412,7 +412,7 @@ public async Task<AddressResponse> RemoveAddressFromStream(string streamId, Stre
{
List<Parameter> headers = ApiClient.ResponHeadersToParameterList(response.Headers);

AddressResponse resp = (AddressResponse)ApiClient.Deserialize(data, typeof(AddressResponse), headers);
DeleteAddressResponse resp = (DeleteAddressResponse)ApiClient.Deserialize(data, typeof(DeleteAddressResponse), headers);
return resp;
}
else
Expand Down
2 changes: 1 addition & 1 deletion MoralisDotNet/Moralis.StreamsApi/Interfaces/IStreamsApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public interface IStreamsApi
/// <param name="streamId"></param>
/// <param name="address"></param>
/// <returns>AddressResponse</returns>
public Task<AddressResponse> RemoveAddressFromStream(string streamId, StreamsAddressRequest address);
public Task<DeleteAddressResponse> RemoveAddressFromStream(string streamId, StreamsAddressRequest address);

}

Expand Down
10 changes: 10 additions & 0 deletions MoralisDotNet/Moralis.StreamsApi/Models/AbiExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Moralis.Moralis.StreamsApi.Models
{
public static class AbiExtensions
{
}
}
27 changes: 16 additions & 11 deletions MoralisDotNet/Moralis.StreamsApi/Models/AbiItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@ namespace Moralis.StreamsApi.Models
{
public class AbiItem
{
[DataMember(Name = "stateMutability", EmitDefaultValue = false)]
[JsonProperty(PropertyName = "stateMutability")]
private string _stateMutability = StateMutabilityTypes.Pure.ToString();

[DataMember(Name = "type", EmitDefaultValue = false)]
[JsonProperty(PropertyName = "type")]
private string _abiType = AbiItemTypes.Event.ToString();

[DataMember(Name = "anonymous", EmitDefaultValue = false)]
[JsonProperty(PropertyName = "anonymous")]
Expand All @@ -29,6 +22,10 @@ public class AbiItem
[JsonProperty(PropertyName = "inputs")]
public List<AbiInput> Inputs { get; set; }

[DataMember(Name = "name", EmitDefaultValue = false)]
[JsonProperty(PropertyName = "name")]
public string Name { get; set; }

[DataMember(Name = "outputs", EmitDefaultValue = false)]
[JsonProperty(PropertyName = "outputs")]
public List<AbiOutput> Outputs { get; set; }
Expand All @@ -37,6 +34,18 @@ public class AbiItem
[JsonProperty(PropertyName = "payable")]
public bool Payable { get; set; }

[DataMember(Name = "stateMutability", EmitDefaultValue = false)]
[JsonProperty(PropertyName = "stateMutability")]
private string _stateMutability = StateMutabilityTypes.Pure.ToString();

[DataMember(Name = "type", EmitDefaultValue = false)]
[JsonProperty(PropertyName = "type")]
private string _abiType = AbiItemTypes.Event.ToString();

[DataMember(Name = "gas", EmitDefaultValue = false)]
[JsonProperty(PropertyName = "gas")]
public BigInteger Gas { get; set; }

[JsonIgnore]
public StateMutabilityTypes StateMutability
{
Expand All @@ -50,9 +59,5 @@ public AbiItemTypes Type
get { return _abiType.ToAbiItemTypes(); }
set { _abiType = value.ToString(); }
}

[DataMember(Name = "gas", EmitDefaultValue = false)]
[JsonProperty(PropertyName = "gas")]
public BigInteger Gas { get; set; }
}
}
21 changes: 12 additions & 9 deletions MoralisDotNet/Moralis.StreamsApi/Models/AddressResponse.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Numerics;
using System.Runtime.Serialization;
using System.Text;

Expand All @@ -11,18 +12,20 @@ namespace Moralis.StreamsApi.Models
/// </summary>
public class AddressResponse
{
/// <summary>
/// The id of the stream the address was added to
/// </summary>
[DataMember(Name = "streamId", EmitDefaultValue = false)]
[JsonProperty(PropertyName = "streamId")]
public string StreamId { get; set; }

/// <summary>
/// The address added to the stream
/// </summary>
[DataMember(Name = "address", EmitDefaultValue = false)]
[JsonProperty(PropertyName = "address")]
public string Address { get; set; }
[DataMember(Name = "result", EmitDefaultValue = false)]
[JsonProperty(PropertyName = "result")]
public List<Addresses> Result { get; set; }

[DataMember(Name = "cursor", EmitDefaultValue = false)]
[JsonProperty(PropertyName = "cursor")]
public string Cursor { get; set; }

[DataMember(Name = "total", EmitDefaultValue = false)]
[JsonProperty(PropertyName = "total")]
public BigInteger Total { get; set; }
}
}
22 changes: 22 additions & 0 deletions MoralisDotNet/Moralis.StreamsApi/Models/Addresses.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Text;

namespace Moralis.StreamsApi.Models
{
public class Addresses
{
/// <summary>
/// The address added to the stream
/// </summary>
[DataMember(Name = "address", EmitDefaultValue = false)]
[JsonProperty(PropertyName = "address")]
public string Address { get; set; }

[DataMember(Name = "id", EmitDefaultValue = false)]
[JsonProperty(PropertyName = "id", NullValueHandling = NullValueHandling.Ignore)]
public string Id { get; set; }
}
}
21 changes: 21 additions & 0 deletions MoralisDotNet/Moralis.StreamsApi/Models/AdvancedOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Runtime.Serialization;

namespace Moralis.StreamsApi.Models
{
public class AdvancedOptions
{
[DataMember(Name = "topic0", EmitDefaultValue = false)]
[JsonProperty(PropertyName = "topic0")]
public string Topic0 { get; set; }

[DataMember(Name = "filter", EmitDefaultValue = false)]
[JsonProperty(PropertyName = "filter")]
public Dictionary<string, object> Filter { get; set; }

[DataMember(Name = "includeNativeTxs", EmitDefaultValue = false)]
[JsonProperty(PropertyName = "includeNativeTxs")]
public bool IncludeNativeTxs { get; set; }
}
}
19 changes: 19 additions & 0 deletions MoralisDotNet/Moralis.StreamsApi/Models/DeleteAddressResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Text;

namespace Moralis.StreamsApi.Models
{
public class DeleteAddressResponse
{
[DataMember(Name = "address", EmitDefaultValue = false)]
[JsonProperty(PropertyName = "address")]
public string Address { get; set; }

[DataMember(Name = "streamId", EmitDefaultValue = false)]
[JsonProperty(PropertyName = "streamId", NullValueHandling = NullValueHandling.Ignore)]
public string StreamId { get; set; }
}
}
6 changes: 3 additions & 3 deletions MoralisDotNet/Moralis.StreamsApi/Models/Erc20Approval.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ public class Erc20Approval
[JsonProperty(PropertyName = "transactionHash")]
public string TransactionHash { get; set; }

[DataMember(Name = "tokenAddress", EmitDefaultValue = false)]
[JsonProperty(PropertyName = "tokenAddress")]
public string TokenAddress { get; set; }
[DataMember(Name = "contract", EmitDefaultValue = false)]
[JsonProperty(PropertyName = "contract")]
public string Contract { get; set; }

[DataMember(Name = "logIndex", EmitDefaultValue = false)]
[JsonProperty(PropertyName = "logIndex")]
Expand Down
10 changes: 3 additions & 7 deletions MoralisDotNet/Moralis.StreamsApi/Models/Erc20Transfer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ public class Erc20Transfer
[JsonProperty(PropertyName = "transactionHash")]
public string TransactionHash { get; set; }

[DataMember(Name = "tokenAddress", EmitDefaultValue = false)]
[JsonProperty(PropertyName = "tokenAddress")]
public string TokenAddress { get; set; }
[DataMember(Name = "contract", EmitDefaultValue = false)]
[JsonProperty(PropertyName = "contract")]
public string Contract { get; set; }

[DataMember(Name = "logIndex", EmitDefaultValue = false)]
[JsonProperty(PropertyName = "logIndex")]
Expand All @@ -32,10 +32,6 @@ public class Erc20Transfer
[JsonProperty(PropertyName = "to")]
public string To { get; set; }

[DataMember(Name = "amount", EmitDefaultValue = false)]
[JsonProperty(PropertyName = "amount")]
public string Amount { get; set; }

[DataMember(Name = "value", EmitDefaultValue = false)]
[JsonProperty(PropertyName = "value")]
public string Value { get; set; }
Expand Down
9 changes: 7 additions & 2 deletions MoralisDotNet/Moralis.StreamsApi/Models/HistoryResponse.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using Moralis.Unit;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
Expand All @@ -14,6 +15,10 @@ public class HistoryResponse

[DataMember(Name = "cursor", EmitDefaultValue = false)]
[JsonProperty(PropertyName = "cursor")]
public string Cursor { get; set;}
public string Cursor { get; set; }

[DataMember(Name = "total", EmitDefaultValue = false)]
[JsonProperty(PropertyName = "total")]
public BigDecimal Total { get; set; }
}
}
13 changes: 11 additions & 2 deletions MoralisDotNet/Moralis.StreamsApi/Models/InternalTransaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,17 @@ public class InternalTransaction
[JsonProperty(PropertyName = "transactionHash")]
public string TransactionHash { get; set; }

[DataMember(Name = "id", EmitDefaultValue = false)]
[JsonProperty(PropertyName = "id")]
[DataMember(Name = "gas", EmitDefaultValue = false)]
[JsonProperty(PropertyName = "gas")]
public string Gas { get; set; }

[DataMember(Name = "streamId", EmitDefaultValue = false)]
[JsonProperty(PropertyName = "streamId")]
public string StreamId { get; set; }

[DataMember(Name = "tag", EmitDefaultValue = false)]
[JsonProperty(PropertyName = "tag")]
public string Tag { get; set; }

}
}
Loading

0 comments on commit de9ff9f

Please sign in to comment.