Where to ask about Bitcoin software?

My Submits are rejected. Going for short to see what happens.

Editing one line at a time.

Where can I research some questions about Bitcoin software and maybe ask questions?
The goal is to use the Bitcoin software to encode / decode Base58. This computer is Windows 11 using Visual Studio 2019. C++ of course. I presume the github version is for Linux and have not recognized a specific section for Windows. The list of includes is quite long and I cannot find them on this computer.

Some examples are from their common.h and a bunch of declarations:
le16toh, le32toh, le64toh, htole16, htole32, htole64, be16toh, be32toh, be64toh, htobe32, htobe64

Here is an example of the use of one of those items:

uint16_t static inline ReadLE16(const unsigned char* ptr)
{
uint16_t x;
memcpy((char*)&x, ptr, 2);
return le16toh(x);
}

Added a few lines at a time and looks like success.
Thank you for your time.
Last edited on
Here's a Base58 implementation in C#:
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
public class BaseX
{
    private string _alphabet;
    private Dictionary<char, int> _alphabetMap = new ();
    private int _base;
    private char _leader;

    public BaseX(string alphabet)
    {
        _alphabet = alphabet;
        _base = alphabet.Length;
        _leader = alphabet[0];

        for (int z = 0; z < alphabet.Length; z++)
        {
            var x = alphabet[z];
            if (_alphabetMap.ContainsKey(x))
                throw new Exception("Ambiguous alphabet for BaseX");
            _alphabetMap[x] = z;
        }
    }

    public string Encode(byte[] source)
    {
        if (source.Length == 0)
            return string.Empty;

        var digits = new List<int>{0};

        for (int i = 0; i < source.Length; i++)
        {
            int carry = source[i];
            for (int j = 0; j < digits.Count; j++)
            {
                carry += digits[j] << 8;
                digits[j] = carry % _base;
                carry /= _base;
            }

            while (carry > 0)
            {
                digits.Add(carry % _base);
                carry /= _base;
            }
        }

        var ret = new StringBuilder();

        // deal with leading zeros
        for (var k = 0; source[k] == 0 && k < source.Length - 1; ++k)
            ret.Append(_leader);
        // convert digits to a string
        for (var q = digits.Count - 1; q >= 0; --q)
            ret.Append(_alphabet[digits[q]]);

        return ret.ToString();
    }

    public byte[] Decode(string input)
    {
        if (input.Length == 0)
            return new byte[0];

        var bytes = new List<byte>{0};

        for (var i = 0; i < input.Length; i++)
        {
            if (!_alphabetMap.TryGetValue(input[i], out var value))
                return null;

            int carry = value;
            for (int j = 0; j < bytes.Count; ++j)
            {
                carry += bytes[j] * _base;
                bytes[j] = (byte)(carry & 0xff);
                carry >>= 8;
            }

            while (carry > 0)
            {
                bytes.Add((byte)(carry & 0xff));
                carry >>= 8;
            }
        }

        // deal with leading zeros
        for (int k = 0; input[k] == _leader && k < input.Length - 1; ++k)
            bytes.Add(0);

        bytes.Reverse();

        return bytes.ToArray();
    }

    public static BaseX Base58 = new BaseX("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
}

Usage:
1
2
var encoded = BaseX.Base58.Encode(new byte[]{ 1, 2, 3, 4 });
var decoded = BaseX.Base58.Decode(encoded);
htole64 for example is linux for endian / byte order correction.

you can use these in windows:
https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/byteswap-uint64-byteswap-ulong-byteswap-ushort?view=msvc-170

and likely just write a macro to convert the unix names to the windows names, but this smacks of a larger problem that the coders used OS specific junk once and probably will again. If you run into too many issues, you can use g++ on windows and it will probably be able to build the code using ported unix headers and libraries; an easy tool for this is cygwin, which has not only g++ but coder tools like grep as well which are nice to stuff into your commandline.

note that intel chips specifically have a hardware level byte reversal that can't be beat for performance, so try to avoid writing your own if you can get access to the chip level one. I am pretty sure the above library calls use the assembly level one.
Last edited on
I have had a difficult time post here and don't know why.
After looking at the bitcoin source code, and its plethora of include files, the conclusion is that I will look elsewhere for base 58 code.
I appreciate the C# code but will look for C++ code before I attempt a translation.
Thank you for taking the time to reply.
Registered users can post here. Sign in or register to post.