Skip to content

Commit

Permalink
13 new notification types (#78)
Browse files Browse the repository at this point in the history
## [1.3.2] - 2023.03.15

### Added

- 13 new notification types to subscribe to
  • Loading branch information
Smrecz committed Mar 21, 2023
1 parent 3a36760 commit 72f1939
Show file tree
Hide file tree
Showing 43 changed files with 1,306 additions and 146 deletions.
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.3.1
1.3.2
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## [1.3.2] - 2023.03.15

### Added

- 13 new notification types to subscribe to

## [1.3.1] - 2023.03.07

### Changed
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# [Tatum C# SDK](http://tatum.com/)

[![Build](https://github.com/tatumio/tatum-csharp/actions/workflows/build.yml/badge.svg?branch=main)](https://github.com/tatumio/tatum-csharp/actions/workflows/build.yml)
<a href="https://www.nuget.org/packages/Tatum"><img alt="Nuget" src="https://buildstats.info/nuget/Tatum"></a>

## Quick Start

Expand Down Expand Up @@ -33,6 +34,10 @@ public SomeController(ITatumSdk tatumSdk)
var allNotificationsResult = await _tatumSdk.Notifications.GetAll();
```

## Documentation

Please find SDK related documentation [here](https://docs.tatum.com/).

## Debug Mode

If there ever is a need to see what is going on under the hood you can use the Debug Mode to output underlying `request curl` and `response content` to the `Debug` console.
Expand All @@ -56,4 +61,4 @@ var tatumSdk = TatumSdk.Init(Network.Testnet, apiKey, config => config.EnableDeb

[Demo App (.NET API)](Tatum.Demo)

- [Examples - Notifications](Tatum.Examples/Notifications/TatumNotifications.cs)
- [Examples - Notifications](Tatum.Examples/Notifications/Examples/Subscribe.cs)
4 changes: 4 additions & 0 deletions README_NUGET.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public SomeController(ITatumSdk tatumSdk)
var allNotificationsResult = await _tatumSdk.Notifications.GetAll();
```

## Documentation

Please find SDK related documentation [here](https://docs.tatum.com/).

## Debug Mode

If there ever is a need to see what is going on under the hood you can use the Debug Mode to output underlying `request curl` and `response content` to the `Debug` console.
Expand Down
12 changes: 11 additions & 1 deletion Tatum.Core/Models/Chain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ namespace Tatum.Core.Models
{
public enum Chain
{
Ethereum = 1
Ethereum = 1,
Solana,
Polygon,
Celo,
Klaytn,
Bitcoin,
Litecoin,
BitcoinCash,
Dogecoin,
Tron,
BinanceSmartChain
}
}
99 changes: 99 additions & 0 deletions Tatum.Core/Models/Currency.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
namespace Tatum.Core.Models
{
public enum Currency {
BTC = 1,
AVAX,
FTM,
REVV,
SAND,
ADA,
BCH,
BNB,
LTC,
ONE,
ETH,
EGLD,
MATIC,
GAMEE,
MATIC_ETH,
USDC_MATIC,
USDC_BSC,
USDC_SOL,
RMD,
GMC,
GMC_BSC,
CELO,
COIIN,
COIIN_BSC,
CUSD,
CEUR,
FLOW,
FUSD,
BSC,
XDC,
DOGE,
XRP,
XLM,
USDT,
TRON,
LEO,
LINK,
LISK,
FREE,
MKR,
USDC,
UNI,
BAT,
TUSD,
PAX,
PLTC,
XCON,
MMY,
PAXG,
VET,
HAG,
BETH,
BUSD,
BBTC,
BADA,
WBNB,
BDOT,
BXRP,
BLTC,
BBCH,
CAKE,
BUSD_BSC,
B2U_BSC,
WBTC,
USDT_TRON,
USDT_MATIC,
LATOKEN,
INRT_TRON,
ALGO,
SOL,
KCS,
NEO,
KLAY,
EOS,
ARB,
OPTIMISM,
NEAR,
CRO,
RSK,
AURORA,
GNO,
DOT,
KSM,
OASIS,
TEZOS,
PALM,
GLMR,
INTENT,
EURTENT,
GOLDAX,
ZCASH,
ZEC,
ZIL,
ETC,
}
}
162 changes: 157 additions & 5 deletions Tatum.Demo/Controllers/NotificationController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using System.ComponentModel.DataAnnotations;
using Microsoft.AspNetCore.Mvc;
using Tatum.Core;
using Tatum.Notifications.Models;
using Tatum.Notifications.Models.Notifications;
using Tatum.Notifications.Models.Notifications.SupportedChains;
using Tatum.Notifications.Models.Responses;

namespace Tatum.Demo.Controllers;
Expand Down Expand Up @@ -55,7 +58,7 @@ public async Task<ActionResult<List<INotification>>> GetAll(int pageSize = 10, i
/// <param name="sortingDirection">Direction in which records should be sorted.</param>
/// <param name="filterFailed">Filter returned results by failed field.</param>
[HttpGet(Name = "GetAllExecutedWebhooks")]
public async Task<ActionResult<List<WebhookExecutionResponse>>> GetAllExecutedWebhooks(int pageSize = 10, int offset = 0, SortingDirection sortingDirection = SortingDirection.Default, bool? filterFailed = null)
public async Task<ActionResult<List<WebhookExecutionResponse>>> GetAllExecutedWebhooks(int pageSize = 10, int offset = 0, [Required] SortingDirection sortingDirection = SortingDirection.Desc, bool? filterFailed = null)
{
var result = await _tatumSdk.Notifications.GetAllExecutedWebhooks(new GetAllExecutedWebhooksQuery
{
Expand All @@ -72,16 +75,149 @@ public async Task<ActionResult<List<WebhookExecutionResponse>>> GetAllExecutedWe

return BadRequest(result.ErrorMessage);
}

/// <summary>
/// Endpoint used to subscribe to a new AddressEvent webhook notification.
/// </summary>
/// <param name="chain">Blockchain of choice.</param>
/// <param name="address">Blockchain address on which events will trigger notification.</param>
/// <param name="url">Url that should be called on event trigger.</param>
[HttpPost(Name = "SubscribeAddressEvent")]
public async Task<ActionResult<AddressBasedNotification<AddressEventChain>>> SubscribeAddressEvent([Required] AddressEventChain chain, [Required] string address, [Required] string url)
=> await SubscribeAddress(chain, address, url, _tatumSdk.Notifications.Subscribe.AddressEvent);

/// <summary>
/// Endpoint used to subscribe to a new FailedTxPerBlock webhook notification.
/// </summary>
/// <param name="chain">Blockchain of choice.</param>
/// <param name="url">Url that should be called on event trigger.</param>
[HttpPost(Name = "SubscribeFailedTxPerBlock")]
public async Task<ActionResult<BlockBasedNotification<FailedTxPerBlockChain>>> SubscribeFailedTxPerBlock([Required] FailedTxPerBlockChain chain,[Required] string url)
=> await SubscribeBlock(chain, url, _tatumSdk.Notifications.Subscribe.FailedTxPerBlock);

/// <summary>
/// Endpoint used to subscribe to a new IncomingNativeTx webhook notification.
/// </summary>
/// <param name="chain">Blockchain of choice.</param>
/// <param name="address">Blockchain address on which events will trigger notification.</param>
/// <param name="url">Url that should be called on event trigger.</param>
[HttpPost(Name = "SubscribeIncomingNativeTx")]
public async Task<ActionResult<AddressBasedNotification<IncomingNativeTxChain>>> SubscribeIncomingNativeTx([Required] IncomingNativeTxChain chain,[Required] string address,[Required] string url)
=> await SubscribeAddress(chain, address, url, _tatumSdk.Notifications.Subscribe.IncomingNativeTx);

/// <summary>
/// Endpoint used to subscribe to a new OutgoingNativeTx webhook notification.
/// </summary>
/// <param name="chain">Blockchain of choice.</param>
/// <param name="address">Blockchain address on which events will trigger notification.</param>
/// <param name="url">Url that should be called on event trigger.</param>
[HttpPost(Name = "SubscribeOutgoingNativeTx")]
public async Task<ActionResult<AddressBasedNotification<OutgoingNativeTxChain>>> SubscribeOutgoingNativeTx([Required] OutgoingNativeTxChain chain,[Required] string address,[Required] string url)
=> await SubscribeAddress(chain, address, url, _tatumSdk.Notifications.Subscribe.OutgoingNativeTx);

/// <summary>
/// Endpoint used to subscribe to a new webhook notification.
/// Endpoint used to subscribe to a new OutgoingFailedTx webhook notification.
/// </summary>
/// <param name="chain">Blockchain of choice.</param>
/// <param name="address">Blockchain address on which events will trigger notification.</param>
/// <param name="url">Url that should be called on event trigger.</param>
[HttpPost(Name = "Subscribe")]
public async Task<ActionResult<AddressEventNotification>> Subscribe(AddressTransactionChain chain = AddressTransactionChain.Ethereum, string? address = null, string? url = null)
[HttpPost(Name = "SubscribeOutgoingFailedTx")]
public async Task<ActionResult<AddressBasedNotification<OutgoingFailedTxChain>>> SubscribeOutgoingFailedTx([Required] OutgoingFailedTxChain chain,[Required] string address,[Required] string url)
=> await SubscribeAddress(chain, address, url, _tatumSdk.Notifications.Subscribe.OutgoingFailedTx);

/// <summary>
/// Endpoint used to subscribe to a new PaidFee webhook notification.
/// </summary>
/// <param name="chain">Blockchain of choice.</param>
/// <param name="address">Blockchain address on which events will trigger notification.</param>
/// <param name="url">Url that should be called on event trigger.</param>
[HttpPost(Name = "SubscribePaidFee")]
public async Task<ActionResult<AddressBasedNotification<PaidFeeChain>>> SubscribePaidFee([Required] PaidFeeChain chain,[Required] string address,[Required] string url)
=> await SubscribeAddress(chain, address, url, _tatumSdk.Notifications.Subscribe.PaidFee);

/// <summary>
/// Endpoint used to subscribe to a new IncomingInternalTx webhook notification.
/// </summary>
/// <param name="chain">Blockchain of choice.</param>
/// <param name="address">Blockchain address on which events will trigger notification.</param>
/// <param name="url">Url that should be called on event trigger.</param>
[HttpPost(Name = "SubscribeIncomingInternalTx")]
public async Task<ActionResult<AddressBasedNotification<IncomingInternalTxChain>>> SubscribeIncomingInternalTx([Required] IncomingInternalTxChain chain,[Required] string address,[Required] string url)
=> await SubscribeAddress(chain, address, url, _tatumSdk.Notifications.Subscribe.IncomingInternalTx);

/// <summary>
/// Endpoint used to subscribe to a new OutgoingInternalTx webhook notification.
/// </summary>
/// <param name="chain">Blockchain of choice.</param>
/// <param name="address">Blockchain address on which events will trigger notification.</param>
/// <param name="url">Url that should be called on event trigger.</param>
[HttpPost(Name = "SubscribeOutgoingInternalTx")]
public async Task<ActionResult<AddressBasedNotification<OutgoingInternalTxChain>>> SubscribeOutgoingInternalTx([Required] OutgoingInternalTxChain chain,[Required] string address,[Required] string url)
=> await SubscribeAddress(chain, address, url, _tatumSdk.Notifications.Subscribe.OutgoingInternalTx);

/// <summary>
/// Endpoint used to subscribe to a new IncomingFungibleTx webhook notification.
/// </summary>
/// <param name="chain">Blockchain of choice.</param>
/// <param name="address">Blockchain address on which events will trigger notification.</param>
/// <param name="url">Url that should be called on event trigger.</param>
[HttpPost(Name = "SubscribeIncomingFungibleTx")]
public async Task<ActionResult<AddressBasedNotification<IncomingFungibleTxChain>>> SubscribeIncomingFungibleTx([Required] IncomingFungibleTxChain chain,[Required] string address,[Required] string url)
=> await SubscribeAddress(chain, address, url, _tatumSdk.Notifications.Subscribe.IncomingFungibleTx);

/// <summary>
/// Endpoint used to subscribe to a new OutgoingFungibleTx webhook notification.
/// </summary>
/// <param name="chain">Blockchain of choice.</param>
/// <param name="address">Blockchain address on which events will trigger notification.</param>
/// <param name="url">Url that should be called on event trigger.</param>
[HttpPost(Name = "SubscribeOutgoingFungibleTx")]
public async Task<ActionResult<AddressBasedNotification<OutgoingFungibleTxChain>>> SubscribeOutgoingFungibleTx([Required] OutgoingFungibleTxChain chain,[Required] string address,[Required] string url)
=> await SubscribeAddress(chain, address, url, _tatumSdk.Notifications.Subscribe.OutgoingFungibleTx);

/// <summary>
/// Endpoint used to subscribe to a new IncomingNftTx webhook notification.
/// </summary>
/// <param name="chain">Blockchain of choice.</param>
/// <param name="address">Blockchain address on which events will trigger notification.</param>
/// <param name="url">Url that should be called on event trigger.</param>
[HttpPost(Name = "SubscribeIncomingNftTx")]
public async Task<ActionResult<AddressBasedNotification<IncomingNftTxChain>>> SubscribeIncomingNftTx([Required] IncomingNftTxChain chain,[Required] string address,[Required] string url)
=> await SubscribeAddress(chain, address, url, _tatumSdk.Notifications.Subscribe.IncomingNftTx);

/// <summary>
/// Endpoint used to subscribe to a new OutgoingNftTx webhook notification.
/// </summary>
/// <param name="chain">Blockchain of choice.</param>
/// <param name="address">Blockchain address on which events will trigger notification.</param>
/// <param name="url">Url that should be called on event trigger.</param>
[HttpPost(Name = "SubscribeOutgoingNftTx")]
public async Task<ActionResult<AddressBasedNotification<OutgoingNftTxChain>>> SubscribeOutgoingNftTx([Required] OutgoingNftTxChain chain,[Required] string address,[Required] string url)
=> await SubscribeAddress(chain, address, url, _tatumSdk.Notifications.Subscribe.OutgoingNftTx);

/// <summary>
/// Endpoint used to subscribe to a new IncomingMultitokenTx webhook notification.
/// </summary>
/// <param name="chain">Blockchain of choice.</param>
/// <param name="address">Blockchain address on which events will trigger notification.</param>
/// <param name="url">Url that should be called on event trigger.</param>
[HttpPost(Name = "SubscribeIncomingMultitokenTx")]
public async Task<ActionResult<AddressBasedNotification<IncomingMultitokenTxChain>>> SubscribeIncomingMultitokenTx([Required] IncomingMultitokenTxChain chain,[Required] string address,[Required] string url)
=> await SubscribeAddress(chain, address, url, _tatumSdk.Notifications.Subscribe.IncomingMultitokenTx);

/// <summary>
/// Endpoint used to subscribe to a new OutgoingMultitokenTx webhook notification.
/// </summary>
/// <param name="chain">Blockchain of choice.</param>
/// <param name="address">Blockchain address on which events will trigger notification.</param>
/// <param name="url">Url that should be called on event trigger.</param>
[HttpPost(Name = "SubscribeOutgoingMultitokenTx")]
public async Task<ActionResult<AddressBasedNotification<OutgoingMultitokenTxChain>>> SubscribeOutgoingMultitokenTx([Required] OutgoingMultitokenTxChain chain,[Required] string address,[Required] string url)
=> await SubscribeAddress(chain, address, url, _tatumSdk.Notifications.Subscribe.OutgoingMultitokenTx);

private async Task<ActionResult<AddressBasedNotification<T>>> SubscribeAddress<T>(T chain, string? address, string? url, Func<AddressBasedNotification<T>, Task<Result<AddressBasedNotification<T>>>> subscribeFunc)
{
var result = await _tatumSdk.Notifications.Subscribe.AddressEvent(new AddressEventNotification
var result = await subscribeFunc(new AddressBasedNotification<T>
{
Chain = chain,
Address = address,
Expand All @@ -96,6 +232,22 @@ public async Task<ActionResult<AddressEventNotification>> Subscribe(AddressTrans
return BadRequest(result.ErrorMessage);
}

private async Task<ActionResult<BlockBasedNotification<T>>> SubscribeBlock<T>(T chain, string? url, Func<BlockBasedNotification<T>, Task<Result<BlockBasedNotification<T>>>> subscribeFunc)
{
var result = await subscribeFunc(new BlockBasedNotification<T>
{
Chain = chain,
Url = url
});

if (result.Success)
{
return Ok(result.Value);
}

return BadRequest(result.ErrorMessage);
}

/// <summary>
/// Removes existing subscription.
/// </summary>
Expand Down
4 changes: 3 additions & 1 deletion Tatum.Demo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

var builder = WebApplication.CreateBuilder(args);

var network = args.Length > 0 && args[0] == "Mainnet" ? Network.Mainnet : Network.Testnet;

// Add services to the container.

builder.Services.AddControllers();
Expand All @@ -30,7 +32,7 @@

var apiKey = Environment.GetEnvironmentVariable("NOTIFICATION_TEST_APIKEY");

builder.Services.AddTatumSdkWithDebug(Network.Testnet, apiKey);
builder.Services.AddTatumSdkWithDebug(network, apiKey);

// ************** /Tatum SDK **************

Expand Down
2 changes: 1 addition & 1 deletion Tatum.Demo/Tatum.Demo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
<PackageReference Include="Swashbuckle.AspNetCore.Newtonsoft" Version="6.5.0" />
<PackageReference Include="Tatum" Version="1.3.0" />
<PackageReference Include="Tatum" Version="*-*" />
</ItemGroup>

</Project>

0 comments on commit 72f1939

Please sign in to comment.