From cb7f7a157f48786d07aa51781ddc2ef117e24e58 Mon Sep 17 00:00:00 2001 From: Jonathan Moody <103143855+moodyjon@users.noreply.github.com> Date: Thu, 20 Oct 2022 14:28:09 -0400 Subject: [PATCH] Register RPC service object. --- server/jsonrpc_blockchain.go | 3 +++ server/jsonrpc_service.go | 13 +++++++++---- server/session.go | 7 ++++++- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/server/jsonrpc_blockchain.go b/server/jsonrpc_blockchain.go index 57e03cb..2705141 100644 --- a/server/jsonrpc_blockchain.go +++ b/server/jsonrpc_blockchain.go @@ -640,6 +640,9 @@ type TransactionBroadcastResp string // 'blockchain.transaction.broadcast' func (s *BlockchainTransactionService) Broadcast(req *TransactionBroadcastReq, resp **TransactionBroadcastResp) error { + if s.sessionMgr == nil { + return errors.New("no session manager, rpc not supported") + } strTx := string(*req) rawTx, err := hex.DecodeString(strTx) if err != nil { diff --git a/server/jsonrpc_service.go b/server/jsonrpc_service.go index ae0d757..af032cc 100644 --- a/server/jsonrpc_service.go +++ b/server/jsonrpc_service.go @@ -98,24 +98,29 @@ fail1: goto fail2 } - // Register other "blockchain.{block,address,scripthash}.*" handlers. + // Register "blockchain.{block,address,scripthash,transaction}.*" handlers. blockchainSvc := &BlockchainBlockService{s.DB, s.Chain} err = s1.RegisterTCPService(blockchainSvc, "blockchain_block") if err != nil { log.Errorf("RegisterTCPService: %v\n", err) goto fail2 } - err = s1.RegisterTCPService(&BlockchainHeadersService{s.DB, s.Chain, nil, nil}, "blockchain_headers") + err = s1.RegisterTCPService(&BlockchainHeadersService{s.DB, s.Chain, s.sessionManager, nil}, "blockchain_headers") if err != nil { log.Errorf("RegisterTCPService: %v\n", err) goto fail2 } - err = s1.RegisterTCPService(&BlockchainAddressService{s.DB, s.Chain, nil, nil}, "blockchain_address") + err = s1.RegisterTCPService(&BlockchainAddressService{s.DB, s.Chain, s.sessionManager, nil}, "blockchain_address") if err != nil { log.Errorf("RegisterTCPService: %v\n", err) goto fail2 } - err = s1.RegisterTCPService(&BlockchainScripthashService{s.DB, s.Chain, nil, nil}, "blockchain_scripthash") + err = s1.RegisterTCPService(&BlockchainScripthashService{s.DB, s.Chain, s.sessionManager, nil}, "blockchain_scripthash") + if err != nil { + log.Errorf("RegisterTCPService: %v\n", err) + goto fail2 + } + err = s1.RegisterTCPService(&BlockchainTransactionService{s.DB, s.Chain, s.sessionManager}, "blockchain_transaction") if err != nil { log.Errorf("RegisterTCPService: %v\n", err) goto fail2 diff --git a/server/session.go b/server/session.go index db95da4..b7b1fa8 100644 --- a/server/session.go +++ b/server/session.go @@ -219,7 +219,7 @@ func (sm *sessionManager) addSession(conn net.Conn) *session { log.Errorf("RegisterName: %v\n", err) } - // Register other "blockchain.{block,address,scripthash}.*" handlers. + // Register "blockchain.{block,address,scripthash,transaction}.*" handlers. blockchainSvc := &BlockchainBlockService{sm.db, sm.chain} err = s1.RegisterName("blockchain.block", blockchainSvc) if err != nil { @@ -241,6 +241,11 @@ func (sm *sessionManager) addSession(conn net.Conn) *session { log.Errorf("RegisterName: %v\n", err) goto fail } + err = s1.RegisterName("blockchain.transaction", &BlockchainTransactionService{sm.db, sm.chain, sm}) + if err != nil { + log.Errorf("RegisterName: %v\n", err) + goto fail + } sm.grp.Add(1) go func() {