From b9cb9d8c5af98aa003af00c659e0741218e67a21 Mon Sep 17 00:00:00 2001 From: Jonathan Moody <103143855+moodyjon@users.noreply.github.com> Date: Tue, 27 Sep 2022 18:08:16 -0500 Subject: [PATCH] Make the service objects independent, so we don't have inheritance. --- server/jsonrpc_blockchain.go | 6 ++++-- server/jsonrpc_blockchain_test.go | 18 ++++++------------ server/jsonrpc_service.go | 7 +++---- 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/server/jsonrpc_blockchain.go b/server/jsonrpc_blockchain.go index 87cfd92..11cd935 100644 --- a/server/jsonrpc_blockchain.go +++ b/server/jsonrpc_blockchain.go @@ -28,12 +28,14 @@ type BlockchainBlockService struct { // BlockchainAddressService methods handle "blockchain.address.*" RPCs type BlockchainAddressService struct { - BlockchainBlockService + DB *db.ReadOnlyDBColumnFamily + Chain *chaincfg.Params } // BlockchainScripthashService methods handle "blockchain.scripthash.*" RPCs type BlockchainScripthashService struct { - BlockchainBlockService + DB *db.ReadOnlyDBColumnFamily + Chain *chaincfg.Params } const CHUNK_SIZE = 96 diff --git a/server/jsonrpc_blockchain_test.go b/server/jsonrpc_blockchain_test.go index 72542f5..7e41780 100644 --- a/server/jsonrpc_blockchain_test.go +++ b/server/jsonrpc_blockchain_test.go @@ -161,10 +161,8 @@ func TestGetBalance(t *testing.T) { } s := &BlockchainAddressService{ - BlockchainBlockService{ - DB: db, - Chain: &chaincfg.RegressionNetParams, - }, + DB: db, + Chain: &chaincfg.RegressionNetParams, } for _, addr := range regTestAddrs { @@ -192,10 +190,8 @@ func TestGetHistory(t *testing.T) { } s := &BlockchainAddressService{ - BlockchainBlockService{ - DB: db, - Chain: &chaincfg.RegressionNetParams, - }, + DB: db, + Chain: &chaincfg.RegressionNetParams, } for _, addr := range regTestAddrs { @@ -223,10 +219,8 @@ func TestListUnspent(t *testing.T) { } s := &BlockchainAddressService{ - BlockchainBlockService{ - DB: db, - Chain: &chaincfg.RegressionNetParams, - }, + DB: db, + Chain: &chaincfg.RegressionNetParams, } for _, addr := range regTestAddrs { diff --git a/server/jsonrpc_service.go b/server/jsonrpc_service.go index f5fc17e..3df87ce 100644 --- a/server/jsonrpc_service.go +++ b/server/jsonrpc_service.go @@ -63,16 +63,15 @@ func (s *Server) StartJsonRPC() error { } // Register other "blockchain.{block,address,scripthash}.*" handlers. - blockchainSvc := &BlockchainBlockService{s.DB, s.Chain} - err = s1.RegisterTCPService(blockchainSvc, "blockchain_block") + err = s1.RegisterTCPService(&BlockchainBlockService{s.DB, s.Chain}, "blockchain_block") if err != nil { log.Errorf("RegisterService: %v\n", err) } - err = s1.RegisterTCPService(&BlockchainAddressService{*blockchainSvc}, "blockchain_address") + err = s1.RegisterTCPService(&BlockchainAddressService{s.DB, s.Chain}, "blockchain_address") if err != nil { log.Errorf("RegisterService: %v\n", err) } - err = s1.RegisterTCPService(&BlockchainScripthashService{*blockchainSvc}, "blockchain_scripthash") + err = s1.RegisterTCPService(&BlockchainScripthashService{s.DB, s.Chain}, "blockchain_scripthash") if err != nil { log.Errorf("RegisterService: %v\n", err) }