From e7a3bd380c606f2369d4cc0eb3341434629c3078 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar=20Cordero=20Rodr=C3=ADguez?= Date: Fri, 3 Oct 2025 16:00:19 -0400 Subject: [PATCH] Delete src directory --- src/PiNetworkClient.cs | 440 ----------------------------------------- src/PiNetworkData.cs | 192 ------------------ 2 files changed, 632 deletions(-) delete mode 100644 src/PiNetworkClient.cs delete mode 100644 src/PiNetworkData.cs diff --git a/src/PiNetworkClient.cs b/src/PiNetworkClient.cs deleted file mode 100644 index 2033d12..0000000 --- a/src/PiNetworkClient.cs +++ /dev/null @@ -1,440 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Threading.Tasks; - -using Newtonsoft.Json; -using RestSharp; -using stellar_dotnet_sdk.responses; -using stellar_dotnet_sdk; - -namespace PiNetworkNet -{ - public class PiNetworkClient - { - private readonly RestClient _restClient = new RestClient("https://api.minepi.com/v2"); - private readonly string _apiKey; - public PiNetworkClient(string apiKey) - { - _restClient.AddDefaultHeader("Content-Type", "application/json"); - //_restClient.AddDefaultHeader("Accept", "application/json"); - _apiKey = apiKey; - } - - public async Task Me(string accessToken) - { - var request = new RestRequest("/me"); - request.AddHeader("Accept", $"application/json"); - request.AddHeader("Authorization", $"Bearer {accessToken}"); - request.Method = Method.Get; - var response = await _restClient.ExecuteAsync(request); - if (response.IsSuccessful) - { - return JsonConvert.DeserializeObject(response.Content); - } - else - { - try - { - PiNetworkError error = JsonConvert.DeserializeObject(response.Content); - if (error != null) - { - throw new PiNetworkException() - { - PiError = error, - }; - } - else - { - throw new Exception($"{response.Content}"); - } - } - catch - { - throw new Exception($"{response.Content}"); - } - } - } - - public async Task Get(string identifier) - { - try - { - var request = new RestRequest($"/payments/{identifier}"); - request.AddHeader("Authorization", $"Key {_apiKey}"); - request.AddHeader("Accept", $"application/json"); - request.Method = Method.Get; - var response = await _restClient.ExecuteAsync(request); - if (response.IsSuccessful) - { - return JsonConvert.DeserializeObject(response.Content); - } - else - { - try - { - PiNetworkError error = JsonConvert.DeserializeObject(response.Content); - if (error != null) - { - throw new PiNetworkException() - { - PiError = error, - }; - } - else - { - throw new Exception($"{response.Content}"); - } - } - catch - { - throw new Exception($"{response.Content}"); - } - } - } - catch { throw; } - } - - public async Task> GetIncompleteServerPayments() - { - try - { - var request = new RestRequest("/payments/incomplete_server_payments"); - request.AddHeader("Accept", $"application/json"); - request.AddHeader("Authorization", $"Key {_apiKey}"); - request.Method = Method.Get; - var response = await _restClient.ExecuteAsync(request); - if (response.IsSuccessful) - { - var payments = JsonConvert.DeserializeObject(response.Content); - if (payments != null && payments.IncompletePayments != null && payments.IncompletePayments.Count > 0) - return payments.IncompletePayments; - } - else - { - try - { - PiNetworkError error = JsonConvert.DeserializeObject(response.Content); - if (error != null) - { - throw new PiNetworkException() - { - PiError = error, - }; - } - else - { - throw new Exception($"{response.Content}"); - } - } - catch - { - throw new Exception($"{response.Content}"); - } - } - } - catch - { - throw; - } - return null; - } - - public async Task Create(CreatePaymentDto dto) - { - try - { - var request = new RestRequest($"/payments"); - request.AddHeader("Authorization", $"Key {_apiKey}"); - request.AddHeader("Accept", $"application/json"); - request.AddJsonBody(JsonConvert.SerializeObject(dto)); - request.Method = Method.Post; - var response = await _restClient.ExecuteAsync(request); - if (response.IsSuccessful) - { - var payment = JsonConvert.DeserializeObject(response.Content); - if (payment != null - && string.IsNullOrEmpty(payment.ToAddress) - && !string.IsNullOrEmpty(payment.Identifier)) - { - return await Get(payment.Identifier); - } - return payment; - } - else - { - try - { - PiNetworkError error = JsonConvert.DeserializeObject(response.Content); - if (error != null) - { - throw new PiNetworkException() - { - PiError = error, - }; - } - else - { - throw new Exception($"{response.Content}"); - } - } - catch - { - throw new Exception($"{response.Content}"); - } - } - } - catch - { - throw; - } - } - - public async Task Approve(string identifier) - { - try - { - var request = new RestRequest($"/payments/{identifier}/approve"); - request.AddHeader("Accept", $"application/json"); - request.AddHeader("Authorization", $"Key {_apiKey}"); - request.Method = Method.Post; - var response = await _restClient.ExecuteAsync(request); - if (response.IsSuccessful) - { - return JsonConvert.DeserializeObject(response.Content); - } - else - { - try - { - PiNetworkError error = JsonConvert.DeserializeObject(response.Content); - if (error != null) - { - throw new PiNetworkException() - { - PiError = error, - }; - } - else - { - throw new Exception($"{response.Content}"); - } - } - catch - { - throw new Exception($"{response.Content}"); - } - } - } - catch { throw; } - } - - public async Task Cancel(string identifier) - { - try - { - var request = new RestRequest($"/payments/{identifier}/cancel"); - request.AddHeader("Accept", $"application/json"); - request.AddHeader("Authorization", $"Key {_apiKey}"); - request.Method = Method.Post; - var response = await _restClient.ExecuteAsync(request); - if (response.IsSuccessful) - { - return JsonConvert.DeserializeObject(response.Content); - } - else - { - try - { - PiNetworkError error = JsonConvert.DeserializeObject(response.Content); - if (error != null) - { - throw new PiNetworkException() - { - PiError = error, - }; - } - else - { - throw new Exception($"{response.Content}"); - } - } - catch - { - throw new Exception($"{response.Content}"); - } - } - } - catch { throw; } - } - - public async Task Complete(string identifier, string tx) - { - var request = new RestRequest($"/payments/{identifier}/complete"); - request.AddHeader("Accept", $"application/json"); - request.AddHeader("Authorization", $"Key {_apiKey}"); - var txid = new Tx() { TxId = tx }; - request.AddJsonBody(JsonConvert.SerializeObject(txid)); - request.Method = Method.Post; - var response = await _restClient.ExecuteAsync(request); - if (response.IsSuccessful) - { - return JsonConvert.DeserializeObject(response.Content); - } - else - { - try - { - PiNetworkError error = JsonConvert.DeserializeObject(response.Content); - if (error != null) - { - throw new PiNetworkException() - { - PiError = error, - }; - } - else - { - throw new Exception($"{response.Content}"); - } - } - catch - { - throw new Exception($"{response.Content}"); - } - } - } - - - protected async Task GetServerAsync(string network) - { - Server server; - if (network == "Pi Network") - { - server = new Server("https://api.mainnet.minepi.com"); - } - else if (network == "Pi Testnet") - { - server = new Server("https://api.testnet.minepi.com"); - } - else - { - server = new Server("https://horizon-testnet.stellar.org"); - } - await Task.CompletedTask; - return server; - } - - public async Task GetAccountBalance(string network, string account) - { - //Set network and server - Server server = await GetServerAsync(network); - KeyPair keypair; - - //Generate a keypair from the account id. - try - { - if (account.StartsWith("S")) - { - keypair = KeyPair.FromSecretSeed(account); - } - else - { - keypair = KeyPair.FromAccountId(account); - } - } - catch - { - return 0.0; - } - - //Load the account - AccountResponse accountResponse = await server.Accounts.Account(keypair.AccountId); - - //Get the balance - Balance[] balances = accountResponse.Balances; - - //Show the balance - for (int i = 0; i < balances.Length; i++) - { - Balance asset = balances[i]; - Console.WriteLine("Asset Code: " + asset.AssetCode); - Console.WriteLine("Asset Amount: " + asset.BalanceString); - if (asset.AssetType == "native") - { - return double.Parse(asset.BalanceString); - } - } - return 0.0; - } - - public async Task SendNativeAssets(string network, string seed, TransactionData data, uint fee = 100000) - { - //Source keypair from the secret seed - KeyPair sourceKeypair = KeyPair.FromSecretSeed(seed); - return await SendNativeAssets(network, sourceKeypair, data, fee); - } - - public async Task SendNativeAssets(string network, KeyPair sourceKeypair, TransactionData data, uint fee = 100000) - { - //Set network and server - Server server = await GetServerAsync(network); - - //Destination keypair from the account id - KeyPair destinationKeyPair = KeyPair.FromAccountId(data.ToAddress); - - //Load source account data - AccountResponse sourceAccountResponse = await server.Accounts.Account(sourceKeypair.AccountId); - - //Create source account object - Account sourceAccount = new Account(sourceKeypair.AccountId, sourceAccountResponse.SequenceNumber); - - //Create asset object with specific amount - //You can use native or non native ones. - Asset asset = new AssetTypeNative(); - double balance = 0.0; - for (int i = 0; i < sourceAccountResponse.Balances.Length; i++) - { - Balance ast = sourceAccountResponse.Balances[i]; - if (ast.AssetType == "native") - { - if (double.TryParse(ast.BalanceString, out balance)) - break; - } - } - if (balance < data.Amount + 0.01) - { - throw new Exception($"Not enough balance ({balance})"); - } - string amount = $"{Math.Floor(data.Amount * 10000000.0)/ 10000000.0:F7}"; - try - { - //Create payment operation - PaymentOperation operation = new PaymentOperation.Builder(destinationKeyPair, asset, amount) - .SetSourceAccount(sourceAccount.KeyPair) - .Build(); - - var Identifier = string.IsNullOrEmpty(data.Identifier) ? $"" : $"{data.Identifier.Trim()}"; - MemoText memo = new MemoText(string.IsNullOrEmpty(Identifier) ? $"" : Identifier.Substring(0, Math.Min(Identifier.Length, 28))); - //Create transaction and add the payment operation we created - Transaction transaction = new TransactionBuilder(sourceAccount) - .AddOperation(operation) - .AddMemo(memo) - .SetFee(fee) - .Build(); - - //Sign Transaction - transaction.Sign(sourceKeypair, new Network(network)); - - //Try to send the transaction - var tx = await server.SubmitTransaction(transaction); - return tx; - } - catch (Exception exception) - { - Console.WriteLine("Send Transaction Failed"); - Console.WriteLine("Exception: " + exception.Message); - throw; - } - } - } -} diff --git a/src/PiNetworkData.cs b/src/PiNetworkData.cs deleted file mode 100644 index 3b95ef1..0000000 --- a/src/PiNetworkData.cs +++ /dev/null @@ -1,192 +0,0 @@ -using System; -using System.Collections.Generic; -using Newtonsoft.Json; - -namespace PiNetworkNet -{ - [JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)] - public sealed class PiAuthDto - { - [JsonProperty("accessToken")] - public string AccessToken { get; set; } - - [JsonProperty("user")] - public PiUser User { get; set; } - } - - [JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)] - public sealed class PiUser - { - [JsonProperty("uid")] - public string Uid { get; set; } - - [JsonProperty("credentials")] - public Credentials Credentials { get; set; } - - [JsonProperty("username")] - public string Username { get; set; } - } - - [JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)] - public sealed class PiValidTime - { - [JsonProperty("timestamp")] - public long TimeStamp { get; set; } - [JsonProperty("iso8601")] - public DateTimeOffset Iso8601 { get; set; } - } - - [JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)] - public sealed class Credentials - { - [JsonProperty("scopes")] - public List Scopes { get; set; } - [JsonProperty("valid_until")] - public PiValidTime ValidTime { get; set; } - }; - - [JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)] - public sealed class PaymentDto - { - [JsonProperty("identifier")] - public string Identifier { get; set; } - - [JsonProperty("user_uid")] - public string Useruid { get; set; } - - [JsonProperty("amount")] - public double Amount { get; set; } - - [JsonProperty("memo")] - public string Memo { get; set; } - - [JsonProperty("metadata")] - public Metadata Metadata { get; set; } - - [JsonProperty("from_address")] - public string FromAddress { get; set; } - - [JsonProperty("to_address")] - public string ToAddress { get; set; } - - [JsonProperty("created_at")] - //public string created_at { get; set; } - public DateTimeOffset CreatedAt { get; set; } - - [JsonProperty("direction")] - public string Direction { get; set; } - - [JsonProperty("network")] - public string Network { get; set; } - - [JsonProperty("status")] - public Status Status { get; set; } - - [JsonProperty("transaction")] - public TransactionStatus Transaction { get; set; } - } - - [JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)] - public sealed class Metadata - { - [JsonProperty("id")] - public Guid? Id { get; set; } - [JsonProperty("cat")] - public string Category { get; set; } - [JsonProperty("data")] - public object Data { get; set; } - } - - [JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)] - public sealed class Status - { - [JsonProperty("developer_approved")] - public bool DeveloperApproved { get; set; } - - [JsonProperty("transaction_verified")] - public bool TransactionVerified { get; set; } - - [JsonProperty("developer_completed")] - public bool DeveloperCompleted { get; set; } - - [JsonProperty("cancelled")] - public bool Cancelled { get; set; } - - [JsonProperty("user_cancelled")] - public bool UserCancelled { get; set; } - } - - [JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)] - public sealed class TransactionStatus - { - [JsonProperty("txid")] - public string TxId { get; set; } - - [JsonProperty("verified")] - public bool Verified { get; set; } - - [JsonProperty("_link")] - public string Link { get; set; } - } - - [JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)] - public sealed class Tx - { - [JsonProperty("txid")] - public string TxId { get; set; } - } - - [JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)] - public sealed class IncompleteServerPayments - { - [JsonProperty("incomplete_server_payments")] - public List IncompletePayments { get; set; } - } - - [JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)] - public sealed class PaymentArgs - { - [JsonProperty("amount")] - public double Amount; - [JsonProperty("memo")] - public string Memo; - [JsonProperty("metadata")] - public object Metadata; - [JsonProperty("uid")] - public string Uid; - } - - [JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)] - public sealed class CreatePaymentDto - { - [JsonProperty("payment")] - public PaymentArgs Payment; - } - - [JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)] - public sealed class TransactionData - { - public double Amount; - public string Identifier; - public string FromAddress; - public string ToAddress; - } - - [JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)] - public sealed class PiNetworkError - { - [JsonProperty("error")] - public string ErrorName { get; set; } - - [JsonProperty("error_message")] - public string ErrorMessage { get; set; } - - [JsonProperty("payment")] - public PaymentDto Payment { get; set; } - } - - public class PiNetworkException: Exception - { - public PiNetworkError PiError { get; set; } - } -}