Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Feathercoin (FTC) #783

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bchain/coins/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/trezor/blockbook/bchain/coins/dogecoin"
"github.com/trezor/blockbook/bchain/coins/ecash"
"github.com/trezor/blockbook/bchain/coins/eth"
"github.com/trezor/blockbook/bchain/coins/feathercoin"
"github.com/trezor/blockbook/bchain/coins/firo"
"github.com/trezor/blockbook/bchain/coins/flo"
"github.com/trezor/blockbook/bchain/coins/fujicoin"
Expand Down Expand Up @@ -126,6 +127,7 @@ func init() {
BlockChainFactories["BitZeny"] = bitzeny.NewBitZenyRPC
BlockChainFactories["Trezarcoin"] = trezarcoin.NewTrezarcoinRPC
BlockChainFactories["ECash"] = ecash.NewECashRPC
BlockChainFactories["Feathercoin"] = feathercoin.NewFeathercoinRPC
}

// GetCoinNameFromConfig gets coin name and coin shortcut from config file
Expand Down
65 changes: 65 additions & 0 deletions bchain/coins/feathercoin/feathercoinparser.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package feathercoin

import (
"github.com/martinboehm/btcd/wire"
"github.com/martinboehm/btcutil/chaincfg"
"github.com/trezor/blockbook/bchain"
"github.com/trezor/blockbook/bchain/coins/btc"
)

// magic numbers
const (
MainnetMagic wire.BitcoinNet = 0x211a1541
)

// chain parameters
var (
MainNetParams chaincfg.Params
)

func init() {
MainNetParams = chaincfg.MainNetParams
MainNetParams.Net = MainnetMagic
MainNetParams.PubKeyHashAddrID = []byte{14}
MainNetParams.ScriptHashAddrID = []byte{5}
MainNetParams.Bech32HRPSegwit = "fc"
}

// FeathercoinParser handle
type FeathercoinParser struct {
*btc.BitcoinLikeParser
baseparser *bchain.BaseParser
}

// NewFeathercoinParser returns new FeathercoinParser instance
func NewFeathercoinParser(params *chaincfg.Params, c *btc.Configuration) *FeathercoinParser {
return &FeathercoinParser{
BitcoinLikeParser: btc.NewBitcoinLikeParser(params, c),
baseparser: &bchain.BaseParser{},
}
}

// GetChainParams contains network parameters for the main Feathercoin network,
// and the test Feathercoin network
func GetChainParams(chain string) *chaincfg.Params {
if !chaincfg.IsRegistered(&chaincfg.MainNetParams) {
chaincfg.RegisterBitcoinParams()
}
if !chaincfg.IsRegistered(&MainNetParams) {
err := chaincfg.Register(&MainNetParams)
if err != nil {
panic(err)
}
}
return &MainNetParams
}

// PackTx packs transaction to byte array using protobuf
func (p *FeathercoinParser) PackTx(tx *bchain.Tx, height uint32, blockTime int64) ([]byte, error) {
return p.baseparser.PackTx(tx, height, blockTime)
}

// UnpackTx unpacks transaction from protobuf byte array
func (p *FeathercoinParser) UnpackTx(buf []byte) (*bchain.Tx, uint32, error) {
return p.baseparser.UnpackTx(buf)
}
71 changes: 71 additions & 0 deletions bchain/coins/feathercoin/feathercoinparser_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//go:build unittest

package feathercoin

import (
"encoding/hex"
"os"
"reflect"
"testing"

"github.com/martinboehm/btcutil/chaincfg"
"github.com/trezor/blockbook/bchain/coins/btc"
)

func TestMain(m *testing.M) {
c := m.Run()
chaincfg.ResetParams()
os.Exit(c)
}

func Test_GetAddrDescFromAddress_Mainnet(t *testing.T) {
type args struct {
address string
}
tests := []struct {
name string
args args
want string
wantErr bool
}{
{
name: "pubkeyhash1",
args: args{address: "6z2aHdD9qpg5J2MW8dsbKTDTekVFG37y2S"},
want: "76a914de9fd965bc63fc198fd7c37de4328ce0bdec88a488ac",
wantErr: false,
},
{
name: "pubkeyhash2",
args: args{address: "729vtmzauQdywB94HAJbtH3zLmUPrmfQws"},
want: "76a914f5f436ad39d4e2b4ecf8c45cafa068b4f7a5a05e88ac",
wantErr: false,
},
{
name: "scripthash1",
args: args{address: "3FfGSMgjEdR7UK8t7WyqSZJy1LEUVTgrFx"},
want: "a914993d0b74ca784f2817a82b8991bb373e2e6c04eb87",
wantErr: false,
},
{
name: "scripthash2",
args: args{address: "3MCEGQuc8gfCavDBDuUS4Lz1jyanSs3ijG"},
want: "a914d5f0c17f0f028ea834ad8fda350f8f5b745ee10387",
wantErr: false,
},
}
parser := NewFeathercoinParser(GetChainParams("main"), &btc.Configuration{})

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := parser.GetAddrDescFromAddress(tt.args.address)
if (err != nil) != tt.wantErr {
t.Errorf("GetAddrDescFromAddress() error = %v, wantErr %v", err, tt.wantErr)
return
}
h := hex.EncodeToString(got)
if !reflect.DeepEqual(h, tt.want) {
t.Errorf("GetAddrDescFromAddress() = %v, want %v", h, tt.want)
}
})
}
}
54 changes: 54 additions & 0 deletions bchain/coins/feathercoin/feathercoinrpc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package feathercoin

import (
"encoding/json"

"github.com/golang/glog"
"github.com/trezor/blockbook/bchain"
"github.com/trezor/blockbook/bchain/coins/btc"
)

// FeathercoinRPC is an interface to JSON-RPC bitcoind service.
type FeathercoinRPC struct {
*btc.BitcoinRPC
}

// NewFeathercoinRPC returns new FeathercoinRPC instance.
func NewFeathercoinRPC(config json.RawMessage, pushHandler func(bchain.NotificationType)) (bchain.BlockChain, error) {
b, err := btc.NewBitcoinRPC(config, pushHandler)
if err != nil {
return nil, err
}

s := &FeathercoinRPC{
b.(*btc.BitcoinRPC),
}
s.RPCMarshaler = btc.JSONMarshalerV2{}
s.ChainConfig.SupportsEstimateFee = false

return s, nil
}

// Initialize initializes FeathercoinRPC instance.
func (b *FeathercoinRPC) Initialize() error {
ci, err := b.GetChainInfo()
if err != nil {
return err
}
chainName := ci.Chain

glog.Info("Chain name ", chainName)
params := GetChainParams(chainName)

// always create parser
b.Parser = NewFeathercoinParser(params, b.ChainConfig)

// parameters for getInfo request
b.Testnet = false
b.Network = "livenet"

glog.Info("rpc: block chain ", params.Name)

return nil
}

9 changes: 7 additions & 2 deletions build/docker/bin/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# initialize from the image defined by BASE_IMAGE
ARG BASE_IMAGE
FROM $BASE_IMAGE
FROM ubuntu:18.04
ARG DEBIAN_FRONTEND=noninteractive
ARG PORTABLE_ROCKSDB

Expand All @@ -11,6 +10,12 @@ RUN apt-get update && \
liblz4-dev graphviz && \
apt-get clean

RUN cd /opt && wget https://download.libsodium.org/libsodium/releases/libsodium-1.0.18-stable.tar.gz && \
tar zxvf libsodium-1.0.18-stable.tar.gz && cd libsodium-stable && \
./configure && make check && make install && ldconfig
RUN cd /opt && wget https://github.com/zeromq/libzmq/releases/download/v4.2.2/zeromq-4.2.2.tar.gz && \
tar -xvf zeromq-4.2.2.tar.gz && cd zeromq-4.2.2 && ./configure && make && make install

ENV GOLANG_VERSION=go1.17.1.linux-amd64
ENV ROCKSDB_VERSION=v6.22.1
ENV GOPATH=/go
Expand Down
2 changes: 1 addition & 1 deletion build/templates/blockbook/debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ override_dh_systemd_start:
override_dh_installinit:

override_dh_shlibdeps:
dh_shlibdeps -- --warnings=0
dh_shlibdeps -- --warnings=0 --ignore-missing-info
{{end}}
70 changes: 70 additions & 0 deletions configs/coins/feathercoin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"coin": {
"name": "Feathercoin",
"shortcut": "FTC",
"label": "Feathercoin",
"alias": "feathercoin"
},
"ports": {
"backend_rpc": 8098,
"backend_message_queue": 38398,
"blockbook_internal": 9098,
"blockbook_public": 9198
},
"ipc": {
"rpc_url_template": "http://127.0.0.1:{{.Ports.BackendRPC}}",
"rpc_user": "rpc",
"rpc_pass": "rpc",
"rpc_timeout": 25,
"message_queue_binding_template": "tcp://127.0.0.1:{{.Ports.BackendMessageQueue}}"
},
"backend": {
"package_name": "backend-feathercoin",
"package_revision": "satoshilabs-1",
"system_user": "feathercoin",
"version": "0.19.1",
"binary_url": "https://github.com/FeatherCoin/Feathercoin/releases/download/v0.19.1/feathercoin-0.19.1-x86_64-linux-gnu.tar.gz",
"verification_type": "sha256",
"verification_source": "56b0ec38ed5643731ba514623785e95f38a25373640c73d6724843b2afb6fa25",
"extract_command": "tar -C backend --strip 1 -xf",
"exclude_files": [
"bin/feathercoin-qt"
],
"exec_command_template": "{{.Env.BackendInstallPath}}/{{.Coin.Alias}}/bin/feathercoind -datadir={{.Env.BackendDataPath}}/{{.Coin.Alias}}/backend -conf={{.Env.BackendInstallPath}}/{{.Coin.Alias}}/{{.Coin.Alias}}.conf -pid=/run/{{.Coin.Alias}}/{{.Coin.Alias}}.pid",
"logrotate_files_template": "{{.Env.BackendDataPath}}/{{.Coin.Alias}}/backend/*.log",
"postinst_script_template": "",
"service_type": "forking",
"service_additional_params_template": "",
"protect_memory": true,
"mainnet": true,
"server_config_file": "bitcoin_like.conf",
"client_config_file": "bitcoin_like_client.conf",
"additional_params": {
"whitelist": "127.0.0.1"
}
},
"blockbook": {
"package_name": "blockbook-feathercoin",
"system_user": "blockbook-feathercoin",
"internal_binding_template": ":{{.Ports.BlockbookInternal}}",
"public_binding_template": ":{{.Ports.BlockbookPublic}}",
"explorer_url": "",
"additional_params": "",
"block_chain": {
"parse": true,
"mempool_workers": 8,
"mempool_sub_workers": 2,
"block_addresses_to_keep": 300,
"xpub_magic": 76069926,
"slip44": 8,
"additional_params": {
"fiat_rates": "coingecko",
"fiat_rates_params": "{\"url\": \"https://api.coingecko.com/api/v3\", \"coin\": \"feathercoin\", \"periodSeconds\": 60}"
}
}
},
"meta": {
"package_maintainer": "IT",
"package_maintainer_email": "[email protected]"
}
}
1 change: 1 addition & 0 deletions docs/ports.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
| BitZeny | 9095 | 9195 | 8095 | 38395 |
| Trezarcoin | 9096 | 9196 | 8096 | 38396 |
| eCash | 9097 | 9197 | 8097 | 38397 |
| Feathercoin | 9098 | 9198 | 8098 | 38398 |
| Bitcoin Signet | 19020 | 19120 | 18020 | 48320 |
| Bitcoin Regtest | 19021 | 19121 | 18021 | 48321 |
| Ethereum Goerli | 19026 | 19126 | 18026 | 48326 p2p |
Expand Down
32 changes: 32 additions & 0 deletions tests/rpc/testdata/feathercoin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"blockHash": "02a020f2615c46baab621129cc48ba224cb603e18d54f786d247eb41d98e9635",
"blockHeight": 4232070,
"blockTime": 1656489414,
"blockTxs": [
"e79b5f89d8bc061ec1be0c4e1981d300c28a71308f0fd6982db8f328e80d3b73"
],
"txDetails": {
"e79b5f89d8bc061ec1be0c4e1981d300c28a71308f0fd6982db8f328e80d3b73": {
"txid": "e79b5f89d8bc061ec1be0c4e1981d300c28a71308f0fd6982db8f328e80d3b73",
"version": 2,
"vin": [
{
"coinbase": "0386934004c605bc62088100036e2b0000007969696d7000",
"sequence": 0
}
],
"vout": [
{
"value": 20.00000000,
"n": 0,
"scriptPubKey": {
"hex": "a914eb95c76c2190549975875f40819b5b5d8a97da8a87"
}
}
],
"hex": "02000000010000000000000000000000000000000000000000000000000000000000000000ffffffff180386934004c605bc62088100036e2b0000007969696d70000000000001009435770000000017a914eb95c76c2190549975875f40819b5b5d8a97da8a8700000000",
"time": 1656489414,
"blocktime": 1656489414
}
}
}
Loading