Commit 1c0f7448 authored by TonyFord's avatar TonyFord
Browse files

initial upload

parent c949bd3e
stages:
- build
- start
- stop
- uninstall
- remove
build:
stage: build
tags:
- FairCoin.Co
only:
refs:
- master
variables:
- $CMD =~ /build/
before_script:
- export RUNNER_UID=`id -u`
- export RUNNER_GID=`id -g`
script:
- docker-compose down
- docker-compose build faircoin
- docker-compose up -d faircoin
- docker-compose up -d php-server
after_script:
- docker-compose down
start:
stage: start
tags:
- FairCoin.Co
only:
refs:
- master
variables:
- $CMD =~ /build|start/
before_script:
- export RUNNER_UID=`id -u`
- export RUNNER_GID=`id -g`
script:
- docker-compose exec -T faircoin ./stop_faircoin_services.sh && sleep 10
- docker-compose stop
- docker-compose up -d --remove-orphans
- docker-compose exec -T faircoin ./start_faircoin_services.sh
- docker-compose stop php-server
- docker-compose start php-server
- docker-compose exec -T php-server /opt/start_server.sh
stop:
stage: stop
tags:
- FairCoin.Co
only:
refs:
- master
variables:
- $CMD =~ /stop/
script:
- docker-compose stop
uninstall:
stage: uninstall
tags:
- FairCoin.Co
only:
refs:
- master
variables:
- $CMD =~ /uninstall/
script:
- docker-compose exec -T faircoin ./stop_faircoin_services.sh && sleep 10
- docker-compose stop
- docker-compose down
remove:
stage: remove
tags:
- FairCoin.Co
only:
refs:
- master
variables:
- $CMD =~ /remove/
script:
- docker-compose stop
- docker-compose down -v --rmi all --remove-orphans
# jsonrpc-api # jsonrpc-api
faircoin jsonrpc for php developers faircoin jsonrpc for php developers
\ No newline at end of file
## Deployment
### Requirements
+ vps server ( to prepare vps server you can find some helpful commands here https://git.fairkom.net/faircoin.co/admin/-/blob/master/SERVERSETUP.md )
+ docker installed ( https://docs.docker.com/engine/install/ )
+ docker-compose installed ( https://docs.docker.com/compose/install/ )
+ gitlab-runner installed ( optional for gitlab deployment ) ( see vps server setup )
## Usage <small>( by gitlab runner automation )</small>
Go into gitlab **CI/CD** -> **Pipeline** and **Run Pipeline**
Enter variable name **CMD**
#### CMD - commands
~~~
build
start # start container ( changes of scripts )
stop # stop container
uninstall # remove container
remove
~~~
#### CI/CD Settings
Go Gitlab **Settings** -> **CI/CD** -> **Variables**
~~~
#### FairCoin.Co group variables ######################
LH_PORT_jsonrpc # php -S 0.0.0.0:${LH_PORT}
~~~
## Manual usage
set localhost port env var
~~~
export LH_PORT_jsonrpc=4000
~~~
follow the commands in the .gitlab-ci.yml and do the same steps as the gitlab-runner would do.
+ go to the section of your choice ( build|start|stop|uninstall|remove )
+ run all commands of ( before_script )
+ run all commands of ( script )
+ run all commands of ( after_script )
version: "3.1"
services:
php-server:
restart: always
container_name: faircoin-php
image: php:7
command: php -S 0.0.0.0:4000 -t /var/www/html
ports:
- ${LH_PORT_jsonrpc}:4000
volumes:
- ./html:/var/www/html
faircoin:
build:
context: ./faircoin
args:
RUNNER_UID: ${RUNNER_UID:-1000}
RUNNER_GID: ${RUNNER_GID:-1000}
container_name: faircoin-services
restart: always
command: ./start_faircoin_services.sh
user: "${RUNNER_UID:-1000}:${RUNNER_GID:-1000}"
volumes:
- faircoin2:/home/faircoin/.faircoin2
- electrumfair:/home/faircoin/.electrumfair
volumes:
faircoin2:
electrumfair:
{
"config_version": 3,
"rpchost": "0.0.0.0",
"rpcpassword": "password",
"rpcport": 7777,
"rpcuser": "user"
}
rpcallowip=0.0.0.0/0
rpcport=8332
rpcuser=user
rpcpassword=password
txindex=1
# Pull base image.
FROM ubuntu:18.04@sha256:5f4bdc3467537cbbe563e80db2c3ec95d548a9145d64453b06939c4592d67b6d
ENV LC_ALL=C.UTF-8 LANG=C.UTF-8
#####################################################################################root##
### install base libraries and dependencies for faircoin daemon ###########################
RUN apt-get update -q && \
apt-get install -qy \
git \
make \
autotools-dev \
autoconf \
libtool \
libssl-dev \
libboost-all-dev \
libevent-dev \
libdb++-dev \
libdb-dev \
wget \
curl
#####################################################################################root##
### install nano commandline editor [optional] ( to edit faircoin.conf later if necessary )
RUN apt-get install -qy nano \
net-tools
#####################################################################################root##
### install python packages
RUN apt-get install -qy \
python3-pip \
python3-pyqt5
RUN python3 -m pip install pip --upgrade
RUN python3 -m pip install python-bitcoinrpc
#####################################################################################root##
### system cleanup ########################################################################
RUN rm -rf /var/lib/apt/lists/* && \
apt-get autoremove -y && \
apt-get clean
#####################################################################################root##
### create and run user account to image ##################################################
ARG RUNNER_GID
ARG RUNNER_UID
RUN groupadd -g $RUNNER_GID faircoin
RUN useradd --create-home --shell /bin/bash faircoin --uid $RUNNER_UID --gid $RUNNER_GID
RUN mkdir -p /home/faircoin/.electrumfair
RUN chown -R faircoin:faircoin /home/faircoin/.electrumfair
RUN mkdir -p /home/faircoin/.faircoin2
COPY .faircoin2/faircoin.conf /home/faircoin/.faircoin2/faircoin.conf
RUN chown -R faircoin:faircoin /home/faircoin/.faircoin2
COPY .electrumfair/config /home/faircoin/.electrumfair/config
RUN chown -R faircoin:faircoin /home/faircoin/.electrumfair/config
COPY ./start_faircoin_services.sh /home/faircoin/start_faircoin_services.sh
RUN chown faircoin:faircoin /home/faircoin/start_faircoin_services.sh
RUN chmod +x /home/faircoin/start_faircoin_services.sh
COPY ./stop_faircoin_services.sh /home/faircoin/stop_faircoin_services.sh
RUN chown faircoin:faircoin /home/faircoin/stop_faircoin_services.sh
RUN chmod +x /home/faircoin/stop_faircoin_services.sh
USER faircoin
#################################################################################faircoin##
### download and build faircoin daemon and cli ############################################
WORKDIR /home/faircoin
ARG source_repository
RUN git clone https://github.com/faircoin/faircoin.git /home/faircoin/faircoin
WORKDIR /home/faircoin/faircoin
RUN ./autogen.sh && \
./configure --disable-tests --disable-bench --with-incompatible-bdb --disable-wallet && \
make
#################################################################################faircoin##
### initialize blockchain with txindex=1 ##################################################
WORKDIR /home/faircoin/faircoin/src
RUN mv ./faircoind /home/faircoin/faircoind
RUN mv ./faircoin-cli /home/faircoin/faircoin-cli
WORKDIR /home/faircoin
RUN git clone https://github.com/faircoin/electrumfair.git
WORKDIR /home/faircoin
#!/bin/bash
if [ ! -d ./electrumfair/packages ]; then ./electrumfair/contrib/make_packages; fi
./electrumfair/run_electrumfair daemon start
./faircoind
#!/bin/bash
./electrumfair/run_electrumfair daemon stop
./faircoin-cli stop
This diff is collapsed.
<?php
/**
*
*/
define('ELECTRUMFAIR_RPC','http://user:password@faircoin:7777');
define('FAIRCOIND_RPC', 'http://user:password@faircoin:8332');
function regex($s,$p){
return preg_match('/'.$p.'/',$s);
}
class faircoind
{
public $param=Array( 'jsonrpc' => '2.0', 'id' => 'curltext' );
function faircoind(){ return $this->rpccall(FAIRCOIND_RPC); }
function rpccall($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST,true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode( $this->param ) );
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
### faircoind methods / blockchain ####
function getbestblockhash(){
$this->param['method']=__FUNCTION__;
$this->param['params']=Array();
return json_decode( $this->faircoind(), true )['result'];
}
function getblock($blockhash){
$this->param['method']=__FUNCTION__;
$this->param['params']=Array( $blockhash );
return json_decode( $this->faircoind(), true )['result'];
}
function getblockchaininfo(){
$this->param['method']=__FUNCTION__;
$this->param['params']=Array();
return json_decode( $this->faircoind(), true )['result'];
}
function getblockcount(){
$this->param['method']=__FUNCTION__;
$this->param['params']=Array();
return json_decode( $this->faircoind(), true )['result'];
}
function getblockhash($index){
$this->param['method']=__FUNCTION__;
$this->param['params']=Array( $index );
return json_decode( $this->faircoind(), true )['result'];
}
function getblockheader($blockhash){
$this->param['method']=__FUNCTION__;
$this->param['params']=Array( $blockhash );
return json_decode( $this->faircoind(), true )['result'];
}
function getchaintips(){
$this->param['method']=__FUNCTION__;
$this->param['params']=Array();
return json_decode( $this->faircoind(), true )['result'];
}
function getmempoolinfo(){
$this->param['method']=__FUNCTION__;
$this->param['params']=Array();
return json_decode( $this->faircoind(), true )['result'];
}
function getrawmempool(){
$this->param['method']=__FUNCTION__;
$this->param['params']=Array();
return json_decode( $this->faircoind(), true )['result'];
}
function gettxoutsetinfo(){
$this->param['method']=__FUNCTION__;
$this->param['params']=Array();
return json_decode( $this->faircoind(), true )['result'];
}
### faircoind methods / control ####
function getinfo(){
$this->param['method']=__FUNCTION__;
$this->param['params']=Array();
return json_decode( $this->faircoind(), true )['result'];
}
### faircoind methods / cvn ####
function estimatefee(){
$this->param['method']=__FUNCTION__;
$this->param['params']=Array(1);
return json_decode( $this->faircoind(), true )['result'];
}
function getactiveadmins(){
$this->param['method']=__FUNCTION__;
$this->param['params']=Array();
return json_decode( $this->faircoind(), true )['result'];
}
function getactivecvns(){
$this->param['method']=__FUNCTION__;
$this->param['params']=Array();
return json_decode( $this->faircoind(), true )['result'];
}
function getchainparameters(){
$this->param['method']=__FUNCTION__;
$this->param['params']=Array();
return json_decode( $this->faircoind(), true )['result'];
}
function getconnectioncount(){
$this->param['method']=__FUNCTION__;
$this->param['params']=Array();
return json_decode( $this->faircoind(), true )['result'];
}
function getnettotals(){
$this->param['method']=__FUNCTION__;
$this->param['params']=Array();
return json_decode( $this->faircoind(), true )['result'];
}
function getnetworkinfo(){
$this->param['method']=__FUNCTION__;
$this->param['params']=Array();
return json_decode( $this->faircoind(), true )['result'];
}
function getpeerinfo(){
$this->param['method']=__FUNCTION__;
$this->param['params']=Array();
return json_decode( $this->faircoind(), true )['result'];
}
### faircoind methods / transaction ###
function decoderawtransaction($tx_hex){
$this->param['method']=__FUNCTION__;
$this->param['params']=Array($tx_hex);
return json_decode( $this->faircoind(), true )['result'];
}
function getrawtransaction($txid){
$this->param['method']=__FUNCTION__;
$this->param['params']=Array($txid);
return json_decode( $this->faircoind(), true )['result'];
}
### faircoin methods / util ###
function validateaddress($address){
$this->param['method']=__FUNCTION__;
$this->param['params']=Array($address);
return json_decode( $this->faircoind(), true )['result'];
}
function validatepubkey($pubkey){
$this->param['method']=__FUNCTION__;
$this->param['params']=Array($pubkey);
return json_decode( $this->faircoind(), true )['result'];
}
function verifymessage($address, $message, $signature){
$this->param['method']=__FUNCTION__;
$this->param['params']=Array( $address, $signature, $message );
return json_decode( $this->faircoind(), true )['result'];
}
}
class electrumfair
{
public $param=Array( 'jsonrpc' => '2.0', 'id' => 'curltext' );
function electrumfair(){ return $this->rpccall(ELECTRUMFAIR_RPC); }
function rpccall($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST,true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode( $this->param ) );
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
### electrumfair methods / messages ###
function verifymessage($address, $message, $signature){
$this->param['method']=__FUNCTION__;
$this->param['params']=Array( 'address' => $address, 'message' => $message, 'signature' => $signature );
return json_decode( $this->electrumfair(), true )['result'];
}
### electrumfair methods / address ###
function getaddressbalance($address){
$this->param['method']=__FUNCTION__;
$this->param['params']=Array( 'address' => $address );
return json_decode( $this->electrumfair(), true )['result'];
}
function getaddresshistory($address){
$this->param['method']=__FUNCTION__;
$this->param['params']=Array( 'address' => $address );
$result=json_decode( $this->electrumfair(), true )['result'];
return $result;
}
function getaddressunspent($address){
$this->param['method']=__FUNCTION__;
$this->param['params']=Array( 'address' => $address );
$result=json_decode( $this->electrumfair(), true )['result'];
return $result;
}
### electrumfair methods / transaction ###
function deserialize($tx_hex){
$this->param['method']=__FUNCTION__;
$this->param['params']=Array( 'tx' => $tx_hex );
$result=json_decode( $this->electrumfair(), true )['result'];
return $result;
}
function gettransaction($txid){
$this->param['method']=__FUNCTION__;
$this->param['params']=Array( 'txid' => $txid );
$result=json_decode( $this->electrumfair(), true )['result'];
return $result;
}
### electrumfair methods / network ###
function getservers(){
$this->param['method']=__FUNCTION__;
$this->param['params']=Array();
$result=json_decode( $this->electrumfair(), true )['result'];
return $result;
}
function getfeerate(){
$this->param['method']=__FUNCTION__;
$this->param['params']=Array();
$result=json_decode( $this->electrumfair(), true )['result'];
return $result;
}
### electrumfair methods / util ###
function validateaddress($address){
$this->param['method']=__FUNCTION__;
$this->param['params']=Array($address);
return json_decode( $this->electrumfair(), true )['result'];
}
}
class Faircoin
{
public $online=false;
public $faircoind=false;
public $electrumfair=false;
function __construct(){
$this->faircoind = new faircoind();
$this->electrumfair = new electrumfair();
$this->online = !empty( $this->electrumfair->getservers() );
}
}
<html>
<head>
<style>
body {
font-family: sans-serif;
padding-bottom: 50px;
}
h4 {
margin-top:5px;
margin-bottom: 0px;
color: grey;
cursor: pointer;
}
h4 b {
color: black;
}
h5 {
color: grey;
}
.hidden {
display: none;
}
textarea {
width: 100%;
padding: 10px;
margin-top: 10px;
margin-bottom: 20px;
}
</style>
<script src="assets/js/jquery.min.js"></script>
</head>
<body>
<h1>jsonrpc-php</h1>
<?php
include_once('functions/faircoin.php');
$address='fJEtS3HDHxqX8Kpa2FChzGypPJYLBTRStq';
$pubkey='04efbdb57592d1d4384a42a16dda525bc217ef7ce5e471ddf750e508096b5e9f5d99a3aa13a461ef4319417239dceae094351006a99134a14d43b32737f10fe405';
$txid='09268782af2883a829d99d4addd3a33142be0663199ebea2292ca791607c0bcc';
$message='Hello';
$signature='HEbYHmm+QlB0aYlA/KK/2/lFqw1gM2yTzomUPjmLBFpwC7NM2iBk3R3aE3q+GaPtUUUPXprPPbETeOfThD+OI7c=';
$F = new Faircoin();
?><hr><h2>Message</h2><?
?><h4 onclick="$(this).next().toggleClass('hidden')">Faircoin->electrumfair-><b>verifymessage($address,$message,$signature)</b></h4><?
?><textarea class="hidden"><?=json_encode($F->electrumfair->verifymessage($address,$message,$signature))?></textarea><?
?><h4 onclick="$(this).next().toggleClass('hidden')">Faircoin->faircoind-><b>verifymessage($address,$message,$signature)</b></h4><?
?><textarea class="hidden"><?=json_encode($F->faircoind->verifymessage($address,$message,$signature))?></textarea><?
?><h4 onclick="$(this).next().toggleClass('hidden')">Faircoin->faircoind-><b>validatepubkey($pubkey)</b></h4><?
?><textarea class="hidden"><?=json_encode($F->faircoind->validatepubkey($pubkey))?></textarea><?
?><hr><h2>Address</h2><?
?><h4 onclick="$(this).next().toggleClass('hidden')">Faircoin->electrumfair-><b>getaddressbalance($address)</b></h4><?
?><textarea class="hidden"><?=json_encode($F->electrumfair->getaddressbalance($address))?></textarea><?
?><h4 onclick="$(this).next().toggleClass('hidden')">Faircoin->electrumfair-><b>getaddresshistory($address)</b></h4><?
?><textarea class="hidden"><?=json_encode($F->electrumfair->getaddresshistory($address))?></textarea><?
?><h4 onclick="$(this).next().toggleClass('hidden')">Faircoin->electrumfair-><b>getaddressunspent($address)</b></h4><?
?><textarea class="hidden"><?=json_encode($F->electrumfair->getaddressunspent($address))?></textarea><?
?><h4 onclick="$(this).next().toggleClass('hidden')">Faircoin->electrumfair-><b>validateaddress($address)</b></h4><?
?><textarea class="hidden"><?=json_encode($F->electrumfair->validateaddress($address))?></textarea><?