-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBTC-miner-updates4.q
96 lines (83 loc) · 3.76 KB
/
BTC-miner-updates4.q
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
\p 5000
\l cryptoq_binary.q
\l cryptoq.q
\l bitcoind.q
sha256:`sha2 2:(`sha256;2);
username:"bitcoin-core-username";
password:"password";
//computeData: ([]blockHeight:"f"$(); partialHeader:`$(); trans:`$(); target:`$() );
computeData: ()!();
initHeight:0f;
flag:1b;
maxInt:4294967294;
hex: "0123456789abcdef";
htb:"0123456789abcdef"!-4#'0b vs/: hex?hex;
bin_to_int:{0b sv x};
hex_to_int:{0x0 sv x};
hex2bin:{raze htb x};
hexstring_to_hex:{"X"$/: 2 cut x};
hex2int:{hex_to_int .cryptoq_binary.bin_to_hex hex2bin x};
doubleSha256:{raze string .cryptoq.hexsha256[raze string[.cryptoq.hexsha256[x]]]};
doubleSha256Byte:{ sha256[sha256[x;count x];32]};
texttohexstr:{raze string "x"$x};
SwapOrder:{raze reverse 2 cut x};
littleEndian:{y#raze string reverse 0x0 vs x}; // int to hexstring
buildmerkleroot:{[leafs]
leafcount: count leafs;
root: $[1 = leafcount;
first leafs;
[
if [0 < leafcount mod 2; leafs: leafs,enlist last leafs; leafcount: 1+leafcount;]; // if odd number, duplicate last record
oddindicies: 1+2*til "i"$(leafcount%2);
evenindicies: 2*til "i"$(leafcount%2);
hashpairs: leafs[evenindicies] ,' leafs[oddindicies];
hashcount: count hashpairs;
branches:{ doubleSha256Byte x } peach hashpairs;
buildmerkleroot[branches]
]
];
root
};
template_request: `mode`capabilities`rules!("template";(enlist "proposal");enlist "segwit");
coinbaseversion:"01000000";
coinbasein:"01";
coinbaseprevtx:"0000000000000000000000000000000000000000000000000000000000000000";
coinbaseprevout:"ffffffff";
coinbaseseq:"00000000";
coinbaseout:"01";
cbpubkey: "866b6c77fd236f9185bb11b4e176328d7f912a4b";
scriptPubKey: "76","A9","14" , cbpubkey, "88", "AC";
coinbasesl: "19";
coinbaselocktime:"00000000";
.bitcoind.initPass[username;password];
blockcount:{[] .bitcoind.getblockcount[][`result]};
loadUpdates:{[]
template: .bitcoind.getblocktemplate[template_request][`result];
Version:hexstring_to_hex littleEndian[template[`version];8] ;
hashPrevBlock:hexstring_to_hex SwapOrder[0N! template[`previousblockhash]];
Time:hexstring_to_hex littleEndian[template[`curtime];8];
Bits:hexstring_to_hex SwapOrder[template[`bits]];
target: hexstring_to_hex template[`target];
height: 0N! template[`height];
coinbasevalue:template[`coinbasevalue];
coinbasesats: littleEndian[coinbasevalue;16];
coinbasescript:"03" , (littleEndian[height;6]), texttohexstr["Reap what you sow."];
coinbasescriptlen:littleEndian["i"$(count coinbasescript)%2;2];
coinbasesommy:coinbasescript;
coinbasescriptlen:littleEndian["i"$(count coinbasesommy)%2;2];
coinbasetrans: coinbaseversion, coinbasein, coinbaseprevtx, coinbaseprevout,coinbasescriptlen,coinbasesommy,coinbaseseq,coinbaseout,coinbasesats,coinbasesl,scriptPubKey,coinbaselocktime;
coinbasetransbytes: .cryptoq_binary.hexstring_to_hex raze string coinbasetrans;
coinbasetranshash:raze string reverse doubleSha256Byte[coinbasetransbytes];
transactions: template[`transactions];
hashlist: {x[`hash]} each transactions;
datalist: {x[`data]} each transactions;
hashlist: (enlist coinbasetranshash), hashlist;
bytehashlist:.cryptoq_binary.hexstring_to_hex peach hashlist;
bytehashlistBigEndian:reverse peach bytehashlist;
Merkleroot: buildmerkleroot[bytehashlistBigEndian];
partialHeader : Version , hashPrevBlock , Merkleroot , Time , Bits ;
trans:(enlist coinbasetrans),datalist;
transcounter:littleEndian[count trans;8];
blk: transcounter , raze trans;
computeData:: `height`partialHeader`trans`target! ( height; partialHeader; blk; target );
};