-
Notifications
You must be signed in to change notification settings - Fork 24
/
Program.cs
executable file
·155 lines (135 loc) · 4.91 KB
/
Program.cs
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using Bitcoin_Tool.DataConverters;
using Bitcoin_Tool.Scripts;
using Bitcoin_Tool.Structs;
using Bitcoin_Tool.Structs.Net;
using Bitcoin_Tool.Util;
using Version = Bitcoin_Tool.Structs.Net.Version;
namespace Bitcoin_Tool
{
class Program
{
static void Main(string[] args)
{
//Apps.ComputeUnspentTxOuts.Main(args);
Apps.ComputeAddressBalances.Main(args);
}
static void _Main(string[] args)
{
TcpClient tcpClient = new TcpClient("10.1.1.40", 8333);
NetworkStream ns = tcpClient.GetStream();
NetAddr localaddr = new NetAddr(Services.NODE_NETWORK,
((IPEndPoint)tcpClient.Client.LocalEndPoint).Address, (UInt16)((IPEndPoint)tcpClient.Client.LocalEndPoint).Port);
NetAddr remaddr = new NetAddr(Services.NODE_NETWORK,
((IPEndPoint)tcpClient.Client.RemoteEndPoint).Address, (UInt16)((IPEndPoint)tcpClient.Client.RemoteEndPoint).Port);
new Message("version", Version.Default(remaddr, localaddr, 0)).Write(ns);
Tx tx = new Tx(HexString.ToByteArray("0100000001b924de36d37e9b46171036c2380dd3f86c33de7868b95f295c79d057abb876c9000000006c493046022100d35d290d515b2310a81850b14522f3965982ad059b08b7d6646372c9f6f98642022100d2d0fa06f8afa2a9df7bf7e06f901f08fc40882f486b292c217c96706912f23a012103b5091600a12d971b056170a682ea596b6680dd8a784f2960b1bfdc891155db44ffffffff0100ae4c2d000000001976a91443e86640aa84e2a53597e79109e912f8f9ebda1188ac00000000"));
Message mtx = new Message("tx", tx);
mtx.Write(ns);
while (tcpClient.Client.Connected)
{
Message msg = Message.FromStream(ns);
ISerialize p = msg.payload;
Console.WriteLine(msg.payload);
switch (msg.strcmd)
{
case "addr":
break;
case "alert":
break;
case "block":
break;
case "getaddr":
{
// Message m = new Message("addr", new Addr());
break;
}
case "getblocks":
break;
case "getdata":
break;
case "getheaders":
break;
case "headers":
break;
case "inv":
{
Inv inv = (Inv)msg.payload;
new Message("getdata", new GetData(inv.inventory)).Write(ns);
break;
}
case "ping":
break;
case "tx":
break;
case "verack":
break;
case "version":
{
Message m = new Message("verack", new VerAck());
m.Write(ns);
break;
}
default:
break;
}
}
/*
string line;
Transaction txUnspent = new Transaction(HexString.ToByteArray("0100000001f165b1179cb8ed7057540375884214287cf1592f2325080364f0bd8ef51d638b010000006a47304402207cf76bb48434e70ff0ea86a949ec4191fff0c31fdbbf6441c28293a09cb6841d022039906ff8b98761aa0d113e975c7af277d091a3cb9aaceae07dffe91f13fd65830121031adaac125ad58a48d1289bd44624d569b3ace8f9c59e02557e8ad00787dc7e06ffffffff0100ae4c2d00000000232102004066b81e658b2535b951c309edc4807a5260d9f1387e5dfda2d91355e562efac00000000"));
Address addr = new Address("1QJqE3KiyFBSCP12kTybW1ZRSeuJZTUwBY");
TxIn txIn = new TxIn(txUnspent.hash, 0, new Byte[0]);
TxOut txOut = new TxOut(760000000, ScriptTemplate.PayToAddress(addr).ToBytes());
Transaction tx = new Transaction(1, new TxIn[] { txIn }, new TxOut[] { txOut }, 0);
PrivateKey pk = PrivateKey.FromWIF("L1F95LNfoyGozceafTC1Pex8296YeF3EbsfETs22E83uhqVF5PBy");
tx.inputs[0].Sign(tx, txUnspent.outputs[0], pk);
Console.WriteLine(HexString.FromByteArray(tx.ToBytes()));
Script t = new Script(tx.inputs[0].scriptSig, txUnspent.outputs[0].scriptPubKey);
Console.WriteLine(t.Evaluate(tx, 0));
/****/
/*
int blockFileNum = 0;
FileStream fs = new FileStream(@"C:\Users\Administrator\AppData\Roaming\Bitcoin\blocks\blk" + blockFileNum.ToString("D5") + ".dat", FileMode.Open);
List<Block_Disk> blocks = new List<Block_Disk>();
List<Byte[]> blockHashes = new List<byte[]>();
List<Address> addrs = new List<Address>();
while (fs.Position < fs.Length)
{
Block_Disk b;
b = Block_Disk.FromStream(fs);
if (b.blockSize == 0)
{
blockFileNum++;
try
{
fs = new FileStream(@"C:\Users\Administrator\AppData\Roaming\Bitcoin\blocks\blk" + blockFileNum.ToString("D5") + ".dat", FileMode.Open);
}
catch (FileNotFoundException)
{
break;
}
continue;
}
foreach (Transaction t in b.txns)
foreach (TxOut txo in t.outputs)
{
addrs.Add(Address.FromScript(txo.script));
//Console.WriteLine(Address.FromScript(txo.script));
//Console.ReadLine();
}
//blockHashes.Add(b.prev_block);
//Console.WriteLine(HexString.FromByteArray(b.hash));
//blocks.Add(b);
}
Console.WriteLine(HexString.FromByteArray(blockHashes[blockHashes.Count() - 1]));
/**/
Console.ReadLine();
}
}
}