[Bitcoin-development] Version bytes

Pieter Wuille pieter.wuille at gmail.com
Thu Jul 7 19:40:08 UTC 2011


On Thu, Jul 07, 2011 at 01:15:57PM +0200, Pieter Wuille wrote:
> Hello everyone,
> 
> after a discussion on IRC, we decided to try to standardize the version bytes
> used by bitcoin for several applications.

I realize my mail may have been a bit unclear. This is about the version bytes
used in addresses and other base58-encoded data structures. I'd like to see some
convention adopted before everyone starts defining their own.

The proposal in the previous mail could be summarized by the following functions
(for non-alternate chains). It is compatible with all currently-used version bytes
that i know of (testnet, realnet, addresses, private keys, namecoin, multicoin):

enum dataclass_t 
{
    address = 0,
    privkey = 4,
    masterkey = 6,
    extended = 7
}

int EncodeVersionByte(dataclass_t class, int nVersion, bool fTestNet)
{
    return (class << 5 + nVersion << 1) ^ fTestNet*111;
}

void DecodeVersionByte(int nByte, dataclass_t& class, int& nVersion, bool& fTestNet)
{
    fTestNet = false;
    if (nByte & 1)
    {
        fTestNet = true;
        nByte ^= 111;
    }
    class = (nByte & 224) >> 5;
    nVersion = (nByte & 14) >> 1;
}

-- 
Pieter





More information about the bitcoin-dev mailing list