-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
82eb162
commit f430b24
Showing
82 changed files
with
1,683 additions
and
614 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using Api.Services.Developers; | ||
using Microsoft.Azure.Functions.Worker; | ||
using Microsoft.Azure.Functions.Worker.Http; | ||
using Microsoft.Extensions.Logging; | ||
using Newtonsoft.Json; | ||
using System.Net; | ||
|
||
namespace ApiNet8.Controllers | ||
{ | ||
public class DevelopersController | ||
{ | ||
private readonly ILogger _logger; | ||
private readonly IWebData _webDevelopers; | ||
|
||
public DevelopersController(ILoggerFactory loggerFactory, IWebData webDevelopersData) | ||
{ | ||
_logger = loggerFactory.CreateLogger<DevelopersController>(); | ||
_webDevelopers = webDevelopersData; | ||
} | ||
|
||
[Function("Developers")] | ||
public HttpResponseData Run([HttpTrigger(AuthorizationLevel.Function, "get")] HttpRequestData req) | ||
{ | ||
_logger.LogInformation("C# HTTP trigger function processed a request."); | ||
var webDevelopers = _webDevelopers.GetWebDevelopersData(); | ||
var response = req.CreateResponse(HttpStatusCode.OK); | ||
response.Headers.Add("Content-Type", "application/json"); | ||
response.WriteString(JsonConvert.SerializeObject(webDevelopers.Result)); | ||
return response; | ||
} | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
using Api.Services.Developers; | ||
using Api.Services.Transaction; | ||
using Azure; | ||
using Data.Wallet; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Azure.Functions.Worker; | ||
using Microsoft.Azure.Functions.Worker.Http; | ||
using Microsoft.Extensions.Logging; | ||
using Newtonsoft.Json; | ||
using System.Net; | ||
|
||
namespace ApiNet8.Controllers | ||
{ | ||
public class TransactionController | ||
{ | ||
private readonly ILogger _logger; | ||
private readonly ITransactionService _transactionService; | ||
|
||
public TransactionController(ILoggerFactory loggerFactory, ITransactionService transactionService) | ||
{ | ||
_logger = loggerFactory.CreateLogger<TransactionController>(); | ||
_transactionService = transactionService; | ||
} | ||
|
||
[Function("TxBuilder")] | ||
public async Task<HttpResponseData> RunTxBuilderAsync([HttpTrigger(AuthorizationLevel.Function, "get")] HttpRequestData req) | ||
{ | ||
_logger.LogInformation("C# HTTP trigger function processed a request."); | ||
string walletFrom = req.Query["walletFrom"]; | ||
string walletTo = req.Query["walletto"]; | ||
string value = req.Query["value"]; | ||
var response = req.CreateResponse(HttpStatusCode.OK); | ||
|
||
|
||
if (string.IsNullOrEmpty(walletFrom)) response = req.CreateResponse(HttpStatusCode.BadRequest); | ||
if (string.IsNullOrEmpty(walletTo)) response = req.CreateResponse(HttpStatusCode.BadRequest); | ||
if (string.IsNullOrEmpty(value)) response = req.CreateResponse(HttpStatusCode.BadRequest); | ||
|
||
try | ||
{ | ||
ulong transferValue = ulong.Parse(value); | ||
var transact = await _transactionService.BuildTransaction(walletFrom, walletTo, transferValue); | ||
response.Headers.Add("Content-Type", "application/json"); | ||
response.WriteString(JsonConvert.SerializeObject(transact)); | ||
return response; | ||
} | ||
catch (Exception e) | ||
{ | ||
response = req.CreateResponse(HttpStatusCode.BadRequest); | ||
} | ||
|
||
return response; | ||
|
||
} | ||
|
||
[Function("TxFee")] | ||
public async Task<HttpResponseData> RunTxFeeAsync([HttpTrigger(AuthorizationLevel.Function, "get")] HttpRequestData req) | ||
{ | ||
_logger.LogInformation("C# HTTP trigger function processed a request."); | ||
string walletFrom = req.Query["walletFrom"]; | ||
string walletTo = req.Query["walletto"]; | ||
string value = req.Query["value"]; | ||
var response = req.CreateResponse(HttpStatusCode.OK); | ||
|
||
|
||
if (string.IsNullOrEmpty(walletFrom)) response = req.CreateResponse(HttpStatusCode.BadRequest); | ||
if (string.IsNullOrEmpty(walletTo)) response = req.CreateResponse(HttpStatusCode.BadRequest); | ||
if (string.IsNullOrEmpty(value)) response = req.CreateResponse(HttpStatusCode.BadRequest); | ||
|
||
try | ||
{ | ||
ulong transferValue = ulong.Parse(value); | ||
var fee = await _transactionService.CalculateFee(walletFrom, walletTo, transferValue); | ||
response.Headers.Add("Content-Type", "application/json"); | ||
response.WriteString(JsonConvert.SerializeObject(fee)); | ||
return response; | ||
} | ||
catch (Exception e) | ||
{ | ||
response = req.CreateResponse(HttpStatusCode.BadRequest); | ||
} | ||
|
||
return response; | ||
|
||
} | ||
|
||
|
||
[Function("TxSign")] | ||
public async Task<HttpResponseData> RunTxSignAsync([HttpTrigger(AuthorizationLevel.Function, "post")] HttpRequestData req) | ||
{ | ||
_logger.LogInformation("C# HTTP trigger function processed a request."); | ||
var response = req.CreateResponse(HttpStatusCode.OK); | ||
|
||
try | ||
{ | ||
string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); | ||
var requestData = JsonConvert.DeserializeObject<TxRequest>(requestBody); | ||
var transaction = await _transactionService.SignTransaction(requestData.transactionCbor, requestData.witness); | ||
response.Headers.Add("Content-Type", "application/json"); | ||
response.WriteString(JsonConvert.SerializeObject(transaction)); | ||
return response; | ||
} | ||
catch (Exception e) | ||
{ | ||
response = req.CreateResponse(HttpStatusCode.BadRequest); | ||
} | ||
|
||
return response; | ||
|
||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
using Api.Services.Wallet; | ||
using CardanoSharp.Wallet.Extensions; | ||
using CardanoSharp.Wallet.Extensions.Models.Transactions.TransactionWitnesses; | ||
using Data.Wallet; | ||
using Microsoft.Azure.Functions.Worker; | ||
using Microsoft.Azure.Functions.Worker.Http; | ||
using Microsoft.Extensions.Logging; | ||
using Newtonsoft.Json; | ||
using System.Net; | ||
|
||
namespace ApiNet8.Controllers | ||
{ | ||
public class WalletController | ||
{ | ||
private readonly ILogger _logger; | ||
private readonly IWalletData _walletData; | ||
|
||
public WalletController(ILoggerFactory loggerFactory, IWalletData walletData) | ||
{ | ||
_logger = loggerFactory.CreateLogger<WalletController>(); | ||
_walletData = walletData; | ||
} | ||
|
||
[Function("WalletsData")] | ||
public async Task<HttpResponseData> RunAsync([HttpTrigger(AuthorizationLevel.Function, "get")] HttpRequestData req) | ||
{ | ||
_logger.LogInformation("C# HTTP trigger function processed a request."); | ||
var products = await _walletData.GetWalletData(); | ||
var response = req.CreateResponse(HttpStatusCode.OK); | ||
response.Headers.Add("Content-Type", "application/json"); | ||
response.WriteString(JsonConvert.SerializeObject(products)); | ||
return response; | ||
} | ||
|
||
|
||
[Function("WitnessGet")] | ||
public async Task<HttpResponseData> RunAsync2([HttpTrigger(AuthorizationLevel.Function, "post")] HttpRequestData req, [FromBody] AddWitnessRequest request) | ||
{ | ||
_logger.LogInformation("C# HTTP trigger function processed a request."); | ||
|
||
var transaction = request.TxCbor; | ||
if (transaction == null) | ||
{ | ||
throw new InvalidOperationException("Could not deserialize txCbor"); | ||
} | ||
|
||
var witnessSet = request.WitnessCbor.HexToByteArray().DeserializeTransactionWitnessSet(); | ||
|
||
foreach (var vkeyWitness in witnessSet.VKeyWitnesses) | ||
{ | ||
transaction.TransactionWitnessSet.VKeyWitnesses.Add(vkeyWitness); | ||
} | ||
foreach (var nativeScript in witnessSet.NativeScripts) | ||
{ | ||
transaction.TransactionWitnessSet.NativeScripts.Add(nativeScript); | ||
} | ||
foreach (var bootstrap in witnessSet.BootStrapWitnesses) | ||
{ | ||
transaction.TransactionWitnessSet.BootStrapWitnesses.Add(bootstrap); | ||
} | ||
var response = req.CreateResponse(HttpStatusCode.OK); | ||
response.Headers.Add("Content-Type", "application/json"); | ||
|
||
var result = new AddWitnessResponse(); | ||
result.Request = request; | ||
result.TxCbor = transaction; | ||
var responseContent = JsonConvert.SerializeObject(result); | ||
await response.WriteStringAsync(responseContent); | ||
return response; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using Api.Services.Developers; | ||
using Api.Services.Oracle; | ||
using Microsoft.Azure.Functions.Worker; | ||
using Microsoft.Azure.Functions.Worker.Http; | ||
using Microsoft.Extensions.Logging; | ||
using Newtonsoft.Json; | ||
using System.Net; | ||
|
||
namespace ApiNet8.Controllers | ||
{ | ||
public class WebPriceController | ||
{ | ||
private readonly ILogger _logger; | ||
private readonly IPriceServices _webPriceSerices; | ||
|
||
public WebPriceController(ILoggerFactory loggerFactory, IPriceServices webPriceSerices) | ||
{ | ||
_logger = loggerFactory.CreateLogger<WebPriceController>(); | ||
_webPriceSerices = webPriceSerices; | ||
} | ||
|
||
[Function("BinanceP2P")] | ||
public HttpResponseData Run([HttpTrigger(AuthorizationLevel.Function, "get")] HttpRequestData req) | ||
{ | ||
_logger.LogInformation("C# HTTP trigger function processed a request."); | ||
var webDevelopers = _webPriceSerices.DollarApiCall(); | ||
var response = req.CreateResponse(HttpStatusCode.OK); | ||
response.Headers.Add("Content-Type", "application/json"); | ||
response.WriteString(JsonConvert.SerializeObject(webDevelopers.Result)); | ||
return response; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using Api; | ||
using Api.Services.Developers; | ||
using Api.Services.Oracle; | ||
using Api.Services.Policy; | ||
using Api.Services.Transaction; | ||
using Api.Services.Wallet; | ||
using CardanoSharp.Koios.Client; | ||
using Microsoft.Azure.Functions.Worker; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.Configuration.Json; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
|
||
class Program | ||
{ | ||
|
||
|
||
public static async Task Main(string[] args) | ||
{ | ||
var builder = Host | ||
.CreateDefaultBuilder(args) | ||
.ConfigureFunctionsWorkerDefaults() | ||
.ConfigureAppConfiguration((hostingContext, config) => | ||
{ | ||
config.SetBasePath(hostingContext.HostingEnvironment.ContentRootPath) | ||
.AddJsonFile("local.settings.json", optional: true, reloadOnChange: true) | ||
.AddEnvironmentVariables(); | ||
}) | ||
.ConfigureServices((hostContext, builder) => | ||
{ | ||
var configuration = (IConfigurationRoot) hostContext.Configuration; | ||
var localSettingsJsonProvider = configuration.Providers.LastOrDefault(provider => provider.GetType() == typeof(JsonConfigurationProvider)); | ||
if (localSettingsJsonProvider != null) | ||
{ | ||
var koiosURL = configuration["KoiosURL"]; | ||
builder.AddKoios(configuration["KoiosURL"]); | ||
} | ||
|
||
|
||
builder.AddSingleton<IWalletData, WalletData>(); | ||
builder.AddSingleton<IWebData, WebDeveloperData>(); | ||
builder.AddSingleton<IPriceServices, PriceServices>(); | ||
builder.AddSingleton<IPolicyManager, PolicyManager>(); | ||
builder.AddSingleton<ITransactionService, TransactionService>(); | ||
|
||
}); | ||
|
||
await builder.Build().RunAsync(); | ||
} | ||
|
||
} |
Oops, something went wrong.