Skip to content

Instantly share code, notes, and snippets.

View FrqSalah's full-sized avatar

Salah FOURAQ FrqSalah

View GitHub Profile
@FrqSalah
FrqSalah / Main.cs
Created January 27, 2024 20:43
test blockhain methods
static void Main(string[] args)
{
var blockchain = new Blockchain();
blockchain.AddBlock("Block 1");
blockchain.AddBlock("Block 2");
blockchain.AddBlock("Block 3");
Console.WriteLine("Is blockchain valid? " + blockchain.IsValid());
Console.WriteLine("Latest block: " + blockchain.GetLatestBlock().Data);
Console.ReadKey();
@FrqSalah
FrqSalah / Blockchain.cs
Created January 27, 2024 20:42
Blockchain class, which will contain a list of all the blocks in the blockchain
public class Blockchain
{
public List<Block> Chain { get; set; }
public Blockchain()
{
Chain = new List<Block> { new Block(0, DateTime.Now, "Genesis Block", "0") };
}
public void AddBlock(string data)
@FrqSalah
FrqSalah / Block.cs
Last active January 27, 2024 20:41
Block class, which will represent each block in the blockchain
public class Block
{
public int Index { get; set; }
public DateTime Timestamp { get; set; }
public string Data { get; set; }
public string PreviousHash { get; set; }
public string Hash { get; set; }
public Block(int index, DateTime timestamp, string data, string previousHash)
{
Index = index;
@FrqSalah
FrqSalah / BitcoinRpcService.cs
Created January 16, 2023 10:06
Example using BitcoinRpc in C#
using BitcoinRpc.Protocol;
using BitcoinRpc.Protocol.Methods;
using BitcoinRpc.Protocol.Models;
// Connect to the Bitcoin RPC
var rpc = new BitcoinRpcClient("http://user:password@127.0.0.1:8332/");
// Get the private key of the sender
var privateKey = "5J3mBbAH58CpQ3Y5RNJpUKPE62SQ5tfcvU2JpbnkeyhfsYB1Jcn";
@FrqSalah
FrqSalah / BitcoinLibService.cs
Created January 16, 2023 10:05
Exemple using BitcoinLib in C#
using BitcoinLib.Services.Coins.Bitcoin;
using BitcoinLib.Responses;
using BitcoinLib.Responses.Bases;
using BitcoinLib.Responses.Shared;
// Create an instance of the BitcoinService class
var bitcoinService = new BitcoinService();
// Get the private key of the sender
var privateKey = "5J3mBbAH58CpQ3Y5RNJpUKPE62SQ5tfcvU2JpbnkeyhfsYB1Jcn";
@FrqSalah
FrqSalah / NBitcoinService.cs
Created January 16, 2023 10:03
Example of using NBitcoin in C#
using NBitcoin;
using NBitcoin.Protocol;
using NBitcoin.Protocol.Behaviors;
// Create a private key for the sender
var privateKey = new Key();
// Get the public address from the private key
var fromAddress = privateKey.PubKey.GetAddress(Network.TestNet);
Console.WriteLine("Sender address: " + fromAddress);
@FrqSalah
FrqSalah / 206_Reverse Linked List_LeetCode.cs
Last active October 5, 2022 20:22
206. Reverse Linked List, Leet Code solution
public class Solution {
public ListNode ReverseList(ListNode head) {
ListNode curr = head;
ListNode prev = null;
ListNode temp = null;
while(curr != null)
{
temp = curr.next; // next value