diff --git a/bchain/coins/bch/bcashrpc.go b/bchain/coins/bch/bcashrpc.go index 4ed4f834..68af837a 100644 --- a/bchain/coins/bch/bcashrpc.go +++ b/bchain/coins/bch/bcashrpc.go @@ -70,16 +70,6 @@ type cmdGetBlock struct { } `json:"params"` } -type resGetBlockRaw struct { - Error *bchain.RPCError `json:"error"` - Result string `json:"result"` -} - -type resGetBlockThin struct { - Error *bchain.RPCError `json:"error"` - Result bchain.ThinBlock `json:"result"` -} - // estimatesmartfee type cmdEstimateSmartFee struct { @@ -89,14 +79,6 @@ type cmdEstimateSmartFee struct { } `json:"params"` } -type resEstimateSmartFee struct { - Error *bchain.RPCError `json:"error"` - Result struct { - Feerate float64 `json:"feerate"` - Blocks int `json:"blocks"` - } `json:"result"` -} - // GetBlock returns block with given hash. func (b *BCashRPC) GetBlock(hash string, height uint32) (*bchain.Block, error) { var err error @@ -126,7 +108,7 @@ func (b *BCashRPC) GetBlock(hash string, height uint32) (*bchain.Block, error) { func (b *BCashRPC) GetBlockRaw(hash string) ([]byte, error) { glog.V(1).Info("rpc: getblock (verbose=0) ", hash) - res := resGetBlockRaw{} + res := btc.ResGetBlockRaw{} req := cmdGetBlock{Method: "getblock"} req.Params.BlockHash = hash req.Params.Verbose = false @@ -153,7 +135,7 @@ func (b *BCashRPC) GetBlockFull(hash string) (*bchain.Block, error) { func (b *BCashRPC) EstimateSmartFee(blocks int, conservative bool) (float64, error) { glog.V(1).Info("rpc: estimatesmartfee ", blocks) - res := resEstimateSmartFee{} + res := btc.ResEstimateSmartFee{} req := cmdEstimateSmartFee{Method: "estimatesmartfee"} req.Params.Blocks = blocks // conservative param is omitted diff --git a/bchain/coins/blockchain.go b/bchain/coins/blockchain.go index be478f64..0bcae649 100644 --- a/bchain/coins/blockchain.go +++ b/bchain/coins/blockchain.go @@ -5,6 +5,7 @@ import ( "blockbook/bchain/coins/bch" "blockbook/bchain/coins/btc" "blockbook/bchain/coins/btg" + "blockbook/bchain/coins/dash" "blockbook/bchain/coins/eth" "blockbook/bchain/coins/zec" "blockbook/common" @@ -32,6 +33,8 @@ func init() { blockChainFactories["Bcash"] = bch.NewBCashRPC blockChainFactories["Bcash Testnet"] = bch.NewBCashRPC blockChainFactories["Bgold"] = btg.NewBGoldRPC + blockChainFactories["Dash"] = dash.NewDashRPC + blockChainFactories["Dash Testnet"] = dash.NewDashRPC } // GetCoinNameFromConfig gets coin name from config file diff --git a/bchain/coins/btc/bitcoinrpc.go b/bchain/coins/btc/bitcoinrpc.go index f02cb060..6c29e75d 100644 --- a/bchain/coins/btc/bitcoinrpc.go +++ b/bchain/coins/btc/bitcoinrpc.go @@ -20,18 +20,19 @@ import ( // BitcoinRPC is an interface to JSON-RPC bitcoind service. type BitcoinRPC struct { - client http.Client - rpcURL string - user string - password string - Parser bchain.BlockChainParser - Testnet bool - Network string - Mempool *bchain.UTXOMempool - ParseBlocks bool - pushHandler func(bchain.NotificationType) - mq *bchain.MQ - ChainConfig *Configuration + client http.Client + rpcURL string + user string + password string + Parser bchain.BlockChainParser + Testnet bool + Network string + Mempool *bchain.UTXOMempool + ParseBlocks bool + pushHandler func(bchain.NotificationType) + mq *bchain.MQ + ChainConfig *Configuration + RPCMarshaler RPCMarshaler } type Configuration struct { @@ -76,13 +77,14 @@ func NewBitcoinRPC(config json.RawMessage, pushHandler func(bchain.NotificationT } s := &BitcoinRPC{ - client: http.Client{Timeout: time.Duration(c.RPCTimeout) * time.Second, Transport: transport}, - rpcURL: c.RPCURL, - user: c.RPCUser, - password: c.RPCPass, - ParseBlocks: c.Parse, - ChainConfig: &c, - pushHandler: pushHandler, + client: http.Client{Timeout: time.Duration(c.RPCTimeout) * time.Second, Transport: transport}, + rpcURL: c.RPCURL, + user: c.RPCUser, + password: c.RPCPass, + ParseBlocks: c.Parse, + ChainConfig: &c, + pushHandler: pushHandler, + RPCMarshaler: JSONMarshalerV2{}, } return s, nil @@ -165,47 +167,47 @@ func (b *BitcoinRPC) GetSubversion() string { // getblockhash -type cmdGetBlockHash struct { +type CmdGetBlockHash struct { Method string `json:"method"` Params struct { Height uint32 `json:"height"` } `json:"params"` } -type resGetBlockHash struct { +type ResGetBlockHash struct { Error *bchain.RPCError `json:"error"` Result string `json:"result"` } // getbestblockhash -type cmdGetBestBlockHash struct { +type CmdGetBestBlockHash struct { Method string `json:"method"` } -type resGetBestBlockHash struct { +type ResGetBestBlockHash struct { Error *bchain.RPCError `json:"error"` Result string `json:"result"` } // getblockcount -type cmdGetBlockCount struct { +type CmdGetBlockCount struct { Method string `json:"method"` } -type resGetBlockCount struct { +type ResGetBlockCount struct { Error *bchain.RPCError `json:"error"` Result uint32 `json:"result"` } // getblockchaininfo -type cmdGetBlockChainInfo struct { +type CmdGetBlockChainInfo struct { Method string `json:"method"` } -type resGetBlockChainInfo struct { +type ResGetBlockChainInfo struct { Error *bchain.RPCError `json:"error"` Result struct { Chain string `json:"chain"` @@ -217,18 +219,18 @@ type resGetBlockChainInfo struct { // getrawmempool -type cmdGetMempool struct { +type CmdGetMempool struct { Method string `json:"method"` } -type resGetMempool struct { +type ResGetMempool struct { Error *bchain.RPCError `json:"error"` Result []string `json:"result"` } // getblockheader -type cmdGetBlockHeader struct { +type CmdGetBlockHeader struct { Method string `json:"method"` Params struct { BlockHash string `json:"blockhash"` @@ -236,14 +238,14 @@ type cmdGetBlockHeader struct { } `json:"params"` } -type resGetBlockHeader struct { +type ResGetBlockHeader struct { Error *bchain.RPCError `json:"error"` Result bchain.BlockHeader `json:"result"` } // getblock -type cmdGetBlock struct { +type CmdGetBlock struct { Method string `json:"method"` Params struct { BlockHash string `json:"blockhash"` @@ -251,24 +253,24 @@ type cmdGetBlock struct { } `json:"params"` } -type resGetBlockRaw struct { +type ResGetBlockRaw struct { Error *bchain.RPCError `json:"error"` Result string `json:"result"` } -type resGetBlockThin struct { +type ResGetBlockThin struct { Error *bchain.RPCError `json:"error"` Result bchain.ThinBlock `json:"result"` } -type resGetBlockFull struct { +type ResGetBlockFull struct { Error *bchain.RPCError `json:"error"` Result bchain.Block `json:"result"` } // getrawtransaction -type cmdGetRawTransaction struct { +type CmdGetRawTransaction struct { Method string `json:"method"` Params struct { Txid string `json:"txid"` @@ -276,19 +278,19 @@ type cmdGetRawTransaction struct { } `json:"params"` } -type resGetRawTransaction struct { +type ResGetRawTransaction struct { Error *bchain.RPCError `json:"error"` Result json.RawMessage `json:"result"` } -type resGetRawTransactionNonverbose struct { +type ResGetRawTransactionNonverbose struct { Error *bchain.RPCError `json:"error"` Result string `json:"result"` } // estimatesmartfee -type cmdEstimateSmartFee struct { +type CmdEstimateSmartFee struct { Method string `json:"method"` Params struct { ConfTarget int `json:"conf_target"` @@ -296,7 +298,7 @@ type cmdEstimateSmartFee struct { } `json:"params"` } -type resEstimateSmartFee struct { +type ResEstimateSmartFee struct { Error *bchain.RPCError `json:"error"` Result struct { Feerate float64 `json:"feerate"` @@ -306,38 +308,38 @@ type resEstimateSmartFee struct { // estimatefee -type cmdEstimateFee struct { +type CmdEstimateFee struct { Method string `json:"method"` Params struct { Blocks int `json:"nblocks"` } `json:"params"` } -type resEstimateFee struct { +type ResEstimateFee struct { Error *bchain.RPCError `json:"error"` Result float64 `json:"result"` } // sendrawtransaction -type cmdSendRawTransaction struct { +type CmdSendRawTransaction struct { Method string `json:"method"` Params []string `json:"params"` } -type resSendRawTransaction struct { +type ResSendRawTransaction struct { Error *bchain.RPCError `json:"error"` Result string `json:"result"` } // getmempoolentry -type cmdGetMempoolEntry struct { +type CmdGetMempoolEntry struct { Method string `json:"method"` Params []string `json:"params"` } -type resGetMempoolEntry struct { +type ResGetMempoolEntry struct { Error *bchain.RPCError `json:"error"` Result *bchain.MempoolEntry `json:"result"` } @@ -347,8 +349,8 @@ func (b *BitcoinRPC) GetBestBlockHash() (string, error) { glog.V(1).Info("rpc: getbestblockhash") - res := resGetBestBlockHash{} - req := cmdGetBestBlockHash{Method: "getbestblockhash"} + res := ResGetBestBlockHash{} + req := CmdGetBestBlockHash{Method: "getbestblockhash"} err := b.Call(&req, &res) if err != nil { @@ -364,8 +366,8 @@ func (b *BitcoinRPC) GetBestBlockHash() (string, error) { func (b *BitcoinRPC) GetBestBlockHeight() (uint32, error) { glog.V(1).Info("rpc: getblockcount") - res := resGetBlockCount{} - req := cmdGetBlockCount{Method: "getblockcount"} + res := ResGetBlockCount{} + req := CmdGetBlockCount{Method: "getblockcount"} err := b.Call(&req, &res) if err != nil { @@ -381,8 +383,8 @@ func (b *BitcoinRPC) GetBestBlockHeight() (uint32, error) { func (b *BitcoinRPC) GetBlockChainInfo() (string, error) { glog.V(1).Info("rpc: getblockchaininfo") - res := resGetBlockChainInfo{} - req := cmdGetBlockChainInfo{Method: "getblockchaininfo"} + res := ResGetBlockChainInfo{} + req := CmdGetBlockChainInfo{Method: "getblockchaininfo"} err := b.Call(&req, &res) if err != nil { @@ -403,8 +405,8 @@ func isErrBlockNotFound(err *bchain.RPCError) bool { func (b *BitcoinRPC) GetBlockHash(height uint32) (string, error) { glog.V(1).Info("rpc: getblockhash ", height) - res := resGetBlockHash{} - req := cmdGetBlockHash{Method: "getblockhash"} + res := ResGetBlockHash{} + req := CmdGetBlockHash{Method: "getblockhash"} req.Params.Height = height err := b.Call(&req, &res) @@ -424,8 +426,8 @@ func (b *BitcoinRPC) GetBlockHash(height uint32) (string, error) { func (b *BitcoinRPC) GetBlockHeader(hash string) (*bchain.BlockHeader, error) { glog.V(1).Info("rpc: getblockheader") - res := resGetBlockHeader{} - req := cmdGetBlockHeader{Method: "getblockheader"} + res := ResGetBlockHeader{} + req := CmdGetBlockHeader{Method: "getblockheader"} req.Params.BlockHash = hash req.Params.Verbose = true err := b.Call(&req, &res) @@ -494,8 +496,8 @@ func (b *BitcoinRPC) getBlockWithoutHeader(hash string, height uint32) (*bchain. func (b *BitcoinRPC) GetBlockRaw(hash string) ([]byte, error) { glog.V(1).Info("rpc: getblock (verbosity=0) ", hash) - res := resGetBlockRaw{} - req := cmdGetBlock{Method: "getblock"} + res := ResGetBlockRaw{} + req := CmdGetBlock{Method: "getblock"} req.Params.BlockHash = hash req.Params.Verbosity = 0 err := b.Call(&req, &res) @@ -516,8 +518,8 @@ func (b *BitcoinRPC) GetBlockRaw(hash string) ([]byte, error) { func (b *BitcoinRPC) GetBlockFull(hash string) (*bchain.Block, error) { glog.V(1).Info("rpc: getblock (verbosity=2) ", hash) - res := resGetBlockFull{} - req := cmdGetBlock{Method: "getblock"} + res := ResGetBlockFull{} + req := CmdGetBlock{Method: "getblock"} req.Params.BlockHash = hash req.Params.Verbosity = 2 err := b.Call(&req, &res) @@ -538,8 +540,8 @@ func (b *BitcoinRPC) GetBlockFull(hash string) (*bchain.Block, error) { func (b *BitcoinRPC) GetMempool() ([]string, error) { glog.V(1).Info("rpc: getrawmempool") - res := resGetMempool{} - req := cmdGetMempool{Method: "getrawmempool"} + res := ResGetMempool{} + req := CmdGetMempool{Method: "getrawmempool"} err := b.Call(&req, &res) if err != nil { @@ -556,8 +558,8 @@ func (b *BitcoinRPC) GetMempool() ([]string, error) { func (b *BitcoinRPC) GetTransactionForMempool(txid string) (*bchain.Tx, error) { glog.V(1).Info("rpc: getrawtransaction nonverbose ", txid) - res := resGetRawTransactionNonverbose{} - req := cmdGetRawTransaction{Method: "getrawtransaction"} + res := ResGetRawTransactionNonverbose{} + req := CmdGetRawTransaction{Method: "getrawtransaction"} req.Params.Txid = txid req.Params.Verbose = false err := b.Call(&req, &res) @@ -582,8 +584,8 @@ func (b *BitcoinRPC) GetTransactionForMempool(txid string) (*bchain.Tx, error) { func (b *BitcoinRPC) GetTransaction(txid string) (*bchain.Tx, error) { glog.V(1).Info("rpc: getrawtransaction ", txid) - res := resGetRawTransaction{} - req := cmdGetRawTransaction{Method: "getrawtransaction"} + res := ResGetRawTransaction{} + req := CmdGetRawTransaction{Method: "getrawtransaction"} req.Params.Txid = txid req.Params.Verbose = true err := b.Call(&req, &res) @@ -617,8 +619,8 @@ func (b *BitcoinRPC) GetMempoolTransactions(address string) ([]string, error) { func (b *BitcoinRPC) EstimateSmartFee(blocks int, conservative bool) (float64, error) { glog.V(1).Info("rpc: estimatesmartfee ", blocks) - res := resEstimateSmartFee{} - req := cmdEstimateSmartFee{Method: "estimatesmartfee"} + res := ResEstimateSmartFee{} + req := CmdEstimateSmartFee{Method: "estimatesmartfee"} req.Params.ConfTarget = blocks if conservative { req.Params.EstimateMode = "CONSERVATIVE" @@ -640,8 +642,8 @@ func (b *BitcoinRPC) EstimateSmartFee(blocks int, conservative bool) (float64, e func (b *BitcoinRPC) EstimateFee(blocks int) (float64, error) { glog.V(1).Info("rpc: estimatefee ", blocks) - res := resEstimateFee{} - req := cmdEstimateFee{Method: "estimatefee"} + res := ResEstimateFee{} + req := CmdEstimateFee{Method: "estimatefee"} req.Params.Blocks = blocks err := b.Call(&req, &res) @@ -658,8 +660,8 @@ func (b *BitcoinRPC) EstimateFee(blocks int) (float64, error) { func (b *BitcoinRPC) SendRawTransaction(tx string) (string, error) { glog.V(1).Info("rpc: sendrawtransaction") - res := resSendRawTransaction{} - req := cmdSendRawTransaction{Method: "sendrawtransaction"} + res := ResSendRawTransaction{} + req := CmdSendRawTransaction{Method: "sendrawtransaction"} req.Params = []string{tx} err := b.Call(&req, &res) @@ -676,8 +678,8 @@ func (b *BitcoinRPC) SendRawTransaction(tx string) (string, error) { func (b *BitcoinRPC) GetMempoolEntry(txid string) (*bchain.MempoolEntry, error) { glog.V(1).Info("rpc: getmempoolentry") - res := resGetMempoolEntry{} - req := cmdGetMempoolEntry{ + res := ResGetMempoolEntry{} + req := CmdGetMempoolEntry{ Method: "getmempoolentry", Params: []string{txid}, } @@ -693,7 +695,7 @@ func (b *BitcoinRPC) GetMempoolEntry(txid string) (*bchain.MempoolEntry, error) } func (b *BitcoinRPC) Call(req interface{}, res interface{}) error { - httpData, err := json.Marshal(req) + httpData, err := b.RPCMarshaler.Marshal(req) if err != nil { return err } diff --git a/bchain/coins/btc/codec.go b/bchain/coins/btc/codec.go new file mode 100644 index 00000000..fa8f8bab --- /dev/null +++ b/bchain/coins/btc/codec.go @@ -0,0 +1,79 @@ +package btc + +import ( + "encoding/json" + "errors" + "reflect" +) + +type RPCMarshaler interface { + Marshal(v interface{}) ([]byte, error) +} + +type JSONMarshalerV2 struct{} + +func (JSONMarshalerV2) Marshal(v interface{}) ([]byte, error) { + d, err := json.Marshal(v) + if err != nil { + return nil, err + } + return d, nil +} + +var InvalidValue = errors.New("Invalid value to marshal") + +type JSONMarshalerV1 struct{} + +func (JSONMarshalerV1) Marshal(v interface{}) ([]byte, error) { + u := cmdUntypedParams{} + + switch v := v.(type) { + case *CmdGetBlock: + var t bool + if v.Params.Verbosity > 0 { + t = true + } + u.Method = v.Method + u.Params = append(u.Params, v.Params.BlockHash) + u.Params = append(u.Params, t) + case *CmdGetRawTransaction: + var n int + if v.Params.Verbose { + n = 1 + } + u.Method = v.Method + u.Params = append(u.Params, v.Params.Txid) + u.Params = append(u.Params, n) + default: + { + v := reflect.ValueOf(v).Elem() + + f := v.FieldByName("Method") + if !f.IsValid() || f.Kind() != reflect.String { + return nil, InvalidValue + } + u.Method = f.String() + + f = v.FieldByName("Params") + if f.IsValid() { + arr := make([]interface{}, f.NumField()) + for i := 0; i < f.NumField(); i++ { + arr[i] = f.Field(i).Interface() + } + u.Params = arr + } + } + } + + d, err := json.Marshal(u) + if err != nil { + return nil, err + } + + return d, nil +} + +type cmdUntypedParams struct { + Method string `json:"method"` + Params []interface{} `json:"params,omitempty"` +} diff --git a/bchain/coins/btg/bgoldparser.go b/bchain/coins/btg/bgoldparser.go index 4421848a..7c20a005 100644 --- a/bchain/coins/btg/bgoldparser.go +++ b/bchain/coins/btg/bgoldparser.go @@ -53,7 +53,7 @@ type BGoldParser struct { *btc.BitcoinParser } -// NewBCashParser returns new BGoldParser instance +// NewBGoldParser returns new BGoldParser instance func NewBGoldParser(params *chaincfg.Params, c *btc.Configuration) *BGoldParser { return &BGoldParser{BitcoinParser: btc.NewBitcoinParser(params, c)} } diff --git a/bchain/coins/dash/dashparser.go b/bchain/coins/dash/dashparser.go new file mode 100644 index 00000000..5590cc87 --- /dev/null +++ b/bchain/coins/dash/dashparser.go @@ -0,0 +1,78 @@ +package dash + +import ( + "blockbook/bchain/coins/btc" + + "github.com/btcsuite/btcd/chaincfg" + "github.com/btcsuite/btcd/wire" +) + +const ( + MainnetMagic wire.BitcoinNet = 0xbd6b0cbf + TestnetMagic wire.BitcoinNet = 0xffcae2ce + RegtestMagic wire.BitcoinNet = 0xdcb7c1fc +) + +var ( + MainNetParams chaincfg.Params + TestNetParams chaincfg.Params + RegtestParams chaincfg.Params +) + +func init() { + MainNetParams = chaincfg.MainNetParams + MainNetParams.Net = MainnetMagic + + // Address encoding magics + MainNetParams.PubKeyHashAddrID = 76 // base58 prefix: X + MainNetParams.ScriptHashAddrID = 16 // base58 prefix: 7 + + TestNetParams = chaincfg.TestNet3Params + TestNetParams.Net = TestnetMagic + + // Address encoding magics + TestNetParams.PubKeyHashAddrID = 140 // base58 prefix: y + TestNetParams.ScriptHashAddrID = 19 // base58 prefix: 8 or 9 + + RegtestParams = chaincfg.RegressionNetParams + RegtestParams.Net = RegtestMagic + + // Address encoding magics + RegtestParams.PubKeyHashAddrID = 140 // base58 prefix: y + RegtestParams.ScriptHashAddrID = 19 // base58 prefix: 8 or 9 + + err := chaincfg.Register(&MainNetParams) + if err == nil { + err = chaincfg.Register(&TestNetParams) + } + if err == nil { + err = chaincfg.Register(&RegtestParams) + } + if err != nil { + panic(err) + } +} + +// DashParser handle +type DashParser struct { + *btc.BitcoinParser +} + +// NewDashParser returns new DashParser instance +func NewDashParser(params *chaincfg.Params, c *btc.Configuration) *DashParser { + return &DashParser{BitcoinParser: btc.NewBitcoinParser(params, c)} +} + +// GetChainParams contains network parameters for the main Dash network, +// the regression test Dash network, the test Dash network and +// the simulation test Dash network, in this order +func GetChainParams(chain string) *chaincfg.Params { + switch chain { + case "test": + return &TestNetParams + case "regtest": + return &RegtestParams + default: + return &MainNetParams + } +} diff --git a/bchain/coins/dash/dashrpc.go b/bchain/coins/dash/dashrpc.go new file mode 100644 index 00000000..3eaa177c --- /dev/null +++ b/bchain/coins/dash/dashrpc.go @@ -0,0 +1,55 @@ +package dash + +import ( + "blockbook/bchain" + "blockbook/bchain/coins/btc" + "encoding/json" + + "github.com/golang/glog" +) + +// DashRPC is an interface to JSON-RPC bitcoind service. +type DashRPC struct { + *btc.BitcoinRPC +} + +// NewDashRPC returns new DashRPC instance. +func NewDashRPC(config json.RawMessage, pushHandler func(bchain.NotificationType)) (bchain.BlockChain, error) { + b, err := btc.NewBitcoinRPC(config, pushHandler) + if err != nil { + return nil, err + } + + s := &DashRPC{ + b.(*btc.BitcoinRPC), + } + s.RPCMarshaler = btc.JSONMarshalerV1{} + + return s, nil +} + +// Initialize initializes DashRPC instance. +func (b *DashRPC) Initialize() error { + chainName, err := b.GetChainInfoAndInitializeMempool(b) + if err != nil { + return err + } + + params := GetChainParams(chainName) + + // always create parser + b.Parser = NewDashParser(params, b.ChainConfig) + + // parameters for getInfo request + if params.Net == MainnetMagic { + b.Testnet = false + b.Network = "livenet" + } else { + b.Testnet = true + b.Network = "testnet" + } + + glog.Info("rpc: block chain ", params.Name) + + return nil +} diff --git a/bchain/coins/zec/zcashrpc.go b/bchain/coins/zec/zcashrpc.go index ca368f10..6790c46f 100644 --- a/bchain/coins/zec/zcashrpc.go +++ b/bchain/coins/zec/zcashrpc.go @@ -21,6 +21,7 @@ func NewZCashRPC(config json.RawMessage, pushHandler func(bchain.NotificationTyp z := &ZCashRPC{ BitcoinRPC: b.(*btc.BitcoinRPC), } + z.RPCMarshaler = btc.JSONMarshalerV1{} return z, nil } @@ -49,46 +50,6 @@ func (z *ZCashRPC) Initialize() error { return nil } -type untypedArrayParams struct { - Method string `json:"method"` - Params []interface{} `json:"params"` -} - -// getblockhash - -type resGetBlockHash struct { - Error *bchain.RPCError `json:"error"` - Result string `json:"result"` -} - -// getblock - -type resGetBlockThin struct { - Error *bchain.RPCError `json:"error"` - Result bchain.ThinBlock `json:"result"` -} - -// getrawtransaction - -type resGetRawTransaction struct { - Error *bchain.RPCError `json:"error"` - Result json.RawMessage `json:"result"` -} - -// getblockheader - -type resGetBlockHeader struct { - Error *bchain.RPCError `json:"error"` - Result bchain.BlockHeader `json:"result"` -} - -// estimatefee - -type resEstimateFee struct { - Error *bchain.RPCError `json:"error"` - Result float64 `json:"result"` -} - // GetBlock returns block with given hash. func (z *ZCashRPC) GetBlock(hash string, height uint32) (*bchain.Block, error) { var err error @@ -101,10 +62,10 @@ func (z *ZCashRPC) GetBlock(hash string, height uint32) (*bchain.Block, error) { glog.V(1).Info("rpc: getblock (verbosity=1) ", hash) - res := resGetBlockThin{} - req := untypedArrayParams{Method: "getblock"} - req.Params = append(req.Params, hash) - req.Params = append(req.Params, true) + res := btc.ResGetBlockThin{} + req := btc.CmdGetBlock{Method: "getblock"} + req.Params.BlockHash = hash + req.Params.Verbosity = 1 err = z.Call(&req, &res) if err != nil { @@ -157,10 +118,10 @@ func (z *ZCashRPC) GetTransactionForMempool(txid string) (*bchain.Tx, error) { func (z *ZCashRPC) GetTransaction(txid string) (*bchain.Tx, error) { glog.V(1).Info("rpc: getrawtransaction ", txid) - res := resGetRawTransaction{} - req := untypedArrayParams{Method: "getrawtransaction"} - req.Params = append(req.Params, txid) - req.Params = append(req.Params, 1) + res := btc.ResGetRawTransaction{} + req := btc.CmdGetRawTransaction{Method: "getrawtransaction"} + req.Params.Txid = txid + req.Params.Verbose = true err := z.Call(&req, &res) if err != nil { @@ -176,76 +137,12 @@ func (z *ZCashRPC) GetTransaction(txid string) (*bchain.Tx, error) { return tx, nil } -// GetBlockHash returns hash of block in best-block-chain at given height. -func (z *ZCashRPC) GetBlockHash(height uint32) (string, error) { - glog.V(1).Info("rpc: getblockhash ", height) - - res := resGetBlockHash{} - req := untypedArrayParams{Method: "getblockhash"} - req.Params = append(req.Params, height) - err := z.Call(&req, &res) - - if err != nil { - return "", errors.Annotatef(err, "height %v", height) - } - if res.Error != nil { - if isErrBlockNotFound(res.Error) { - return "", bchain.ErrBlockNotFound - } - return "", errors.Annotatef(res.Error, "height %v", height) - } - return res.Result, nil -} - -// GetBlockHeader returns header of block with given hash. -func (z *ZCashRPC) GetBlockHeader(hash string) (*bchain.BlockHeader, error) { - glog.V(1).Info("rpc: getblockheader") - - res := resGetBlockHeader{} - req := untypedArrayParams{Method: "getblockheader"} - req.Params = append(req.Params, hash) - req.Params = append(req.Params, true) - err := z.Call(&req, &res) - - if err != nil { - return nil, errors.Annotatef(err, "hash %v", hash) - } - if res.Error != nil { - if isErrBlockNotFound(res.Error) { - return nil, bchain.ErrBlockNotFound - } - return nil, errors.Annotatef(res.Error, "hash %v", hash) - } - return &res.Result, nil -} - // EstimateSmartFee returns fee estimation. func (z *ZCashRPC) EstimateSmartFee(blocks int, conservative bool) (float64, error) { glog.V(1).Info("rpc: estimatesmartfee") - return z.estimateFee(blocks) -} - -// EstimateFee returns fee estimation. -func (z *ZCashRPC) EstimateFee(blocks int) (float64, error) { - glog.V(1).Info("rpc: estimatefee ", blocks) - - return z.estimateFee(blocks) -} - -func (z *ZCashRPC) estimateFee(blocks int) (float64, error) { - res := resEstimateFee{} - req := untypedArrayParams{Method: "estimatefee"} - req.Params = append(req.Params, blocks) - err := z.Call(&req, &res) - - if err != nil { - return 0, err - } - if res.Error != nil { - return 0, res.Error - } - return res.Result, nil + // return z.estimateFee(blocks) + return z.EstimateFee(blocks) } // GetMempoolEntry returns mempool data for given transaction diff --git a/build/deb/debian/blockbook-dash-testnet.conffiles b/build/deb/debian/blockbook-dash-testnet.conffiles new file mode 100644 index 00000000..e08c4c86 --- /dev/null +++ b/build/deb/debian/blockbook-dash-testnet.conffiles @@ -0,0 +1 @@ +/opt/coins/blockbook/dash_testnet/config/blockchaincfg.json diff --git a/build/deb/debian/blockbook-dash-testnet.cron.daily b/build/deb/debian/blockbook-dash-testnet.cron.daily new file mode 100644 index 00000000..9c293fb2 --- /dev/null +++ b/build/deb/debian/blockbook-dash-testnet.cron.daily @@ -0,0 +1,2 @@ +#!/bin/sh +/opt/coins/blockbook/dash_testnet/bin/logrotate.sh diff --git a/build/deb/debian/blockbook-dash-testnet.dirs b/build/deb/debian/blockbook-dash-testnet.dirs new file mode 100644 index 00000000..fa8b8ee8 --- /dev/null +++ b/build/deb/debian/blockbook-dash-testnet.dirs @@ -0,0 +1,2 @@ +/opt/coins/data/dash_testnet/blockbook +/opt/coins/blockbook/dash_testnet/logs diff --git a/build/deb/debian/blockbook-dash-testnet.install b/build/deb/debian/blockbook-dash-testnet.install new file mode 100755 index 00000000..a581ae9f --- /dev/null +++ b/build/deb/debian/blockbook-dash-testnet.install @@ -0,0 +1,6 @@ +#!/usr/bin/dh-exec +blockbook /opt/coins/blockbook/dash_testnet/bin +cert /opt/coins/blockbook/dash_testnet +static /opt/coins/blockbook/dash_testnet +configs/dash_testnet.json => /opt/coins/blockbook/dash_testnet/config/blockchaincfg.json +logrotate.sh /opt/coins/blockbook/dash_testnet/bin diff --git a/build/deb/debian/blockbook-dash-testnet.links b/build/deb/debian/blockbook-dash-testnet.links new file mode 100644 index 00000000..1d915f43 --- /dev/null +++ b/build/deb/debian/blockbook-dash-testnet.links @@ -0,0 +1,2 @@ +/opt/coins/blockbook/dash_testnet/cert/testcert.crt /opt/coins/blockbook/dash_testnet/cert/blockbook.crt +/opt/coins/blockbook/dash_testnet/cert/testcert.key /opt/coins/blockbook/dash_testnet/cert/blockbook.key diff --git a/build/deb/debian/blockbook-dash-testnet.postinst b/build/deb/debian/blockbook-dash-testnet.postinst new file mode 100644 index 00000000..fb2ff016 --- /dev/null +++ b/build/deb/debian/blockbook-dash-testnet.postinst @@ -0,0 +1,23 @@ +#!/bin/bash +set -e + +case "$1" in + + configure) + if ! id -u blockbook-dash &> /dev/null + then + useradd --system -M -U blockbook-dash -s /bin/false + fi + + for dir in /opt/coins/data/dash_testnet/blockbook /opt/coins/blockbook/dash_testnet/logs + do + if [ "$(stat -c '%U' $dir)" != "blockbook-dash" ] + then + chown -R blockbook-dash:blockbook-dash $dir + fi + done + ;; + +esac + +#DEBHELPER# diff --git a/build/deb/debian/blockbook-dash-testnet.service b/build/deb/debian/blockbook-dash-testnet.service new file mode 100644 index 00000000..8eb2b64e --- /dev/null +++ b/build/deb/debian/blockbook-dash-testnet.service @@ -0,0 +1,43 @@ +# It is not recommended to modify this file in-place, because it will +# be overwritten during package upgrades. If you want to add further +# options or overwrite existing ones then use +# $ systemctl edit blockbook-dash-testnet.service +# See "man systemd.service" for details. + +[Unit] +Description=Blockbook daemon (Dash testnet) +After=network.target +Wants=dash-testnet.service + +[Service] +ExecStart=/opt/coins/blockbook/dash_testnet/bin/blockbook -blockchaincfg=/opt/coins/blockbook/dash_testnet/config/blockchaincfg.json -datadir=/opt/coins/data/dash_testnet/blockbook/db -sync -httpserver=:19033 -socketio=:19133 -certfile=/opt/coins/blockbook/dash_testnet/cert/blockbook -explorer=https://dash-explorer.trezor.io/ -log_dir=/opt/coins/blockbook/dash_testnet/logs +User=blockbook-dash +Type=simple +Restart=on-failure +WorkingDirectory=/opt/coins/blockbook/dash_testnet + +# Resource limits +LimitNOFILE=500000 + +# Hardening measures +#################### + +# Provide a private /tmp and /var/tmp. +PrivateTmp=true + +# Mount /usr, /boot/ and /etc read-only for the process. +ProtectSystem=full + +# Disallow the process and all of its children to gain +# new privileges through execve(). +NoNewPrivileges=true + +# Use a new /dev namespace only populated with API pseudo devices +# such as /dev/null, /dev/zero and /dev/random. +PrivateDevices=true + +# Deny the creation of writable and executable memory mappings. +MemoryDenyWriteExecute=true + +[Install] +WantedBy=multi-user.target diff --git a/build/deb/debian/blockbook-dash.conffiles b/build/deb/debian/blockbook-dash.conffiles new file mode 100644 index 00000000..e228f725 --- /dev/null +++ b/build/deb/debian/blockbook-dash.conffiles @@ -0,0 +1 @@ +/opt/coins/blockbook/dash/config/blockchaincfg.json diff --git a/build/deb/debian/blockbook-dash.cron.daily b/build/deb/debian/blockbook-dash.cron.daily new file mode 100644 index 00000000..0dd836dc --- /dev/null +++ b/build/deb/debian/blockbook-dash.cron.daily @@ -0,0 +1,2 @@ +#!/bin/sh +/opt/coins/blockbook/dash/bin/logrotate.sh diff --git a/build/deb/debian/blockbook-dash.dirs b/build/deb/debian/blockbook-dash.dirs new file mode 100644 index 00000000..5b20974e --- /dev/null +++ b/build/deb/debian/blockbook-dash.dirs @@ -0,0 +1,2 @@ +/opt/coins/data/dash/blockbook +/opt/coins/blockbook/dash/logs diff --git a/build/deb/debian/blockbook-dash.install b/build/deb/debian/blockbook-dash.install new file mode 100755 index 00000000..aaee4542 --- /dev/null +++ b/build/deb/debian/blockbook-dash.install @@ -0,0 +1,6 @@ +#!/usr/bin/dh-exec +blockbook /opt/coins/blockbook/dash/bin +cert /opt/coins/blockbook/dash +static /opt/coins/blockbook/dash +configs/dash.json => /opt/coins/blockbook/dash/config/blockchaincfg.json +logrotate.sh /opt/coins/blockbook/dash/bin diff --git a/build/deb/debian/blockbook-dash.links b/build/deb/debian/blockbook-dash.links new file mode 100644 index 00000000..5df68a1c --- /dev/null +++ b/build/deb/debian/blockbook-dash.links @@ -0,0 +1,2 @@ +/opt/coins/blockbook/dash/cert/testcert.crt /opt/coins/blockbook/dash/cert/blockbook.crt +/opt/coins/blockbook/dash/cert/testcert.key /opt/coins/blockbook/dash/cert/blockbook.key diff --git a/build/deb/debian/blockbook-dash.postinst b/build/deb/debian/blockbook-dash.postinst new file mode 100644 index 00000000..4e259841 --- /dev/null +++ b/build/deb/debian/blockbook-dash.postinst @@ -0,0 +1,23 @@ +#!/bin/bash +set -e + +case "$1" in + + configure) + if ! id -u blockbook-dash &> /dev/null + then + useradd --system -M -U blockbook-dash -s /bin/false + fi + + for dir in /opt/coins/data/dash/blockbook /opt/coins/blockbook/dash/logs + do + if [ "$(stat -c '%U' $dir)" != "blockbook-dash" ] + then + chown -R blockbook-dash:blockbook-dash $dir + fi + done + ;; + +esac + +#DEBHELPER# diff --git a/build/deb/debian/blockbook-dash.service b/build/deb/debian/blockbook-dash.service new file mode 100644 index 00000000..e0a0b20b --- /dev/null +++ b/build/deb/debian/blockbook-dash.service @@ -0,0 +1,43 @@ +# It is not recommended to modify this file in-place, because it will +# be overwritten during package upgrades. If you want to add further +# options or overwrite existing ones then use +# $ systemctl edit blockbook-dash.service +# See "man systemd.service" for details. + +[Unit] +Description=Blockbook daemon (Dash mainnet) +After=network.target +Wants=dash.service + +[Service] +ExecStart=/opt/coins/blockbook/dash/bin/blockbook -blockchaincfg=/opt/coins/blockbook/dash/config/blockchaincfg.json -datadir=/opt/coins/data/dash/blockbook/db -sync -httpserver=:9033 -socketio=:9133 -certfile=/opt/coins/blockbook/dash/cert/blockbook -explorer=https://dash-explorer.trezor.io/ -log_dir=/opt/coins/blockbook/dash/logs +User=blockbook-dash +Type=simple +Restart=on-failure +WorkingDirectory=/opt/coins/blockbook/dash + +# Resource limits +LimitNOFILE=500000 + +# Hardening measures +#################### + +# Provide a private /tmp and /var/tmp. +PrivateTmp=true + +# Mount /usr, /boot/ and /etc read-only for the process. +ProtectSystem=full + +# Disallow the process and all of its children to gain +# new privileges through execve(). +NoNewPrivileges=true + +# Use a new /dev namespace only populated with API pseudo devices +# such as /dev/null, /dev/zero and /dev/random. +PrivateDevices=true + +# Deny the creation of writable and executable memory mappings. +MemoryDenyWriteExecute=true + +[Install] +WantedBy=multi-user.target diff --git a/build/deb/debian/control b/build/deb/debian/control index 9f3721dc..c2edc808 100644 --- a/build/deb/debian/control +++ b/build/deb/debian/control @@ -44,3 +44,13 @@ Package: blockbook-bgold Architecture: amd64 Depends: ${shlibs:Depends}, ${misc:Depends}, coreutils, passwd, findutils, psmisc, bgold Description: Satoshilabs blockbook server (Bitcoin Gold mainnet) + +Package: blockbook-dash +Architecture: amd64 +Depends: ${shlibs:Depends}, ${misc:Depends}, coreutils, passwd, findutils, psmisc, dash +Description: Satoshilabs blockbook server (Dash mainnet) + +Package: blockbook-dash-testnet +Architecture: amd64 +Depends: ${shlibs:Depends}, ${misc:Depends}, coreutils, passwd, findutils, psmisc, dash-testnet +Description: Satoshilabs blockbook server (Dash testnet) diff --git a/configs/dash.json b/configs/dash.json new file mode 100644 index 00000000..8ecf4818 --- /dev/null +++ b/configs/dash.json @@ -0,0 +1,13 @@ +{ + "coin_name": "Dash", + "rpcURL": "http://127.0.0.1:8033", + "rpcUser": "rpc", + "rpcPass": "rpc", + "rpcTimeout": 25, + "parse": true, + "zeroMQBinding": "tcp://127.0.0.1:38333", + "subversion": "/Dash Core:0.12.2.3/", + "mempoolWorkers": 8, + "mempoolSubWorkers": 2, + "blockAddressesToKeep": 300 +} diff --git a/configs/dash_testnet.json b/configs/dash_testnet.json new file mode 100644 index 00000000..7a613a4d --- /dev/null +++ b/configs/dash_testnet.json @@ -0,0 +1,13 @@ +{ + "coin_name": "Dash Testnet", + "rpcURL": "http://localhost:18033", + "rpcUser": "rpc", + "rpcPass": "rpc", + "rpcTimeout": 25, + "parse": true, + "zeroMQBinding": "tcp://127.0.0.1:48333", + "subversion": "/Dash Core:0.12.2.3/", + "mempoolWorkers": 8, + "mempoolSubWorkers": 2, + "blockAddressesToKeep": 300 +} diff --git a/contrib/backends/Makefile b/contrib/backends/Makefile index bc6b128c..0531302a 100644 --- a/contrib/backends/Makefile +++ b/contrib/backends/Makefile @@ -1,4 +1,4 @@ -TARGETS = bitcoin zcash bcash ethereum bgold +TARGETS = bitcoin zcash bcash ethereum bgold dash IMAGE = blockbook-backend-build-deb NO_CACHE = false diff --git a/contrib/backends/dash/Makefile b/contrib/backends/dash/Makefile new file mode 100644 index 00000000..9f379102 --- /dev/null +++ b/contrib/backends/dash/Makefile @@ -0,0 +1,14 @@ +DASH_VERSION := 0.12.2 +DASH_BUILD := .3 + +all: + wget https://github.com/dashpay/dash/releases/download/v${DASH_VERSION}${DASH_BUILD}/dashcore-${DASH_VERSION}${DASH_BUILD}-linux64.tar.gz + tar -xf dashcore-${DASH_VERSION}${DASH_BUILD}-linux64.tar.gz + mv dashcore-${DASH_VERSION} dash + rm dash/bin/dash-qt + rm dash/bin/test_dash + + +clean: + rm -rf dash + rm -f dashcore-${DASH_VERSION}${DASH_BUILD}-linux64.tar.gz diff --git a/contrib/backends/dash/dash.conf b/contrib/backends/dash/dash.conf new file mode 100644 index 00000000..b5425fc1 --- /dev/null +++ b/contrib/backends/dash/dash.conf @@ -0,0 +1,20 @@ +daemon=1 +server=1 +nolisten=1 +rpcuser=rpc +rpcpassword=rpc +rpcport=8033 +txindex=1 +addressindex=1 +timestampindex=1 +spentindex=1 + +zmqpubhashtx=tcp://127.0.0.1:38333 +zmqpubhashblock=tcp://127.0.0.1:38333 +zmqpubrawblock=tcp://127.0.0.1:38333 +zmqpubrawtx=tcp://127.0.0.1:38333 + +mempoolexpiry=72 +rpcworkqueue=1100 +maxmempool=2000 +dbcache=1000 diff --git a/contrib/backends/dash/dash_testnet.conf b/contrib/backends/dash/dash_testnet.conf new file mode 100644 index 00000000..ffb85a0c --- /dev/null +++ b/contrib/backends/dash/dash_testnet.conf @@ -0,0 +1,20 @@ +daemon=1 +server=1 +testnet=1 +nolisten=1 +rpcuser=rpc +rpcpassword=rpc +rpcport=18033 +txindex=1 +addressindex=1 +timestampindex=1 +spentindex=1 + +zmqpubhashtx=tcp://127.0.0.1:48333 +zmqpubhashblock=tcp://127.0.0.1:48333 +zmqpubrawblock=tcp://127.0.0.1:48333 +zmqpubrawtx=tcp://127.0.0.1:48333 + +rpcworkqueue=1100 +maxmempool=2000 +dbcache=1000 diff --git a/contrib/backends/dash/debian/changelog b/contrib/backends/dash/debian/changelog new file mode 100644 index 00000000..3283a8fd --- /dev/null +++ b/contrib/backends/dash/debian/changelog @@ -0,0 +1,5 @@ +dash (0.12.2-satoshilabs1) unstable; urgency=medium + + * Initial build + + -- Jakub Matys Fri, 08 Jun 2018 11:27:03 +0200 diff --git a/contrib/backends/dash/debian/compat b/contrib/backends/dash/debian/compat new file mode 100644 index 00000000..ec635144 --- /dev/null +++ b/contrib/backends/dash/debian/compat @@ -0,0 +1 @@ +9 diff --git a/contrib/backends/dash/debian/control b/contrib/backends/dash/debian/control new file mode 100644 index 00000000..d7f3e93f --- /dev/null +++ b/contrib/backends/dash/debian/control @@ -0,0 +1,16 @@ +Source: dash +Section: satoshilabs +Priority: optional +Maintainer: jakub.matys@satoshilabs.com +Build-Depends: debhelper, wget, tar, gzip, make, dh-systemd, dh-exec +Standards-Version: 3.9.5 + +Package: dash +Architecture: amd64 +Depends: ${shlibs:Depends}, ${misc:Depends}, logrotate +Description: Satoshilabs packaged dash server + +Package: dash-testnet +Architecture: amd64 +Depends: ${shlibs:Depends}, ${misc:Depends}, logrotate +Description: Satoshilabs packaged dash server diff --git a/contrib/backends/dash/debian/dash-testnet.conffiles b/contrib/backends/dash/debian/dash-testnet.conffiles new file mode 100644 index 00000000..ca92fe83 --- /dev/null +++ b/contrib/backends/dash/debian/dash-testnet.conffiles @@ -0,0 +1 @@ +/opt/coins/nodes/dash_testnet/dash_testnet.conf diff --git a/contrib/backends/dash/debian/dash-testnet.dirs b/contrib/backends/dash/debian/dash-testnet.dirs new file mode 100644 index 00000000..552e900d --- /dev/null +++ b/contrib/backends/dash/debian/dash-testnet.dirs @@ -0,0 +1 @@ +/opt/coins/data/dash_testnet/backend diff --git a/contrib/backends/dash/debian/dash-testnet.install b/contrib/backends/dash/debian/dash-testnet.install new file mode 100644 index 00000000..2159f454 --- /dev/null +++ b/contrib/backends/dash/debian/dash-testnet.install @@ -0,0 +1,2 @@ +dash/* /opt/coins/nodes/dash_testnet +dash_testnet.conf /opt/coins/nodes/dash_testnet diff --git a/contrib/backends/dash/debian/dash-testnet.logrotate b/contrib/backends/dash/debian/dash-testnet.logrotate new file mode 100644 index 00000000..b87cf5a3 --- /dev/null +++ b/contrib/backends/dash/debian/dash-testnet.logrotate @@ -0,0 +1,10 @@ +/opt/coins/data/dash_testnet/backend/testnet3/debug.log +/opt/coins/data/dash_testnet/backend/testnet3/db.log +{ + rotate 7 + daily + compress + missingok + notifempty + copytruncate +} diff --git a/contrib/backends/dash/debian/dash-testnet.postinst b/contrib/backends/dash/debian/dash-testnet.postinst new file mode 100644 index 00000000..33c0a50b --- /dev/null +++ b/contrib/backends/dash/debian/dash-testnet.postinst @@ -0,0 +1,20 @@ +#!/bin/bash +set -e + +case "$1" in + + configure) + if ! id -u dash &> /dev/null + then + useradd --system -M -U dash -s /bin/false + fi + + if [ "$(stat -c '%U' /opt/coins/data/dash_testnet/backend)" != "dash" ] + then + chown -R dash:dash /opt/coins/data/dash_testnet/backend + fi + ;; + +esac + +#DEBHELPER# diff --git a/contrib/backends/dash/debian/dash-testnet.service b/contrib/backends/dash/debian/dash-testnet.service new file mode 100644 index 00000000..f2496a91 --- /dev/null +++ b/contrib/backends/dash/debian/dash-testnet.service @@ -0,0 +1,47 @@ +# It is not recommended to modify this file in-place, because it will +# be overwritten during package upgrades. If you want to add further +# options or overwrite existing ones then use +# $ systemctl edit dash-testnet.service +# See "man systemd.service" for details. + +# Note that almost all daemon options could be specified in +# /opt/coins/nodes/dash_testnet/dash_testnet.conf + +[Unit] +Description=DASH daemon (testnet) +After=network.target + +[Service] +ExecStart=/opt/coins/nodes/dash_testnet/bin/dashd -datadir=/opt/coins/data/dash_testnet/backend -conf=/opt/coins/nodes/dash_testnet/dash_testnet.conf -pid=/run/dashd/dash_testnet.pid +# Creates /run/dashd owned by dash +RuntimeDirectory=dashd +User=dash +Type=forking +PIDFile=/run/dashd/dash_testnet.pid +Restart=on-failure + +# Resource limits +LimitNOFILE=500000 + +# Hardening measures +#################### + +# Provide a private /tmp and /var/tmp. +PrivateTmp=true + +# Mount /usr, /boot/ and /etc read-only for the process. +ProtectSystem=full + +# Disallow the process and all of its children to gain +# new privileges through execve(). +NoNewPrivileges=true + +# Use a new /dev namespace only populated with API pseudo devices +# such as /dev/null, /dev/zero and /dev/random. +PrivateDevices=true + +# Deny the creation of writable and executable memory mappings. +MemoryDenyWriteExecute=true + +[Install] +WantedBy=multi-user.target diff --git a/contrib/backends/dash/debian/dash.conffiles b/contrib/backends/dash/debian/dash.conffiles new file mode 100644 index 00000000..a760cf85 --- /dev/null +++ b/contrib/backends/dash/debian/dash.conffiles @@ -0,0 +1 @@ +/opt/coins/nodes/dash/dash.conf diff --git a/contrib/backends/dash/debian/dash.dirs b/contrib/backends/dash/debian/dash.dirs new file mode 100644 index 00000000..d96cc5d2 --- /dev/null +++ b/contrib/backends/dash/debian/dash.dirs @@ -0,0 +1 @@ +/opt/coins/data/dash/backend diff --git a/contrib/backends/dash/debian/dash.install b/contrib/backends/dash/debian/dash.install new file mode 100644 index 00000000..08e4581a --- /dev/null +++ b/contrib/backends/dash/debian/dash.install @@ -0,0 +1,2 @@ +dash/* /opt/coins/nodes/dash +dash.conf /opt/coins/nodes/dash diff --git a/contrib/backends/dash/debian/dash.logrotate b/contrib/backends/dash/debian/dash.logrotate new file mode 100644 index 00000000..689060ea --- /dev/null +++ b/contrib/backends/dash/debian/dash.logrotate @@ -0,0 +1,10 @@ +/opt/coins/data/dash/backend/debug.log +/opt/coins/data/dash/backend/db.log +{ + rotate 7 + daily + compress + missingok + notifempty + copytruncate +} diff --git a/contrib/backends/dash/debian/dash.postinst b/contrib/backends/dash/debian/dash.postinst new file mode 100644 index 00000000..3e34a47b --- /dev/null +++ b/contrib/backends/dash/debian/dash.postinst @@ -0,0 +1,20 @@ +#!/bin/bash +set -e + +case "$1" in + + configure) + if ! id -u dash &> /dev/null + then + useradd --system -M -U dash -s /bin/false + fi + + if [ "$(stat -c '%U' /opt/coins/data/dash/backend)" != "dash" ] + then + chown -R dash:dash /opt/coins/data/dash/backend + fi + ;; + +esac + +#DEBHELPER# diff --git a/contrib/backends/dash/debian/dash.service b/contrib/backends/dash/debian/dash.service new file mode 100644 index 00000000..151491a1 --- /dev/null +++ b/contrib/backends/dash/debian/dash.service @@ -0,0 +1,47 @@ +# It is not recommended to modify this file in-place, because it will +# be overwritten during package upgrades. If you want to add further +# options or overwrite existing ones then use +# $ systemctl edit dash.service +# See "man systemd.service" for details. + +# Note that almost all daemon options could be specified in +# /opt/coins/nodes/dash/dash.conf + +[Unit] +Description=DASH daemon (mainnet) +After=network.target + +[Service] +ExecStart=/opt/coins/nodes/dash/bin/dashd -datadir=/opt/coins/data/dash/backend -conf=/opt/coins/nodes/dash/dash.conf -pid=/run/dashd/dash.pid +# Creates /run/dashd owned by dash +RuntimeDirectory=dashd +User=dash +Type=forking +PIDFile=/run/dashd/dash.pid +Restart=on-failure + +# Resource limits +LimitNOFILE=500000 + +# Hardening measures +#################### + +# Provide a private /tmp and /var/tmp. +PrivateTmp=true + +# Mount /usr, /boot/ and /etc read-only for the process. +ProtectSystem=full + +# Disallow the process and all of its children to gain +# new privileges through execve(). +NoNewPrivileges=true + +# Use a new /dev namespace only populated with API pseudo devices +# such as /dev/null, /dev/zero and /dev/random. +PrivateDevices=true + +# Deny the creation of writable and executable memory mappings. +MemoryDenyWriteExecute=true + +[Install] +WantedBy=multi-user.target diff --git a/contrib/backends/dash/debian/rules b/contrib/backends/dash/debian/rules new file mode 100755 index 00000000..f69489df --- /dev/null +++ b/contrib/backends/dash/debian/rules @@ -0,0 +1,11 @@ +#!/usr/bin/make -f + +DH_VERBOSE = 1 + +%: + dh $@ --with=systemd + +override_dh_systemd_start: + dh_systemd_start --no-start + +override_dh_installinit: