github.com/intfoundation/intchain@v0.0.0-20220727031208-4316ad31ca73/internal/intapi/backend.go (about)

     1  // Copyright 2015 The go-ethereum Authors
     2  // This file is part of the go-ethereum library.
     3  //
     4  // The go-ethereum library is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU Lesser General Public License as published by
     6  // the Free Software Foundation, either version 3 of the License, or
     7  // (at your option) any later version.
     8  //
     9  // The go-ethereum library is distributed in the hope that it will be useful,
    10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    12  // GNU Lesser General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU Lesser General Public License
    15  // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
    16  
    17  // Package intapi implements the general INT Chain API functions.
    18  package intapi
    19  
    20  import (
    21  	"context"
    22  	"math/big"
    23  
    24  	"github.com/intfoundation/intchain/accounts"
    25  	"github.com/intfoundation/intchain/common"
    26  	"github.com/intfoundation/intchain/core"
    27  	"github.com/intfoundation/intchain/core/state"
    28  	"github.com/intfoundation/intchain/core/types"
    29  	"github.com/intfoundation/intchain/core/vm"
    30  	"github.com/intfoundation/intchain/event"
    31  	"github.com/intfoundation/intchain/intdb"
    32  	"github.com/intfoundation/intchain/intprotocol/downloader"
    33  	"github.com/intfoundation/intchain/params"
    34  	"github.com/intfoundation/intchain/rpc"
    35  )
    36  
    37  // Backend interface provides the common API services (that are provided by
    38  // both full and light clients) with access to necessary functions.
    39  type Backend interface {
    40  	// General Ethereum API
    41  	Downloader() *downloader.Downloader
    42  	ProtocolVersion() int
    43  	SuggestPrice(ctx context.Context) (*big.Int, error)
    44  	ChainDb() intdb.Database
    45  	EventMux() *event.TypeMux
    46  	AccountManager() *accounts.Manager
    47  
    48  	// BlockChain API
    49  	SetHead(number uint64)
    50  	HeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*types.Header, error)
    51  	BlockByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*types.Block, error)
    52  	StateAndHeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*state.StateDB, *types.Header, error)
    53  	GetBlock(ctx context.Context, blockHash common.Hash) (*types.Block, error)
    54  	GetReceipts(ctx context.Context, blockHash common.Hash) (types.Receipts, error)
    55  	GetTd(blockHash common.Hash) *big.Int
    56  	GetEVM(ctx context.Context, msg core.Message, state *state.StateDB, header *types.Header, vmCfg vm.Config) (*vm.EVM, func() error, error)
    57  	SubscribeChainEvent(ch chan<- core.ChainEvent) event.Subscription
    58  	SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) event.Subscription
    59  	SubscribeChainSideEvent(ch chan<- core.ChainSideEvent) event.Subscription
    60  
    61  	// TxPool API
    62  	SendTx(ctx context.Context, signedTx *types.Transaction) error
    63  	GetPoolTransactions() (types.Transactions, error)
    64  	GetPoolTransaction(txHash common.Hash) *types.Transaction
    65  	GetPoolNonce(ctx context.Context, addr common.Address) (uint64, error)
    66  	Stats() (pending int, queued int)
    67  	TxPoolContent() (map[common.Address]types.Transactions, map[common.Address]types.Transactions)
    68  	SubscribeTxPreEvent(chan<- core.TxPreEvent) event.Subscription
    69  
    70  	ChainConfig() *params.ChainConfig
    71  	CurrentBlock() *types.Block
    72  
    73  	//SetInnerAPIBridge(inBridge InnerAPIBridge)
    74  	//GetInnerAPIBridge() InnerAPIBridge
    75  	GetCrossChainHelper() core.CrossChainHelper
    76  
    77  	BroadcastTX3ProofData(proofData *types.TX3ProofData)
    78  }
    79  
    80  func GetAPIs(apiBackend Backend, solcPath string) []rpc.API {
    81  	compiler := makeCompilerAPIs(solcPath)
    82  	nonceLock := new(AddrLocker)
    83  	txapi := NewPublicTransactionPoolAPI(apiBackend, nonceLock)
    84  	//apiBackend.SetInnerAPIBridge(&APIBridge{txapi: txapi})
    85  
    86  	all := []rpc.API{
    87  		{
    88  			Namespace: "eth",
    89  			Version:   "1.0",
    90  			Service:   NewPublicINTChainAPI(apiBackend),
    91  			Public:    true,
    92  		}, {
    93  			Namespace: "eth",
    94  			Version:   "1.0",
    95  			Service:   NewPublicBlockChainAPI(apiBackend),
    96  			Public:    true,
    97  		}, {
    98  			Namespace: "eth",
    99  			Version:   "1.0",
   100  			Service:   txapi,
   101  			Public:    true,
   102  		}, {
   103  			Namespace: "int",
   104  			Version:   "1.0",
   105  			Service:   NewPublicINTChainAPI(apiBackend),
   106  			Public:    true,
   107  		}, {
   108  			Namespace: "int",
   109  			Version:   "1.0",
   110  			Service:   NewPublicBlockChainAPI(apiBackend),
   111  			Public:    true,
   112  		}, {
   113  			Namespace: "int",
   114  			Version:   "1.0",
   115  			Service:   txapi,
   116  			Public:    true,
   117  		}, {
   118  			Namespace: "txpool",
   119  			Version:   "1.0",
   120  			Service:   NewPublicTxPoolAPI(apiBackend),
   121  			Public:    true,
   122  		}, {
   123  			Namespace: "debug",
   124  			Version:   "1.0",
   125  			Service:   NewPublicDebugAPI(apiBackend),
   126  			Public:    true,
   127  		}, {
   128  			Namespace: "debug",
   129  			Version:   "1.0",
   130  			Service:   NewPrivateDebugAPI(apiBackend),
   131  		}, {
   132  			Namespace: "eth",
   133  			Version:   "1.0",
   134  			Service:   NewPublicAccountAPI(apiBackend.AccountManager()),
   135  			Public:    true,
   136  		}, {
   137  			Namespace: "int",
   138  			Version:   "1.0",
   139  			Service:   NewPublicAccountAPI(apiBackend.AccountManager()),
   140  			Public:    true,
   141  		}, {
   142  			Namespace: "personal",
   143  			Version:   "1.0",
   144  			Service:   NewPrivateAccountAPI(apiBackend, nonceLock),
   145  			Public:    false,
   146  		}, {
   147  			Namespace: "int",
   148  			Version:   "1.0",
   149  			Service:   NewPublicINTAPI(apiBackend, nonceLock),
   150  			Public:    true,
   151  		},
   152  	}
   153  	return append(compiler, all...)
   154  }