github.com/turingchain2020/turingchain@v1.1.21/rpc/types/server.go (about)

     1  // Copyright Turing Corp. 2018 All Rights Reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package types
     6  
     7  import (
     8  	"net/rpc"
     9  
    10  	"github.com/turingchain2020/turingchain/account"
    11  	"github.com/turingchain2020/turingchain/client"
    12  	"github.com/turingchain2020/turingchain/queue"
    13  	"github.com/turingchain2020/turingchain/types"
    14  	"google.golang.org/grpc"
    15  )
    16  
    17  // RPCServer interface
    18  type RPCServer interface {
    19  	GetQueueClient() queue.Client
    20  	GRPC() *grpc.Server
    21  	JRPC() *rpc.Server
    22  }
    23  
    24  // ChannelClient interface
    25  type ChannelClient struct {
    26  	client.QueueProtocolAPI
    27  	accountdb *account.DB
    28  	grpc      interface{}
    29  	jrpc      interface{}
    30  }
    31  
    32  // Init init function
    33  func (c *ChannelClient) Init(name string, s RPCServer, jrpc, grpc interface{}) {
    34  	if c.QueueProtocolAPI == nil {
    35  		c.QueueProtocolAPI, _ = client.New(s.GetQueueClient(), nil)
    36  	}
    37  	if jrpc != nil {
    38  		s.JRPC().RegisterName(name, jrpc)
    39  	}
    40  	c.grpc = grpc
    41  	c.jrpc = jrpc
    42  	types.AssertConfig(c.QueueProtocolAPI)
    43  	c.accountdb = account.NewCoinsAccount(c.GetConfig())
    44  }
    45  
    46  // GetCoinsAccountDB  return accountdb
    47  func (c *ChannelClient) GetCoinsAccountDB() *account.DB {
    48  	return c.accountdb
    49  }