Tuesday, March 17, 2020

The script to start and stop wordpress using docker

<code>
#!/bin/bash
netexist=$(docker network ls --format "{{.Name}}" -f "name=rccc")
if [[ $1 == "start" ]]; then
  if [[ -z $netexist ]]; then
    docker network create rccc
  fi
  docker run -d --name mysql --network rccc \
    -v $(pwd)/data:/var/lib/mysql \
    -e MYSQL_ROOT_PASSWORD=mysecret \
    -e MYSQL_DATABASE=wordpress \
    -e MYSQL_USER=tongli -e MYSQL_PASSWORD=secret \
    mysql:latest mysqld --default-authentication-plugin=mysql_native_password

  sleep 3

  while : ; do
    res=$(docker logs mysql 2>&1 | grep 'ready for connections')
      if [[ ! -z $res ]]; then
        break
      fi
      echo 'Waiting for mysql to be ready...'
      sleep 3
  done

  docker run -d --name rcccsite --network rccc \
    -v $(pwd)/content:/var/www/html \
    -e WORDPRESS_DB_HOST=mysql \
    -e WORDPRESS_DB_USER=tongli \
    -e WORDPRESS_DB_PASSWORD=secret \
    -e WORDPRESS_DB_NAME=wordpress \
    -p 8080:80 wordpress:latest

elif [[ $1 == "stop" ]]; then
  docker rm -f rcccsite mysql
  if [[ $netexist == "rccc" ]]; then
    docker network rm rccc
  fi
fi
</code>

Wednesday, March 11, 2020

IBM Blockchain Platform vscode extension wallet structure

File directory structure:

<root>/
    Admin/
        <hashcode>-priv
        <hashcode>-pub
        Admin -- this is a json file with the following structure
           {"name":"Admin",
             "mspid":"org0examplecom",
             "role": null, "affiliation": "",
             "enrollmentSecret": "",
             "enrollment": {
                  "signingIdentity": <hash, which used as the priv and pub name>,
                  "identity": {"certificate": "The plan new line contained certificate"}
             }
           }

Monday, March 9, 2020

New Go chaincode header import

import (
    "encoding/base64"
    "encoding/json"
    "fmt"
    "github.com/golang/protobuf/proto"
    "github.com/hyperledger/fabric-chaincode-go/shim"
    "github.com/hyperledger/fabric-protos-go/common"
    "github.com/hyperledger/fabric-protos-go/msp"
    pb "github.com/hyperledger/fabric-protos-go/peer"
    "math/rand"
    "time"
)

Thursday, February 27, 2020

The real process to join an org and peer to an existing channel

1. The new org has to be added into an application channel.
2. Once the new org is part of the application channel, the new org admin can add its peers to the channel by following the below steps:

      a). Use peer channel fetch oldest to get the oldest block which is the genesis block
      b). Then use the genesis block to join the peer.

Wednesday, February 26, 2020

Disable ubuntu daily update service

sudo apt-get remove unattended-upgrades
sudo systemctl stop apt-daily.timer
sudo systemctl disable apt-daily.timer
sudo systemctl disable apt-daily.service
sudo systemctl daemon-reload

Set static IP for ubuntu servers

Edit the file in /etc/netplan/50-cloud-init.yaml file like the following

network:
    ethernets:
        enp0s3:
            dhcp4: false
            addresses: [192.168.56.101/24]
            nameservers:
                addresses: [8.8.8.8, 8.8.4.4]
        enp0s8:
            addresses: []
            dhcp4: true
            optional: true
    version: 2

Thursday, February 20, 2020

Using hyperledger discover service


# This assumes the following information available
1. a user's private key, public key and its belonging org mspid
  2. a peer's tlsca cert and its endpoint
 
# Produce the conf.yaml file based on the information provided
discover --configFile conf.yaml --peerTLSCA ca.crt \
--userKey priv_sk --userCert admin.pem --MSP org0examplecom saveConfig

# Discover peers
discover --configFile conf.yaml peers --channel mychannel \
--server peer1.org0.example.com:7051

# Discover config
discover --configFile conf.yaml config --channel mychannel \
--server peer1.org0.example.com:7051

# Discover endorsers for a chaincode
discover --configFile conf.yaml endorsers --channel mychannel \
--chaincode simple --server peer1.org0.example.com:7051 
 
# Choose not to use config file, pass necessary info as command line parameters
discover peers --peerTLSCA ca.crt --userKey priv_sk --userCert admin.pem \
--MSP org0examplecom --channel mychannel --server peer1.org0.example.com:7051
 
discover config --peerTLSCA ca.crt --userKey priv_sk --userCert admin.pem \
--MSP org0examplecom --channel mychannel --server peer1.org0.example.com:7051
 
discover endorsers --peerTLSCA ca.crt --userKey priv_sk --userCert admin.pem \
--MSP org0examplecom --channel mychannel --server peer1.org0.example.com:7051 \
--chaincode simple