Skip to content
Permalink
Browse files

add rdd coin

  • Loading branch information
matyushkins committed Dec 25, 2020
1 parent 7b2196d commit 4188e73fd0c766ffd16557769dab5ebee3e48377
@@ -49,6 +49,7 @@ import (
"github.com/trezor/blockbook/bchain/coins/snowgem"
"github.com/trezor/blockbook/bchain/coins/unobtanium"
"github.com/trezor/blockbook/bchain/coins/verge"
"github.com/trezor/blockbook/bchain/coins/rdd"
"github.com/trezor/blockbook/bchain/coins/vertcoin"
"github.com/trezor/blockbook/bchain/coins/viacoin"
"github.com/trezor/blockbook/bchain/coins/vipstarcoin"
@@ -130,6 +131,8 @@ func init() {
BlockChainFactories["Creamcoin"] = creamcoin.NewCreamCoinRPC
BlockChainFactories["Komodo"] = kmd.NewKmdRPC
BlockChainFactories["Aryacoin"] = aryacoin.NewAryaCoinRPC
BlockChainFactories["Reddcoin"] = rdd.NewReddRPC
BlockChainFactories["Reddcoin Testnet"] = rdd.NewReddRPC
}

// GetCoinNameFromConfig gets coin name and coin shortcut from config file
@@ -0,0 +1,196 @@
package rdd

import (
"github.com/trezor/blockbook/bchain"
"github.com/trezor/blockbook/bchain/coins/btc"
"math/big"
"time"

"github.com/martinboehm/btcd/chaincfg/chainhash"
"github.com/martinboehm/btcd/wire"
"github.com/martinboehm/btcutil/chaincfg"
)

const (
// MainNet represents the main bitcoin network.
MainReddNet wire.BitcoinNet = 0x504852 // PHR
TestReddNet wire.BitcoinNet = 0x545048 // TP
)

var (
// bigOne is 1 represented as a big.Int. It is defined here to avoid
// the overhead of creating it multiple times.
bigOne = big.NewInt(1)

// mainPowLimit is the highest proof of work value a Bitcoin block can
// have for the main network. It is the value 2^224 - 1.
mainPowLimit = new(big.Int).Sub(new(big.Int).Lsh(bigOne, 255), bigOne)

MainNetParams chaincfg.Params
TestNetParams chaincfg.Params
)

var genesisHash = chainhash.Hash([chainhash.HashSize]byte{ // Make go vet happy.
0xb8, 0x68, 0xe0, 0xd9, 0x5a, 0x3c, 0x3c, 0x0e,
0x0d, 0xad, 0xc6, 0x7e, 0xe5, 0x87, 0xaa, 0xf9,
0xdc, 0x8a, 0xcb, 0xf9, 0x9e, 0x3b, 0x4b, 0x31,
0x10, 0xfa, 0xd4, 0xeb, 0x74, 0xc1, 0xde, 0xcc,
})

func newHashFromStr(hexStr string) *chainhash.Hash {
hash, err := chainhash.NewHashFromStr(hexStr)
if err != nil {
panic(err)
}
return hash
}

var ReddMainNetParams = chaincfg.Params{
Name: "mainRedd",
Net: MainReddNet,
DefaultPort: "45444",
DNSSeeds: []chaincfg.DNSSeed{
{"seed.reddcoin.com", true},
{"dnsseed01.redd.ink", true},
{"dnsseed02.redd.ink", true},
{"dnsseed03.redd.ink", true},
},

// Chain parameters
GenesisBlock: nil, // not required
GenesisHash: &genesisHash,
PowLimit: mainPowLimit,
PowLimitBits: 0x1d00ffff,
BIP0034Height: 227931,
BIP0065Height: 388381,
BIP0066Height: 363725,
CoinbaseMaturity: 100,
SubsidyReductionInterval: 210000,
TargetTimespan: time.Hour * 24, // 24 hours
TargetTimePerBlock: time.Minute, // 1 minute
RetargetAdjustmentFactor: 4, // 25% less, 400% more
ReduceMinDifficulty: false,
MinDiffReductionTime: 0,
GenerateSupported: false,

// Checkpoints ordered from oldest to newest.
Checkpoints: []chaincfg.Checkpoint{
},

// Mempool parameters
RelayNonStdTxs: false,

// Human-readable part for Bech32 encoded segwit addresses, as defined in
// BIP 173.
Bech32HRPSegwit: "bc", // always bc for main net

AddressMagicLen: 1,

// Address encoding magics
PubKeyHashAddrID: []byte{0x3D}, // starts with 61
ScriptHashAddrID: []byte{0x05}, // starts with 5
PrivateKeyID: []byte{0xBD},
WitnessPubKeyHashAddrID: nil,
WitnessScriptHashAddrID: nil,

// BIP32 hierarchical deterministic extended key magics
HDPrivateKeyID: [4]byte{0x04, 0x35, 0x83, 0x94}, // starts with xprv
HDPublicKeyID: [4]byte{0x04, 0x35, 0x87, 0xCF}, // starts with xpub

// BIP44 coin type used in the hierarchical deterministic path for
// address generation.
HDCoinType: 0x80000004,
}

var ReddTestNetParams = chaincfg.Params{
Name: "testnetRedd",
Net: TestReddNet,
DefaultPort: "55444",
DNSSeeds: []chaincfg.DNSSeed{
{"testnet-seed.reddcoin.com", true},
{"testnet-dnsseed.redd.ink", true},
},

// Chain parameters
GenesisBlock: nil, // unused
GenesisHash: nil, // unused
PowLimit: mainPowLimit,
PowLimitBits: 0x207fffff,
BIP0034Height: 0, // unused
BIP0065Height: 0, // unused
BIP0066Height: 0, // unused
CoinbaseMaturity: 50,
TargetTimespan: time.Minute, // 1 minute
TargetTimePerBlock: time.Minute, // 1 minutes
RetargetAdjustmentFactor: 4, // 25% less, 400% more
ReduceMinDifficulty: false,
MinDiffReductionTime: 0,
GenerateSupported: true,
Checkpoints: []chaincfg.Checkpoint{},
RelayNonStdTxs: false,
Bech32HRPSegwit: "bc",

AddressMagicLen: 1,

// Address encoding magics
PubKeyHashAddrID: []byte{0x8B}, // starts with x or y
ScriptHashAddrID: []byte{0x13}, // starts with 8 or 9
PrivateKeyID: []byte{0xEF}, // starts with '9' or 'c' (Bitcoin defaults)
WitnessPubKeyHashAddrID: nil,
WitnessScriptHashAddrID: nil,

HDPrivateKeyID: [4]byte{0x3a, 0x80, 0x61, 0xa0},
HDPublicKeyID: [4]byte{0x3a, 0x80, 0x58, 0x37},

HDCoinType: 0x80000001,
}


func init() {
MainNetParams = ReddMainNetParams
TestNetParams = ReddTestNetParams
}

// ReddParser handle
type ReddParser struct {
*btc.BitcoinParser
baseparser *bchain.BaseParser
}

// NewReddParser returns new ReddParser instance
func NewReddParser(params *chaincfg.Params, c *btc.Configuration) *ReddParser {
return &ReddParser{
BitcoinParser: btc.NewBitcoinParser(params, c),
baseparser: &bchain.BaseParser{},
}
}

// GetChainParams contains network parameters for the main ReedCoin network,
// and the test ReddCoin network
func GetChainParams(chain string) *chaincfg.Params {
if !chaincfg.IsRegistered(&MainNetParams) {
err := chaincfg.Register(&MainNetParams)
if err == nil {
err = chaincfg.Register(&TestNetParams)
}
if err != nil {
panic(err)
}
}
switch chain {
case "test":
return &TestNetParams
default:
return &MainNetParams
}
}

// PackTx packs transaction to byte array using protobuf
func (p *ReddParser) 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 *ReddParser) UnpackTx(buf []byte) (*bchain.Tx, uint32, error) {
return p.baseparser.UnpackTx(buf)
}
@@ -0,0 +1,102 @@
package rdd

import (
"github.com/trezor/blockbook/bchain"
"github.com/trezor/blockbook/bchain/coins/btc"
"encoding/json"

"github.com/golang/glog"
"github.com/juju/errors"
)

type ReedRPC struct {
*btc.BitcoinRPC
}

func NewReddRPC(config json.RawMessage, pushHandler func(bchain.NotificationType)) (bchain.BlockChain, error) {
b, err := btc.NewBitcoinRPC(config, pushHandler)
if err != nil {
return nil, err
}
g := &ReedRPC{
BitcoinRPC: b.(*btc.BitcoinRPC),
}
g.RPCMarshaler = btc.JSONMarshalerV1{}
return g, nil
}

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

params := GetChainParams(chainName)

b.Parser = NewReddParser(params, b.ChainConfig)

// parameters for getInfo request
if params.Net == MainReddNet {
b.Testnet = false
b.Network = "livenet"
} else {
b.Testnet = true
b.Network = "testnet"
}

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

return nil
}

// GetBlock returns block with given hash.
func (s *ReedRPC) GetBlock(hash string, height uint32) (*bchain.Block, error) {
var err error
if hash == "" && height > 0 {
hash, err = s.GetBlockHash(height)
if err != nil {
return nil, err
}
}

glog.V(1).Info("rpc: getblock (verbosity=1) ", hash)

res := btc.ResGetBlockThin{}
req := btc.CmdGetBlock{Method: "getblock"}
req.Params.BlockHash = hash
req.Params.Verbosity = 1
err = s.Call(&req, &res)

if err != nil {
return nil, errors.Annotatef(err, "hash %v", hash)
}
if res.Error != nil {
return nil, errors.Annotatef(res.Error, "hash %v", hash)
}

txs := make([]bchain.Tx, 0, len(res.Result.Txids))
for _, txid := range res.Result.Txids {
tx, err := s.GetTransaction(txid)
if err != nil {
if err == bchain.ErrTxNotFound {
glog.Errorf("rpc: getblock: skipping transanction in block %s due error: %s", hash, err)
continue
}
return nil, err
}
txs = append(txs, *tx)
}
block := &bchain.Block{
BlockHeader: res.Result.BlockHeader,
Txs: txs,
}
return block, nil
}

// GetTransactionForMempool returns a transaction by the transaction ID.
// It could be optimized for mempool, i.e. without block time and confirmations
func (s *ReedRPC) GetTransactionForMempool(txid string) (*bchain.Tx, error) {
return s.GetTransaction(txid)
}
@@ -41,7 +41,7 @@ RUN \
trap cleanup EXIT && \
mkdir -p $GOPATH/src/github.com/trezor && \
cd $GOPATH/src/github.com/trezor && \
git clone https://github.com/trezor/blockbook.git && \
git clone https://github.com/guardaco/blockbook.git && \
cd blockbook && \
go mod download

@@ -0,0 +1,67 @@
{
"coin": {
"name": "Reddcoin",
"shortcut": "RDD",
"label": "Reddcoin",
"alias": "reddcoin"
},
"ports": {
"backend_rpc": 8047,
"backend_message_queue": 38347,
"blockbook_internal": 9047,
"blockbook_public": 9147
},
"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-reddcoin",
"package_revision": "satoshilabs-1",
"system_user": "reddcoin",
"version": "3.10.3",
"binary_url": "https://download.reddcoin.com/bin/reddcoin-core-3.10.3/reddcoin-3.10.3-linux64.tar.gz",
"verification_type": "gpg-sha256",
"verification_source": "https://download.reddcoin.com/bin/reddcoin-core-3.10.3/SHA256SUMS",
"extract_command": "tar -C backend --strip 1 -xf",
"exclude_files": [
"bin/reddcoin-qt",
"bin/test_reddcoin",
"bin/test_reddcoin-qt"
],
"exec_command_template": "{{.Env.BackendInstallPath}}/{{.Coin.Alias}}/bin/reddcoind -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": {
"deprecatedrpc": "estimatefee"
}
},
"blockbook": {
"package_name": "blockbook-reddcoin",
"system_user": "blockbook-reddcoin",
"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,
"additional_params": {}
}
},
"meta": {
"package_maintainer": "Mateusz Jachna",
"package_maintainer_email": "anchaj@phore.io"
}
}

0 comments on commit 4188e73

Please sign in to comment.