2017 m. rugsėjo 11 d., pirmadienis

bitcoin configuration options

############################################################
#  Bitcoin-cash                                          #
#                                                          #
#  To start bitcoin:                               #
#      # systemctl start bitcoind                          #
#  To communicate with bitcoin-classic as a normal user:   #
#      $ bitcoin-cli help                                  #
#                                                          #
#  Config:        /etc/bitcoin/bitcoin.conf                #
#  Blockchain:    /var/lib/bitcoind                        #
#                                                          #
############################################################


Before running bitcoin, you can specify configuration file:
$ bitcoin-qt -conf=/home/$USER/.bitcoin/bitcoin.conf

Generating key:

To generate private key:
$ walletpassphrase your-wallet-passphrase 300


Getting key:

The easiest way is to export your private keys using the dumpprivkey functionality.
DumpPrivKey: returns the wallet-import-format (WIP) private key corresponding to an address. (But does not remove it from the wallet.) Bitcoin Developer Reference

Dump private key:
$ dumpprivkey <your bitcoin address>


-prune=<n>
Reduce storage requirements by pruning (deleting) old blocks. This mode disables wallet support and is incompatible with -txindex. Warning: Reverting this setting requires re-downloading the entire blockchain. (default: 0 = disable pruning blocks, >%u = target size in MiB to use for block files)

A value of 0 disables pruning. The minimal value above 0 is 550.Where 550 is the size in MB you want the node to ocupy in your system.



Give Higher CPU Priority to Bitcoin-Qt Process

$ sudo renice -20 -p 2202

-20 is the nice value a value between -20 and +19. The lower the nice value, the higher priority the process gets.

$ sudo renice -20 -p `pgrep bitcoin-qt`


Other interesting options:



RPC server options:
-server Accept command line and JSON-RPC commands
-rest Accept public REST requests (default: 0)
-rpcuser=<user> Username for JSON-RPC connections
-rpcpassword=<pw> Password for JSON-RPC connections
-conf=<file> Specify configuration file (default: bitcoin.conf)
-addnode=<ip> Add a node to connect to and attempt to keep the connection open
-onion=<ip:port> Use separate SOCKS5 proxy to reach peers via Tor hidden services (default: -proxy)


Connection options:
-port=<port> Listen for connections on <port> (default: 8333 or testnet: 18333)
-proxy=<ip:port> Connect through SOCKS5 proxy
-proxyrandomize Randomize credentials for every proxy connection. This enables Tor stream isolation (default: 1)
-torcontrol=<ip>:<port> Tor control port to use if onion listening enabled (default: 127.0.0.1:9051)
-torpassword=<pass> Tor control port password (default: empty)

Wallet options:

-disablewallet Do not load the wallet and disable wallet RPC calls
-mintxfee=<amt> Fees (in BTC/kB) smaller than this are considered zero fee for transaction creation (default: 0.00001)
-paytxfee=<amt> Fee (in BTC/kB) to add to transactions you send (default: 0.00)
-rescan Rescan the block chain for missing wallet transactions on startup
-salvagewallet Attempt to recover private keys from a corrupt wallet on startup
-wallet=<file> Specify wallet file (within data directory) (default: wallet.dat)


Other:
Transferring from bitcoin fullnode to electrum.
https://en.bitcoin.it/wiki/Transferring_coins_from_Bitcoin-Qt_to_Electrum

2017 m. rugsėjo 9 d., šeštadienis

python Async style of concurrent programming

Async - A style of concurrent programming in which tasks release the CPU during waiting period, so that other tasks can use it.

Analogy: Synchronous Chess Exhibition
Guy who plays many opponents is CPU.
When opponents think CPU is released, to go to next table.


Examples:
https://gist.github.com/miguelgrinberg/f15bc03471f610cfebeba62438435508

Resources:
https://www.youtube.com/watch?v=iG6fr81xHKA -  Miguel Grinberg Asynchronous Python for the Complete Beginner

python exceptions

except

General format:
try:
    a = 10 / 0
except ZeroDivisionError as err:
    print("Error " + str(err))
else:
    print("It's ok...")  # Else is executed if try statement passes without exception
finally:  # Finally is executed either way

    print("Finalizing")

Python 3.X catching an exception named Exception ignores exceptions related to system exits.


raise

Assert is mostly intended for trapping user-defined constraints, because Python traps programming errors itself,

Assertion example:
def f(x):
    assert x < 0, 'x must be negative'
    return x ** 2

print(f(10))

Assertions can be skipped by running:
$ python -O raise.py

2017 m. rugsėjo 5 d., antradienis

About .wsdl .xsd .xml

Definitions:
SOAP (originally Simple Object Access Protocol)
XSD : XML Schema Definition.
XML : eXtensible Markup Language.
WSDL : Web Service Description Language.


SOAP allows processes running on disparate operating systems (such as Windows and Linux) to communicate using Extensible Markup Language (XML).

XSD a recommendation of the World Wide Web Consortium (W3C), specifies how to formally (a way(a set of rules) in which something is usually done) describe the elements in an Extensible Markup Language (XML) document.

WSDL
Is often used in combination with SOAP and an XML Schema to provide Web services over the Internet. A client program connecting to a Web service can read the WSDL file to determine what operations are available on the server. Any special datatypes used are embedded in the WSDL file in the form of XML Schema. The client can then use SOAP to actually call one of the operations listed in the WSDL file using for example XML over HTTP.


XML (Extensible Markup Language (XML) is a markup language that defines a set of rules for encoding documents in a format that is both human-readable and machine-readable.

.XSD files - Generated domain classes
Actually the xsd is xml itself. Its purpose is to validate the structure of another xml document.*
  1. XSD is based and written on XML. 
  2. XSD defines elements and structures that can appear in the document, while XML does not. 
  3. XSD ensures that the data is properly interpreted, while XML does not. 
  4. An XSD document is validated as XML, but the opposite may not always be true. 
  5. XSD is better at catching errors than XML.

Working with suds:

About .key .pem .p12 certificates

Key types:
.key This is a PEM formatted file containing just the private-key of a specific certificate and is merely a conventional name and not a standardized one. In Apache installs, this frequently resides in /etc/ssl/private. The rights on these files are very important, and some programs will refuse to load these certificates if they are set wrong.

.pkcs12 .pfx .p12 Originally defined by RSA in the Public-Key Cryptography Standards, the "12" variant was enhanced by Microsoft. This is a passworded container format that contains both public and private certificate pairs. Unlike .pem files, this container is fully encrypted. Openssl can turn this into a .pem file with both public and private keys:

How to add .p12  in browser ?
This solves "This site can’t provide a secure connection", picture below:

Using Chrome:
Settings- >Advanced-> Privacy and Security -> Manage certificates

It is possible to convert from .p12 to key.pem

# Removes key
$ openssl pkcs12 -in original.p12 -passin pass:password -out converted_from_p21.pem

$ openssl pkcs12 -in original.p12 -out cert.pem -nodes


-in option specifies what file to read the keys / certificates from.
-passin lets the user specify the password protecting the source PKCS12 file.
-out indicates which file to save the result to (the result being in this case both the public and private keys of alice). The default output format is PEM so we don’t need to specify anything else.
-nodes don't encrypt the private keys at all.*

.pem Defined in RFC's 1421 through 1424, this is a container format that may include just the public certificate (such as with Apache installs, and CA certificate files /etc/ssl/certs), or may include an entire certificate chain including public key, private key, and root certificates. Confusingly, it may also encode a CSR (e.g. as used here) as the PKCS10 format can be translated into PEM. The name is from Privacy Enhanced Mail (PEM), a failed method for secure email but the container format it used lives on, and is a base64 translation of the x509 ASN.1 keys.

PEM Governed by RFCs, it's used preferentially by open-source software. It can have a variety of extensions (.pem, .key, .cer, .cert, more)


Python 
Upgrading python libs:
$ python-m pip install --upgrade requests
$ python -m pip install --upgrade pip
$ python -m pip install --upgrade pyOpenSSL
$ python -m pip install requests[security]


Python `.pem` errors:
urllib2.URLError: <urlopen error [SSL: SSLV3_ALERT_BAD_CERTIFICATE] sslv3 alert bad certificate (_ssl.c:590)>

urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590)


Requests lib:

If connection is not secure:
>>> import requests
>>> response = requests.get(far_url, cert=bundle_file, verify=False)
>>> print(response.content)

You can pass verify the path to a CA_BUNDLE file or directory with certificates of trusted CAs:
>>> requests.get('https://github.com', verify='/path/to/certfile')

This list of trusted CAs can also be specified through the REQUESTS_CA_BUNDLE environment variable.

Client Side Certificates
You can also specify a local cert to use as client side certificate, as a single file (containing the private key and the certificate) or as a tuple of both files' paths:

>>> requests.get('https://kennethreitz.org', cert=('/path/client.cert', '/path/client.key')



Errors:

CERTIFICATE_VERIFY_FAILED
usually means that the server is providing a certificate that is not signed by a CA certificate your client trusts (i.e. you've given the client the "wrong" CA root certificate), or that the server does not provide a complete chain of certificates from the root to the server certificate.


(Caused by SSLError(SSLError(0, u'unknown error (_ssl.c:2947)'),))
Read about this error here



Definitions:

RSA - RSA key is a private key based on RSA algorithm. Private Key is used for authentication and a symmetric key exchange during establishment of an SSL/TLS session.

It is a part of the public key infrastructure that is generally used in case of SSL certificates. A public key infrastructure assumes asymmetric encryption where two types of keys are used: Private Key and Public Key (it is included in an SSL certificate). Since encrypted data transmission takes too much time in case of asymmetric encryption, this kind of encryption is used for a secure symmetric key exchange that is used for actual transmitted data encryption and decryption.
*
CA - certificate authority or certification authority (CA) is an entity that issues digital certificates.
PKI  - Public Key Infrastructure.
CSR - Certification Request is a message sent from an applicant to a certificate authority in order to apply for a digital identity certificate. It usually contains the public key for which the certificate should be issued, identifying information (such as a domain name) and integrity protection (e.g., a digital signature). The most common format for CSRs is the PKCS #10 specification and another is the Signed Public Key and Challenge SPKAC format generated by some web browsers.
c_rehash - Create symbolic links to files named by the hash values. *


Key usages:

Digital signature - Use when the public key is used with a digital signature mechanism to support security services other than non-repudiation, certificate signing, or CRL signing. A digital signature is often used for entity authentication and data origin authentication with integrity.
Certificate signing:
Use when the subject public key is used to verify a signature on certificates. This extension can be used only in CA certificates.
Certificate signing - Use when the subject public key is used to verify a signature on certificates. This extension can be used only in CA certificates.

Extended key usage further refines key usage extensions. An extended key is either critical or non-critical. If the extension is critical, the certificate must be used only for the indicated purpose or purposes. If the certificate is used for another purpose, it is in violation of the CA's policy.
*



Resourses:
https://serverfault.com/questions/9708/what-is-a-pem-file-and-how-does-it-differ-from-other-openssl-generated-key-file - More information about certificates types.
https://wiki.openssl.org/index.php/Manual:Pkcs12(1) - openssl commands.
https://www.youtube.com/watch?v=Y2yXEjxNG04 - Cryptography/SSL 101 #5: SSL certificate chain in depth.
https://tools.ietf.org/html/rfc5280#section-4.2.1.3 - Internet X.509 Public Key Infrastructure certificate and Certificate Revocation List (CRL) Profile.


https://www.youtube.com/watch?v=OKg4PqD01Z0 - Python blockchain digital signature tutorial

2017 m. rugsėjo 1 d., penktadienis

How to Compile Fedoracoin(Tips) Source Code with linux

This tutorial is outdated, you can download fedoracoin linux version here.

Download fedacoin source:
$ cd
$ git clone https://github.com/fedoracoin-dev/fedoracoin
$ cd fedoracoin/

Fedoracoin(Tips) uses the Berkley DB 4.8, we need to download  and install it.
$ TIPS_ROOT=$(pwd) 
$ BDB_PREFIX="${TIPS_ROOT}/db4"
$ mkdir -p $BDB_PREFIX
$ wget 'http://download.oracle.com/berkeley-db/db-4.8.30.NC.tar.gz'
$ tar -xzvf db-4.8.30.NC.tar.gz
cd db-4.8.30.NC/build_unix/
$ ../dist/configure --enable-cxx --disable-shared --with-pic --prefix=$BDB_PREFIX
$ make install

Compile fedoracoin:
$ cd $TIPS_ROOT

Compiling fedoracoind for server use on Ubuntu (Without GUI):
$ ./autogen.sh ./configure LDFLAGS="-L${BDB_PREFIX}/lib/" CPPFLAGS="-I${BDB_PREFIX}/include/" -without-gui --without-miniupnpc --disable-tests
With GUI, DONT WORK
$ ./autogen.sh
$ ./configure LDFLAGS="-L${BDB_PREFIX}/lib/" CPPFLAGS="-I${BDB_PREFIX}/include/" --with-gui=qt5

Configure parameters:
--with-gui=qt5 - By default will compile with qt4
CFLAGS  - C compiler flags
LDFLAGS -  linker flags, e.g. -L<lib dir> if you have libraries in a nonstandard directory <lib dir>*

Make process may take up to 5-10 mins based on your system
$ make
$ make -s -j5 # To use 5 threads for faster compilation


Other compiling option from feathercoin:

$ make clean
$ ./autogen.sh
$ autoupdate
$ ./configure --with-incompatible-bdb
$ qmake -project

$ make

Files can be found:
/usr/local/bin/fedoracoin-cli - Allows you to send RPC commands to bitcoind from the command line. For example, bitcoin-cli help.
/usr/local/bin/fedoracoind - Is more useful for programming: it provides a full peer which you can interact with through RPCs to port 8332 (or 18332 for testnet).
/usr/local/bin/fedoracoind-qt -  Provides a combination full Bitcoin peer and wallet frontend. From the Help menu, you can access a console where you can enter the RPC commands used throughout this document.


Creating .conf file:
$ nano ~/.fedoracoin/fedoracoin.conf
rpcpassword=change_this_to_a_long_random_password
addnode=90.35.187.174
addnode 90.35.187.174

You should also make the .conf file only readable to its owner"
$ chmod 0600 bitcoin.conf

Fixing compilation problems:

Problem:
$ ./autogen.sh 
./autogen.sh: 3: ./autogen.sh: autoreconf: not found
Solution:
$ sudo apt-get install autoconf autogen

Problem:
configure: error: libdb_cxx headers missing S
Solution:
$ sudo apt-get install libdb++-dev

Problem:
Makefile:921: recipe for target 'all-recursive' failed
make[2]: *** [all-recursive] Error 1
Makefile:675: recipe for target 'all' failed
make[1]: *** [all] Error 2
Makefile:511: recipe for target 'all-recursive' failed
make: *** [all-recursive] Error 1

Solution:
Don't use make -s -j5 option when compling from virtual-box

Problem when compiling with QT:
fatal error: QJsonObject: No such file or directory
Solution:
No solution at the moment

Where qt files are located:
~/fedoracoin $ locate qjsonobject.h
/usr/include/x86_64-linux-gnu/qt5/QtCore/qjsonobject.h
 ~/fedoracoin $ locate qprinter.h
/usr/include/qt4/Qt/qprinter.h
/usr/include/qt4/QtGui/qprinter.h
/usr/include/x86_64-linux-gnu/qt5/QtPrintSupport/qprinter.h

Dependencies:
$ sudo apt-get install libqt5gui5 libqt5core5a libqt5dbus5 qttools5-dev qttools5-dev-tools libprotobuf-dev protobuf-compiler -y

Other dependencies:
$ sudo apt-get install autoconf libboost-all-dev libssl-dev libprotobuf-dev protobuf-compiler libqt4-dev libqrencode-dev libtool -y

2017 m. rugpjūčio 11 d., penktadienis

How to fix pycharm OSError: [Errno 2] No such file or directory

Add fallowing:
$ echo $PATH output from terminal to pycharm environment variables.