لایت کوین یک ارز دیجیتال همتا به همتا است که امکان پرداخت های نسبتا فوری و کم هزینه را در سراسر جهان فراهم میکند. دارای سیستم P2P برای پرداخت های میکروی پول های دیجیتالی مثل BitCoin و LiteCoin از طریق شبکه بدون مقیاس از کانال های پرداخت دوطرفه، بدون نیاز به اعتماد به شخص ثالث می باشد.
PeerCoin
PeerCoin یک ارز دیجیتالی peer-to-peer است که از سیستم های اثبات سهام و اثبات کار (proof-of-work) استفاده می کند. پیرکوین با هدف صرفه جویی در انرژی که نمونه آن کاهش میزان انرژی الکتریکی مصرفی مورد نیاز برای استفاده از شبکه بیت کوین است فعالیت خود را در سال 2012 شروع کرده است.
ایجاد BlockChain در VB. NET
در قدم اول ویژوال استودیو را باز کرده و یک پروژه Visual Basic Class Library ایجاد کنید. این پروژه بر اساس پلت فرم Ethereum است.
کلاسی را به پروژه اضافه کنید و نام آن را Node بگذارید (یا چیزی شبیه به این). کد زیر را به آن اضافه کنید:
Public Class Node
Private btValue As Byte()
Private btKey As Byte()
End Class
کلاس زیر را برای رمزگذاری بایت ها به هگزادسیمال و برعکس اضافه کنید:
Imports System.IO
Public NotInheritable Class CompactEncoder
Private Shared Delimiter As Byte = 16
Public Shared Function CompactEncode(btHex As Byte()) As Byte()
Dim btTerminate As Byte = 0
If btHex(btHex.Length - 1) = Delimiter Then
btTerminate = 1
btHex = Encoder.RemoveLastBytes(btHex, 1)
End If
Dim intOddLength As Integer = btHex.Length Mod 2
Dim intFlag As Integer = 2 * btTerminate + intOddLength
If intOddLength 0 Then
Dim btFlags As Byte() = New Byte() {CByte(intFlag)}
btHex = Encoder.JoinByteArrays(btFlags, btHex)
Else
Dim btFlags As Byte() = New Byte() {CByte(intFlag), 0}
btHex = Encoder.JoinByteArrays(btFlags, btHex)
End If
Dim msBuffer As New MemoryStream()
For i As Integer = 0 To btHex.Length - 1 Step 2
msBuffer.WriteByte(CByte(16 * btHex(i) + btHex(i + 1)))
Next
Return msBuffer.ToArray()
End Function
Public Shared Function CompactDecode(btString As Byte()) _
As Byte()
Dim btRes As Byte() = CompactHexDecode(btString)
btRes = Encoder.RemoveLastBytes(btRes, 1)
If btRes(0) >= 2 Then
btRes = Encoder.AppendByteToArray(btRes, Delimiter)
End If
If btRes(0) Mod 2 = 1 Then
btRes = Encoder.RemoveFirstBytes(btRes, 1)
Else
btRes = Encoder.RemoveFirstBytes(btRes, 2)
End If
Return btRes
End Function
Public Shared Function CompactHexDecode(btEncodedHexadecimal _
As Byte()) As Byte()
Dim chrCharacters As Char() = New Char() {"0"c, "1"c, "2"c, _
"3"c, "4"c, "5"c, "6"c, "7"c, "8"c, "9"c, "a"c, "b"c, _
"c"c, "d"c, "e"c, "f"c}
Dim btHex As Byte() = New Byte(-1) {}
For Each btNumber As Byte In btEncodedHexadecimal
Dim hexValue As String = btNumber.ConvertToHex()
Dim chrHexValue As Char() = hexValue.ToCharArray()
btHex = Encoder.AppendByteToArray(btHex, _
CByte(Array.IndexOf(chrCharacters, chrHexValue(0))))
btHex = Encoder.AppendByteToArray(btHex, _
CByte(Array.IndexOf(chrCharacters, chrHexValue(1))))
Next
btHex = Encoder.AppendByteToArray(btHex, Delimiter)
Return btHex
End Function
End Class
بیشتر بدانید: کاربرد بلاکچین در پرداخت
extension module زیر را برای تبدیل بایت به هگزادسیمال اضافه کنید:
Imports System.Text
Public Module Converter
Public Function ConvertByteArrayToUInt64(btInput As Byte()) _
As UInt64
If btInput.Length Dim tempArray As Byte() = New Byte(7) {}
Array.Copy(btInput, 0, tempArray, (tempArray.Length - _
btInput.Length), btInput.Length)
Array.Reverse(tempArray)
Return BitConverter.ToUInt64(tempArray, 0)
End If
Return BitConverter.ToUInt64(btInput, 0)
End Function
Private ReadOnly HexStringTable As String() = New String() _
{"00", "01", "02", "03", "04", "05", "06", "07", "08", _
"09", "0a", "0b", "0c", "0d", "0e", "0f", "10", "11", "12", _
"13", "14", "15", "16", "17", "18", "19", "1a", "1b", "1c", _
"1d", "1e", "1f", "20", "21", "22", "23", "24", "25", "26", _
"27", "28", "29", "2a", "2b", "2c", "2d", "2e", "2f", "30", _
"31", "32", "33", "34", "35", "36", "37", "38", "39", "3a", _
"3b", "3c", "3d", "3e", "3f", "40", "41", "42", "43", "44", _
"45", "46", "47", "48", "49", "4a", "4b", "4c", "4d", "4e", _
"4f", "50", "51", "52", "53", "54", "55", "56", "57", "58", _
"59", "5a", "5b", "5c", "5d", "5e", "5f", "60", "61", "62", _
"63", "64", "65", "66", "67", "68", "69", "6a", "6b", "6c", _
"6d", "6e", "6f", "70", "71", "72", "73", "74", "75", "76", _
"77", "78", "79", "7a", "7b", "7c", "7d", "7e", "7f", "80", _
"81", "82", "83", "84", "85", "86", "87", "88", "89", "8a", _
"8b", "8c", "8d", "8e", "8f", "90", "91", "92", "93", "94", _
"95", "96", "97", "98", "99", "9a", "9b", "9c", "9d", "9e", _
"9f", "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", _
"a9", "aa", "ab", "ac", "ad", "ae", "af", "b0", "b1", "b2", _
"b3", "b4", "b5", "b6", "b7", "b8", "b9", "ba", "bb", "bc", _
"bd", "be", "bf", "c0", "c1", "c2", "c3", "c4", "c5", "c6", _
"c7", "c8", "c9", "ca", "cb", "cc", "cd", "ce", "cf", "d0", _
"d1", "d2", "d3", "d4", "d5", "d6", "d7", "d8", "d9", "da", _
"db", "dc", "dd", "de", "df", "e0", "e1", "e2", "e3", "e4", _
"e5", "e6", "e7", "e8", "e9", "ea", "be", "ec", "ed", "ee", _
"ef", "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", _
"f9", "fa", "fb", "fc", "fd", "fe", "ff"}
Public Function ConvertToHex(btVal As Byte()) As String
Dim sbString As New StringBuilder()
If btVal IsNot Nothing Then
For Each b As Byte In btVal
sbString.Append(HexStringTable(b))
Next
End If
Return sbString.ToString()
End Function
End Module
کد پایین برای رمزگشایی و گذاشتن رمز در اشیای گرفته شده از آرایه های بایت ، که بعد ها به هگزا تبدیل خواهند شد،اضافه نمایید:
Public Class Decode
Private uPos As UInt64
Private oDecoded As
Public Sub New(Pos As UInt64, Decoded As )
Me.uPos = Pos
Me.oDecoded = Decoded
End Sub
Public Function GetPos() As UInt64
Return uPos
End Function
Public Function GetDecoded() As
Return oDecoded
End Function
End Class
Imports System.Text
Public NotInheritable Class Encoder
Public Shared Function ToHex(oInput As ) As Byte()
Dim uInput As UInt64
Dim blnNumber As Boolean = _
UInt64.TryParse(oInput.ToString(), uInput)
If blnNumber Then
Return If((uInput = 0), New Byte(-1) {}, _
ConvertUInt64ToByteArray(uInput))
ElseIf TypeOf oInput() Is String Then
Dim strInput As String = DirectCast(oInput(), String)
Return Encoding.ASCII.GetBytes(strInput.ToCharArray())
End If
End Function
Public Shared Function ConvertUInt64ToByteArray(uInput _
As UInt64) As Byte()
Dim btBytes As Byte() = BitConverter.GetBytes(uInput)
Array.Reverse(btBytes)
Dim i = 0
While btBytes(i) = 0
i += 1
End While
Dim btResult As Byte() = New Byte(btBytes.Length - i - 1) {}
Array.Copy(btBytes, i, btResult, 0, btBytes.Length - i)
Return btResult
End Function
Public Shared Function JoinByteArrays(btInputA As Byte(), _
btInputB As Byte()) As Byte()
Dim btResult As Byte() = New Byte(btInputA.Length + _
(btInputB.Length - 1)) {}
Array.Copy(btInputA, 0, btResult, 0, btInputA.Length)
Array.Copy(btInputB, 0, btResult, btInputA.Length, _
btInputB.Length)
Return btResult
End Function
Public Shared Function AppendByteToArray(btInputArr As Byte(), _
btInput As Byte) As Byte()
Dim btResult As Byte() = New Byte(btInputArr.Length) {}
Array.Copy(btInputArr, 0, btResult, 0, btInputArr.Length)
btResult(btResult.Length - 1) = btInput
Return btResult
End Function
Public Shared Function RemoveLastBytes(btInput As Byte(), _
intAmount As Integer) As Byte()
Dim btResult As Byte() = New Byte(btInput.Length - _
intAmount - 1) {}
Array.Copy(btInput, 0, btResult, 0, btInput.Length - _
intAmount)
Return btResult
End Function
Public Shared Function RemoveFirstBytes(btInput As Byte(), _
intAmount As Integer) As Byte()
Dim btResult As Byte() = New Byte(btInput.Length - _
intAmount - 1) {}
Array.Copy(btInput, intAmount, btResult, 0, _
btInput.Length - intAmount)
Return btResult
End Function
End Class
کد قبلی با تمام منطق بلاک چین سرو کار دارد، اما هنوز هم باید بتوانیم به طور صحیح استخراج را انجام دهیم، که بعدا باید انجام شود، بنابراین لطفا آن را درنظر بگیرید!
Solidity
Solidity یک زبان سطح بالا و contract-oriented است که ماشین مجازی Ethereum را هدف قرار داده است. می توانید مستقیما از طریق ویژوال استودیو برنامه های Solidity Blockchain را کدنویسی کرده و مورد استفاده قرار دهید. این افزونه را می توانید از مارکت ویژوال استادیو دانلود کنید، تنظیم و شروع به کار با آن بسیار آسان است.
این پروژه به اتمام نرسیده است. اما این شروع مناسبی برای ساخت بلاک چین برای شماست. انجام این کار ها به همان میزان که جذاب به نظر می رسد، شاید سخت هم باشد!
امیدواریم از مطلب" مقدمهای بر برنامه نویسی بلاکچین blockchain " استفاده کرده باشید.
Read the full article