-
Notifications
You must be signed in to change notification settings - Fork 11
/
Main.lua
104 lines (82 loc) · 2.61 KB
/
Main.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
local Block = require(game.ServerScriptService.BTC.BlockBuilder)
local LatestHash = require(game.ServerScriptService.BTC.LatestHash)
local hex = require(game.ServerScriptService.BTC.Hexidecimal)
local tx = require(game.ServerScriptService.BTC.TXGetter)
local Merkle = require(game.ServerScriptService.BTC.Merkle)
local waitForPlayer = true
game.Players.PlayerAdded:connect(function(player)
player.Chatted:connect(function(message)
if message == "start" then
waitForPlayer = false
end
end)
end)
while true do
if waitForPlayer == false then
print("player started")
break
end
wait(1)
end
local Transactions = tx(50) -- Get 50 unproccesed transactions and get the merkle root
local MerkleRoot = Merkle(Transactions)
print("Merkle Root: " .. MerkleRoot)
local function toDEC(str)
str = tostring(str)
if str:sub(1,2)=='0x' then str=str:sub(3) end
local tot = 0
local lkUp = {a = 10, b = 11, c = 12, d = 13, e = 14, f = 15}
local pow = 0
for a = str:len(), 1, -1 do
local char = str:sub(a, a)
local num = lkUp[char] or tonumber(char)
if not num then return nil end
num = num*(16^pow)
tot = tot + num
pow = pow + 1
end
return tot
end
local function base256(x)
local r = ""
local base = 256
local nums = {}
while x > 0 do
r = (x % base )
table.insert(nums, 1, r)
x = math.floor(x / base)
end
return nums
end
local function Bits(z)
--[[
convert the integer into base 256.
if the first (most significant) digit is greater than 127 (0x7f), prepend a zero digit
the first byte of the 'compact' format is the number of digits in the above base 256 representation, including the prepended zero if it's present
the following three bytes are the first three digits of the above representation. If less than three digits are present, then one or more of the last bytes of the compact representation will be zero.
--]]
local d = base256(z)
local t
t =string.format("%02s", hex["toHex"](#d))
--t =string.format("%02s", (#d))
for i=1,3 do
if d[i] == nil then
t = t .. "00"
else
t = t .. string.format("%02s", hex["toHex"](d[i] ))
--t = t .. string.format("%02s",d[i])
end
end
print(t)
--toHEX add precision numbers
end
--Bits( hex["toDec"]("0x696f3ffffffe0c000000000000000000000000000000000"))
-- Block = Version + hashPrevBlock + hashMerkleroot + Time + Bits + Nonce
-- stuck on : this this
--print(LatestHash())
local PreviousBlock = require(game.ServerScriptService.BTC.GetLastBlock)()
local b = Block(PreviousBlock["data"]["hash"],
Transactions,
"201893210853",
MerkleRoot,
0)