github.com/neatlab/neatio@v1.7.3-0.20220425043230-d903e92fcc75/internal/neatapi/backend.go (about)

     1  package neatapi
     2  
     3  import (
     4  	"context"
     5  	"math/big"
     6  
     7  	"github.com/neatlab/neatio/chain/accounts"
     8  	"github.com/neatlab/neatio/chain/core"
     9  	"github.com/neatlab/neatio/chain/core/state"
    10  	"github.com/neatlab/neatio/chain/core/types"
    11  	"github.com/neatlab/neatio/chain/core/vm"
    12  	"github.com/neatlab/neatio/neatdb"
    13  	"github.com/neatlab/neatio/neatptc/downloader"
    14  	"github.com/neatlab/neatio/network/rpc"
    15  	"github.com/neatlab/neatio/params"
    16  	"github.com/neatlab/neatio/utilities/common"
    17  	"github.com/neatlab/neatio/utilities/event"
    18  )
    19  
    20  type Backend interface {
    21  	Downloader() *downloader.Downloader
    22  	ProtocolVersion() int
    23  	SuggestPrice(ctx context.Context) (*big.Int, error)
    24  	ChainDb() neatdb.Database
    25  	EventMux() *event.TypeMux
    26  	AccountManager() *accounts.Manager
    27  
    28  	SetHead(number uint64)
    29  	HeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*types.Header, error)
    30  	BlockByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*types.Block, error)
    31  	StateAndHeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*state.StateDB, *types.Header, error)
    32  	GetBlock(ctx context.Context, blockHash common.Hash) (*types.Block, error)
    33  	GetReceipts(ctx context.Context, blockHash common.Hash) (types.Receipts, error)
    34  	GetTd(blockHash common.Hash) *big.Int
    35  	GetEVM(ctx context.Context, msg core.Message, state *state.StateDB, header *types.Header, vmCfg vm.Config) (*vm.EVM, func() error, error)
    36  	SubscribeChainEvent(ch chan<- core.ChainEvent) event.Subscription
    37  	SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) event.Subscription
    38  	SubscribeChainSideEvent(ch chan<- core.ChainSideEvent) event.Subscription
    39  
    40  	SendTx(ctx context.Context, signedTx *types.Transaction) error
    41  	GetPoolTransactions() (types.Transactions, error)
    42  	GetPoolTransaction(txHash common.Hash) *types.Transaction
    43  	GetPoolNonce(ctx context.Context, addr common.Address) (uint64, error)
    44  	Stats() (pending int, queued int)
    45  	TxPoolContent() (map[common.Address]types.Transactions, map[common.Address]types.Transactions)
    46  	SubscribeTxPreEvent(chan<- core.TxPreEvent) event.Subscription
    47  
    48  	ChainConfig() *params.ChainConfig
    49  	CurrentBlock() *types.Block
    50  
    51  	GetCrossChainHelper() core.CrossChainHelper
    52  
    53  	BroadcastTX3ProofData(proofData *types.TX3ProofData)
    54  }
    55  
    56  func GetAPIs(apiBackend Backend, solcPath string) []rpc.API {
    57  	compiler := makeCompilerAPIs(solcPath)
    58  	nonceLock := new(AddrLocker)
    59  	txapi := NewPublicTransactionPoolAPI(apiBackend, nonceLock)
    60  
    61  	all := []rpc.API{
    62  		{
    63  			Namespace: "eth",
    64  			Version:   "1.0",
    65  			Service:   NewPublicNEATChainAPI(apiBackend),
    66  			Public:    true,
    67  		}, {
    68  			Namespace: "eth",
    69  			Version:   "1.0",
    70  			Service:   NewPublicBlockChainAPI(apiBackend),
    71  			Public:    true,
    72  		}, {
    73  			Namespace: "eth",
    74  			Version:   "1.0",
    75  			Service:   txapi,
    76  			Public:    true,
    77  		}, {
    78  			Namespace: "neat",
    79  			Version:   "1.0",
    80  			Service:   NewPublicNEATChainAPI(apiBackend),
    81  			Public:    true,
    82  		}, {
    83  			Namespace: "neat",
    84  			Version:   "1.0",
    85  			Service:   NewPublicBlockChainAPI(apiBackend),
    86  			Public:    true,
    87  		}, {
    88  			Namespace: "neat",
    89  			Version:   "1.0",
    90  			Service:   txapi,
    91  			Public:    true,
    92  		}, {
    93  			Namespace: "txpool",
    94  			Version:   "1.0",
    95  			Service:   NewPublicTxPoolAPI(apiBackend),
    96  			Public:    true,
    97  		}, {
    98  			Namespace: "debug",
    99  			Version:   "1.0",
   100  			Service:   NewPublicDebugAPI(apiBackend),
   101  			Public:    true,
   102  		}, {
   103  			Namespace: "debug",
   104  			Version:   "1.0",
   105  			Service:   NewPrivateDebugAPI(apiBackend),
   106  		}, {
   107  			Namespace: "eth",
   108  			Version:   "1.0",
   109  			Service:   NewPublicAccountAPI(apiBackend.AccountManager()),
   110  			Public:    true,
   111  		}, {
   112  			Namespace: "neat",
   113  			Version:   "1.0",
   114  			Service:   NewPublicAccountAPI(apiBackend.AccountManager()),
   115  			Public:    true,
   116  		}, {
   117  			Namespace: "personal",
   118  			Version:   "1.0",
   119  			Service:   NewPrivateAccountAPI(apiBackend, nonceLock),
   120  			Public:    false,
   121  		}, {
   122  			Namespace: "neat",
   123  			Version:   "1.0",
   124  			Service:   NewPublicNEATAPI(apiBackend, nonceLock),
   125  			Public:    true,
   126  		},
   127  	}
   128  	return append(compiler, all...)
   129  }