How to make an altcoin

 truffle(development)> truffle test
SyntaxError: Unexpected identifier
    at REPLServer.Interface._onLine (readline.js:282:10)
    at REPLServer.emit (events.js:211:7)
    at emitOne (events.js:116:13)
    at REPLServer.onLine (repl.js:468:10)
    at REPLServer.runBound [as eval] (domain.js:314:12)
    at bound (domain.js:301:14)
    at ReplManager.interpret (/usr/local/lib/node_modules/truffle/build/webpack:/~/truffle-core/lib/repl.js:119:1)
    at Console.interpret (/usr/local/lib/node_modules/truffle/build/webpack:/~/truffle-core/lib/console.js:164:1)
    at Object.runInContext (vm.js:119:10)
    at createScript (vm.js:80:10)


pip install pip==9.0.3


  Complete output from command python setup.py egg_info:

    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-f_oeAm/merkle-proofs/setup.py", line 4, in <module>
        from pip.req import parse_requirements
    ImportError: No module named req
    
    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-f_oeAm/merkle-proofs/
ERROR: Service 'query_svc' failed to build: The command '/bin/sh -c pip install -r requirements.txt' returned a non-zero code: 1



ERROR: An HTTP request took too long to complete. Retry with --verbose to obtain debug information.

https://hyperledger-fabric.readthedocs.io/en/release-1.1/write_first_app.html


https://mshk.top/2017/11/go-ethereum-1-7-2-mist-0-9-2-token/?utm_medium=hao.caibaojian.com&utm_source=hao.caibaojian.com

geth --networkid 123 --dev --datadir data3 --rpc --rpcaddr 192.168.1.6 --rpcport 8989 --port 3000


geth attach ipc:geth.ipc
personal.listAccounts
personal.newAccount("123456")

https://plus.google.com/communities/104092405342699579599

sudo cp -rf node-gyp/ ./../../



Excluding it from installation.

[3/4] Linking dependencies...
warning " > gulp-babel@7.0.1" has unmet peer dependency "babel-core@6 || 7 || ^7.0.0-alpha || ^7.0.0-beta || ^7.0.0-rc".
warning " > gulp-spawn-mocha@3.3.1" has unmet peer dependency "istanbul@^0.4.3".
[4/4] Building fresh packages...
[1/7] ⠂ sha3
[2/7] ⠂ secp256k1
[3/7] ⠂ keccak
[6/7] ⠂ electron
error /home/tsinghua-yincheng/mist/node_modules/sha3: Command failed.
Exit code: 1
Command: node-gyp rebuild
Arguments:
Directory: /home/tsinghua-yincheng/mist/node_modules/sha3
Output:
module.js:549
    throw err;
    ^

Error: Cannot find module '/home/tsinghua-yincheng/.nvm/versions/node/v8.11.1/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Function.Module.runMain (module.js:693:10)







https://stackoverflow.com/questions/48143945/err-code-enolocal-npm-err-could-not-install-from



rpcserver.cpp:467:102: error: wrong number of template arguments (2, should be 1)
 t::shared_ptr< basic_socket_acceptor<Protocol, SocketAcceptorService> > accepto
                                                                     ^
In file included from /usr/local/include/boost/asio.hpp:30:0,
                 from rpcprotocol.h:15,
                 from rpcserver.h:10,
                 from rpcserver.cpp:6:
/usr/local/include/boost/asio/basic_socket_acceptor.hpp:73:7: note: provided for ‘template<class Protocol> class boost::asio::basic_socket_acceptor’
 class basic_socket_acceptor
       ^
rpcserver.cpp:467:104: error: template argument 1 is invalid
 :shared_ptr< basic_socket_acceptor<Protocol, SocketAcceptorService> > acceptor,
                                                                     ^
rpcserver.cpp:477:95: error: wrong number of template arguments (2, should be 1)
 t::shared_ptr< basic_socket_acceptor<Protocol, SocketAcceptorService> > accepto
                                                                     ^
In file included from /usr/local/include/boost/asio.hpp:30:0,
                 from rpcprotocol.h:15,
                 from rpcserver.h:10,
                 from rpcserver.cpp:6:
/usr/local/include/boost/asio/basic_socket_acceptor.hpp:73:7: note: provided for ‘template<class Protocol> class boost::asio::basic_socket_acceptor’
 class basic_socket_acceptor
       ^
rpcserver.cpp:477:97: error: template argument 1 is invalid
 :shared_ptr< basic_socket_acceptor<Protocol, SocketAcceptorService> > acceptor,
                                                     












说明成功安装docker。

下面添加阿里云的docker镜像。
注:这里还可以添加daocloud的镜像等其他镜像。
sudo mkdir -p /etc/docker
sudo gedit /etc/docker/daemon.json
将以下内容写入文本:

{
 "registry-mirrors": ["https://obou6wyb.mirror.aliyuncs.com"]
}

sudo systemctl daemon-reload
sudo systemctl restart docker
注销并重新登录。

出现这个问题,一般的原因是无法连接到 docker hub,通过:

systemctl stop docker
echo "DOCKER_OPTS=\"\$DOCKER_OPTS --registry-mirror=http://f2d6cb40.m.daocloud.io\"" | sudo tee -a /etc/default/docker
 service docker restart
然后就能正常使用docker  pull 

 sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 AAAD1D3563E5A736A4F561EE884D6308E89713C4


gnutls_handshake() failed: The TLS connection was non-properly terminated.

gpg: 找不到有效的 OpenPGP 数据。

卸载旧版本

老版本的Docker被称为dockerdocker-engine如果这些已安装,请将其卸载:

$ sudo apt-get remove docker docker-engine docker.io

如果apt-get报告说没有安装这些软件包,那就行了。

/var/lib/docker/包括图像,容器,卷和网络的内容将被保留。现在调用Docker CE包docker-ce

支持的存储驱动

Ubuntu上的Docker CE支持overlay2aufs存储驱动程序。

  • 对于Linux内核版本4及更高版本的新安装,overlay2 支持并优先于此aufs
  • 对于Linux内核的版本3,aufs支持因overlay或 overlay2驱动程序不是由内核版本的支持。

如果你需要使用aufs,你需要做如下所述的额外准备。

AUFS的额外步骤

对于Ubuntu 16.04及更高版本,Linux内核包含对OverlayFS的支持,而Docker CE overlay2默认使用存储驱动程序。如果您需要使用aufs,则需要手动配置。aufs

安装Docker CE

您可以根据您的需要以不同的方式安装Docker CE:

  • 大多数用户 设置Docker的存储库并从中进行安装,以便安装和升级任务。这是推荐的方法。

  • 有些用户下载DEB软件包并 手动安装,并完全手动管理升级。这对于在无法访问互联网的空隙系统上安装Docker等情况很有用。

  • 在测试和开发环境中,一些用户选择使用自动 便利脚本来安装Docker。

使用存储库进行安装

首次在新主机上安装Docker CE之前,需要设置Docker存储库。之后,您可以从存储库安装和更新Docker。

设置存储库
  1. 更新apt包裹索引:

    $ sudo apt-get update
    
  2. 安装软件包以允许apt通过HTTPS使用存储库:

    $ sudo apt-get install \
        apt-transport-https \
        ca-certificates \
        curl \
        software-properties-common
    
  3. 添加Docker的官方GPG密钥:

    $ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
    

    9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88通过搜索指纹的最后8个字符,确认您现在拥有带指纹的密钥 

    $ sudo apt-key fingerprint 0EBFCD88
    
    pub   4096R/0EBFCD88 2017-02-22
          Key fingerprint = 9DC8 5822 9FC7 DD38 854A  E2D8 8D81 803C 0EBF CD88
    uid                  Docker Release (CE deb) <docker@docker.com>
    sub   4096R/F273FCD8 2017-02-22
    
  4. 使用以下命令设置稳定的存储库。即使您想从边缘测试存储库安装构建,也总是需要稳定的存储 库。要添加边缘或 测试存储库,请在下面的命令中添加单词(或两者)后面的单词edgeteststable

    注意:下面的lsb_release -cs子命令返回您的Ubuntu发行版的名称,例如xenial有时候,在像Linux Mint这样的发行版中,您可能需要更改$(lsb_release -cs) 为您的父级Ubuntu发行版。例如,如果您正在使用Linux Mint Rafaela,您可以使用trusty

    $ sudo add-apt-repository \
       "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
       $(lsb_release -cs) \
       stable"
    

    注意:从Docker 17.06开始,稳定版本也被推到边缘测试版本库。

    了解稳定边缘频道

安装DOCKER CE
  1. 更新apt软件包索引。

    $ sudo apt-get update
    
  2. 安装最新版本的Docker CE,或者转到下一步安装特定版本:

    $ sudo apt-get install docker-ce
    

    有多个Docker存储库?

    如果启用了多个Docker存储库,则安装或更新时如果未指定版本apt-get install或 apt-get update命令,则始终会安装尽可能高的版本,这可能不适合您的稳定性需求。

  3. 要安装特定版本的Docker CE,请列出回购站中的可用版本,然后选择并安装:

    一个。列出您的回购中可用的版本:

    $ apt-cache madison docker-ce
    
    docker-ce | 18.03.0~ce-0~ubuntu | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
    

    湾 例如,通过其完全限定的软件包名称来安装特定的版本,该名称是软件包名称(docker-ce)加上版本字符串(第2列),直到第一个连字符,用等号(=) 分隔docker-ce=18.03.0.ce

    $ sudo apt-get install docker-ce=<VERSION>
    

    Docker守护进程自动启动。

  4. 通过运行hello-world 映像验证是否正确安装了Docker CE 

    $ sudo docker run hello-world
    

    该命令下载测试图像并将其运行到容器中。当容器运行时,它会打印一条信息消息并退出。

Docker CE已安装并正在运行。docker组已创建,但未添加用户。您需要使用sudo运行Docker命令。继续Linux postinstall以允许非特权用户运行Docker命令以及其他可选配置步骤。

升级DOCKER CE

要升级Docker CE,首先运行sudo apt-get update,然后按照 安装说明选择要安装的新版本。

从包中安装

如果您不能使用Docker的存储库来安装Docker CE,则可以下载该 .deb文件以供手动安装。每次要升级Docker CE时,都需要下载一个新文件。

  1. 转到https://download.docker.com/linux/ubuntu/dists/,选择你的Ubuntu版本,浏览pool/stable/和选择amd64armhfppc64el,或s390x下载.deb您想要安装的Docker版本文件。

    注意:要安装边缘 软件包,stable请将URL中的单词更改 edge。 了解稳定边缘频道

  2. 安装Docker CE,将下面的路径更改为您下载Docker软件包的路径。

    $ sudo dpkg -i /path/to/package.deb
    

    Docker守护进程自动启动。

  3. 通过运行hello-world 映像验证是否正确安装了Docker CE 

    $ sudo docker run hello-world
    

    该命令下载测试图像并将其运行到容器中。当容器运行时,它会打印一条信息消息并退出。

Docker CE已安装并正在运行。docker组已创建,但未添加用户。您需要使用sudo运行Docker命令。继续进行Linux的安装后步骤,以允许非特权用户运行Docker命令以及其他可选配置步骤。

升级DOCKER CE

要升级Docker CE,请下载较新的软件包文件并重复 安装过程,指向新文件。

使用便捷脚本进行安装

Docker在get.docker.com 和test.docker.com上提供了便捷脚本,用于快速非交互式地将Docker CE的边缘和测试版本安装到开发环境中。脚本的源代码位于 docker-install存储库中。 不建议在生产环境中使用这些脚本,并且在使用它们之前应了解其潜在风险:

  • 脚本需要rootsudo权限才能运行。因此,在运行脚本之前,应仔细检查和审核脚本。
  • 这些脚本会尝试检测您的Linux发行版和版本,并为您配置您的软件包管理系统。另外,这些脚本不允许您自定义任何安装参数。这可能会导致不支持的配置,无论是从Docker的角度还是从您自己的组织准则和标准。
  • 这些脚本会安装包管理器的所有依赖关系和建议,而不要求确认。这可能会安装大量的包,具体取决于主机的当前配置。
  • 该脚本不提供指定要安装哪个版本的Docker的选项,并安装在“边缘”通道中发布的最新版本。
  • 如果Docker已经使用其他机制安装在主机上,请勿使用便捷脚本。

本示例使用get.docker.com的脚本在Linux上安装Docker CE的最新版本。要安装最新的测试版本,请改用test.docker.com在下面的每个命令,取代每次出现gettest

警告

在本地运行之前,始终检查从互联网上下载的脚本。

$ curl -fsSL get.docker.com -o get-docker.sh
$ sudo sh get-docker.sh

<output truncated>

If you would like to use Docker as a non-root user, you should now consider
adding your user to the "docker" group with something like:

  sudo usermod -aG docker your-user

Remember to log out and back in for this to take effect!

WARNING: Adding a user to the "docker" group grants the ability to run
         containers which can be used to obtain root privileges on the
         docker host.
         Refer to https://docs.docker.com/engine/security/security/#docker-daemon-attack-surface
         for more information.

Docker CE已安装。它会自动启动DEB基于目录的分发。在 RPM基于分布的情况下,您需要使用适当systemctlservice命令手动启动它 如消息所示,非root用户默认情况下不能运行Docker命令。

在使用便利脚本后升级DOCKER

如果您使用便捷脚本安装Docker,则应直接使用软件包管理器升级Docker。重新运行便捷脚本没有任何优势,如果它试图重新添加已添加到主机的存储库,则会产生问题。

卸载Docker CE

  1. 卸载Docker CE软件包:

    $ sudo apt-get purge docker-ce
    
  2. 不会自动删除主机上的图像,容器,卷或自定义配置文件。删除所有图像,容器和卷:

    $ sudo rm -rf /var/lib/docker
    

您必须手动删除任何已编辑的配置文件。









卸载组件

第1步:卸载CLI工具

任何正在运行的CLI工具实例都应在继续之前停止。如果您有任何正在运行的Composer REST服务器实例,请确保这些实例在继续之前停止。composer-rest-server如果您不确定是否有任何正在运行的实例,则可以查找该进程

  1. 卸载所有CLI工具的当前安装版本:

    复制
    npm uninstall -g composer-cli composer-rest-server generator-hyperledger-composer
    

第2步:卸载Playground

如果您在开发计算机上安装了浏览器应用程序“Playground”,则还需要卸载此应用程序。如果您有任何正在运行的浏览器应用程序实例,请确保在继续之前停止这些实例。composer-playground如果您不确定是否有任何正在运行的实例,则可以查找该进程

  1. 卸载当前安装的浏览器应用程序版本:

    复制
    npm uninstall -g composer-playground
    

第3步:删除业务网卡存储

商业网卡存储在商业网络卡商店中,默认情况下它是当前用户主目录中的一个目录。删除此目录以删除所有业务网卡。要注意的是,这也将删除存储在商业网络存储卡中的所有身份(公共证书和私钥),因此您可能希望在继续之前对其进行备份!

  1. 删除商业网络卡商店:

    复制
    rm -rf ~/.composer
    

步骤4:卸载Hyperledger Fabric

您可以使用一组脚本来控制本地Hyperledger Fabric运行时,~/fabric-tools如果您遵循了建议的默认值,您将在其中找到这些脚本

  1. 停止本地Hyperledger Fabric运行时并删除任何运行时Docker容器或映像:

    复制
    ~/fabric-tools/stopFabric.sh
    ~/fabric-tools/teardownFabric.sh
    
  2. 卸载本地Hyperledger Fabric运行时:

    复制
    rm -rf ~/fabric-tools
    

恭喜,你已经卸载了你的开发环境。要继续开发区块链应用程序,您需要从头开始安装开发工具。




test/test_test_bitcoin-arith_uint256_tests.o: In function `arith_uint256_tests::shifts::test_method()':

/home/tsinghua-yincheng/桌面/mmm/bitcoin/src/test/arith_uint256_tests.cpp:162: undefined reference to `boost::test_tools::tt_detail::report_assertion(boost::test_tools::assertion_result const&, boost::unit_test::lazy_ostream const&, boost::unit_test::basic_cstring<char const>, unsigned long, boost::test_tools::tt_detail::tool_level, boost::test_tools::tt_detail::check_type, unsigned long, ...)'




Most recent 'Cryptocurrency 101' blog post at 


http://dillingers.com/blog/2015/04/18/how-to-make-an-altcoin/

Explains how to adapt the Bitcoin 0.10 sources to make an altcoin.


For educational purposes mostly, although I'm sure it will mean some people make alts that otherwise wouldn't have.  


Here's a paste of the full text article:  Additions and corrections are welcome.
http://blog.luoyuanhang.com/2018/04/08/fastcoin-multinodes/?utm_source=tuicool&utm_medium=referral

How to make an altcoin

Okay, I’m going to preface this article by asking you two things:

First, WHY do you want to create an altcoin?

This is a starting point.  If you don’t have some original ideas, and the ability to actually read and write C++ code to implement them, then you’re going to create something that can’t do anything Bitcoin can’t do, and in that case there’s no point in releasing it.  So don’t.

If you want to release an altcoin, pump it, get a lot of suckers to invest their money, bribe a cryptocurrency exchange to put up a trading market in it, and then dump a bunch of premined coins on the inflated market and leave all the suckers holding the bag, then “don’t” isn’t quite all the advice I want to give you.  Additionally, “go die in a fire”.

So. If you have a reason to create an altcoin – something you’ve thought of a way to do that won’t ever get into Bitcoin itself and which would enable your ideal cryptocurrency to function in ways Bitcoin can’t – then I have a second question for you.

Can you commit yourself to maintaining a release?

This is serious. If you’re going to release an altcoin, you’re going to have a forty-hour-a-week job supporting it. You’re going to have to spend time every day just reading the code to make sure you know what every part of it does. And you’ll need that knowledge, because you’re going to have to figure out technical problems and make technical fixes, in emergency situations, when some joker attacks your block chain. Bitcoin has some stability because Bitcoin has a majority of the hashing power on the planet devoted to it. Your altcoin isn’t even a fart in a hurricane yet, and your proof-of-work block chain will be subject to attacks that you’re going to have to either anticipate or counter in real time. Reading code every day is preparation. The only way you can find your way around it fast enough to make fixes is if you know it inside and out. Anyway, you can have a full time job, or a social and family life, and maintain a released altcoin – but probably not both, unless you’re one of those people who regards sleep as a wholly inadequate time-wasting substitute for caffeine.

Now, with all that said, this article will cover only the beginning of the process: shamelessly cloning an existing coin. Whatever innovations you intend to make, I can’t anticipate them, so there’s no guide here to making them. You have to read the code until you understand it well enough to make them yourself. For purposes of this article, we’re going to use Bitcoin’s 0.10 source code, we’re going to make a near-clone of it named “Newcoin”, and I’m going to be working with Debian Jessie.

Get the source code
Open up a command line shell. Make a new directory in your home directory named src. It’s where you’ll be working. So your first three command lines are

Code:
cd
mkdir src
cd src

Now use your web browser to go to  https://bitcoin.org/en/download , find the button in the lower right corner of the box that says “source code”, and get the archive. Its name should be bitcoin-0.10.0(1).tar.gz. Copy it into your new directory and unpack it using the commands:

Code:
cp ~/Downloads/bitcoin-0.10.0\(1\).tar.gz .
tar xvf bitcoin-0.10.0\(1\).tar.gz
cp -r bitcoin-0.10.0 newcoin

In the above two commands, the backslashes before the parens are because there are actual parentheses in the filename, and if you just type them, your shell will try to interpret the command differently. And the directory ~/Downloads is where stuff lands on my system when I download it with my web browser. If you’ve got yours set up differently, you should adjust the command to use your download directory instead, whatever it’s named.

And the last command makes a clone of the bitcoin-0.10.0 directory named newcoin – with its own copies of all the files you just extracted. You should use whatever you want thename of your new altcoin to be for the name of this directory.

Next, you need to get all the stuff that building Bitcoin depends on. Here’s a sequence of commands to do that.

Get the stuff the code depends on

Code:
su
echo 'deb-src ftp://ftp.us.debian.org/debian/ sid main contrib non-free' >> /etc/apt/sources.list
apt-get update
apt-get build-dep bitcoin
apt-get –install-recommends install libbitcoin-dev
exit
Now, I cheated a little bit here. Debian has a Bitcoin package available in its ‘sid’ distribution, but it doesn’t use the same version of the source code we want to work with. The first line makes you root, because root has the permission to modify sources.list and install packages. It’ll ask for the root password and you need to enter it. The second line changes sources.list to add the sid sources to what’s available to your apt command. The third line tells Debian to download all the meta-information about those sources, so it knows what the build process for these packages require. The fourth and fifth lines tell it to download and install all the stuff you would need to build the sid Bitcoin source code package. But you didn’t download the sid source code package, you downloaded the new source code directly from the site instead. The cheat is that the dependencies are the same, so this is an easy way to get everything you need to build. And the last line is to quit being root.

Test build to make sure you got everything set up
The next step is build Bitcoin just to make sure you got everything. So let’s do that. Here are some more command lines. Some of these may take a few minutes to run to completion; this is normal.
Code:
cd bitcoin-0.10.0
aclocal
automake --add-missing
./configure --with-incompatible-bdb
make
How all that worked. (the Automake system)
aclocal generates a file called ‘aclocal.m4′ which is a bunch of macro definitions and so on that automake works with. There was already an aclocal.m4 in the directory, but it is for a version of automake that probably isn’t the one installed on your Jessie system.

automake –add-missing invokes automake, which uses those macros and the file Makefile.am, which is already there, to create another file named Makefile.in. The –add-missing argument tells it to create a couple of standard macro packages that automake uses, because the Bitcoin sources didn’t provide them; it didn’t need to provide them, because it uses the defaults provided by –add-missing.

Makefile.in specifies what configuration needs to know and do and saves that in a shell script named configure. Then ./configure runs that shell script, which tests a lot of things on your system, finds what’s available to build with and link against, and generally figures out in detail how to build the Bitcoin sources it’s looking at, saving that information in a makefile. The –with-incompatible-bdb argument says it’s okay with you to use a version of the Berkeley database later than the one the original Bitcoin client was built with.

Finally make actually uses the makefile that you just built using ./configure, to build the Bitcoin project.

And if you got all the stuff you needed to build with, the whole process should finish without an error.

Check to make sure your test build worked.
Here’s a couple more command lines to make sure that the build worked, by checking to make sure the executable files it was supposed to build are actually there.

Code:
ls src/bitcoind
ls src/bitcoin-cli
ls src/qt/bitcoin-qt
Got ‘em? Excellent! That means your build environment has everything you need to work with to make an altcoin. So, now that the smoke test is over, it’s time to actually go to the newcoin directory and start making your altcoin. So here are some more command lines:
Start your altcoin by using its name instead of Bitcoin's
Code:
cd ~/src/newcoin
find . -type f -print0 | xargs -0 sed -i 's/bitcoin/newcoin/g'
find . -type f -print0 | xargs -0 sed -i 's/Bitcoin/Newcoin/g'
find . -type f -print0 | xargs -0 sed -i 's/BitCoin/Newcoin/g'
find . -type f -print0 | xargs -0 sed -i 's/BITCOIN/NEWCOIN/g'
find . -type f -print0 | xargs -0 sed -i 's/BTC/NCN/g'
find . -type f -print0 | xargs -0 sed -i 's/btc/NCN/g'
find . -type f -print0 | xargs -0 sed -i 's/Btc/NCN/g'
The first four commands change every occurrence of the string ‘bitcoin’ in four capitalizations to the string ‘newcoin’ in all the files in this directory or under it, in three different capitalizations. The second three commands do the same thing to the string ‘btc’, transforming every instance of it into all-caps.

Rename 'bitcoin' filenames to the name of your altcoin
Now, because this also affected makefiles which contain filenames, and affected source files which have filenames in their include statements, you’ve got to change all the filenames that have the string ‘bitcoin’ in them to match what’s now in the include statements and makefiles. Fortunately, this is just as easy.
Code:
find . -exec rename 's/bitcoin/newcoin/' {} ";"
find . -exec rename 's/btc/NCN/' {} ";"
Will rename every file that has ‘bitcoin’ or ‘btc’ in the name, recursing into subdirectories as needed. So now your filenames match up with your changed makefiles and include statements.


Check for stuff your edits missed because it was misspelled.
Now look for misspellings of it.
Code:
grep -ir bitc
Aside from uncovering a bunch of references in source code to nDebitCached and a few similarly named variables, reveals that in Arabic translations ‘Bitcoin’ was rendered as ‘Bitcion’ in several translated sentences. In Dutch, it mentions a "bitcon:-URI", and it became ‘Bitconi’ once in a language I don’t recognize at all but which may be Estonian.

The Dutch is certainly a misspelling, because URI’s are spelled the same regardless of language. So
Code:
sed -i 's/bitcon/newcoin/' src/qt/locale/newcoin_da.ts
sorts that.

I remember about Arabic that it inflects words using patterns of triple vowels, and ‘bitcion’ is used more than once, so it might not be a misspelling. A quick check on Google, however, reveals a lot of instances of ‘Bitcoin’ misspelled in English, and no Arabic pages. So with more evidence, I think I’ll conclude that it probably is a misspelling – about which, again, there’s a chance I’m wrong, and if ‘newcoin’ were what you were actually naming your new alt, you should write on your list of things to do asking someone who actually speaks Arabic about it. But for now patch it using
Code:
sed -i 's/bitcion/newcoin/' src/qt/locale/newcoin_ar.ts
And then there’s the Estonian-or-whatever-it-is. I haven’t heard of any languages outside the middle east that inflect by modifying vowel sequences, and ‘Bitconi’ seems likely to be a misspelling, so once more I’ll just make a possibly-dumb assumption and patch it.
Code:
sed -i 's/Bitconi/Newcoin/' src/qt/locale/newcoin_et.ts
Fix the copyright notices and credits

Now, the license under which you have access to this code mentions, among other things, leaving copyright notices intact – and you mangled ‘em when you switched ‘Bitcoin’ to ‘Newcoin’ because the boilerplate line there refers to the ‘Bitcoin Development Team’. So you need to change ‘Newcoin’ back to ‘Bitcoin’ but only on the lines where it’s part of a copyright statement.
Code:
find . -type f -print0 | xargs -0 sed -i '/opyright/ s/Newcoin/Bitcoin/' {} ";"
sorts that. I left the first letter off of ‘Copyright’ because I didn’t want it to care about the capitalization.

There were also a lot of references to Bitcoin in the release-notes files, and it would be an outright lie to pretend that those earlier releases were releases of your alt rather than releases of Bitcoin, so those need changed back, too.
Code:
sed -i 's/newcoin/bitcoin/g' doc/release-notes/*
sed -i 's/Newcoin/Bitcoin/g' doc/release-notes/*
handles that.

Change the port numbers
Bitcoin uses ports 8332 and 18332 on its main net and 8333 and 18333 on its test net. You want newcoin to use different ports, just to make it handy for people to run both clients at the same time.
Code:
find . -type f -print0 | xargs -0 sed -i 's/8332/9443/' {} ";"
find . -type f -print0 | xargs -0 sed -i 's/8333/9444/' {} ";"
will switch newcoin to using ports 9443 and 19443 on mainnet and 9444 and 19444 on testnet. Once again, you should provide your own values. But don’t change any of the port numbers to anything below 1000, or nobody except root will be able to run it. I should mention here that in addition to the port numbers, you just changed a couple of hex strings in the testing directory that the test framework feeds to the RPC interface. But you were going to fail those tests anyway, because other edits you’re making will make Newcoin keys different from Bitcoin keys.

Use your own artwork
You don’t really want to show Bitcoin’s icons and images every time you start up, so you need to go and edit some graphics in the directory src/qt/res. When editing, be sure to save new images that are exactly the same size and file format as the old ones. When you want to change the sizes and/or file formats, you need to understand the QT framework first.

I don’t have any nifty command lines that can help you make good art, so you’re on your own here. At the very least, you’re going to want to edit newcoin.ico, newcoin.png, newcoin_testnet.ico, newcoin_testnet.png, and newcoin.icns. I suggest using GIMP for all of these edits; it speaks all those graphics formats. The ico and icns files are particularly annoying to deal with because you have to make similar (but not identical) changes on many different layers of the saved image.

Build for the first time
Now we’re done with wholesale edits. It’s time to see whether you broke anything yet. So type
Code:
aclocal;automake --add-missing;./configure --with-incompatible-bdb;make
and wait a few minutes. 

Did it build? You now have newcoind, newcoin-cli, and newcoin-qt? Awesome! So now that we managed to get the wholesale edits right, it’s time to actually look at source code and start doing some very specific edits. 

In chainparams.cpp, edit the checkpoints

Get your favorite programming editor, go to the newcoin/src/ directory, and open up chainparams.cpp.

Search for the string ‘mapCheckpoints’ and it will take you immediately to line 55, which sets a static variable named mapCheckpoints to a list of pairs – the first member of each pair is the block height, and the second is the hash of that block. The Bitcoin client uses these as it verifies the Bitcoin block chain. So if you leave those in, the newcoin client will be looking for blocks that don’t exist in the newcoin block chain. So get rid of ‘em, and put a place holder for your genesis block in instead. This place holder will be wrong, but we can’t fix it until after we mine a genesis block. After your edit, it should look like this:

Code:
static Checkpoints::MapCheckpoints mapCheckpoints =
boost::assign::map_list_of
( 0, uint256("0x001"));
Zero is the block height of the genesis block, and uint256(“0×001″) is a wild guess about what the hash is going to be.

Make the same edit at the locations where it sets ‘mapCheckpointsTestnet’ and ‘mapCheckpointsRegtest’.

Edit the Checkpoint Data
Right under each of these edited checkpoint lists, there are statements that set a corresponding variable. These are named data (for the main network), dataTestnet (for the test network), and dataRegtest (for regression testing). Go to the command line and type
Code:
date +%s
to find out what the current unix epoch date is, then overwrite the first number in each of these blocks with the current date. You’ll have to do this again (and mine new genesis blocks) right before launch. The second number in each block is a transaction count as of the most recent checkpoint; it should be replaced by zero, because there are no transactions before the genesis block. The third number doesn’t matter as much, but for now I suggest 500 for the main network, 250 for the test network, and zero for the regtest. Updating these numbers as the amount of traffic on your coin’s block chain changes is one of the things you do as dev, if you want your clients to make accurate estimates of their progress as they reindex or verify the block chain.

Change the protocol 'magic' bytes

The next block after dataRegtest is setting another variable named CMainParams. And you have a lot of things to change here. The first four lines of code set values in an array called pchMessageStart. These are the network ‘magic bytes’; They’re a series of four bytes that identify messages as belonging to a particular protocol. 0xf9, 0xbe, 0xb4, and 0xd9 are the ones Bitcoin uses. You want to use something else, so that nobody can ever trick your newcoin client into connecting to the Bitcoin network, or vice versa. It doesn’t matter what these are except that they shouldn’t match the ones used in other protocols (particularly other cryptocurrency block chains). They have to be values between 0 and 255. I suggest going back to the shell and using
Code:
echo $RANDOM
Just repeat the command, and write down the last three digits whenever they’re under 255. When you’ve got four of them, set the pchMessageStart values in CMainParams. When you’ve got four more, set the pchMessageStart values in CTestNetParams. And when you’ve got four more, set the pchMessageStart values in CRegTestParams.

Make your alert and genesis coinbase keys
The next line (in the first two params objects) sets vAlertPubKey values. So go back to the command line to get some.
Code:
openssl ecparam -genkey -name secp256k1 -out alertkey.pem
openssl ec -in alertkey.pem -text > alertkey.hex
openssl ecparam -genkey -name secp256k1 -out testnetalert.pem
openssl ec -in testnetalert.pem -text > testnetalert.hex
openssl ecparam -genkey -name secp256k1 -out genesiscoinbase.pem
openssl ec -in testnetalert.pem -text > genesiscoinbase.hex
Will create private keys and drop them into files named alertkey.pem, testnetalert.pem, and genesiscoinbase.pem, then expand them into key pairs and drop the key pairs in hex format into files named alertkey.hex, testnetalert.hex, and genesiscoinbase.hex.

Insert your alert keys
Code:
cat alertkey.hex
Will show the contents of alertkey.hex. Copy the four lines that appear between ‘pub’ and ‘ASN1 OID: secp256k1′ and paste them into the source code file replacing the string contents in the line that says vAlertPubKey = ParseHex(“…”);

Then edit to strip the colon characters and linefeeds out of it, and you’ve got an alert key. If you ever need to send an alert out over the network, you can use the corresponding private key.
Code:
cat testnetalert.hex
will show you a key for testnet, so you can set the vAlertPubKey the CTestNetParams block. The CRegTest block doesn’t have one of its own; if it ever needs one, it uses the testnet key.

Edit the timestamp string
Now we skip down to the famous timestamp string, at the line
Code:
const char* pszTimestamp = "The Times 03/Jan/2009 Chancellor on brink of second bailout for banks";
It’s traditional to pick a newspaper headline for the day of launch, but you don’t have to. Whatever you use, keep it short. If it’s over 90 characters or so the block will fail a length check that’s supposed to prevent denial-of-service attacks from people attaching big data to transactions.

Insert the genesis pubkey.
Code:
cat genesiscoinbase.hex
will show you a key for the genesis coinbase transaction, so you can paste that into the CMainParams block replacing the string contents in the line
Code:
txNew.vout[0].scriptPubKey = CScript() << ParseHex("...") << OP_CHECKSIG;

Set the date in CMainParams
Going down a little more, change the line in the CMainParams block that sets genesis.nTime so that it sets it to the same Unix epoch date you got using the ‘date’ command above. Repeat that edit in the CTestNetParams block.

Delete Bitcoin's seed nodes
Skipping down past the hashGenesisBlock stuff, you’ll see a series of lines that set values for a list named vSeeds. These are network addresses where long-lived Bitcoin nodes are supposed to be found, so that people can always connect to the Bitcoin network. Which, as you’re establishing now, is not your network. Until you put up servers to do that for your new network, replace these lines (in both CMainParams and CTestNetParams) with the simple statements:
Code:
vFixedSeeds.clear();
vSeeds.clear();

Change the Key prefixes
Moving on down, we get to a block of statements that set values in an array of lists named base58Prefixes. These are prefix bytes that are added to the keys. By setting them to different values, you can assure that keys for coins on Newcoin’s network will never be valid Bitcoin keys and vice versa. To a certain extent, setting these numbers also determines what characters the base58 form of the keys that users see starts with. The chances of a random collision in keys are ridiculous, but “chances” and “random” are quaint old-fashioned ideas here; you’re working on code that somebody is going to deliberately attack. So change the values. You can use echo $RANDOM at the command line again if you want. If you care about what initial characters your choices will result in for the base58 form of the keys, consult the list at the Bitcoin wiki. There is one important constraint here: none of the lists can be identical, because the clients look at the initial bytes to figure out what kind of key they’re dealing with. Also, don’t change the length of any list until you’ve read the code enough to know everything that will affect.

PUBKEY_ADDRESS is the value prefixed to public keys – these are the public half of the pubkey/private key pair that represents a txOut and the ability to spend it. SECRET_KEY, predictably, are the prefixes for the private half of the pair. SCRIPT_ADDRESS is affixed to addresses that are the hashes of scripts; looking for the difference between the initial bytes is how the client knows which of the two “default” spend scripts to apply. Finally, EXT_PUBLIC_KEY and EXT_SECRET_KEY are four-byte prefixes for the so-called “stealth addresses” that got introduced in Bitcoin version 0.9, which allow fun things like addresses that can be used to generate new keys that can receive payments but not spend them. Aaaanyway, it doesn’t matter what you change them to, it just matters that they don’t match anything they might ever be confused with, like Bitcoin keys – or each other. So give them new values in CMainParams, CTestNetParams, and CRegTestParams.

Add code to mine a genesis block
Finally, we’re just about ready to mine a Genesis block. But the code to actually mine a Genesis block hasn’t been in Bitcoin for a long time; that block is already mined. Its parameters are there to check against, but there’s no code to establish what some of them ought to be. You need to fix that. So in the CMainParams initializer, right after
Code:
genesis.nNonce = 414098458;
and before
Code:
hashGenesisBlock = genesis.GetHash();
assert(hashGenesisBlock == uint256("....."));
assert(genesis.hashMerkleRoot == uint256("....."));
paste this code:
Code:
hashGenesisBlock = uint256("0x01");
if (true && genesis.GetHash() != hashGenesisBlock)
        {
            Logprintf("recalculating params for mainnet.\n");
            Logprintf("old mainnet genesis nonce: %s\n", genesis.nNonce.ToString().c_str());
            Logprintf("old mainnet genesis hash:  %s\n", hashGenesisBlock.ToString().c_str());
            // deliberately empty for loop finds nonce value.
            for(genesis.nNonce == 0; genesis.GetHash() > bnProofOfWorkLimit; genesis.nNonce++){ } 
            Logprintf("new mainnet genesis merkle root: %s\n", genesis.hashMerkleRoot.ToString().c_str());
            Logprintf("new mainnet genesis nonce: %s\n", genesis.nNonce.ToString().c_str());
            Logprintf("new mainnet genesis hash: %s\n", genesis.GetHash().ToString().c_str());
        }
Use the same code in the CTestNetParams initializer, except change ‘mainnet’ into ‘testnet.’ Likewise the CRegTestParams initializer, except change ‘mainnet’ into ‘regtest’.

Now build again. This time you have already done all the autoconf stuff, so you just need to type
Code:
make
and you only changed one file, which isn’t included anywhere else. So it should be built in a few seconds.

Mine the genesis block and insert the new values
Got all that? Now run newcoin-qt.

It will throw up a dialog box asking where to install. Let it have the default it wants, which will be a new subdirectory of your home directory named ~/.newcoin.

Then Nothing will happen.  For twenty minutes to an hour, usually.  Maybe more than an hour, depending on dumb luck and the speed of your computer.  If your computer’s slow, this may be a good time to go get a sandwich.

Here's what's actually happening.  It set the nonce, hashed the genesis block, noticed it didn’t match 0x01, and is now living in that tight little empty for loop, incrementing the hash, hashing the block, and checking to see whether the new hash is low enough to meet proof-of-work requirements.

After a while, it will die. Meaning, it found a nonce that gave the genesis block a hash low enough to pass proof-of-work, got out of the for loop, logged the new hash and nonce and the Merkle tree value, and then hit the assert that still insists on the hash value being Bitcoin’s genesis block hash value. So you want to see the new values. Type
Code:
tail ~/.newcoin/debug.log
and you’ll see the last few lines of logfile output.
Now you have a nonce and a hash and a Merkle root so go change the necessary lines in the CMainNet initializer.

In the code you pasted in, you initialized hashGenesisBlock to uint256("0x01").  Change that to your new genesis hash.

Right above the code you pasted in, you’ll see a line that sets a value for genesis.nNonce. Change it to your new nonce value.

Right below the code you pasted in, you’ll find assert() statements that check the value of the Merkle root and the hash. Change those to your new Merkle root and Hash values.

Near the top of the file, there’s your mapCheckpoints list, claiming that the hash of the genesis block is 0×01. Change that to your new hash value.

Mine the Testnet and Regtest genesis blocks
Once you’ve made these edits, recompile and run it again. The same thing will happen all over, but this time for testnet. And you change the same things in the CTestNetParams initializer (and the testnet checkpoints) that you changed for CMainParams.

Recompile and run it again, and it will trip on the regtest values. So you change the same things in the CRegTestParams initializer.

STOP mining genesis blocks
Okay? Now you have mined your genesis block. Now, in the code you pasted in, see where the stupid-looking if condition checks for
Code:
if (true && genesis.GetHash() != hashGenesisBlock)
?
Change those three ‘true’s to ‘false’s. The purpose of this ‘true/false’ business is to make it easy for you to switch back and forth from mining genesis blocks to not mining genesis blocks. You’ll need to mine a new genesis block right before launch, and may need several more during testing and development depending on whether you do anything that changes the block headers or initial coinbase transaction. But in the client you actually test and release, you don’t want genesis block mining turned on. If it sees a wrong genesis block in its folder, you want it to bomb out immediately, not sit there chewing and trying to create a new one.

Whenever you need to mine new genesis blocks because you changed something that invalidated the old one during development, you can come back to chainparams.cpp, update the date parameter and timestamp string, make the three true/false edits, recompile, do
Code:
rm -rf ~/.newcoin 
so it doesn’t see the (now) wrong former genesis block in the data there, and mine new genesis blocks.

What you've got

At this point you have created a complete, and completely simple, clone of Bitcoin version 0.10. If this is all you’re doing, then it’s been a nice learning experience but don’t launch this coin. Unless doing something new, there is no point.

Problems you still need to fix

This thing you have created cannot possibly survive as an altcoin; Aside from having no network seeds of its own, its difficulty adjustment algorithm will not respond quickly enough to prevent your block chain from getting instamined, and then stuck. Mining whales will scoop up two weeks of coins while processing almost no transactions, in less than an hour while your block chain is profitable, then when the difficulty adjustment for that two weeks hits they’ll leave your chain with an impossibly high difficulty and go on to something else. You won’t get a block for days and nobody will be able to use your alt to make any kind of transaction because of it. The result is a block chain that can handle transactions for maybe two hours out of every year, which is useless to everyone.

So the next thing you need to do is go fix that. And when you’ve fixed it, your new alt still won’t be capable of surviving; everybody has fixes for the difficulty problem that a cloned coin creates. Once again, you either have a new idea and the ability to develop and support it, or you don’t have anything that’s worthwhile to launch. What I have shown you here are the first three steps on a long road.

I’ll talk about one way to fix the difficulty in the next installment.






git checkout 0.10


find . -type f -print0 | xargs -0 sed -i 's/bitcoin/yinchengcoin/g'


find . -type f -print0 | xargs -0 sed -i 's/Bitcoin/Yinchengcoin/g'


find . -type f -print0 | xargs -0 sed -i 's/BitCoin/Yinchengcoin/g'


find . -type f -print0 | xargs -0 sed -i 's/BITCOIN/YINCHENGCOIN/g'


find . -type f -print0 | xargs -0 sed -i 's/BTC/YCC/g'


find . -type f -print0 | xargs -0 sed -i 's/btc/YCC/g'


find . -type f -print0 | xargs -0 sed -i 's/Btc/YCC/g'


find . -exec rename 's/bitcoin/yinchengcoin/' {} ";"


find . -exec rename 's/btc/YCC/' {} ";"


find . -type f -print0 | xargs -0 sed -i 's/8332/9443/' {} ";"


find . -type f -print0 | xargs -0 sed -i 's/8333/9444/' {} ";"











// Copyright (c) 2010 Satoshi Nakamoto
// Copyright (c) 2009-2014 The Xuncoin developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.


#include "chainparams.h"


#include "random.h"
#include "util.h"
#include "utilstrencodings.h"


#include <assert.h>
#include<stdio.h>
#include <boost/assign/list_of.hpp>


using namespace std;
using namespace boost::assign;


struct SeedSpec6 {
    uint8_t addr[16];
    uint16_t port;
};


#include "chainparamsseeds.h"


/**
 * Main network
 */


//! Convert the pnSeeds6 array into usable address objects.
static void convertSeed6(std::vector<CAddress> &vSeedsOut, const SeedSpec6 *data, unsigned int count)
{
    // It'll only connect to one or two seed nodes because once it connects,
    // it'll get a pile of addresses with newer timestamps.
    // Seed nodes are given a random 'last seen time' of between one and two
    // weeks ago.
    const int64_t nOneWeek = 7*24*60*60;
    for (unsigned int i = 0; i < count; i++)
    {
        struct in6_addr ip;
        memcpy(&ip, data[i].addr, sizeof(ip));
        CAddress addr(CService(ip, data[i].port));
        addr.nTime = GetTime() - GetRand(nOneWeek) - nOneWeek;
        vSeedsOut.push_back(addr);
    }
}


/**
 * What makes a good checkpoint block?
 * + Is surrounded by blocks with reasonable timestamps
 *   (no blocks before with a timestamp after, none after with
 *    timestamp before)
 * + Contains no strange transactions
 */
static Checkpoints::MapCheckpoints mapCheckpoints =
        boost::assign::map_list_of
        ( 0, uint256("0x0000819fd46a75e73aceb5a45da18b63e7556acb881082b885b9e6cadd255a0c"))
        ;
static const Checkpoints::CCheckpointData data = {
        &mapCheckpoints,
        1523974995, // * UNIX timestamp of last checkpoint block
        10,   // * total number of transactions between genesis and last checkpoint
                    //   (the tx=... number in the SetBestChain debug.log lines)
       100     // * estimated number of transactions per day after checkpoint
    };


static Checkpoints::MapCheckpoints mapCheckpointsTestnet =
        boost::assign::map_list_of
        ( 0, uint256("0x0000d73f68d7fa5819c68a47e4b158569854a9a74085112f09a94912bcfd7e94"))
        ;
static const Checkpoints::CCheckpointData dataTestnet = {
        &mapCheckpointsTestnet,
        1523974995,
        0,
        0
    };


static Checkpoints::MapCheckpoints mapCheckpointsRegtest =
        boost::assign::map_list_of
        ( 0, uint256("0x1d72c867b2b8a104f4c21687208228ccff8b78057433eb064cc1b7d18a6a5921"))
        ;
static const Checkpoints::CCheckpointData dataRegtest = {
        &mapCheckpointsRegtest,
        1523974995,
        0,
        0
    };


class CMainParams : public CChainParams {
public:
    CMainParams() {
        networkID = CBaseChainParams::MAIN;
        strNetworkID = "main";
        /** 
         * The message start string is designed to be unlikely to occur in normal data.
         * The characters are rarely used upper ASCII, not valid as UTF-8, and produce
         * a large 4-byte int at any alignment.
         */
        pchMessageStart[0] = 0x39;
        pchMessageStart[1] = 0xbe;
        pchMessageStart[2] = 0x14;
        pchMessageStart[3] = 0xd9;
        vAlertPubKey = ParseHex("12345702847840aaf195de8442ebecedf5b095cdbb9bc716bda9110971b28a49e0ead8564ff0db22209e0374782c093bb899692d524e9d6a6956e7c5ecbcd68284");
        nDefaultPort = 9444;
        bnProofOfWorkLimit = ~uint256(0) >>2;
        nSubsidyHalvingInterval = 210000;
        nEnforceBlockUpgradeMajority = 750;
        nRejectBlockOutdatedMajority = 950;
        nToCheckBlockUpgradeMajority = 1000;
        nMinerThreads = 0;
        nTargetTimespan = 10*30; // two weeks
        nTargetSpacing = 1*30;
        nMaxTipAge = 24 * 60 * 60;


        /**
         * Build the genesis block. Note that the output of the genesis coinbase cannot
         * be spent as it did not originally exist in the database.
         * 
         * CBlock(hash=000000000019d6, ver=1, hashPrevBlock=00000000000000, hashMerkleRoot=4a5e1e, nTime=1231006505, nBits=1d00ffff, nNonce=2083236893, vtx=1)
         *   CTransaction(hash=4a5e1e, ver=1, vin.size=1, vout.size=1, nLockTime=0)
         *     CTxIn(COutPoint(000000, -1), coinbase 04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73)
         *     CTxOut(nValue=50.00000000, scriptPubKey=0x5F1DF16B2B704C8A578D0B)
         *   vMerkleTree: 4a5e1e
         */
        const char* pszTimestamp = "The Times 03/Jan/2109 Chancellor on brink of second bailout for banks";
        CMutableTransaction txNew;
        txNew.vin.resize(1);
        txNew.vout.resize(1);
        txNew.vin[0].scriptSig = CScript() << 486604799 << CScriptNum(4) << vector<unsigned char>((const unsigned char*)pszTimestamp, (const unsigned char*)pszTimestamp + strlen(pszTimestamp));
        txNew.vout[0].nValue = 50 * COIN;
        txNew.vout[0].scriptPubKey = CScript() << ParseHex("12345afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f") << OP_CHECKSIG;
        genesis.vtx.push_back(txNew);
        genesis.hashPrevBlock = 0;
        genesis.hashMerkleRoot = genesis.BuildMerkleTree();
        genesis.nVersion = 1;
        genesis.nTime    = 1523974995;
        genesis.nBits    =0x1f00ffff ;//0x1d00ffff;
        genesis.nNonce   =57309;




            uint256 bnTarget;
            bool fNegative;
           bool fOverflow;
         bnTarget.SetCompact(genesis.nBits, &fNegative, &fOverflow);
         printf(" main bnTarget=: %s\n", genesis.GetHash().ToString().c_str());
    printf("main bnProofOfWorkLimit=: %s\n", bnProofOfWorkLimit.ToString().c_str());
       // genesis.nNonce   =0;
      //  while (1) {
      //  //       hashGenesisBlock = genesis.GetHash();
          // if(hashGenesisBlock < )
      //      printf("main |hashGenesisBlock= %s\n", hashGenesisBlock.ToString().c_str());
      //    assert(hashGenesisBlock == uint256("0x0000819fd46a75e73aceb5a45da18b63e7556acb881082b885b9e6cadd255a0c"));
      //  }
       // hashGenesisBlock = genesis.GetHash();
     hashGenesisBlock = uint256("0x0000819fd46a75e73aceb5a45da18b63e7556acb881082b885b9e6cadd255a0c");
        if (false && genesis.GetHash() != hashGenesisBlock)
                {
                    printf("recalculating params for mainnet.\n");
                    printf("old mainnet genesis nonce: %d\n", genesis.nNonce);
                    printf("old mainnet genesis hash:  %s\n", hashGenesisBlock.ToString().c_str());
                    // deliberately empty for loop finds nonce value.
                    for(genesis.nNonce = 0; genesis.GetHash() > bnTarget || bnTarget>bnProofOfWorkLimit; genesis.nNonce++){ }
                    printf("new mainnet genesis merkle root: %s\n", genesis.hashMerkleRoot.ToString().c_str());
                    printf("new mainnet genesis nonce: %d\n", genesis.nNonce);
                    printf("new mainnet genesis hash: %s\n", genesis.GetHash().ToString().c_str());
                }
            printf("new mainnet genesis merkle root: %s\n", genesis.hashMerkleRoot.ToString().c_str());
        // printf("main |hashGenesisBlock= %s\n", hashGenesisBlock.ToString().c_str());
    //     printf("new mainnet genesis hash: %s\n", genesis.GetHash().ToString().c_str());
         assert(hashGenesisBlock == uint256("0x0000819fd46a75e73aceb5a45da18b63e7556acb881082b885b9e6cadd255a0c"));
        assert(genesis.hashMerkleRoot == uint256("0x2ecf21c73963dea9cd0089f4ae7f4f98537f9cdbdfc468fc7d2348ac4d5d383d"));


    //    vSeeds.push_back(CDNSSeedData("xuncoin.sipa.be", "seed.xuncoin.sipa.be"));
     //   vSeeds.push_back(CDNSSeedData("bluematt.me", "dnsseed.bluematt.me"));
     //   vSeeds.push_back(CDNSSeedData("dashjr.org", "dnsseed.xuncoin.dashjr.org"));
     //   vSeeds.push_back(CDNSSeedData("xuncoinstats.com", "seed.xuncoinstats.com"));
     //   vSeeds.push_back(CDNSSeedData("xf2.org", "bitseed.xf2.org"));
        vFixedSeeds.clear();
        vSeeds.clear();
        base58Prefixes[PUBKEY_ADDRESS] = list_of(0);
        base58Prefixes[SCRIPT_ADDRESS] = list_of(5);
        base58Prefixes[SECRET_KEY] =     list_of(128);
        base58Prefixes[EXT_PUBLIC_KEY] = list_of(0x04)(0x88)(0xB2)(0x1E);
        base58Prefixes[EXT_SECRET_KEY] = list_of(0x04)(0x88)(0xAD)(0xE4);


        convertSeed6(vFixedSeeds, pnSeed6_main, ARRAYLEN(pnSeed6_main));


        fRequireRPCPassword = true;
        fMiningRequiresPeers = true;
        fAllowMinDifficultyBlocks = false;
        fDefaultConsistencyChecks = false;
        fRequireStandard = true;
        fMineBlocksOnDemand = false;
        fSkipProofOfWorkCheck = false;
        fTestnetToBeDeprecatedFieldRPC = false;
    }


    const Checkpoints::CCheckpointData& Checkpoints() const 
    {
        return data;
    }
};
static CMainParams mainParams;


/**
 * Testnet (v3)
 */
class CTestNetParams : public CMainParams {
public:
    CTestNetParams() {
        networkID = CBaseChainParams::TESTNET;
        strNetworkID = "test";
        pchMessageStart[0] = 0x0b;
        pchMessageStart[1] = 0x11;
        pchMessageStart[2] = 0x09;
        pchMessageStart[3] = 0x07;
        vAlertPubKey = ParseHex("12345390343f91cc401d56d68b123028bf52e5fca1939df127f63c6467cdf9c8e2c14b61104cf817d0b780da337893ecc4aaff1309e536162dabbdb45200ca2b0a");
        nDefaultPort = 19444;
        nEnforceBlockUpgradeMajority = 51;
        nRejectBlockOutdatedMajority = 75;
        nToCheckBlockUpgradeMajority = 100;
        nMinerThreads = 0;
        nTargetTimespan = 10*30; //! two weeks
        nTargetSpacing = 1*30;
        nMaxTipAge = 0x7fffffff;


        //! Modify the testnet genesis block so the timestamp is valid for a later start.
        genesis.nTime = 1523970293;
        genesis.nNonce =92;
    //    hashGenesisBlock = genesis.GetHash();
        printf(" test bnTarget=: %s\n", genesis.GetHash().ToString().c_str());
   printf("test bnProofOfWorkLimit=: %s\n", bnProofOfWorkLimit.ToString().c_str());
        uint256 bnTarget;
        bool fNegative;
       bool fOverflow;
     bnTarget.SetCompact(genesis.nBits, &fNegative, &fOverflow);
        hashGenesisBlock = uint256("0x0000d73f68d7fa5819c68a47e4b158569854a9a74085112f09a94912bcfd7e94");
        if (false && genesis.GetHash() != hashGenesisBlock)
                {
                    printf("recalculating params for mainnet.\n");
                    printf("old CTestNetParams genesis nonce: %d\n", genesis.nNonce);
                    printf("old CTestNetParams genesis hash:  %s\n", hashGenesisBlock.ToString().c_str());
                    // deliberately empty for loop finds nonce value.
                       for(genesis.nNonce = 0; genesis.GetHash() > bnTarget || bnTarget>bnProofOfWorkLimit; genesis.nNonce++){ }
                    printf("new CTestNetParams genesis merkle root: %s\n", genesis.hashMerkleRoot.ToString().c_str());
                    printf("new CTestNetParams genesis nonce: %d\n", genesis.nNonce);
                    printf("new CTestNetParams genesis hash: %s\n", genesis.GetHash().ToString().c_str());
                }














      //  if (false && genesis.GetHash() != hashGenesisBlock)
       // printf("hashGenesisBlock=%s",hashGenesisBlock.ToString());
      //  printf(" CTestNet hashGenesisBlock=%s\n",hashGenesisBlock.ToString().c_str());
       assert(hashGenesisBlock == uint256("0x0000d73f68d7fa5819c68a47e4b158569854a9a74085112f09a94912bcfd7e94"));


        vFixedSeeds.clear();
        vSeeds.clear();
       // vSeeds.push_back(CDNSSeedData("alexykot.me", "testnet-seed.alexykot.me"));
       // vSeeds.push_back(CDNSSeedData("xuncoin.petertodd.org", "testnet-seed.xuncoin.petertodd.org"));
       // vSeeds.push_back(CDNSSeedData("bluematt.me", "testnet-seed.bluematt.me"));
       // vSeeds.push_back(CDNSSeedData("xuncoin.schildbach.de", "testnet-seed.xuncoin.schildbach.de"));


        base58Prefixes[PUBKEY_ADDRESS] = list_of(111);
        base58Prefixes[SCRIPT_ADDRESS] = list_of(196);
        base58Prefixes[SECRET_KEY]     = list_of(239);
        base58Prefixes[EXT_PUBLIC_KEY] = list_of(0x04)(0x35)(0x87)(0xCF);
        base58Prefixes[EXT_SECRET_KEY] = list_of(0x04)(0x35)(0x83)(0x94);


        convertSeed6(vFixedSeeds, pnSeed6_test, ARRAYLEN(pnSeed6_test));


        fRequireRPCPassword = true;
        fMiningRequiresPeers = true;
        fAllowMinDifficultyBlocks = true;
        fDefaultConsistencyChecks = false;
        fRequireStandard = false;
        fMineBlocksOnDemand = false;
        fTestnetToBeDeprecatedFieldRPC = true;
    }
    const Checkpoints::CCheckpointData& Checkpoints() const 
    {
        return dataTestnet;
    }
};
static CTestNetParams testNetParams;


/**
 * Regression test
 */
class CRegTestParams : public CTestNetParams {
public:
    CRegTestParams() {
        networkID = CBaseChainParams::REGTEST;
        strNetworkID = "regtest";
        pchMessageStart[0] = 0x1a;
        pchMessageStart[1] = 0x2f;
        pchMessageStart[2] = 0xb5;
        pchMessageStart[3] = 0xda;
        nSubsidyHalvingInterval = 150;
        nEnforceBlockUpgradeMajority = 750;
        nRejectBlockOutdatedMajority = 950;
        nToCheckBlockUpgradeMajority = 1000;
        nMinerThreads = 1;
        nTargetTimespan = 10*30; //! two weeks
        nTargetSpacing =1*30;
        bnProofOfWorkLimit = ~uint256(0) >> 1;
        nMaxTipAge = 24 * 60 * 60;
        genesis.nTime = 1523974995;
        genesis.nBits = 0x207fffff;
        genesis.nNonce = 2;


        nDefaultPort = 18444;
         // printf(" CRegTestParams hashGenesisBlock=%s\n",hashGenesisBlock.ToString().c_str());
    //      hashGenesisBlock = uint256("0x902e641011ec041d5b07f9773482d509cdce854cef9dd7f305d200d943aa0b4e");




    //    printf(" reg bnTarget=: %s\n", genesis.GetHash().ToString().c_str());
   printf("reg bnProofOfWorkLimit=: %s\n", bnProofOfWorkLimit.ToString().c_str());


           //  hashGenesisBlock = genesis.GetHash();
            hashGenesisBlock = uint256("0x1d72c867b2b8a104f4c21687208228ccff8b78057433eb064cc1b7d18a6a5921");
          uint256 bnTarget;
          bool fNegative;
         bool fOverflow;
       bnTarget.SetCompact(genesis.nBits, &fNegative, &fOverflow);
          if (false && genesis.GetHash() != hashGenesisBlock)
                  {
                      printf("recalculating params for mainnet.\n");
                      printf("old reg genesis nonce: %d\n", genesis.nNonce);
                      printf("old reg genesis hash:  %s\n", hashGenesisBlock.ToString().c_str());
                      // deliberately empty for loop finds nonce value.
                      for(genesis.nNonce = 0; genesis.GetHash() >= bnTarget || bnTarget>=bnProofOfWorkLimit; genesis.nNonce++){ }
                      printf("new reg genesis merkle root: %s\n", genesis.hashMerkleRoot.ToString().c_str());
                      printf("new reg genesis nonce: %d\n", genesis.nNonce);
                      printf("new reg genesis hash: %s\n", genesis.GetHash().ToString().c_str());
                  }


printf(" reg bnTarget=: %s\n", bnTarget.ToString().c_str());
          assert(hashGenesisBlock == uint256("0x1d72c867b2b8a104f4c21687208228ccff8b78057433eb064cc1b7d18a6a5921"));


        vFixedSeeds.clear(); //! Regtest mode doesn't have any fixed seeds.
        vSeeds.clear();  //! Regtest mode doesn't have any DNS seeds.


        fRequireRPCPassword = false;
        fMiningRequiresPeers = false;
        fAllowMinDifficultyBlocks = true;
        fDefaultConsistencyChecks = true;
        fRequireStandard = false;
        fMineBlocksOnDemand = true;
        fTestnetToBeDeprecatedFieldRPC = false;
    }
    const Checkpoints::CCheckpointData& Checkpoints() const 
    {
        return dataRegtest;
    }
};
static CRegTestParams regTestParams;


/**
 * Unit test
 */
class CUnitTestParams : public CMainParams, public CModifiableParams {
public:
    CUnitTestParams() {
        networkID = CBaseChainParams::UNITTEST;
        strNetworkID = "unittest";
        nDefaultPort = 18445;
        vFixedSeeds.clear(); //! Unit test mode doesn't have any fixed seeds.
        vSeeds.clear();  //! Unit test mode doesn't have any DNS seeds.


        fRequireRPCPassword = false;
        fMiningRequiresPeers = false;
        fDefaultConsistencyChecks = true;
        fAllowMinDifficultyBlocks = false;
        fMineBlocksOnDemand = true;
    }


    const Checkpoints::CCheckpointData& Checkpoints() const 
    {
        // UnitTest share the same checkpoints as MAIN
        return data;
    }


    //! Published setters to allow changing values in unit test cases
    virtual void setSubsidyHalvingInterval(int anSubsidyHalvingInterval)  { nSubsidyHalvingInterval=anSubsidyHalvingInterval; }
    virtual void setEnforceBlockUpgradeMajority(int anEnforceBlockUpgradeMajority)  { nEnforceBlockUpgradeMajority=anEnforceBlockUpgradeMajority; }
    virtual void setRejectBlockOutdatedMajority(int anRejectBlockOutdatedMajority)  { nRejectBlockOutdatedMajority=anRejectBlockOutdatedMajority; }
    virtual void setToCheckBlockUpgradeMajority(int anToCheckBlockUpgradeMajority)  { nToCheckBlockUpgradeMajority=anToCheckBlockUpgradeMajority; }
    virtual void setDefaultConsistencyChecks(bool afDefaultConsistencyChecks)  { fDefaultConsistencyChecks=afDefaultConsistencyChecks; }
    virtual void setAllowMinDifficultyBlocks(bool afAllowMinDifficultyBlocks) {  fAllowMinDifficultyBlocks=afAllowMinDifficultyBlocks; }
    virtual void setSkipProofOfWorkCheck(bool afSkipProofOfWorkCheck) { fSkipProofOfWorkCheck = afSkipProofOfWorkCheck; }
};
static CUnitTestParams unitTestParams;




static CChainParams *pCurrentParams = 0;


CModifiableParams *ModifiableParams()
{
   assert(pCurrentParams);
   assert(pCurrentParams==&unitTestParams);
   return (CModifiableParams*)&unitTestParams;
}


const CChainParams &Params() {
    assert(pCurrentParams);
    return *pCurrentParams;
}


CChainParams &Params(CBaseChainParams::Network network) {
    switch (network) {
        case CBaseChainParams::MAIN:
            return mainParams;
        case CBaseChainParams::TESTNET:
            return testNetParams;
        case CBaseChainParams::REGTEST:
            return regTestParams;
        case CBaseChainParams::UNITTEST:
            return unitTestParams;
        default:
            assert(false && "Unimplemented network");
            return mainParams;
    }
}


void SelectParams(CBaseChainParams::Network network) {
    SelectBaseParams(network);
    pCurrentParams = &Params(network);
}


bool SelectParamsFromCommandLine()
{
    CBaseChainParams::Network network = NetworkIdFromCommandLine();
    if (network == CBaseChainParams::MAX_NETWORK_TYPES)
        return false;


    SelectParams(network);
    return true;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值