Skip to content

Commit

Permalink
added cool stuff to LL and resolved bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobhuberdotme committed Nov 8, 2023
1 parent c7a2c1e commit 3815e34
Show file tree
Hide file tree
Showing 20 changed files with 496 additions and 130 deletions.
2 changes: 1 addition & 1 deletion Maize/Helpers/Timers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public static void ApiStopWatchCheck(Stopwatch apiSw)
{
apiSw.Stop();
TimeSpan elapsed = apiSw.Elapsed;
TimeSpan maxDelay = TimeSpan.FromSeconds(0.5);
TimeSpan maxDelay = TimeSpan.FromSeconds(0.2);

if (elapsed < maxDelay)
{
Expand Down
2 changes: 1 addition & 1 deletion Maize/Maize.csproj.user
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<_LastSelectedProfileId>C:\Users\cobmin\OneDrive\Code\MaizeConsoleApplication\Maize\Maize\Properties\PublishProfiles\FolderProfile1.pubxml</_LastSelectedProfileId>
<_LastSelectedProfileId>C:\Users\cobmin\OneDrive\Code\MaizeConsoleApplication\Maize\Maize\Properties\PublishProfiles\FolderProfile.pubxml</_LastSelectedProfileId>
</PropertyGroup>
</Project>
14 changes: 14 additions & 0 deletions Maize/Models/Responses/GasPriceResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Maize.Models.Responses
{
public class GasPriceResponse
{
public string Price { get; set; }
}

}
2 changes: 2 additions & 0 deletions Maize/Models/Responses/RefreshNftResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ namespace Maize.Models.Responses
{
public class RefreshNftResponse
{
public string name { get; set; }
public string nftId { get; set; }
public string status { get; set; }
public long createdAt { get; set; }
public long updatedAt { get; set; }
Expand Down
1 change: 1 addition & 0 deletions Maize/Services/ILoopringService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public interface ILoopringService
Task<RefreshNftResponse> RefreshNft(string nftId, string collectionAddress);
Task<string> PostImage(string filePath);
Task<string> PostMetadata(string metadataJson, string metadataFileName);
Task<decimal?> GetRecommendedGasPrice();
Task<List<UserAssetsResponse>> GetUserAssetsForFees(string apiKey, int accountId);
Task<List<CollectionMinted>> GetUserMintedCollections(string apiKey, string owner);
Task<List<CollectionOwned>> GetUserOwnedCollections(string apiKey, int accountId);
Expand Down
26 changes: 26 additions & 0 deletions Maize/Services/LoopringService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,32 @@ public async Task<string> PostMetadata(string metadataJson, string metadataFileN
return null;
}
}
public async Task<decimal?> GetRecommendedGasPrice()
{
var request = new RestRequest("api/v3/eth/recommendedGasPrice");

try
{
var response = await _client.GetAsync(request);

if (response.IsSuccessful)
{
var responseData = JsonConvert.DeserializeObject<GasPriceResponse>(response.Content);

// Convert the string price to a decimal (or another numeric type)
if (decimal.TryParse(responseData?.Price, out var gasPrice))
{
return gasPrice;
}
}
}
catch (HttpRequestException httpException)
{
// Handle the exception as needed
}

return null;
}
public async Task<string> PostImage(string filePath)
{

Expand Down
70 changes: 58 additions & 12 deletions Maize/Services/LoopringServiceUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
using Newtonsoft.Json;
using PoseidonSharp;
using RestSharp;
using System.Collections.Generic;
using System.Drawing;
using System.Threading.Tasks;
using System.Numerics;
using System.Diagnostics;
using Newtonsoft.Json.Linq;
Expand All @@ -33,9 +30,10 @@ public async Task<RefreshNftResponse> RefreshNft(string nftId, string collection
request.AddHeader("Content-Type", "application/json");
try
{
var apiSw = Stopwatch.StartNew();
var response = await _client.PostAsync(request);
var data = JsonConvert.DeserializeObject< RefreshNftResponse> (response.Content!);
Thread.Sleep(100);
Timers.ApiStopWatchCheck(apiSw);
return data;
}
catch (HttpRequestException httpException)
Expand Down Expand Up @@ -114,15 +112,46 @@ public async Task<List<UserAssetsResponse>> GetUserAssetsForFees(string apiKey,
request.AddParameter("tokens", "0,1,272");
try
{
var apiSw = Stopwatch.StartNew();
var response = await _client.GetAsync(request);
var data = JsonConvert.DeserializeObject<List<UserAssetsResponse>>(response.Content!);
Timers.ApiStopWatchCheck(apiSw);
return data;
}
catch (HttpRequestException httpException)
{
return null;
}
}
public async Task<decimal?> GetRecommendedGasPrice()
{
var request = new RestRequest("api/v3/eth/recommendedGasPrice");

try
{
var response = await _client.GetAsync(request);

if (response.IsSuccessful)
{
var apiSw = Stopwatch.StartNew();
var responseData = JsonConvert.DeserializeObject<GasPriceResponse>(response.Content);

// Convert the string price to a decimal (or another numeric type)
if (decimal.TryParse(responseData?.Price, out var gasPrice))
{
Timers.ApiStopWatchCheck(apiSw);
return gasPrice;
}
}
}
catch (HttpRequestException httpException)
{
// Handle the exception as needed
}

return null;
}

public async Task<List<CollectionOwned>> GetUserOwnedCollections(string apiKey, int accountId)
{
List<CollectionOwned> allData = new();
Expand All @@ -134,12 +163,14 @@ public async Task<List<CollectionOwned>> GetUserOwnedCollections(string apiKey,
request.AddParameter("offset", offset);
try
{
var apiSw = Stopwatch.StartNew();
var response = await _client.GetAsync(request);
var data = JsonConvert.DeserializeObject<UserOwnedCollectionResponse>(response.Content!);
if (data.collections.Count != 0)
{
allData.AddRange(data.collections);
}
Timers.ApiStopWatchCheck(apiSw);
return allData;
}
catch (HttpRequestException httpException)
Expand All @@ -158,12 +189,14 @@ public async Task<List<CollectionOwned>> GetUserOwnedCollections(string apiKey,
request.AddParameter("offset", offset);
try
{
var apiSw = Stopwatch.StartNew();
var response = await _client.GetAsync(request);
var data = JsonConvert.DeserializeObject<UserOwnedCollectionResponse>(response.Content!);
if (data.totalNum != 0)
{
allData.AddRange(data.collections);
}
Timers.ApiStopWatchCheck(apiSw);
return (allData, data.totalNum);
}
catch (HttpRequestException httpException)
Expand All @@ -183,14 +216,17 @@ public async Task<List<CollectionMinted>> GetUserMintedCollections(string apiKey
request.AddParameter("offset", offset);
try
{
var apiSw = Stopwatch.StartNew();
var response = await _client.GetAsync(request);
var data = JsonConvert.DeserializeObject<UserMintedCollectionResponse>(response.Content!);
if (data.collections.Count != 0)
{
allData.AddRange(data.collections.ToList());
}
Timers.ApiStopWatchCheck(apiSw);
while (data.collections.Count != 0)
{
apiSw = Stopwatch.StartNew();
offset += 12;
request.AddOrUpdateParameter("offset", offset);
response = await _client.GetAsync(request);
Expand All @@ -199,6 +235,7 @@ public async Task<List<CollectionMinted>> GetUserMintedCollections(string apiKey
{
allData.AddRange(data.collections.ToList());
}
Timers.ApiStopWatchCheck(apiSw);
}
return allData;
}
Expand All @@ -218,12 +255,14 @@ public async Task<List<CollectionMinted>> GetUserMintedCollections(string apiKey
request.AddParameter("offset", offset);
try
{
var apiSw = Stopwatch.StartNew();
var response = await _client.GetAsync(request);
var data = JsonConvert.DeserializeObject<UserMintedCollectionResponse>(response.Content!);
if (data.totalNum != 0)
{
allData.AddRange(data.collections);
}
Timers.ApiStopWatchCheck(apiSw);
return (allData, data.totalNum);
}
catch (HttpRequestException httpException)
Expand All @@ -240,19 +279,23 @@ public async Task<NftResponseFromCollection> GetCollectionNfts(string apiKey, st
request.AddParameter("limit", 50);
try
{
var apiSw = Stopwatch.StartNew();
var offset = 50;
var response = await _client.GetAsync(request);
var data = JsonConvert.DeserializeObject<NftResponseFromCollection>(response.Content!);
var total = data.totalNum;

Timers.ApiStopWatchCheck(apiSw);
while (total > 50)
{
apiSw = Stopwatch.StartNew();
total -= 50;
request.AddOrUpdateParameter("offset", offset);
response = await _client.GetAsync(request);
var moreData = JsonConvert.DeserializeObject<NftResponseFromCollection>(response.Content!);
data.nftTokenInfos.AddRange(moreData.nftTokenInfos);
offset += 50;
Timers.ApiStopWatchCheck(apiSw);
}
return data;
}
Expand Down Expand Up @@ -689,9 +732,11 @@ public async Task<NftBalance> GetTokenId(string apiKey, int accountId, string nf
request.AddParameter("nftDatas", nftData);
try
{
var apiSw = Stopwatch.StartNew();
var response = await _client.GetAsync(request);
var data = JsonConvert.DeserializeObject<NftBalance>(response.Content!);
counter++;
Timers.ApiStopWatchCheck(apiSw);
return data;
}
catch (HttpRequestException httpException)
Expand All @@ -708,8 +753,10 @@ public async Task<StorageId> GetNextStorageId(string apiKey, int accountId, int
request.AddParameter("sellTokenId", sellTokenId);
try
{
var apiSw = Stopwatch.StartNew();
var response = await _client.GetAsync(request);
var data = JsonConvert.DeserializeObject<StorageId>(response.Content!);
Timers.ApiStopWatchCheck(apiSw);
return data;
}
catch (HttpRequestException httpException)
Expand All @@ -726,8 +773,10 @@ public async Task<OffchainFee> GetOffChainFee(string apiKey, int accountId, int
request.AddParameter("amount", amount);
try
{
var apiSw = Stopwatch.StartNew();
var response = await _client.GetAsync(request);
var data = JsonConvert.DeserializeObject<OffchainFee>(response.Content!);
Timers.ApiStopWatchCheck(apiSw);
return data;
}
catch (HttpRequestException httpException)
Expand All @@ -744,7 +793,6 @@ public async Task<string> CheckForEthAddress(ILoopringService LoopringService, s
{
var apiSw = Stopwatch.StartNew();
var varHexAddress = await LoopringService.GetHexAddress(apiKey, address);

Timers.ApiStopWatchCheck(apiSw);

return string.IsNullOrEmpty(varHexAddress.data) ? null : varHexAddress.data;
Expand Down Expand Up @@ -779,6 +827,7 @@ public async Task<NftTransferAuditInformation> NftTransfer(
CounterFactualInfo? isCounterFactual
)
{
validUntil = ApplicationUtilitiesUI.GetUnixTimestamp() + (int)TimeSpan.FromDays(365).TotalSeconds;
string toAddressInitial = toAddress;
var airdropNumberOn = 0;
var gasFeeTotal = 0m;
Expand Down Expand Up @@ -806,7 +855,6 @@ public async Task<NftTransferAuditInformation> NftTransfer(
//string[] walletAddressLineArray = line.Split(',');
//toAddressInitial = walletAddressLineArray[2].Trim();
//nftData = walletAddressLineArray[0].Trim();
Thread.Sleep(90);
var userNftToken = await loopringService.GetTokenId(loopringApiKey, fromAccountId, nftData);
if (userNftToken.totalNum == 0)
{
Expand All @@ -820,15 +868,12 @@ public async Task<NftTransferAuditInformation> NftTransfer(
//font.ToTertiaryInline($"\rDrop: {++airdropNumberOn}/{howManyLines} Wallet: {toAddressInitial}");

toAddress = toAddressInitial.ToLower().Trim();
Thread.Sleep(90);
var storageId = await loopringService.GetNextStorageId(loopringApiKey, fromAccountId, nftTokenId);
Thread.Sleep(90);
OffchainFee offChainFee;
if (payPayeeUpdateAccount == false)
offChainFee = await loopringService.GetOffChainFee(loopringApiKey, fromAccountId, 11, "0");
else
offChainFee = await loopringService.GetOffChainFee(loopringApiKey, fromAccountId, 19, "0");
Thread.Sleep(90);
toAddress = await loopringService.CheckForEthAddress(loopringService, loopringApiKey, toAddress);

//if (toAddress == "invalid eth address")
Expand Down Expand Up @@ -966,16 +1011,15 @@ public async Task<NftTransferAuditInformation> NftTransfer(
Eip712TypedDataSigner signer = new();
EthECKey ethECKey = new(null);
if (MMorGMEPrivateKey == "")
ethECKey = new Nethereum.Signer.EthECKey(loopringPrivateKey.Replace("0x", ""));
ethECKey = new EthECKey(loopringPrivateKey.Replace("0x", ""));
else
ethECKey = new Nethereum.Signer.EthECKey(MMorGMEPrivateKey.Replace("0x", ""));
ethECKey = new EthECKey(MMorGMEPrivateKey.Replace("0x", ""));
var encodedTypedData = signer.EncodeTypedData(eip712TypedData);
var ECDRSASignature = ethECKey.SignAndCalculateV(Sha3Keccack.Current.CalculateHash(encodedTypedData));
var serializedECDRSASignature = EthECDSASignature.CreateStringSignature(ECDRSASignature);
var ecdsaSignature = serializedECDRSASignature + "0" + (int)2;

//Submit nft transfer
Thread.Sleep(90);
var nftTransferResponse = await loopringService.SubmitNftTransfer(
apiKey: loopringApiKey,
exchange: environmentExchange,
Expand Down Expand Up @@ -1076,8 +1120,10 @@ public async Task<string> SubmitNftTransfer(
request.AddParameter("payPayeeUpdateAccount", "true");
try
{
var apiSw = Stopwatch.StartNew();
var response = await _client.ExecutePostAsync(request);
var data = response.Content;
Timers.ApiStopWatchCheck(apiSw);
return data;
}
catch (HttpRequestException httpException)
Expand Down
1 change: 0 additions & 1 deletion MaizeUI/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Avalonia;
using Avalonia.ReactiveUI;
using System;

namespace MaizeUI
{
Expand Down
Loading

0 comments on commit 3815e34

Please sign in to comment.