Skip to content

Commit

Permalink
Merge pull request #25 from RemarkableTools/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
axenteoctavian authored Apr 30, 2023
2 parents 48492d9 + 6cf5b3a commit a74256e
Show file tree
Hide file tree
Showing 11 changed files with 530 additions and 2 deletions.
150 changes: 150 additions & 0 deletions src/Mx.NET.SDK/Domain/Data/Block/Block.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
using Mx.NET.SDK.Domain.Data.Common;
using Mx.NET.SDK.Domain.Helper;
using Mx.NET.SDK.Provider.Dtos.API.Block;
using System;

namespace Mx.NET.SDK.Domain.Data.Block
{
public class Block
{
/// <summary>
/// Block hash
/// </summary>
public string Hash { get; private set; }

/// <summary>
/// Block epoch
/// </summary>
public int Epoch { get; private set; }

/// <summary>
/// Block nonce
/// </summary>
public ulong Nonce { get; private set; }

/// <summary>
/// Block previous hash
/// </summary>
public string PrevHash { get; private set; }

/// <summary>
/// Block proposer
/// </summary>
public string Proposer { get; private set; }

/// <summary>
/// Block proposer identity
/// </summary>
public ProposerIdentity ProposerIdentity { get; private set; }

/// <summary>
/// Block public key bitmap
/// </summary>
public string PubKeyBitmap { get; private set; }

/// <summary>
/// Block round
/// </summary>
public ulong Round { get; private set; }

/// <summary>
/// Block shard
/// </summary>
public int Shard { get; private set; }

/// <summary>
/// Block size
/// </summary>
public int Size { get; private set; }

/// <summary>
/// Block size txs
/// </summary>
public int SizeTxs { get; private set; }

/// <summary>
/// Block state root hash
/// </summary>
public string StateRootHash { get; private set; }

/// <summary>
/// Block creation date
/// </summary>
public DateTime CreationDate { get; private set; }

/// <summary>
/// Block transactions count
/// </summary>
public long TxCount { get; private set; }

/// <summary>
/// Block gas consumed
/// </summary>
public ulong GasConsumed { get; private set; }

/// <summary>
/// Block gas refunded
/// </summary>
public ulong GasRefunded { get; private set; }

/// <summary>
/// Block gas penalized
/// </summary>
public ulong GasPenalized { get; private set; }

/// <summary>
/// Block max gas limit
/// </summary>
public ulong MaxGasLimit { get; private set; }

/// <summary>
/// Mini blocks hashes
/// </summary>
public string[] MiniBlocksHashes { get; private set; }

/// <summary>
/// Notarized blocks hashes
/// </summary>
public string[] NotarizedBlocksHashes { get; private set; }

/// <summary>
/// Block validators
/// </summary>
public string[] Validators { get; private set; }

private Block() { }

/// <summary>
/// Creates a new Block from data
/// </summary>
/// <param name="block">Block Data Object from API</param>
/// <returns></returns>
public static Block From(BlockDto block)
{
return new Block()
{
Hash = block.Hash,
Epoch = block.Epoch ?? 0,
Nonce = block.Nonce ?? 0,
PrevHash = block.PrevHash,
Proposer = block.Proposer,
ProposerIdentity = ProposerIdentity.From(block.ProposerIdentity),
PubKeyBitmap = block.PubKeyBitmap,
Round = block.Round ?? 0,
Shard = block.Shard ?? 0,
Size = block.Size ?? 0,
SizeTxs = block.SizeTxs ?? 0,
StateRootHash = block.StateRootHash,
CreationDate = (block.Timestamp ?? 0).ToDateTime(),
TxCount = block.TxCount ?? 0,
GasConsumed = block.GasConsumed ?? 0,
GasRefunded = block.GasRefunded ?? 0,
GasPenalized = block.GasPenalized ?? 0,
MaxGasLimit = block.MaxGasLimit ?? 0,
MiniBlocksHashes = block.MiniBlocksHashes,
NotarizedBlocksHashes = block.NotarizedBlocksHashes,
Validators = block.Validators
};
}
}
}
133 changes: 133 additions & 0 deletions src/Mx.NET.SDK/Domain/Data/Block/Blocks.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
using Mx.NET.SDK.Domain.Data.Common;
using Mx.NET.SDK.Domain.Helper;
using Mx.NET.SDK.Provider.Dtos.API.Block;
using System;
using System.Linq;

namespace Mx.NET.SDK.Domain.Data.Block
{
public class Blocks
{
/// <summary>
/// Block hash
/// </summary>
public string Hash { get; private set; }

/// <summary>
/// Block epoch
/// </summary>
public int Epoch { get; private set; }

/// <summary>
/// Block nonce
/// </summary>
public ulong Nonce { get; private set; }

/// <summary>
/// Block previous hash
/// </summary>
public string PrevHash { get; private set; }

/// <summary>
/// Block proposer
/// </summary>
public string Proposer { get; private set; }

/// <summary>
/// Block proposer identity
/// </summary>
public ProposerIdentity ProposerIdentity { get; private set; }

/// <summary>
/// Block public key bitmap
/// </summary>
public string PubKeyBitmap { get; private set; }

/// <summary>
/// Block round
/// </summary>
public ulong Round { get; private set; }

/// <summary>
/// Block shard
/// </summary>
public int Shard { get; private set; }

/// <summary>
/// Block size
/// </summary>
public int Size { get; private set; }

/// <summary>
/// Block size txs
/// </summary>
public int SizeTxs { get; private set; }

/// <summary>
/// Block state root hash
/// </summary>
public string StateRootHash { get; private set; }

/// <summary>
/// Block creation date
/// </summary>
public DateTime CreationDate { get; private set; }

/// <summary>
/// Block transactions count
/// </summary>
public long TxCount { get; private set; }

/// <summary>
/// Block gas consumed
/// </summary>
public ulong GasConsumed { get; private set; }

/// <summary>
/// Block gas refunded
/// </summary>
public ulong GasRefunded { get; private set; }

/// <summary>
/// Block gas penalized
/// </summary>
public ulong GasPenalized { get; private set; }

/// <summary>
/// Block max gas limit
/// </summary>
public ulong MaxGasLimit { get; private set; }

private Blocks() { }

/// <summary>
/// Creates a new array of Blocks from data
/// </summary>
/// <param name="blocks">Array of Blocks Data Object from API</param>
/// <returns>Array of Blocks objects</returns>
public static Blocks[] From(BlocksDto[] blocks)
{
return blocks.Select(block => new Blocks()
{
Hash = block.Hash,
Epoch = block.Epoch ?? 0,
Nonce = block.Nonce ?? 0,
PrevHash = block.PrevHash,
Proposer = block.Proposer,
ProposerIdentity = ProposerIdentity.From(block.ProposerIdentity),
PubKeyBitmap = block.PubKeyBitmap,
Round = block.Round ?? 0,
Shard = block.Shard ?? 0,
Size = block.Size ?? 0,
SizeTxs = block.SizeTxs ?? 0,
StateRootHash = block.StateRootHash,
CreationDate = (block.Timestamp ?? 0).ToDateTime(),
TxCount = block.TxCount ?? 0,
GasConsumed = block.GasConsumed ?? 0,
GasRefunded = block.GasRefunded ?? 0,
GasPenalized = block.GasPenalized ?? 0,
MaxGasLimit = block.MaxGasLimit ?? 0,
}).ToArray();
}
}
}
56 changes: 56 additions & 0 deletions src/Mx.NET.SDK/Domain/Data/Common/ProposerIdentity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using Mx.NET.SDK.Provider.Dtos.API.Block;

namespace Mx.NET.SDK.Domain.Data.Common
{
/// <summary>
/// Proposer Identity for Block
/// </summary>
public class ProposerIdentity
{
public string Identity { get; private set; }
public string Name { get; private set; }
public string Description { get; private set; }
public string Avatar { get; private set; }
public string Website { get; private set; }
public string Twitter { get; private set; }
public string Location { get; private set; }
public double Score { get; private set; }
public int Validators { get; private set; }
public string Stake { get; private set; }
public string TopUp { get; private set; }
public string Locked { get; private set; }
public dynamic Distribution { get; private set; }
public string[] Providers { get; private set; }
public double StakePercent { get; private set; }
public double Apr { get; private set; }
public int Rank { get; private set; }

private ProposerIdentity() { }

public static ProposerIdentity From(ProposerIdentityDto proposerIdentity)
{
if (proposerIdentity == null) return null;

return new ProposerIdentity()
{
Identity = proposerIdentity.Identity,
Name = proposerIdentity.Name,
Description = proposerIdentity.Description,
Avatar = proposerIdentity.Avatar,
Website = proposerIdentity.Website,
Twitter = proposerIdentity.Twitter,
Location = proposerIdentity.Location,
Score = proposerIdentity.Score ?? 0,
Validators = proposerIdentity.Validators ?? 0,
Stake = proposerIdentity.Stake,
TopUp = proposerIdentity.TopUp,
Locked = proposerIdentity.Locked,
Distribution = proposerIdentity.Distribution,
Providers = proposerIdentity.Providers,
StakePercent = proposerIdentity.StakePercent ?? 0,
Apr = proposerIdentity.Apr ?? 0,
Rank = proposerIdentity.Rank ?? 0
};
}
}
}
2 changes: 1 addition & 1 deletion src/Mx.NET.SDK/Domain/Data/NFT/NFT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public static NFT From(NFTDto nft)

/// <summary>
/// Creates a new array of NFTs from data
/// </summary>a
/// </summary>
/// <param name="nfts">Array of NFT Data Object from API</param>
/// <returns>Array of NFT objects</returns>
public static NFT[] From(NFTDto[] nfts)
Expand Down
16 changes: 16 additions & 0 deletions src/Mx.NET.SDK/Domain/Helper/TimestampConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,26 @@ namespace Mx.NET.SDK.Domain.Helper
{
public static class TimestampConverter
{
/// <summary>
/// Converts the timestamp to datetime
/// </summary>
/// <param name="timestamp"></param>
/// <returns>UTC datetime</returns>
public static DateTime ToDateTime(this long timestamp)
{
DateTime dateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
return dateTime.AddSeconds(timestamp).ToUniversalTime();
}

/// <summary>
/// Converts the datetime to timestamp
/// </summary>
/// <param name="dateTime">UTC DateTime</param>
/// <returns>timestamp</returns>
public static long ToTimestamp(this DateTime dateTime)
{
DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
return (long)dateTime.Subtract(origin).TotalSeconds;
}
}
}
2 changes: 1 addition & 1 deletion src/Mx.NET.SDK/Mx.NET.SDK.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<RepositoryUrl>https://github.com/RemarkableTools/Mx.NET.SDK</RepositoryUrl>
<RepositoryType>GitHub</RepositoryType>
<Company>Remarkable Tools</Company>
<Version>1.0.16</Version>
<Version>1.0.17</Version>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Title>RemarkableTools.Mx</Title>
<PackageReadmeFile>README.md</PackageReadmeFile>
Expand Down
Loading

0 comments on commit a74256e

Please sign in to comment.