예제 #1
0
        public Web3EthApi(IStateReader stateReader,
                          IDeltaResolver deltaResolver,
                          IDeltaCache deltaCache,
                          IDeltaExecutor executor,
                          IStorageProvider storageProvider,
                          IStateProvider stateProvider,
                          ITransactionRepository receipts,
                          ITransactionReceivedEvent transactionReceived,
                          IPeerRepository peerRepository,
                          IMempool <PublicEntryDao> mempoolRepository,
                          IDfsService dfsService,
                          IHashProvider hashProvider,
                          SyncState syncState,
                          IMapperProvider mapperProvider,
                          IPeerSettings peerSettings)
        {
            _receipts            = receipts;
            _transactionReceived = transactionReceived ?? throw new ArgumentNullException(nameof(transactionReceived));
            HashProvider         = hashProvider;
            _peerId            = peerSettings.PeerId;
            _mempoolRepository = mempoolRepository;
            PeerRepository     = peerRepository;
            _mapperProvider    = mapperProvider;

            StateReader     = stateReader ?? throw new ArgumentNullException(nameof(stateReader));
            DeltaResolver   = deltaResolver ?? throw new ArgumentNullException(nameof(deltaResolver));
            DeltaCache      = deltaCache ?? throw new ArgumentNullException(nameof(deltaCache));
            Executor        = executor ?? throw new ArgumentNullException(nameof(executor));
            StorageProvider = storageProvider ?? throw new ArgumentNullException(nameof(storageProvider));
            StateProvider   = stateProvider ?? throw new ArgumentNullException(nameof(stateProvider));
            DfsService      = dfsService;
            SyncState       = syncState;
        }
        protected override BlockForRpc Handle(BlockParameter block, IWeb3EthApi api)
        {
            Cid  deltaHash;
            long blockNumber;

            IDeltaCache    deltaCache    = api.DeltaCache;
            IDeltaResolver deltaResolver = api.DeltaResolver;

            switch (block.Type)
            {
            case BlockParameterType.Earliest:
                deltaHash   = deltaCache.GenesisHash;
                blockNumber = 0;
                break;

            case BlockParameterType.Latest:
                deltaHash   = deltaResolver.LatestDelta;
                blockNumber = deltaResolver.LatestDeltaNumber;
                break;

            case BlockParameterType.Pending:
                deltaHash   = deltaResolver.LatestDelta;
                blockNumber = deltaResolver.LatestDeltaNumber;
                break;

            case BlockParameterType.BlockNumber:
                blockNumber = block.BlockNumber.Value;
                if (!deltaResolver.TryResolve(blockNumber, out deltaHash))
                {
                    return(null);
                }

                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            DeltaWithCid deltaWithCid = api.GetDeltaWithCid(deltaHash);

            return(BuildBlock(deltaWithCid, blockNumber, api.HashProvider));
        }
예제 #3
0
 public Web3EthApi(IDeltaExecutor deltaExecutor, IStateReader stateReader, IStateRootResolver stateRootResolver, IDeltaResolver deltaResolver)
 {
     DeltaExecutor     = deltaExecutor ?? throw new ArgumentNullException(nameof(deltaExecutor));
     StateReader       = stateReader ?? throw new ArgumentNullException(nameof(stateReader));
     StateRootResolver = stateRootResolver ?? throw new ArgumentNullException(nameof(stateRootResolver));
     DeltaResolver     = deltaResolver ?? throw new ArgumentNullException(nameof(deltaResolver));
 }