diff --git a/README.md b/README.md index 6cbacaa6..b379d23a 100644 --- a/README.md +++ b/README.md @@ -146,12 +146,14 @@ The data are separated to different column families: | Ethereum Classic | 9037 | 9137 | 8037 | 38337* | | Dogecoin | 9038 | 9138 | 8038 | 38338 | | Namecoin | 9039 | 9139 | 8039 | 38339 | +| Vertcoin | 9040 | 9140 | 8040 | 38340 | | Bitcoin Testnet | 19030 | 19130 | 18030 | 48330 | | Bcash Testnet | 19031 | 19131 | 18031 | 48331 | | Zcash Testnet | 19032 | 19132 | 18032 | 48332 | | Dash Testnet | 19033 | 19133 | 18033 | 48333 | | Litecoin Testnet | 19034 | 19134 | 18034 | 48334 | | Ethereum Testnet Ropsten | 19036 | 19136 | 18036 | 48336* | +| Vertcoin Testnet | 19040 | 19140 | 18040 | 48340 | \* geth listens on this port, however not as zmq service diff --git a/bchain/coins/bch/bcashrpc_test.go b/bchain/coins/bch/bcashrpc_test.go index 8185fd05..948c1f0f 100644 --- a/bchain/coins/bch/bcashrpc_test.go +++ b/bchain/coins/bch/bcashrpc_test.go @@ -19,6 +19,7 @@ func getRPCClient(cfg json.RawMessage) (bchain.BlockChain, error) { if err != nil { return nil, err } + cli.Mempool = bchain.NewUTXOMempool(cli, cli.ChainConfig.MempoolWorkers, cli.ChainConfig.MempoolSubWorkers) return cli, nil } @@ -43,3 +44,27 @@ func TestBCashRPC_GetBlock(t *testing.T) { func TestBCashRPC_GetTransaction(t *testing.T) { rpcTest.TestGetTransaction(t) } + +func TestBCashRPC_TestGetTransactionForMempool(t *testing.T) { + rpcTest.TestGetTransactionForMempool(t) +} + +func TestBCashRPC_TestMempoolSync(t *testing.T) { + rpcTest.TestMempoolSync(t) +} + +func TestBCashRPC_GetMempoolEntry(t *testing.T) { + rpcTest.TestGetMempoolEntry(t) +} + +func TestBCashRPC_SendRawTransaction(t *testing.T) { + rpcTest.TestSendRawTransaction(t) +} + +func TestBCashRPC_EstimateSmartFee(t *testing.T) { + rpcTest.TestEstimateSmartFee(t) +} + +func TestBCashRPC_EstimateFee(t *testing.T) { + rpcTest.TestEstimateFee(t) +} diff --git a/bchain/coins/blockchain.go b/bchain/coins/blockchain.go index 605d80b3..84e08655 100644 --- a/bchain/coins/blockchain.go +++ b/bchain/coins/blockchain.go @@ -9,6 +9,7 @@ import ( "blockbook/bchain/coins/dogecoin" "blockbook/bchain/coins/eth" "blockbook/bchain/coins/litecoin" + "blockbook/bchain/coins/vertcoin" "blockbook/bchain/coins/namecoin" "blockbook/bchain/coins/zec" "blockbook/common" @@ -41,6 +42,8 @@ func init() { blockChainFactories["Litecoin"] = litecoin.NewLitecoinRPC blockChainFactories["Litecoin Testnet"] = litecoin.NewLitecoinRPC blockChainFactories["Dogecoin"] = dogecoin.NewDogecoinRPC + blockChainFactories["Vertcoin"] = vertcoin.NewVertcoinRPC + blockChainFactories["Vertcoin Testnet"] = vertcoin.NewVertcoinRPC blockChainFactories["Namecoin"] = namecoin.NewNamecoinRPC } diff --git a/bchain/coins/btc/bitcoinrpc_test.go b/bchain/coins/btc/bitcoinrpc_test.go index 52b09898..266e6a35 100644 --- a/bchain/coins/btc/bitcoinrpc_test.go +++ b/bchain/coins/btc/bitcoinrpc_test.go @@ -19,6 +19,7 @@ func getRPCClient(cfg json.RawMessage) (bchain.BlockChain, error) { if err != nil { return nil, err } + cli.Mempool = bchain.NewUTXOMempool(cli, cli.ChainConfig.MempoolWorkers, cli.ChainConfig.MempoolSubWorkers) return cli, nil } @@ -43,3 +44,27 @@ func TestBitcoinRPC_GetBlock(t *testing.T) { func TestBitcoinRPC_GetTransaction(t *testing.T) { rpcTest.TestGetTransaction(t) } + +func TestBitcoinRPC_TestGetTransactionForMempool(t *testing.T) { + rpcTest.TestGetTransactionForMempool(t) +} + +func TestBitcoinRPC_TestMempoolSync(t *testing.T) { + rpcTest.TestMempoolSync(t) +} + +func TestBitcoinRPC_GetMempoolEntry(t *testing.T) { + rpcTest.TestGetMempoolEntry(t) +} + +func TestBitcoinRPC_SendRawTransaction(t *testing.T) { + rpcTest.TestSendRawTransaction(t) +} + +func TestBitcoinRPC_EstimateSmartFee(t *testing.T) { + rpcTest.TestEstimateSmartFee(t) +} + +func TestBitcoinRPC_EstimateFee(t *testing.T) { + rpcTest.TestEstimateFee(t) +} diff --git a/bchain/coins/dash/dashrpc_test.go b/bchain/coins/dash/dashrpc_test.go index 90c09bb4..ebfa2847 100644 --- a/bchain/coins/dash/dashrpc_test.go +++ b/bchain/coins/dash/dashrpc_test.go @@ -16,6 +16,7 @@ func getRPCClient(cfg json.RawMessage) (bchain.BlockChain, error) { } cli := c.(*DashRPC) cli.Parser = NewDashParser(GetChainParams("test"), cli.ChainConfig) + cli.Mempool = bchain.NewUTXOMempool(cli, cli.ChainConfig.MempoolWorkers, cli.ChainConfig.MempoolSubWorkers) return cli, nil } @@ -40,3 +41,23 @@ func TestDashRPC_GetBlock(t *testing.T) { func TestDashRPC_GetTransaction(t *testing.T) { rpcTest.TestGetTransaction(t) } + +func TestDashRPC_TestGetTransactionForMempool(t *testing.T) { + rpcTest.TestGetTransactionForMempool(t) +} + +func TestDashRPC_TestMempoolSync(t *testing.T) { + rpcTest.TestMempoolSync(t) +} + +func TestDashRPC_SendRawTransaction(t *testing.T) { + rpcTest.TestSendRawTransaction(t) +} + +func TestDashRPC_EstimateSmartFee(t *testing.T) { + rpcTest.TestEstimateSmartFee(t) +} + +func TestDashRPC_EstimateFee(t *testing.T) { + rpcTest.TestEstimateFee(t) +} diff --git a/bchain/coins/vertcoin/vertcoin_test.go b/bchain/coins/vertcoin/vertcoin_test.go new file mode 100644 index 00000000..2331667f --- /dev/null +++ b/bchain/coins/vertcoin/vertcoin_test.go @@ -0,0 +1,211 @@ +// build unittest + +package vertcoin + +import ( + "blockbook/bchain" + "blockbook/bchain/coins/btc" + "encoding/hex" + "reflect" + "testing" +) + +func TestAddressToOutputScript_Mainnet(t *testing.T) { + type args struct { + address string + } + tests := []struct { + name string + args args + want string + wantErr bool + }{ + { + name: "pubkeyhash1", + args: args{address: "Ve7SkjuVgVm1z3X8aqqxnzGV6GraUcde6K"}, + want: "76a9142d20ebccc60a8b7dcba607701c6e5bda05eb6d9a88ac", + wantErr: false, + }, + { + name: "pubkeyhash2", + args: args{address: "Vavx3LENdGctDMsaVm426McFE5iDDrSuk5"}, + want: "76a9140a3c6a3970a5b6b94ee0c1da82d6a87899d169da88ac", + wantErr: false, + }, + { + name: "scripthash1", + args: args{address: "36c8VAv74dPZZa4cFayb92hzozkPL4fBPe"}, + want: "a91435ec06fa05f2d3b16e88cd7eda7651a10ca2e01987", + wantErr: false, + }, + { + name: "scripthash2", + args: args{address: "38A1RNvbA5c9wNRfyLVn1FCH5TPKJVG8YR"}, + want: "a91446eb90e002f137f05385896c882fe000cc2e967f87", + wantErr: false, + }, + { + name: "witness_v0_keyhash", + args: args{address: "vtc1qd80qaputavyhtvszlz9zprueqch0qd003g520j"}, + want: "001469de0e878beb0975b202f88a208f99062ef035ef", + wantErr: false, + }, + } + parser := NewVertcoinParser(GetChainParams("main"), &btc.Configuration{}) + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := parser.AddressToOutputScript(tt.args.address) + if (err != nil) != tt.wantErr { + t.Errorf("AddressToOutputScript() error = %v, wantErr %v", err, tt.wantErr) + return + } + h := hex.EncodeToString(got) + if !reflect.DeepEqual(h, tt.want) { + t.Errorf("AddressToOutputScript() = %v, want %v", h, tt.want) + } + }) + } +} + +var ( + testTx1 bchain.Tx + + testTxPacked1 = "000e87768bb386b878010000000146fd781834a34e0399ccda1edf9ec47d715e17d904ad0958d533a240b3605ad6000000006a473044022026b352a0c35c232342339e2b50ec9f04587b990d5213174e368cc76dc82686f002207d0787461ad846825872a50d3d6fc748d5a836575c1daf6ad0ca602f9c4a8826012103d36b6b829c571ed7caa565eca9bdc2aa36519b7ab8551ace5edb0356d477ad3cfdffffff020882a400000000001976a91499b16da88a7e29b913b6131df2644d6d06cb331b88ac80f0fa020000000017a91446eb90e002f137f05385896c882fe000cc2e967f8774870e00" +) + +func init() { + var ( + addr1, addr2 bchain.Address + err error + ) + addr1, err = bchain.NewBaseAddress("Vp1UqzsmVecaexfbWFGSFFL5x1g2XQnrGR") + if err == nil { + addr2, err = bchain.NewBaseAddress("38A1RNvbA5c9wNRfyLVn1FCH5TPKJVG8YR") + } + if err != nil { + panic(err) + } + + testTx1 = bchain.Tx{ + Hex: "010000000146fd781834a34e0399ccda1edf9ec47d715e17d904ad0958d533a240b3605ad6000000006a473044022026b352a0c35c232342339e2b50ec9f04587b990d5213174e368cc76dc82686f002207d0787461ad846825872a50d3d6fc748d5a836575c1daf6ad0ca602f9c4a8826012103d36b6b829c571ed7caa565eca9bdc2aa36519b7ab8551ace5edb0356d477ad3cfdffffff020882a400000000001976a91499b16da88a7e29b913b6131df2644d6d06cb331b88ac80f0fa020000000017a91446eb90e002f137f05385896c882fe000cc2e967f8774870e00", + Blocktime: 1529925180, + Txid: "d58c11aa970449c3e0ee5e0cdf78532435a9d2b28a2da284a8dd4dd6bdd0331c", + LockTime: 952180, + Vin: []bchain.Vin{ + { + ScriptSig: bchain.ScriptSig{ + Hex: "473044022026b352a0c35c232342339e2b50ec9f04587b990d5213174e368cc76dc82686f002207d0787461ad846825872a50d3d6fc748d5a836575c1daf6ad0ca602f9c4a8826012103d36b6b829c571ed7caa565eca9bdc2aa36519b7ab8551ace5edb0356d477ad3c", + }, + Txid: "d65a60b340a233d55809ad04d9175e717dc49edf1edacc99034ea3341878fd46", + Vout: 0, + Sequence: 4294967293, + }, + }, + Vout: []bchain.Vout{ + { + Value: 0.10781192, + N: 0, + ScriptPubKey: bchain.ScriptPubKey{ + Hex: "76a91499b16da88a7e29b913b6131df2644d6d06cb331b88ac", + Addresses: []string{ + "Vp1UqzsmVecaexfbWFGSFFL5x1g2XQnrGR", + }, + }, + Address: addr1, + }, + { + Value: 0.5000000, + N: 1, + ScriptPubKey: bchain.ScriptPubKey{ + Hex: "a91446eb90e002f137f05385896c882fe000cc2e967f87", + Addresses: []string{ + "38A1RNvbA5c9wNRfyLVn1FCH5TPKJVG8YR", + }, + }, + Address: addr2, + }, + }, + } +} + +func Test_PackTx(t *testing.T) { + type args struct { + tx bchain.Tx + height uint32 + blockTime int64 + parser *VertcoinParser + } + tests := []struct { + name string + args args + want string + wantErr bool + }{ + { + name: "vertcoin-1", + args: args{ + tx: testTx1, + height: 952182, + blockTime: 1529925180, + parser: NewVertcoinParser(GetChainParams("main"), &btc.Configuration{}), + }, + want: testTxPacked1, + wantErr: false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := tt.args.parser.PackTx(&tt.args.tx, tt.args.height, tt.args.blockTime) + if (err != nil) != tt.wantErr { + t.Errorf("packTx() error = %v, wantErr %v", err, tt.wantErr) + return + } + h := hex.EncodeToString(got) + if !reflect.DeepEqual(h, tt.want) { + t.Errorf("packTx() = %v, want %v", h, tt.want) + } + }) + } +} + +func Test_UnpackTx(t *testing.T) { + type args struct { + packedTx string + parser *VertcoinParser + } + tests := []struct { + name string + args args + want *bchain.Tx + want1 uint32 + wantErr bool + }{ + { + name: "vertcoin-1", + args: args{ + packedTx: testTxPacked1, + parser: NewVertcoinParser(GetChainParams("main"), &btc.Configuration{}), + }, + want: &testTx1, + want1: 952182, + wantErr: false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + b, _ := hex.DecodeString(tt.args.packedTx) + got, got1, err := tt.args.parser.UnpackTx(b) + if (err != nil) != tt.wantErr { + t.Errorf("unpackTx() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("unpackTx() got = %v, want %v", got, tt.want) + } + if got1 != tt.want1 { + t.Errorf("unpackTx() got1 = %v, want %v", got1, tt.want1) + } + }) + } +} diff --git a/bchain/coins/vertcoin/vertcoinparser.go b/bchain/coins/vertcoin/vertcoinparser.go new file mode 100644 index 00000000..6f33a9ae --- /dev/null +++ b/bchain/coins/vertcoin/vertcoinparser.go @@ -0,0 +1,62 @@ +package vertcoin + +import ( + "blockbook/bchain/coins/btc" + + "github.com/btcsuite/btcd/chaincfg" + "github.com/btcsuite/btcd/wire" +) + +const ( + MainnetMagic wire.BitcoinNet = 0xdab5bffb + TestnetMagic wire.BitcoinNet = 0x74726576 // "vert" word + RegtestMagic wire.BitcoinNet = 0xdab5bffc +) + +var ( + MainNetParams chaincfg.Params + TestNetParams chaincfg.Params +) + +func init() { + MainNetParams = chaincfg.MainNetParams + MainNetParams.Net = MainnetMagic + MainNetParams.PubKeyHashAddrID = 71 + MainNetParams.ScriptHashAddrID = 5 + MainNetParams.Bech32HRPSegwit = "vtc" + + TestNetParams = chaincfg.TestNet3Params + TestNetParams.Net = TestnetMagic + TestNetParams.PubKeyHashAddrID = 74 + TestNetParams.ScriptHashAddrID = 196 + TestNetParams.Bech32HRPSegwit = "tvtc" + + err := chaincfg.Register(&MainNetParams) + if err == nil { + err = chaincfg.Register(&TestNetParams) + } + if err != nil { + panic(err) + } +} + +// VertcoinParser handle +type VertcoinParser struct { + *btc.BitcoinParser +} + +// NewVertcoinParser returns new VertcoinParser instance +func NewVertcoinParser(params *chaincfg.Params, c *btc.Configuration) *VertcoinParser { + return &VertcoinParser{BitcoinParser: btc.NewBitcoinParser(params, c)} +} + +// GetChainParams contains network parameters for the main Vertcoin network, +// and the test Vertcoin network +func GetChainParams(chain string) *chaincfg.Params { + switch chain { + case "test": + return &TestNetParams + default: + return &MainNetParams + } +} diff --git a/bchain/coins/vertcoin/vertcoinrpc.go b/bchain/coins/vertcoin/vertcoinrpc.go new file mode 100644 index 00000000..878b9682 --- /dev/null +++ b/bchain/coins/vertcoin/vertcoinrpc.go @@ -0,0 +1,61 @@ +package vertcoin + +import ( + "blockbook/bchain" + "blockbook/bchain/coins/btc" + "encoding/json" + + "github.com/golang/glog" +) + +// VertcoinRPC is an interface to JSON-RPC bitcoind service. +type VertcoinRPC struct { + *btc.BitcoinRPC +} + +// NewVertcoinRPC returns new VertcoinRPC instance. +func NewVertcoinRPC(config json.RawMessage, pushHandler func(bchain.NotificationType)) (bchain.BlockChain, error) { + b, err := btc.NewBitcoinRPC(config, pushHandler) + if err != nil { + return nil, err + } + + s := &VertcoinRPC{ + b.(*btc.BitcoinRPC), + } + s.RPCMarshaler = btc.JSONMarshalerV2{} + + return s, nil +} + +// Initialize initializes VertcoinRPC instance. +func (b *VertcoinRPC) Initialize() error { + chainName, err := b.GetChainInfoAndInitializeMempool(b) + if err != nil { + return err + } + + glog.Info("Chain name ", chainName) + params := GetChainParams(chainName) + + // always create parser + b.Parser = NewVertcoinParser(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 +} + +// EstimateFee returns fee estimation. +func (b *VertcoinRPC) EstimateFee(blocks int) (float64, error) { + return b.EstimateSmartFee(blocks, true) +} diff --git a/bchain/coins/zec/zcashrpc_test.go b/bchain/coins/zec/zcashrpc_test.go index a69ffa77..4c6f7e1f 100644 --- a/bchain/coins/zec/zcashrpc_test.go +++ b/bchain/coins/zec/zcashrpc_test.go @@ -16,6 +16,7 @@ func getRPCClient(cfg json.RawMessage) (bchain.BlockChain, error) { } cli := c.(*ZCashRPC) cli.Parser = NewZCashParser(cli.ChainConfig) + cli.Mempool = bchain.NewUTXOMempool(cli, cli.ChainConfig.MempoolWorkers, cli.ChainConfig.MempoolSubWorkers) return cli, nil } @@ -40,3 +41,23 @@ func TestZCashRPC_GetBlock(t *testing.T) { func TestZCashRPC_GetTransaction(t *testing.T) { rpcTest.TestGetTransaction(t) } + +func TestZCashRPC_TestGetTransactionForMempool(t *testing.T) { + rpcTest.TestGetTransactionForMempool(t) +} + +func TestZCashRPC_TestMempoolSync(t *testing.T) { + rpcTest.TestMempoolSync(t) +} + +func TestZCashRPC_SendRawTransaction(t *testing.T) { + rpcTest.TestSendRawTransaction(t) +} + +func TestZCashRPC_EstimateSmartFee(t *testing.T) { + rpcTest.TestEstimateSmartFee(t) +} + +func TestZCashRPC_EstimateFee(t *testing.T) { + rpcTest.TestEstimateFee(t) +} diff --git a/bchain/tests/rpc/rpc.go b/bchain/tests/rpc/rpc.go index 0a486963..9cee0ac8 100644 --- a/bchain/tests/rpc/rpc.go +++ b/bchain/tests/rpc/rpc.go @@ -5,8 +5,10 @@ package rpc import ( "blockbook/bchain" "encoding/json" + "math/rand" "reflect" "testing" + "time" ) type TestConfig struct { @@ -103,6 +105,7 @@ func (rt *Test) TestGetBlock(t *testing.T) { } } + func (rt *Test) TestGetTransaction(t *testing.T) { for txid, want := range rt.TestData.TxDetails { got, err := rt.Client.GetTransaction(txid) @@ -110,7 +113,6 @@ func (rt *Test) TestGetTransaction(t *testing.T) { t.Error(err) return } - // Confirmations is variable field, we just check if is set and reset it if got.Confirmations > 0 { got.Confirmations = 0 @@ -124,3 +126,197 @@ func (rt *Test) TestGetTransaction(t *testing.T) { } } } + +func (rt *Test) getMempool(t *testing.T) []string { + var ( + txs []string + err error + ) + // attempts to get transactions for 2 min + for i := 0; i < 8; i++ { + txs, err = rt.Client.GetMempool() + if err != nil { + t.Fatal(err) + } + if len(txs) == 0 { + time.Sleep(15 * time.Second) + continue + } + + // done + break + } + if len(txs) == 0 { + t.Skipf("Skipping test, all attempts to get mempool failed") + } + + return txs +} + +func (rt *Test) getMempoolTransaction(t *testing.T, txid string) *bchain.Tx { + tx, err := rt.Client.GetTransactionForMempool(txid) + if err != nil { + t.Fatal(err) + } + if tx.Confirmations > 0 { + t.Skip("Skipping test, transaction moved away from mepool") + } + + return tx +} + +func (rt *Test) TestGetTransactionForMempool(t *testing.T) { + txs := rt.getMempool(t) + txid := txs[rand.Intn(len(txs))] + got := rt.getMempoolTransaction(t, txid) + + want, err := rt.Client.GetTransaction(txid) + if err != nil { + t.Fatal(err) + } + + if !reflect.DeepEqual(got, want) { + t.Errorf("GetTransactionForMempool() got %v, want %v", got, want) + } +} + +func (rt *Test) getMempoolAddresses(t *testing.T, txs []string) map[string][]string { + txid2addrs := map[string][]string{} + for i := 0; i < len(txs); i++ { + tx := rt.getMempoolTransaction(t, txs[i]) + addrs := []string{} + for _, vin := range tx.Vin { + for _, a := range vin.Addresses { + addrs = append(addrs, a) + } + } + for _, vout := range tx.Vout { + for _, a := range vout.ScriptPubKey.Addresses { + addrs = append(addrs, a) + } + } + if len(addrs) > 0 { + txid2addrs[tx.Txid] = addrs + } + } + return txid2addrs +} + +func (rt *Test) TestMempoolSync(t *testing.T) { + for i := 0; i < 3; i++ { + txs := rt.getMempool(t) + txid2addrs := rt.getMempoolAddresses(t, txs) + if len(txid2addrs) == 0 { + t.Fatal("No transaction in mempool has any address") + } + + n, err := rt.Client.ResyncMempool(nil) + if err != nil { + t.Fatal(err) + } + + if tmp := rt.getMempool(t); len(txs) != len(tmp) { + // mempool reset + continue + } + + if len(txs) != n { + t.Fatalf("ResyncMempool() returned different number of transactions than backend call") + } + + for txid, addrs := range txid2addrs { + for _, a := range addrs { + txs, err := rt.Client.GetMempoolTransactions(a) + if err != nil { + t.Fatal(err) + } + if !containsString(txs, txid) { + t.Errorf("ResyncMempool() - for address %s, transaction %s wasn't found in mempool", a, txid) + return + } + } + } + + // done + return + } + t.Skip("Skipping test, all attempts to sync mempool failed due to network state changes") +} + +func containsString(slice []string, s string) bool { + for i := 0; i < len(slice); i++ { + if slice[i] == s { + return true + } + } + return false +} + +func (rt *Test) TestGetMempoolEntry(t *testing.T) { + for i := 0; i < 3; i++ { + txs := rt.getMempool(t) + h, err := rt.Client.GetBestBlockHeight() + if err != nil { + t.Fatal(err) + } + + tx := rt.getMempoolTransaction(t, txs[rand.Intn(len(txs))]) + e, err := rt.Client.GetMempoolEntry(tx.Txid) + if err != nil { + if err, ok := err.(*bchain.RPCError); ok && err.Code == -5 { + // mempool reset + continue + } + } + + if e.Height-h > 1 { + t.Errorf("GetMempoolEntry() got height %d, want %d", e.Height, h) + } + if e.Size <= 0 { + t.Errorf("GetMempoolEntry() got zero or negative size %d", e.Size) + } + if e.Fee <= 0 { + t.Errorf("GetMempoolEntry() got zero or negative fee %f", e.Fee) + } + + // done + return + } + t.Skip("Skipping test, all attempts to get mempool entry failed due to network state changes") +} + +func (rt *Test) TestSendRawTransaction(t *testing.T) { + for txid, tx := range rt.TestData.TxDetails { + _, err := rt.Client.SendRawTransaction(tx.Hex) + if err != nil { + if err, ok := err.(*bchain.RPCError); ok && err.Code == -27 { + continue + } + } + t.Errorf("SendRawTransaction() for %s returned unexpected error: %#v", txid, err) + } +} + +func (rt *Test) TestEstimateSmartFee(t *testing.T) { + for _, blocks := range []int{1, 2, 3, 5, 10} { + fee, err := rt.Client.EstimateSmartFee(blocks, true) + if err != nil { + t.Error(err) + } + if fee != -1 && (fee < 0 || fee > 1) { + t.Errorf("EstimateSmartFee() returned unexpected fee rate: %f", fee) + } + } +} + +func (rt *Test) TestEstimateFee(t *testing.T) { + for _, blocks := range []int{1, 2, 3, 5, 10} { + fee, err := rt.Client.EstimateFee(blocks) + if err != nil { + t.Error(err) + } + if fee != -1 && (fee < 0 || fee > 1) { + t.Errorf("EstimateFee() returned unexpected fee rate: %f", fee) + } + } +} diff --git a/bchain/tests/rpc/testdata/Bcash_Testnet.json b/bchain/tests/rpc/testdata/Bcash_Testnet.json index 99d94025..39eba5e7 100644 --- a/bchain/tests/rpc/testdata/Bcash_Testnet.json +++ b/bchain/tests/rpc/testdata/Bcash_Testnet.json @@ -1,142 +1,106 @@ { - "blockHeight": 1239639, - "blockHash": "0000000075dd9708c23f5830de27c5d644983bb877c575c52926f19be7d80fe2", + "blockHeight": 1241851, + "blockHash": "00000000ff54973b45ac277fc9e92408479703d785eae0e96508bc5aa792d621", "blockTxs": [ - "f12d490ad439ff37c91e9ec5ecd5440c2d4a96653f2668402c5ebacc6d07dcf8", - "0e78e3276bd59dd403306334ab05b2d58167b4cf04dbb94ae76dc189db5bf3df", - "9eeba85181725993afc6a89e2e98c07e12bbd9c732b851af448eb6055d8d8ba7", - "045f898538c5b9a99a4bf21c8e06aa7279caacdf7616994b7d4f0ed39637dff7", - "8614ae1addce0983f8b1bb2e6139fca4e7aa2d4f57f28ce1145bd1103c75a307", - "1d10b63e6d336b19ce7f7a867639b52b42be7e63ea53a86e5c7b101eb8f5bf59", - "1cbb193374d455ad09f1ae4486418dbbd65435ac14b1b8733897976bd776478b", - "722d99abace73265477b42849c86f9a8460a07aef7497187db24cffb4b27c856", - "a856b35655852ec5d698561633f997b945ee03d57a7b60e3c86eaabdd3a90054", - "e82cdbb67f6c23c72d0273bdd976697d5bfc4b2373e637f4eeb5211134b84bd6", - "efd3295c37cd3988f16efc09d083dbbc27f5c0074b9ea0dffd4f8540b36dd02c", - "b955bc3e800aa6d72c1a9eb9ce4a513f409ec923c31e30075f58336c830040a8", - "9730ec3e10e5a3bf358e533a497e75f44aceaf28da8248534326e5d7dac0d048", - "a90df75c045e638a0c00902d35c9c72592d0e76ac0fa34fba6aad749c5aded21", - "0e21dd654596cac9f579e21a549a533d1be7319470fcf8f920a35d64cf020d1f" + "0cbcd28da300a850fd922caf633f2aaca0fd0a2d4ce46c6f07314c644287527a", + "32fe2a3a60eb952d6ade53b7030ddb6ad8af5797391857baaad37c5b20f3b5ca" ], "txDetails": { - "9eeba85181725993afc6a89e2e98c07e12bbd9c732b851af448eb6055d8d8ba7": { - "hex": "0200000001b2c673aede02a4054a8c23e456e581d684f47dadb54083317d6152949d55d94e010000006b483045022100f31a23984a44f485a570a102899e3a25cdf6d1234259e602dbe61f2c3e77e490022069a6a7b013452bd66ed3c11aba22a64559134cd1af3d283730a9b7fb33631cca412103cb05918b81d36c387c791d2accfaefead287a4a30427387fb1095fc0c363ef8efeffffff0200c2eb0b0000000017a914ac90ed8510c9a7445b104fd1602341dc2f890d15878906e1e1160000001976a9147f7ed17e71afc40beac9b8d0b0fb53731161339c88ac56ea1200", - "txid": "9eeba85181725993afc6a89e2e98c07e12bbd9c732b851af448eb6055d8d8ba7", - "blocktime":1528796166, - "time":1528796166, - "locktime": 1239638, + "0cbcd28da300a850fd922caf633f2aaca0fd0a2d4ce46c6f07314c644287527a": { + "hex": "01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0a03fbf212055374617368ffffffff01483b5009000000001976a914014dc11b35cafe7605b4c1798a5b86efd788cff488ac00000000", + "txid": "0cbcd28da300a850fd922caf633f2aaca0fd0a2d4ce46c6f07314c644287527a", + "blocktime":1529571678, + "time":1529571678, + "locktime": 0, "vin": [ { - "txid": "4ed9559d9452617d318340b5ad7df484d681e556e4238c4a05a402deae73c6b2", - "vout": 1, - "sequence": 4294967294, - "scriptSig": { - "hex": "483045022100f31a23984a44f485a570a102899e3a25cdf6d1234259e602dbe61f2c3e77e490022069a6a7b013452bd66ed3c11aba22a64559134cd1af3d283730a9b7fb33631cca412103cb05918b81d36c387c791d2accfaefead287a4a30427387fb1095fc0c363ef8e" - } + "coinbase": "03fbf212055374617368", + "sequence": 4294967295 } ], "vout": [ { - "value": 2.0, + "value": 1.56253000, "n": 0, "scriptPubKey": { - "hex": "a914ac90ed8510c9a7445b104fd1602341dc2f890d1587" - } - }, - { - "value": 982.78901385, - "n": 1, - "scriptPubKey": { - "hex": "76a9147f7ed17e71afc40beac9b8d0b0fb53731161339c88ac" + "hex": "76a914014dc11b35cafe7605b4c1798a5b86efd788cff488ac" } } ] }, - "0e21dd654596cac9f579e21a549a533d1be7319470fcf8f920a35d64cf020d1f": { - "hex": "0200000008349c1ef994e931d4da1f545d2e578f898ddf457392c5485dc75378de8f36bef4010000006a4730440220351f1566e3ef02e900942103c60cba5a768cd710d3d1afbc75406099ad2d9e4702206e0f639a9991c7afb2136fb2e437629103ad0989898d1c90078ded5f08f5cb3341210303ae341929bdb242226a9a8c15cdbed5b89fa286842714d8be7e3f16c63abe11feffffff4ae685c8efc7f090e75b80f1b705d7bf5fa6dbbcf88c5f5cf2dc0678a9646fb4000000006b483045022100b8dae1825b0d0ccbe212e8da6767ea049bad9acfc737e5c5ef3dc5eeef6d313c02207e4c669956f871a4a5f71903bf38a8c587b81940943682364b11fb1cd9c078d7412103c9bd0064d2759628c1f6e5ad9d6345a5bce64dc4f4bb0675162f77acd557e4e2feffffff1ac21ded05387165cb7d0d95e2036a82f79a314575f065407e0c32a6b24b2f1d010000006b483045022100ef4a9469a5b3dbc0f03e8d8c5f254ad86f2c1e92e75a5ee737c3b3186b5edd95022076abcdfa976c3c78d2b196fb79699057248fad6d3d5e782524b85d84704394cc412103882df93f092501520bb36206703dadb65b25a3fbd0323c690dc8e72f5ee4a770feffffffea6905abb313a2aa3f6c8a056294abe06774dbf75688b03b96b8a2132aaf0cbf010000006b483045022100e4ab9dd0a75bc76c6c2cf549fb37c5577bad7f58953a7103abe4a77a95b873c10220545aa0c2b2869d444fb99d237549d6ac270c711d60788a6463ef4fee63ebd8fc4121031adea1da6e87b0771ea8c2a4723127d8cc9328b0594d159570ebe97b1e021c9efeffffff8c9a7a668dad3766f953d9779861f9c007b0a06f6ea2afbf8ab30137f34300fa000000006a47304402207253f724d891f5e1e66ec0c8084ade910a52257a1257933c23bd1b4da862e33a0220363df96e31dffa0a599b56c5049519a4d8ed34e96dc1fefecfd2bc31fc6d79d9412103186a4fc8445b3b437587c71f00fc9da7a267c0a38915fcf567528e310a73c0bdfeffffff82445d5b10b84b5256ef028615465e2d139c45584884c06e68bc38930d826e72010000006a47304402204846adc41599336307a087d4fa779a059ffe12c69456c82fa4b03942c901284002203e5f0c5e72b9ded7f48b4d22cbdb39390bea33003d46d8b4652c8ede1f13b3e54121031adea1da6e87b0771ea8c2a4723127d8cc9328b0594d159570ebe97b1e021c9efeffffffb8816c2c3b95aa8126f6d2d04798632b3167e6e2144d5f4e84cfb29e9d6f442d010000006a473044022078b1aff9a4ed3452f782db38341d846edd295f9a907c7373519408fb33eeb3240220578da5e91ec0c82604982b09cbd1f44e28260fcd640bcc55f086ce296ef32ef7412103c9bd0064d2759628c1f6e5ad9d6345a5bce64dc4f4bb0675162f77acd557e4e2feffffff70628ac9b2814f99fe4cd5f67a76047af533774ae90331fa8cb68e4dcbff1cb0010000006b483045022100cd88592589ab3bbd6e23920770a067a37ffbff3a31238167731377f11903676202202cb1c019365870dad3113abb3b0bc68ab9e65d9d60592f3315ffa444dfd88be741210393bd44ad6ed9295bf408e01bcdbdf6e4e8fd4a573ad20f37e54ff6e9b1596028feffffff027f766c02000000001976a9149f96c6e6c3aabf438eef5c589c47fa4b4f96592a88ac1c3d0f00000000001976a914e2ffd7cf2fe9468512878196d1b48fee9e9d003288ac56ea1200", - "txid": "0e21dd654596cac9f579e21a549a533d1be7319470fcf8f920a35d64cf020d1f", - "blocktime":1528796166, - "time":1528796166, - "locktime": 1239638, + "32fe2a3a60eb952d6ade53b7030ddb6ad8af5797391857baaad37c5b20f3b5ca": { + "hex": "010000000321d231b0d81f74e29145cc5c7dc92b45aecaedc84ed0178d223c1ba75024ff58030000006a473044022004739fe75329dee2f6deedca41eec94ca9c5d6e3a3ad807f28813c81406b6db002204153c2c0c72214295aaeb637ff6390e8ea220adf7ef30f5c0e7b95933f880bed4121027909d648cd5d774d250e5f8ab4c4aadfba07f4abb835f9100387bdc047e176bcfeffffff21d231b0d81f74e29145cc5c7dc92b45aecaedc84ed0178d223c1ba75024ff58040000006a47304402206fd8709b72836a8a7c7d3059a2bcd11e835de7966277aa14a70aaa978a557ea3022036dc594d1050e98091f2382715461bae03faef774ca7ec1f9d6bd852cf3e12a84121028b5d4e481b88bcdb98cf5baff279ba364d73cf1a001bcbebee25895577897e67feffffff21d231b0d81f74e29145cc5c7dc92b45aecaedc84ed0178d223c1ba75024ff58050000006b483045022100cb820ff34bad9ac75e73c8eedc0929547021ec2e0b9099db39177702c1d5ac3802200f2b9727a1396f68e3bcf16a9b5f2ea0587a3496d9f483007b1d940a6edeb52841210387f3f2b2ef3d3ee85fb4530bb702af0fa3644b23d61e8c0e50c87d828cf27136feffffff06e8030000000000001976a9142d2fa4c2a38862814cca01f2f0b78d58f093dfc288ace8030000000000001976a9140ab1ed3b3358a1caec5e75475a1db96b668432b288ace8030000000000001976a914a65b5515f02325e02d3a296be60fe6f612265ea088ac60670100000000001976a914fc92ae15367bd3f9154bf475e07a4017bfadccac88ac48d0bd0b000000001976a91496c4871f24d2534c7c592699045940df9f3cb70088acc0150c00000000001976a9149c0d281ac7ae4e471cdd607af502cdeb038849c488ac00000000", + "txid": "32fe2a3a60eb952d6ade53b7030ddb6ad8af5797391857baaad37c5b20f3b5ca", + "blocktime":1529571678, + "time":1529571678, + "locktime": 0, "vin": [ { - "txid": "f4be368fde7853c75d48c5927345df8d898f572e5d541fdad431e994f91e9c34", - "vout": 1, + "txid": "58ff2450a71b3c228d17d04ec8edcaae452bc97d5ccc4591e2741fd8b031d221", + "vout": 3, "sequence": 4294967294, "scriptSig": { - "hex": "4730440220351f1566e3ef02e900942103c60cba5a768cd710d3d1afbc75406099ad2d9e4702206e0f639a9991c7afb2136fb2e437629103ad0989898d1c90078ded5f08f5cb3341210303ae341929bdb242226a9a8c15cdbed5b89fa286842714d8be7e3f16c63abe11" + "hex": "473044022004739fe75329dee2f6deedca41eec94ca9c5d6e3a3ad807f28813c81406b6db002204153c2c0c72214295aaeb637ff6390e8ea220adf7ef30f5c0e7b95933f880bed4121027909d648cd5d774d250e5f8ab4c4aadfba07f4abb835f9100387bdc047e176bc" } }, { - "txid": "b46f64a97806dcf25c5f8cf8bcdba65fbfd705b7f1805be790f0c7efc885e64a", - "vout": 0, + "txid": "58ff2450a71b3c228d17d04ec8edcaae452bc97d5ccc4591e2741fd8b031d221", + "vout": 4, "sequence": 4294967294, "scriptSig": { - "hex": "483045022100b8dae1825b0d0ccbe212e8da6767ea049bad9acfc737e5c5ef3dc5eeef6d313c02207e4c669956f871a4a5f71903bf38a8c587b81940943682364b11fb1cd9c078d7412103c9bd0064d2759628c1f6e5ad9d6345a5bce64dc4f4bb0675162f77acd557e4e2" + "hex": "47304402206fd8709b72836a8a7c7d3059a2bcd11e835de7966277aa14a70aaa978a557ea3022036dc594d1050e98091f2382715461bae03faef774ca7ec1f9d6bd852cf3e12a84121028b5d4e481b88bcdb98cf5baff279ba364d73cf1a001bcbebee25895577897e67" } }, { - "txid": "1d2f4bb2a6320c7e4065f07545319af7826a03e2950d7dcb65713805ed1dc21a", - "vout": 1, + "txid": "58ff2450a71b3c228d17d04ec8edcaae452bc97d5ccc4591e2741fd8b031d221", + "vout": 5, "sequence": 4294967294, "scriptSig": { - "hex": "483045022100ef4a9469a5b3dbc0f03e8d8c5f254ad86f2c1e92e75a5ee737c3b3186b5edd95022076abcdfa976c3c78d2b196fb79699057248fad6d3d5e782524b85d84704394cc412103882df93f092501520bb36206703dadb65b25a3fbd0323c690dc8e72f5ee4a770" - } - }, - { - "txid": "bf0caf2a13a2b8963bb08856f7db7467e0ab9462058a6c3faaa213b3ab0569ea", - "vout": 1, - "sequence": 4294967294, - "scriptSig": { - "hex": "483045022100e4ab9dd0a75bc76c6c2cf549fb37c5577bad7f58953a7103abe4a77a95b873c10220545aa0c2b2869d444fb99d237549d6ac270c711d60788a6463ef4fee63ebd8fc4121031adea1da6e87b0771ea8c2a4723127d8cc9328b0594d159570ebe97b1e021c9e" - } - }, - { - "txid": "fa0043f33701b38abfafa26e6fa0b007c0f9619877d953f96637ad8d667a9a8c", - "vout": 0, - "sequence": 4294967294, - "scriptSig": { - "hex": "47304402207253f724d891f5e1e66ec0c8084ade910a52257a1257933c23bd1b4da862e33a0220363df96e31dffa0a599b56c5049519a4d8ed34e96dc1fefecfd2bc31fc6d79d9412103186a4fc8445b3b437587c71f00fc9da7a267c0a38915fcf567528e310a73c0bd" - } - }, - { - "txid": "726e820d9338bc686ec0844858459c132d5e46158602ef56524bb8105b5d4482", - "vout": 1, - "sequence": 4294967294, - "scriptSig": { - "hex": "47304402204846adc41599336307a087d4fa779a059ffe12c69456c82fa4b03942c901284002203e5f0c5e72b9ded7f48b4d22cbdb39390bea33003d46d8b4652c8ede1f13b3e54121031adea1da6e87b0771ea8c2a4723127d8cc9328b0594d159570ebe97b1e021c9e" - } - }, - { - "txid": "2d446f9d9eb2cf844e5f4d14e2e667312b639847d0d2f62681aa953b2c6c81b8", - "vout": 1, - "sequence": 4294967294, - "scriptSig": { - "hex": "473044022078b1aff9a4ed3452f782db38341d846edd295f9a907c7373519408fb33eeb3240220578da5e91ec0c82604982b09cbd1f44e28260fcd640bcc55f086ce296ef32ef7412103c9bd0064d2759628c1f6e5ad9d6345a5bce64dc4f4bb0675162f77acd557e4e2" - } - }, - { - "txid": "b01cffcb4d8eb68cfa3103e94a7733f57a04767af6d54cfe994f81b2c98a6270", - "vout": 1, - "sequence": 4294967294, - "scriptSig": { - "hex": "483045022100cd88592589ab3bbd6e23920770a067a37ffbff3a31238167731377f11903676202202cb1c019365870dad3113abb3b0bc68ab9e65d9d60592f3315ffa444dfd88be741210393bd44ad6ed9295bf408e01bcdbdf6e4e8fd4a573ad20f37e54ff6e9b1596028" + "hex": "483045022100cb820ff34bad9ac75e73c8eedc0929547021ec2e0b9099db39177702c1d5ac3802200f2b9727a1396f68e3bcf16a9b5f2ea0587a3496d9f483007b1d940a6edeb52841210387f3f2b2ef3d3ee85fb4530bb702af0fa3644b23d61e8c0e50c87d828cf27136" } } ], "vout": [ { - "value": 0.40662655, + "value": 0.00001000, "n": 0, "scriptPubKey": { - "hex": "76a9149f96c6e6c3aabf438eef5c589c47fa4b4f96592a88ac" + "hex": "76a9142d2fa4c2a38862814cca01f2f0b78d58f093dfc288ac" } }, { - "value": 0.00998684, + "value": 0.00001000, "n": 1, "scriptPubKey": { - "hex": "76a914e2ffd7cf2fe9468512878196d1b48fee9e9d003288ac" + "hex": "76a9140ab1ed3b3358a1caec5e75475a1db96b668432b288ac" + } + }, + { + "value": 0.00001000, + "n": 2, + "scriptPubKey": { + "hex": "76a914a65b5515f02325e02d3a296be60fe6f612265ea088ac" + } + }, + { + "value": 0.00092000, + "n": 3, + "scriptPubKey": { + "hex": "76a914fc92ae15367bd3f9154bf475e07a4017bfadccac88ac" + } + }, + { + "value": 1.96989000, + "n": 4, + "scriptPubKey": { + "hex": "76a91496c4871f24d2534c7c592699045940df9f3cb70088ac" + } + }, + { + "value": 0.00792000, + "n": 5, + "scriptPubKey": { + "hex": "76a9149c0d281ac7ae4e471cdd607af502cdeb038849c488ac" } } ] diff --git a/bchain/tests/rpc/testdata/Bitcoin_Testnet.json b/bchain/tests/rpc/testdata/Bitcoin_Testnet.json index 0eb09a8a..ece3c941 100644 --- a/bchain/tests/rpc/testdata/Bitcoin_Testnet.json +++ b/bchain/tests/rpc/testdata/Bitcoin_Testnet.json @@ -78,43 +78,43 @@ } ] }, - "5bef621ad6d0970939ae36270a3228d3c315f8008fb04eebffab5f7a3589d114": { - "hex": "01000000025b0551bd0fffcf55881e285e15b364ab9a831d2494d2eb7a163a4bbd6f551151000000006b483045022100dff500e8c060a9c8810483d4ada8f91c0b844e92778cc762300040870109c0be02207029fa781ec37ddeb0ffbfa7160e625afdd126f30ec11fb9bc25f4d2164933bb0121023c6017ab9f471a69157180c5e30b9aef2ff73ea2a1a774c53a975e2557536314ffffffffd49a58913818610b0aa065d4f32995863d216c44040a49d454f6b7eeb65c9adc010000006b483045022100dce24b819b70f920d0bb60fa1241fa14f2500412a60aceeaae2610e1593b5e3c022041fdc5a02dc26af043bea27713f1245340b98bd47aa283e23b96ecc4aae157a4012102d18a88bcf5f65d937de7d9bc24d2f492a55216087262bf4683d0055dd0521a56feffffff02da869800000000001976a914b4f1349ec3e7c751c6720e2c0783e3449e21e36888ac80fe210a000000001976a914b4f1349ec3e7c751c6720e2c0783e3449e21e36888ac00000000", - "txid": "5bef621ad6d0970939ae36270a3228d3c315f8008fb04eebffab5f7a3589d114", + "3005378ee85fc905a1812bdfae4b2e0e9bb09f5867a53fd73237bb319a1774aa": { + "hex": "01000000000102c997f74e9ad52a44446302381e0fa6de080dadadf55842588bde1be8a47b438000000000171600147edbcdda98080eeb6e8a63c63da135498295c3cdffffffff563c9674a40bf1aa1063f767a50d2288146116fe869012ad3dad03d71e74a8800100000017160014af97d082fd5de049bce2991d9dcaa5d3035a1b04ffffffff0290f4f700000000001976a914abba3808b854c70b63ff038fcddfbafcb707713988ac74b77b030100000017a914fb1e0f36e2d8e91a43c7faba7dae18a610070c4a87024730440220538fcd8fbbf39b813372a7ff6251f1d22c9e940f54272ab525e1d1dc5f03049b022066cc5a1c445573e7e069fdaf3aa33d6665ef5f7936cb155cfd9093e888ca9461012102b45e239d96f8504ae45a32af7c80f6164f7b9658166e318521ee822192fee3ef0248304502210089e579ce52f765c8de6033e1cee93c94aa9a5ef3a194fec12885ed163dc60688022050aadd6aa170c6cfb58f406497949b0140327b4889ca7e082bdcfa8cc03d487f012103fb1a838f38d587dea0532f4a15a39b96e411cdb37c5160ba576a4cb0072db01900000000", + "txid": "3005378ee85fc905a1812bdfae4b2e0e9bb09f5867a53fd73237bb319a1774aa", "blocktime": 1528788394, "time": 1528788394, "locktime": 0, "vin": [ { - "txid": "5111556fbd4b3a167aebd294241d839aab64b3155e281e8855cfff0fbd51055b", + "txid": "80437ba4e81bde8b584258f5adad0d08dea60f1e38026344442ad59a4ef797c9", "vout": 0, "sequence": 4294967295, "scriptSig": { - "hex": "483045022100dff500e8c060a9c8810483d4ada8f91c0b844e92778cc762300040870109c0be02207029fa781ec37ddeb0ffbfa7160e625afdd126f30ec11fb9bc25f4d2164933bb0121023c6017ab9f471a69157180c5e30b9aef2ff73ea2a1a774c53a975e2557536314" + "hex": "1600147edbcdda98080eeb6e8a63c63da135498295c3cd" } }, { - "txid": "dc9a5cb6eeb7f654d4490a04446c213d869529f3d465a00a0b61183891589ad4", + "txid": "80a8741ed703ad3dad129086fe16611488220da567f76310aaf10ba474963c56", "vout": 1, - "sequence": 4294967294, + "sequence": 4294967295, "scriptSig": { - "hex": "483045022100dce24b819b70f920d0bb60fa1241fa14f2500412a60aceeaae2610e1593b5e3c022041fdc5a02dc26af043bea27713f1245340b98bd47aa283e23b96ecc4aae157a4012102d18a88bcf5f65d937de7d9bc24d2f492a55216087262bf4683d0055dd0521a56" + "hex": "160014af97d082fd5de049bce2991d9dcaa5d3035a1b04" } } ], "vout": [ { - "value": 0.09995994, + "value": 0.16250000, "n": 0, "scriptPubKey": { - "hex": "76a914b4f1349ec3e7c751c6720e2c0783e3449e21e36888ac" + "hex": "76a914abba3808b854c70b63ff038fcddfbafcb707713988ac" } }, { - "value": 1.7, + "value": 43.53406836, "n": 1, "scriptPubKey": { - "hex": "76a914b4f1349ec3e7c751c6720e2c0783e3449e21e36888ac" + "hex": "a914fb1e0f36e2d8e91a43c7faba7dae18a610070c4a87" } } ] diff --git a/bchain/tests/rpc/testdata/Ethereum_Testnet.json b/bchain/tests/rpc/testdata/Ethereum_Testnet.json index cef9511f..82bbf3c7 100644 --- a/bchain/tests/rpc/testdata/Ethereum_Testnet.json +++ b/bchain/tests/rpc/testdata/Ethereum_Testnet.json @@ -33,6 +33,24 @@ } } ] + }, + "0x17ee235fc0359155b25419e0e4c65d9c500df6e71e8288d6ef020d04cc2f2cb3": { + "hex": "7b226e6f6e6365223a223078346566222c226761735072696365223a223078626134336237343030222c22676173223a2230783936653838222c22746f223a22307864303534323939633438326164356362333961336661383734373235663965326132306433343963222c2276616c7565223a22307830222c22696e707574223a2230783165626366613630303030303030303030303030303030303030303030303030633034383732383566313736663532306635636434363732306236383662366534366165636430373030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303031303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030313430303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030633461303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303530303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030353831303030303030303030303030303030303030303030303030633365313631343261306432366336616530623163656238643961373236653734653164613664663666656562653137653437306464626434656261663364623938333136386235316337623136363732613131623966306662383864623438323962653237346230303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303034363336663665363230303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303437323666373336313030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030222c2268617368223a22307831376565323335666330333539313535623235343139653065346336356439633530306466366537316538323838643665663032306430346363326632636233222c22626c6f636b4e756d626572223a223078326263616630222c2266726f6d223a22307838623461353365353739303739343466633261653539623837373066393331623639326232373062222c227472616e73616374696f6e496e646578223a22307830222c2276223a2230783163222c2272223a22307866633739633836353638323039313030323134616339353662373930653066383935656130343135313438643233613239353632356564393761633936333534222c2273223a223078373232303833616331643764663662626162393939383537616163323561336665646265386130633561326266376364653835393738363266373862313937227d", + "txid": "0x17ee235fc0359155b25419e0e4c65d9c500df6e71e8288d6ef020d04cc2f2cb3", + "blocktime": 1521515026, + "time": 1521515026, + "vin": [ + { + "addresses": ["0x8b4a53e57907944fc2ae59b8770f931b692b270b"] + } + ], + "vout": [ + { + "scriptPubKey": { + "addresses": ["0xd054299c482ad5cb39a3fa874725f9e2a20d349c"] + } + } + ] } } } diff --git a/bchain/types.go b/bchain/types.go index 09052918..e2aa7276 100644 --- a/bchain/types.go +++ b/bchain/types.go @@ -32,14 +32,14 @@ type Vin struct { Vout uint32 `json:"vout"` ScriptSig ScriptSig `json:"scriptSig"` Sequence uint32 `json:"sequence"` - Addresses []string `json:"addresses,omitempty"` + Addresses []string `json:"addresses"` } type ScriptPubKey struct { // Asm string `json:"asm"` Hex string `json:"hex,omitempty"` // Type string `json:"type"` - Addresses []string `json:"addresses,omitempty"` + Addresses []string `json:"addresses"` } type Address interface { diff --git a/build/deb/debian/blockbook-vertcoin-testnet.conffiles b/build/deb/debian/blockbook-vertcoin-testnet.conffiles new file mode 100644 index 00000000..bd430e24 --- /dev/null +++ b/build/deb/debian/blockbook-vertcoin-testnet.conffiles @@ -0,0 +1 @@ +/opt/coins/blockbook/vertcoin_testnet/config/blockchaincfg.json diff --git a/build/deb/debian/blockbook-vertcoin-testnet.cron.daily b/build/deb/debian/blockbook-vertcoin-testnet.cron.daily new file mode 100644 index 00000000..fa2948c5 --- /dev/null +++ b/build/deb/debian/blockbook-vertcoin-testnet.cron.daily @@ -0,0 +1,2 @@ +#!/bin/sh +/opt/coins/blockbook/vertcoin_testnet/bin/logrotate.sh diff --git a/build/deb/debian/blockbook-vertcoin-testnet.dirs b/build/deb/debian/blockbook-vertcoin-testnet.dirs new file mode 100644 index 00000000..56e480b5 --- /dev/null +++ b/build/deb/debian/blockbook-vertcoin-testnet.dirs @@ -0,0 +1,2 @@ +/opt/coins/data/vertcoin_testnet/blockbook +/opt/coins/blockbook/vertcoin_testnet/logs diff --git a/build/deb/debian/blockbook-vertcoin-testnet.install b/build/deb/debian/blockbook-vertcoin-testnet.install new file mode 100755 index 00000000..31fd887c --- /dev/null +++ b/build/deb/debian/blockbook-vertcoin-testnet.install @@ -0,0 +1,6 @@ +#!/usr/bin/dh-exec +blockbook /opt/coins/blockbook/vertcoin_testnet/bin +cert /opt/coins/blockbook/vertcoin_testnet +static /opt/coins/blockbook/vertcoin_testnet +configs/vertcoin_testnet.json => /opt/coins/blockbook/vertcoin_testnet/config/blockchaincfg.json +logrotate.sh /opt/coins/blockbook/vertcoin_testnet/bin diff --git a/build/deb/debian/blockbook-vertcoin-testnet.links b/build/deb/debian/blockbook-vertcoin-testnet.links new file mode 100644 index 00000000..c5f3c713 --- /dev/null +++ b/build/deb/debian/blockbook-vertcoin-testnet.links @@ -0,0 +1,2 @@ +/opt/coins/blockbook/vertcoin_testnet/cert/testcert.crt /opt/coins/blockbook/vertcoin_testnet/cert/blockbook.crt +/opt/coins/blockbook/vertcoin_testnet/cert/testcert.key /opt/coins/blockbook/vertcoin_testnet/cert/blockbook.key diff --git a/build/deb/debian/blockbook-vertcoin-testnet.postinst b/build/deb/debian/blockbook-vertcoin-testnet.postinst new file mode 100644 index 00000000..158bd67c --- /dev/null +++ b/build/deb/debian/blockbook-vertcoin-testnet.postinst @@ -0,0 +1,23 @@ +#!/bin/bash +set -e + +case "$1" in + + configure) + if ! id -u blockbook-vertcoin &> /dev/null + then + useradd --system -M -U blockbook-vertcoin -s /bin/false + fi + + for dir in /opt/coins/data/vertcoin_testnet/blockbook /opt/coins/blockbook/vertcoin_testnet/logs + do + if [ "$(stat -c '%U' $dir)" != "blockbook-vertcoin" ] + then + chown -R blockbook-vertcoin:blockbook-vertcoin $dir + fi + done + ;; + +esac + +#DEBHELPER# diff --git a/build/deb/debian/blockbook-vertcoin-testnet.service b/build/deb/debian/blockbook-vertcoin-testnet.service new file mode 100644 index 00000000..9d391f83 --- /dev/null +++ b/build/deb/debian/blockbook-vertcoin-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-vertcoin-testnet.service +# See "man systemd.service" for details. + +[Unit] +Description=Blockbook daemon (Vertcoin testnet) +After=network.target +Wants=backend-vertcoin-testnet.service + +[Service] +ExecStart=/opt/coins/blockbook/vertcoin_testnet/bin/blockbook -blockchaincfg=/opt/coins/blockbook/vertcoin_testnet/config/blockchaincfg.json -datadir=/opt/coins/data/vertcoin_testnet/blockbook/db -sync -httpserver=:19040 -socketio=:19140 -certfile=/opt/coins/blockbook/vertcoin_testnet/cert/blockbook -explorer=http://explorer.vertcointools.com/ -log_dir=/opt/coins/blockbook/vertcoin_testnet/logs +User=blockbook-vertcoin +Type=simple +Restart=on-failure +WorkingDirectory=/opt/coins/blockbook/vertcoin_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-vertcoin.conffiles b/build/deb/debian/blockbook-vertcoin.conffiles new file mode 100644 index 00000000..50db5a5b --- /dev/null +++ b/build/deb/debian/blockbook-vertcoin.conffiles @@ -0,0 +1 @@ +/opt/coins/blockbook/vertcoin/config/blockchaincfg.json diff --git a/build/deb/debian/blockbook-vertcoin.cron.daily b/build/deb/debian/blockbook-vertcoin.cron.daily new file mode 100644 index 00000000..f4a8a2c9 --- /dev/null +++ b/build/deb/debian/blockbook-vertcoin.cron.daily @@ -0,0 +1,2 @@ +#!/bin/sh +/opt/coins/blockbook/vertcoin/bin/logrotate.sh diff --git a/build/deb/debian/blockbook-vertcoin.dirs b/build/deb/debian/blockbook-vertcoin.dirs new file mode 100644 index 00000000..5b381887 --- /dev/null +++ b/build/deb/debian/blockbook-vertcoin.dirs @@ -0,0 +1,2 @@ +/opt/coins/data/vertcoin/blockbook +/opt/coins/blockbook/vertcoin/logs diff --git a/build/deb/debian/blockbook-vertcoin.install b/build/deb/debian/blockbook-vertcoin.install new file mode 100755 index 00000000..7fdafb01 --- /dev/null +++ b/build/deb/debian/blockbook-vertcoin.install @@ -0,0 +1,6 @@ +#!/usr/bin/dh-exec +blockbook /opt/coins/blockbook/vertcoin/bin +cert /opt/coins/blockbook/vertcoin +static /opt/coins/blockbook/vertcoin +configs/vertcoin.json => /opt/coins/blockbook/vertcoin/config/blockchaincfg.json +logrotate.sh /opt/coins/blockbook/vertcoin/bin diff --git a/build/deb/debian/blockbook-vertcoin.links b/build/deb/debian/blockbook-vertcoin.links new file mode 100644 index 00000000..bf9efb36 --- /dev/null +++ b/build/deb/debian/blockbook-vertcoin.links @@ -0,0 +1,2 @@ +/opt/coins/blockbook/vertcoin/cert/testcert.crt /opt/coins/blockbook/vertcoin/cert/blockbook.crt +/opt/coins/blockbook/vertcoin/cert/testcert.key /opt/coins/blockbook/vertcoin/cert/blockbook.key diff --git a/build/deb/debian/blockbook-vertcoin.postinst b/build/deb/debian/blockbook-vertcoin.postinst new file mode 100644 index 00000000..772ac44e --- /dev/null +++ b/build/deb/debian/blockbook-vertcoin.postinst @@ -0,0 +1,23 @@ +#!/bin/bash +set -e + +case "$1" in + + configure) + if ! id -u blockbook-vertcoin &> /dev/null + then + useradd --system -M -U blockbook-vertcoin -s /bin/false + fi + + for dir in /opt/coins/data/vertcoin/blockbook /opt/coins/blockbook/vertcoin/logs + do + if [ "$(stat -c '%U' $dir)" != "blockbook-vertcoin" ] + then + chown -R blockbook-vertcoin:blockbook-vertcoin $dir + fi + done + ;; + +esac + +#DEBHELPER# diff --git a/build/deb/debian/blockbook-vertcoin.service b/build/deb/debian/blockbook-vertcoin.service new file mode 100644 index 00000000..9f19ba13 --- /dev/null +++ b/build/deb/debian/blockbook-vertcoin.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-vertcoin.service +# See "man systemd.service" for details. + +[Unit] +Description=Blockbook daemon (Vertcoin mainnet) +After=network.target +Wants=backend-vertcoin.service + +[Service] +ExecStart=/opt/coins/blockbook/vertcoin/bin/blockbook -blockchaincfg=/opt/coins/blockbook/vertcoin/config/blockchaincfg.json -datadir=/opt/coins/data/vertcoin/blockbook/db -sync -httpserver=:9040 -socketio=:9140 -certfile=/opt/coins/blockbook/vertcoin/cert/blockbook -explorer=https://insight.vertcoin.org/ -log_dir=/opt/coins/blockbook/vertcoin/logs +User=blockbook-vertcoin +Type=simple +Restart=on-failure +WorkingDirectory=/opt/coins/blockbook/vertcoin + +# 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 05cc65fd..55652522 100644 --- a/build/deb/debian/control +++ b/build/deb/debian/control @@ -80,6 +80,16 @@ Architecture: amd64 Depends: ${shlibs:Depends}, ${misc:Depends}, coreutils, passwd, findutils, psmisc, backend-dogecoin Description: Satoshilabs blockbook server (Dogecoin mainnet) +Package: blockbook-vertcoin +Architecture: amd64 +Depends: ${shlibs:Depends}, ${misc:Depends}, coreutils, passwd, findutils, psmisc, backend-dogecoin +Description: Satoshilabs blockbook server (Vertcoin mainnet) + +Package: blockbook-vertcoin-testnet +Architecture: amd64 +Depends: ${shlibs:Depends}, ${misc:Depends}, coreutils, passwd, findutils, psmisc, backend-dogecoin +Description: Satoshilabs blockbook server (Vertcoin testnet) + Package: blockbook-namecoin Architecture: amd64 Depends: ${shlibs:Depends}, ${misc:Depends}, coreutils, passwd, findutils, psmisc, backend-namecoin diff --git a/configs/vertcoin.json b/configs/vertcoin.json new file mode 100644 index 00000000..b1dec1d5 --- /dev/null +++ b/configs/vertcoin.json @@ -0,0 +1,12 @@ +{ + "coin_name": "Vertcoin", + "rpcURL": "http://localhost:8040", + "rpcUser": "rpc", + "rpcPass": "rpc", + "rpcTimeout": 25, + "parse": true, + "zeroMQBinding": "tcp://localhost:38340", + "mempoolWorkers": 8, + "mempoolSubWorkers": 2, + "blockAddressesToKeep": 300 +} diff --git a/configs/vertcoin_testnet.json b/configs/vertcoin_testnet.json new file mode 100644 index 00000000..45bead82 --- /dev/null +++ b/configs/vertcoin_testnet.json @@ -0,0 +1,12 @@ +{ + "coin_name": "Vertcoin Testnet", + "rpcURL": "http://localhost:18040", + "rpcUser": "rpc", + "rpcPass": "rpc", + "rpcTimeout": 25, + "parse": true, + "zeroMQBinding": "tcp://localhost:48340", + "mempoolWorkers": 8, + "mempoolSubWorkers": 2, + "blockAddressesToKeep": 300 +} diff --git a/contrib/backends/Makefile b/contrib/backends/Makefile index be61a88e..fc211070 100644 --- a/contrib/backends/Makefile +++ b/contrib/backends/Makefile @@ -1,4 +1,4 @@ -TARGETS = bitcoin zcash bcash ethereum bgold dash litecoin dogecoin namecoin +TARGETS = bitcoin zcash bcash ethereum bgold dash litecoin dogecoin vertcoin namecoin IMAGE = blockbook-backend-build-deb NO_CACHE = false diff --git a/contrib/backends/vertcoin/Makefile b/contrib/backends/vertcoin/Makefile new file mode 100644 index 00000000..ad6c3121 --- /dev/null +++ b/contrib/backends/vertcoin/Makefile @@ -0,0 +1,10 @@ +VERTCOIN_VERSION := 0.13.2 + +all: + wget https://github.com/vertcoin-project/vertcoin-core/releases/download/${VERTCOIN_VERSION}/vertcoind-v${VERTCOIN_VERSION}-linux-amd64.zip + mkdir vertcoin + unzip vertcoind-v${VERTCOIN_VERSION}-linux-amd64.zip -d vertcoin/ + +clean: + rm -rf vertcoin + rm -f vertcoind-v${VERTCOIN_VERSION}-linux-amd64.zip diff --git a/contrib/backends/vertcoin/debian/backend-vertcoin-testnet.conffiles b/contrib/backends/vertcoin/debian/backend-vertcoin-testnet.conffiles new file mode 100644 index 00000000..8b042541 --- /dev/null +++ b/contrib/backends/vertcoin/debian/backend-vertcoin-testnet.conffiles @@ -0,0 +1 @@ +/opt/coins/nodes/vertcoin_testnet/vertcoin_testnet.conf diff --git a/contrib/backends/vertcoin/debian/backend-vertcoin-testnet.dirs b/contrib/backends/vertcoin/debian/backend-vertcoin-testnet.dirs new file mode 100644 index 00000000..0ed9e6bb --- /dev/null +++ b/contrib/backends/vertcoin/debian/backend-vertcoin-testnet.dirs @@ -0,0 +1 @@ +/opt/coins/data/vertcoin_testnet/backend diff --git a/contrib/backends/vertcoin/debian/backend-vertcoin-testnet.install b/contrib/backends/vertcoin/debian/backend-vertcoin-testnet.install new file mode 100644 index 00000000..3e93aa2c --- /dev/null +++ b/contrib/backends/vertcoin/debian/backend-vertcoin-testnet.install @@ -0,0 +1,2 @@ +vertcoin/* /opt/coins/nodes/vertcoin_testnet +vertcoin_testnet.conf /opt/coins/nodes/vertcoin_testnet diff --git a/contrib/backends/vertcoin/debian/backend-vertcoin-testnet.logrotate b/contrib/backends/vertcoin/debian/backend-vertcoin-testnet.logrotate new file mode 100644 index 00000000..5a3eed96 --- /dev/null +++ b/contrib/backends/vertcoin/debian/backend-vertcoin-testnet.logrotate @@ -0,0 +1,10 @@ +/opt/coins/data/vertcoin_testnet/backend/testnet3/debug.log +/opt/coins/data/vertcoin_testnet/backend/testnet3/db.log +{ + rotate 7 + daily + compress + missingok + notifempty + copytruncate +} diff --git a/contrib/backends/vertcoin/debian/backend-vertcoin-testnet.postinst b/contrib/backends/vertcoin/debian/backend-vertcoin-testnet.postinst new file mode 100644 index 00000000..24ccddb2 --- /dev/null +++ b/contrib/backends/vertcoin/debian/backend-vertcoin-testnet.postinst @@ -0,0 +1,20 @@ +#!/bin/bash +set -e + +case "$1" in + + configure) + if ! id -u vertcoin &> /dev/null + then + useradd --system -M -U vertcoin -s /bin/false + fi + + if [ "$(stat -c '%U' /opt/coins/data/vertcoin_testnet/backend)" != "vertcoin" ] + then + chown -R vertcoin:vertcoin /opt/coins/data/vertcoin_testnet/backend + fi + ;; + +esac + +#DEBHELPER# diff --git a/contrib/backends/vertcoin/debian/backend-vertcoin-testnet.service b/contrib/backends/vertcoin/debian/backend-vertcoin-testnet.service new file mode 100644 index 00000000..c2e8443f --- /dev/null +++ b/contrib/backends/vertcoin/debian/backend-vertcoin-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 vertcoin-testnet.service +# See "man systemd.service" for details. + +# Note that almost all daemon options could be specified in +# /opt/coins/nodes/vertcoin_testnet/vertcoin_testnet.conf + +[Unit] +Description=vertcoin daemon (testnet) +After=network.target + +[Service] +ExecStart=/opt/coins/nodes/vertcoin_testnet/vertcoind -datadir=/opt/coins/data/vertcoin_testnet/backend -conf=/opt/coins/nodes/vertcoin_testnet/vertcoin_testnet.conf -pid=/run/vertcoind/vertcoin_testnet.pid +# Creates /run/vertcoind owned by vertcoin +RuntimeDirectory=vertcoind +User=vertcoin +Type=forking +PIDFile=/run/vertcoind/vertcoin_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/vertcoin/debian/backend-vertcoin.conffiles b/contrib/backends/vertcoin/debian/backend-vertcoin.conffiles new file mode 100644 index 00000000..790936f6 --- /dev/null +++ b/contrib/backends/vertcoin/debian/backend-vertcoin.conffiles @@ -0,0 +1 @@ +/opt/coins/nodes/vertcoin/vertcoin.conf diff --git a/contrib/backends/vertcoin/debian/backend-vertcoin.dirs b/contrib/backends/vertcoin/debian/backend-vertcoin.dirs new file mode 100644 index 00000000..4651768b --- /dev/null +++ b/contrib/backends/vertcoin/debian/backend-vertcoin.dirs @@ -0,0 +1 @@ +/opt/coins/data/vertcoin/backend diff --git a/contrib/backends/vertcoin/debian/backend-vertcoin.install b/contrib/backends/vertcoin/debian/backend-vertcoin.install new file mode 100644 index 00000000..26372258 --- /dev/null +++ b/contrib/backends/vertcoin/debian/backend-vertcoin.install @@ -0,0 +1,2 @@ +vertcoin/* /opt/coins/nodes/vertcoin +vertcoin.conf /opt/coins/nodes/vertcoin diff --git a/contrib/backends/vertcoin/debian/backend-vertcoin.logrotate b/contrib/backends/vertcoin/debian/backend-vertcoin.logrotate new file mode 100644 index 00000000..0b756cbb --- /dev/null +++ b/contrib/backends/vertcoin/debian/backend-vertcoin.logrotate @@ -0,0 +1,10 @@ +/opt/coins/data/vertcoin/backend/debug.log +/opt/coins/data/vertcoin/backend/db.log +{ + rotate 7 + daily + compress + missingok + notifempty + copytruncate +} diff --git a/contrib/backends/vertcoin/debian/backend-vertcoin.postinst b/contrib/backends/vertcoin/debian/backend-vertcoin.postinst new file mode 100644 index 00000000..fe11d62f --- /dev/null +++ b/contrib/backends/vertcoin/debian/backend-vertcoin.postinst @@ -0,0 +1,20 @@ +#!/bin/bash +set -e + +case "$1" in + + configure) + if ! id -u vertcoin &> /dev/null + then + useradd --system -M -U vertcoin -s /bin/false + fi + + if [ "$(stat -c '%U' /opt/coins/data/vertcoin/backend)" != "vertcoin" ] + then + chown -R vertcoin:vertcoin /opt/coins/data/vertcoin/backend + fi + ;; + +esac + +#DEBHELPER# diff --git a/contrib/backends/vertcoin/debian/backend-vertcoin.service b/contrib/backends/vertcoin/debian/backend-vertcoin.service new file mode 100644 index 00000000..cb533569 --- /dev/null +++ b/contrib/backends/vertcoin/debian/backend-vertcoin.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 vertcoin.service +# See "man systemd.service" for details. + +# Note that almost all daemon options could be specified in +# /opt/coins/nodes/vertcoin/vertcoin.conf + +[Unit] +Description=vertcoin daemon (mainnet) +After=network.target + +[Service] +ExecStart=/opt/coins/nodes/vertcoin/vertcoind -datadir=/opt/coins/data/vertcoin/backend -conf=/opt/coins/nodes/vertcoin/vertcoin.conf -pid=/run/vertcoind/vertcoin.pid +# Creates /run/vertcoind owned by vertcoin +RuntimeDirectory=vertcoind +User=vertcoin +Type=forking +PIDFile=/run/vertcoind/vertcoin.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/vertcoin/debian/changelog b/contrib/backends/vertcoin/debian/changelog new file mode 100644 index 00000000..cf4bf9e0 --- /dev/null +++ b/contrib/backends/vertcoin/debian/changelog @@ -0,0 +1,5 @@ +vertcoin (0.13.2-satoshilabs1) unstable; urgency=medium + + * Initial build + + -- Petr Kracik Thu, 21 Jun 2018 11:42:00 +0200 diff --git a/contrib/backends/vertcoin/debian/compat b/contrib/backends/vertcoin/debian/compat new file mode 100644 index 00000000..ec635144 --- /dev/null +++ b/contrib/backends/vertcoin/debian/compat @@ -0,0 +1 @@ +9 diff --git a/contrib/backends/vertcoin/debian/control b/contrib/backends/vertcoin/debian/control new file mode 100644 index 00000000..7ac3d718 --- /dev/null +++ b/contrib/backends/vertcoin/debian/control @@ -0,0 +1,16 @@ +Source: vertcoin +Section: satoshilabs +Priority: optional +Maintainer: petr.kracik@satoshilabs.com +Build-Depends: debhelper, wget, tar, gzip, make, dh-systemd, dh-exec +Standards-Version: 3.9.5 + +Package: backend-vertcoin +Architecture: amd64 +Depends: ${shlibs:Depends}, ${misc:Depends}, logrotate +Description: Satoshilabs packaged vertcoin server + +Package: backend-vertcoin-testnet +Architecture: amd64 +Depends: ${shlibs:Depends}, ${misc:Depends}, logrotate +Description: Satoshilabs packaged vertcoin server diff --git a/contrib/backends/vertcoin/debian/rules b/contrib/backends/vertcoin/debian/rules new file mode 100755 index 00000000..f69489df --- /dev/null +++ b/contrib/backends/vertcoin/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: diff --git a/contrib/backends/vertcoin/vertcoin.conf b/contrib/backends/vertcoin/vertcoin.conf new file mode 100644 index 00000000..56b81bd6 --- /dev/null +++ b/contrib/backends/vertcoin/vertcoin.conf @@ -0,0 +1,17 @@ +daemon=1 +server=1 +nolisten=1 +rpcuser=rpc +rpcpassword=rpc +rpcport=8040 +txindex=1 +whitelist=127.0.0.1 + +zmqpubhashtx=tcp://127.0.0.1:38340 +zmqpubhashblock=tcp://127.0.0.1:38340 + +rpcworkqueue=1100 +maxmempool=2000 +dbcache=1000 + + diff --git a/contrib/backends/vertcoin/vertcoin_testnet.conf b/contrib/backends/vertcoin/vertcoin_testnet.conf new file mode 100644 index 00000000..24fdacdb --- /dev/null +++ b/contrib/backends/vertcoin/vertcoin_testnet.conf @@ -0,0 +1,15 @@ +daemon=1 +server=1 +testnet=1 +nolisten=1 +rpcuser=rpc +rpcpassword=rpc +rpcport=18040 +txindex=1 + +zmqpubhashtx=tcp://127.0.0.1:48340 +zmqpubhashblock=tcp://127.0.0.1:48340 + +rpcworkqueue=1100 +maxmempool=2000 +dbcache=1000 diff --git a/contrib/backends/zcash/debian/backend-zcash-testnet.postinst b/contrib/backends/zcash/debian/backend-zcash-testnet.postinst index f93bd12d..40166f69 100644 --- a/contrib/backends/zcash/debian/backend-zcash-testnet.postinst +++ b/contrib/backends/zcash/debian/backend-zcash-testnet.postinst @@ -14,7 +14,7 @@ case "$1" in chown -R zcash:zcash /opt/coins/data/zcash_testnet/backend fi - HOME=/opt/coins/data/zcash_testnet/backend /opt/coins/nodes/zcash_testnet/bin/zcash-fetch-params + HOME=/opt/coins/data/zcash_testnet/backend /opt/coins/nodes/zcash_testnet/bin/zcash-fetch-params --testnet ;; esac diff --git a/contrib/scripts/start-backend-tunnels.sh b/contrib/scripts/start-backend-tunnels.sh index 913a8e81..3f77437e 100755 --- a/contrib/scripts/start-backend-tunnels.sh +++ b/contrib/scripts/start-backend-tunnels.sh @@ -15,7 +15,7 @@ testnet_ports=$(gawk 'match($0, /"rpcURL":\s+"(http|ws):\/\/[^:]+:([0-9]+)"/, a) for port in $testnet_ports do - ssh -nNT -L $port:localhost:$port blockbook-dev.corp & + ssh -nNT -L $port:localhost:$port $host & pid=$! echo "Started tunnel to ${host}:${port} (pid: ${pid})" done @@ -25,4 +25,10 @@ at_exit() { } trap at_exit EXIT -sleep inf + +wait -n +code=$? + +if [ $code != 0 ]; then + exit $code +fi