public inbox for bitcoindev@googlegroups.com
 help / color / mirror / Atom feed
From: Pieter Wuille <pieter.wuille@gmail•com>
To: bitcoin-development@lists•sourceforge.net
Subject: Re: [Bitcoin-development] Version bytes
Date: Thu, 7 Jul 2011 21:40:08 +0200	[thread overview]
Message-ID: <20110707194007.GA27416@ulyssis.org> (raw)
In-Reply-To: <20110707111557.GA5231@ulyssis.org>

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




  reply	other threads:[~2011-07-07 19:40 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-07 11:15 Pieter Wuille
2011-07-07 19:40 ` Pieter Wuille [this message]
2011-07-08  6:36 ` Stefan Thomas
2011-07-08  8:16   ` John Smith
2011-07-08  8:18     ` John Smith
2011-07-08  9:25       ` Pieter Wuille

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110707194007.GA27416@ulyssis.org \
    --to=pieter.wuille@gmail$(echo .)com \
    --cc=bitcoin-development@lists$(echo .)sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox