-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsrc.cpp
60 lines (51 loc) · 1.64 KB
/
src.cpp
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
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <bitcoin/bitcoin.hpp>
// Function to chunk transactions into 4MB chunks
std::vector<std::vector<bc::transaction>> chunk_transactions(const std::vector<bc::transaction>& transactions)
{
std::vector<std::vector<bc::transaction>> chunks;
std::vector<bc::transaction> current_chunk;
size_t current_chunk_size = 0;
for (const auto& tx : transactions)
{
size_t tx_size = bc::satoshi_size(bc::serialize(tx));
if (current_chunk_size + tx_size > 4000000)
{
chunks.push_back(current_chunk);
current_chunk.clear();
current_chunk_size = 0;
}
current_chunk.push_back(tx);
current_chunk_size += tx_size;
}
if (!current_chunk.empty())
{
chunks.push_back(current_chunk);
}
return chunks;
}
int main()
{
// Connect to Bitcoin Core
bc::config::endpoint endpoint("127.0.0.1", "8332");
bc::client::obelisk_client client(endpoint);
// Get the transactions for a given address
bc::payment_address address("1SomeAddress");
std::vector<bc::transaction> transactions;
client.list_unspent(address, transactions);
// Chunk the transactions into 4MB chunks
std::vector<std::vector<bc::transaction>> chunks = chunk_transactions(transactions);
// Output the chunks
for (size_t i = 0; i < chunks.size(); ++i)
{
std::cout << "Chunk " << i << ":" << std::endl;
for (const auto& tx : chunks[i])
{
std::cout << " " << bc::encode_base16(bc::serialize(tx)) << std::endl;
}
}
return 0;
}