Exemple #1
0
//C++ TO C# CONVERTER WARNING: 'const' methods are not available in C#:
//ORIGINAL LINE: bool isTransactionRecentlyDeleted(const Crypto::Hash& hash) const
        private bool isTransactionRecentlyDeleted(Crypto.Hash hash)
        {
            var it = recentlyDeletedTransactions.find(hash);

//C++ TO C# CONVERTER TODO TASK: Iterators are only converted within the context of 'while' and 'for' loops:
            return(it != recentlyDeletedTransactions.end() && it.second >= timeout);
        }
    public void waitBlockchainUpdate()
    {
        m_logger.functorMethod(Logging.Level.DEBUGGING) << "Waiting for blockchain updates";
        m_stopped = false;

        Crypto.Hash lastBlockHash = requestLastBlockHash();

        while (!m_stopped)
        {
//C++ TO C# CONVERTER TODO TASK: Only lambda expressions having all locals passed by reference can be converted to C#:
//ORIGINAL LINE: m_sleepingContext.spawn([this]()
            m_sleepingContext.spawn(() =>
            {
                System.Timer timer = new System.Timer(m_dispatcher);
                timer.sleep(std::chrono.seconds(m_pollingInterval));
            });

            m_sleepingContext.wait();

            if (lastBlockHash != requestLastBlockHash())
            {
                m_logger.functorMethod(Logging.Level.DEBUGGING) << "Blockchain has been updated";
                break;
            }
        }

        if (m_stopped)
        {
            m_logger.functorMethod(Logging.Level.DEBUGGING) << "Blockchain monitor has been stopped";
            throw System.InterruptedException();
        }
    }
    private Crypto.Hash requestLastBlockHash()
    {
        m_logger.functorMethod(Logging.Level.DEBUGGING) << "Requesting last block hash";

        try
        {
            CryptoNote.HttpClient client = new CryptoNote.HttpClient(m_dispatcher, m_daemonHost, new ushort(m_daemonPort));

            CryptoNote.COMMAND_RPC_GET_LAST_BLOCK_HEADER.request  request  = new CryptoNote.COMMAND_RPC_GET_LAST_BLOCK_HEADER.request();
            CryptoNote.COMMAND_RPC_GET_LAST_BLOCK_HEADER.response response = new CryptoNote.COMMAND_RPC_GET_LAST_BLOCK_HEADER.response();

            System.EventLock lk = new System.EventLock(m_httpEvent);
            CryptoNote.JsonRpc.invokeJsonRpcCommand(client, "getlastblockheader", request, response);

            if (response.status != DefineConstants.CORE_RPC_STATUS_OK)
            {
                throw new System.Exception("Core responded with wrong status: " + response.status);
            }

            Crypto.Hash blockHash = new Crypto.Hash();
            if (!Common.GlobalMembers.podFromHex(response.block_header.hash, blockHash))
            {
                throw new System.Exception("Couldn't parse block hash: " + response.block_header.hash);
            }

            m_logger.functorMethod(Logging.Level.DEBUGGING) << "Last block hash: " << Common.GlobalMembers.podToHex(blockHash);

            return(blockHash);
        }
        catch (System.Exception e)
        {
            m_logger.functorMethod(Logging.Level.ERROR) << "Failed to request last block hash: " << e.Message;
            throw;
        }
    }
Exemple #4
0
 public BlockchainWriteBatch removeCachedBlock(Crypto.Hash blockHash, uint blockIndex)
 {
     rawKeysToRemove.emplace_back(DB.GlobalMembers.serializeKey(DB.GlobalMembers.BLOCK_INDEX_TO_BLOCK_INFO_PREFIX, blockIndex));
     rawKeysToRemove.emplace_back(DB.GlobalMembers.serializeKey(DB.GlobalMembers.BLOCK_INDEX_TO_TX_HASHES_PREFIX, blockIndex));
     rawKeysToRemove.emplace_back(DB.GlobalMembers.serializeKey(DB.GlobalMembers.BLOCK_HASH_TO_BLOCK_INDEX_PREFIX, blockHash));
     rawDataToInsert.emplace_back(DB.GlobalMembers.serialize(DB.GlobalMembers.BLOCK_INDEX_TO_BLOCK_HASH_PREFIX, DB.GlobalMembers.LAST_BLOCK_INDEX_KEY, blockIndex - 1));
     return(this);
 }
        //---------------------------------------------------------------------------
        public bool addCheckpoint(uint index, string hash_str)
        {
            Crypto.Hash h = GlobalMembers.NULL_HASH;

            if (!Common.GlobalMembers.podFromHex(hash_str, h))
            {
                logger(ERROR, BRIGHT_RED) << "INVALID HASH IN CHECKPOINTS!";
                return(false);
            }

            /* The return value lets us check if it was inserted or not. If it wasn't,
             * there is already a key (i.e., a height value) existing */
            if (!points.insert({ index, h }).second)
Exemple #6
0
        public void addBlocks(Crypto.Hash blockHashes, uint height, uint count)
        {
            Debug.Assert(blockHashes);
            var size = m_blockchain.Count;

            if (size)
            {
            }
            // Dummy fix for simplewallet or walletd when sync
            if (height == 0)
            {
                height = 1;
            }
            Debug.Assert(size == height);
//C++ TO C# CONVERTER TODO TASK: There is no direct equivalent to the STL vector 'insert' method in C#:
            m_blockchain.insert(m_blockchain.end(), blockHashes, blockHashes + count);
        }
Exemple #7
0
        private void workerFunc(BlockTemplate blockTemplate, ulong difficulty, uint nonceStep)
        {
            try
            {
//C++ TO C# CONVERTER TODO TASK: The following line was determined to contain a copy constructor call - this should be verified and a copy constructor should be created:
//ORIGINAL LINE: BlockTemplate block = blockTemplate;
                BlockTemplate block = new BlockTemplate(blockTemplate);

                while (m_state == MiningState.MINING_IN_PROGRESS)
                {
                    CachedBlock cachedBlock = new CachedBlock(block);
                    Crypto.Hash hash        = cachedBlock.getBlockLongHash();
                    if (check_hash(hash, difficulty))
                    {
                        m_logger.functorMethod(Logging.Level.INFO) << "Found block for difficulty " << difficulty;

                        if (!setStateBlockFound())
                        {
                            m_logger.functorMethod(Logging.Level.DEBUGGING) << "block is already found or mining stopped";
                            return;
                        }

//C++ TO C# CONVERTER TODO TASK: The following line was determined to be a copy assignment (rather than a reference assignment) - this should be verified and a 'CopyFrom' method should be created:
//ORIGINAL LINE: m_block = block;
                        m_block.CopyFrom(block);
                        return;
                    }

                    incrementHashCount();
                    block.nonce += nonceStep;
                }
            }
            catch (System.Exception e)
            {
                m_logger.functorMethod(Logging.Level.ERROR) << "Miner got error: " << e.Message;
                m_state = MiningState.MINING_STOPPED;
            }
        }
Exemple #8
0
 public abstract bool HasTransaction(Crypto.Hash transactionHash);
Exemple #9
0
 public abstract bool GetTransactionGlobalIndexes(Crypto.Hash transactionHash, List <uint> globalIndexes);
Exemple #10
0
 public abstract bool HasBlock(Crypto.Hash blockHash);
Exemple #11
0
 public abstract BlockTemplate GetBlockByHash(Crypto.Hash blockHash);
Exemple #12
0
 // Extra
 public abstract bool GetPaymentId(Crypto.Hash paymentId);
Exemple #13
0
//C++ TO C# CONVERTER WARNING: 'const' methods are not available in C#:
//ORIGINAL LINE: virtual const CachedTransaction& getTransaction(const Crypto::Hash& hash) const override
        public override CachedTransaction getTransaction(Crypto.Hash hash)
        {
            return(transactionPool.getTransaction(hash));
        }
Exemple #14
0
//C++ TO C# CONVERTER TODO TASK: 'rvalue references' have no equivalent in C#:
        public abstract void getPoolSymmetricDifference(List <Crypto.Hash> && knownPoolTxIds, Crypto.Hash knownBlockId, ref bool isBcActual, List <std::unique_ptr <ITransactionReader> > newTxs, List <Crypto.Hash> deletedTxIds, Callback callback);
Exemple #15
0
 public abstract BlockDetails GetBlockDetails(Crypto.Hash blockHash);
Exemple #16
0
 public abstract void getTransactionHashesByPaymentId(Crypto.Hash paymentId, List <Crypto.Hash> transactionHashes, Callback callback);
Exemple #17
0
 public abstract void getTransactionOutsGlobalIndices(Crypto.Hash transactionHash, List <uint> outsGlobalIndices, Callback callback);
Exemple #18
0
 public SynchronizationState(Crypto.Hash genesisBlockHash)
 {
     m_blockchain.Add(genesisBlockHash);
 }
Exemple #19
0
 public override bool removeTransaction(Crypto.Hash hash)
 {
     return(transactionPool.removeTransaction(hash));
 }
Exemple #20
0
 // Extra
 public abstract void SetPaymentId(Crypto.Hash paymentId);
Exemple #21
0
 public abstract bool GetPoolChanges(Crypto.Hash lastBlockHash, List <Crypto.Hash> knownHashes, List <BinaryArray> addedTransactions, List <Crypto.Hash> deletedTransactions);
Exemple #22
0
 public abstract List <Crypto.Hash> GetTransactionHashesByPaymentId(Crypto.Hash paymentId);
Exemple #23
0
 public abstract bool GetPoolChangesLite(Crypto.Hash lastBlockHash, List <Crypto.Hash> knownHashes, List <TransactionPrefixInfo> addedTransactions, List <Crypto.Hash> deletedTransactions);
Exemple #24
0
//C++ TO C# CONVERTER WARNING: 'const' methods are not available in C#:
//ORIGINAL LINE: virtual ulong getTransactionReceiveTime(const Crypto::Hash& hash) const override
        public override ulong getTransactionReceiveTime(Crypto.Hash hash)
        {
            return(transactionPool.getTransactionReceiveTime(hash));
        }
Exemple #25
0
 public abstract TransactionDetails GetTransactionDetails(Crypto.Hash transactionHash);
Exemple #26
0
//C++ TO C# CONVERTER WARNING: 'const' methods are not available in C#:
//ORIGINAL LINE: virtual bool checkIfTransactionPresent(const Crypto::Hash& hash) const override
        public override bool checkIfTransactionPresent(Crypto.Hash hash)
        {
            return(transactionPool.checkIfTransactionPresent(hash));
        }
Exemple #27
0
//C++ TO C# CONVERTER WARNING: 'const' methods are not available in C#:
//ORIGINAL LINE: virtual ClassicVector<TransactionsInBlockInfo> getTransactions(const Crypto::Hash& blockHash, uint count) const = 0;
        public abstract List <TransactionsInBlockInfo> getTransactions(Crypto.Hash blockHash, uint count);
//C++ TO C# CONVERTER TODO TASK: C# has no equivalent to ' = delete':
//  PaymentServiceJsonRpcServer(const PaymentServiceJsonRpcServer&) = delete;

        protected override void processJsonRpcRequest(Common.JsonValue req, Common.JsonValue resp)
        {
            try
            {
                prepareJsonResponse(req.functorMethod, resp.functorMethod);

                if (!config.serviceConfig.legacySecurity)
                {
                    string clientPassword;
                    if (!req.contains("password"))
                    {
                        makeInvalidPasswordResponse(resp.functorMethod);
                        return;
                    }
                    if (!req.functorMethod("password").isString())
                    {
                        makeInvalidPasswordResponse(resp.functorMethod);
                        return;
                    }
                    clientPassword = req.functorMethod("password").getString();

                    List <byte> rawData        = new List <byte>(clientPassword.GetEnumerator(), clientPassword.end());
                    Crypto.Hash hashedPassword = new Crypto.Hash();
                    Crypto.GlobalMembers.cn_slow_hash_v0(rawData.data(), rawData.Count, hashedPassword);
                    if (hashedPassword != config.rpcSecret)
                    {
                        makeInvalidPasswordResponse(resp.functorMethod);
                        return;
                    }
                }

                if (!req.contains("method"))
                {
                    logger.functorMethod(Logging.Level.WARNING) << "Field \"method\" is not found in json request: " << req.functorMethod;
                    makeGenericErrorReponse(resp.functorMethod, "Invalid Request", -3600);
                    return;
                }

                if (!req.functorMethod("method").isString())
                {
                    logger.functorMethod(Logging.Level.WARNING) << "Field \"method\" is not a string type: " << req.functorMethod;
                    makeGenericErrorReponse(resp.functorMethod, "Invalid Request", -3600);
                    return;
                }

                string method = req.functorMethod("method").getString();

                var it = handlers.find(method);
                if (it == handlers.end())
                {
                    logger.functorMethod(Logging.Level.WARNING) << "Requested method not found: " << method;
                    makeMethodNotFoundResponse(resp.functorMethod);
                    return;
                }

                logger.functorMethod(Logging.Level.DEBUGGING) << method << " request came";

                Common.JsonValue @params = new Common.JsonValue(Common.JsonValue.OBJECT);
                if (req.contains("params"))
                {
                    @params = req.functorMethod("params");
                }

//C++ TO C# CONVERTER TODO TASK: Iterators are only converted within the context of 'while' and 'for' loops:
                it.second(@params.functorMethod, resp.functorMethod);
            }
            catch (System.Exception e)
            {
                logger.functorMethod(Logging.Level.WARNING) << "Error occurred while processing JsonRpc request: " << e.Message;
                makeGenericErrorReponse(resp.functorMethod, e.Message);
            }
        }
Exemple #29
0
//C++ TO C# CONVERTER WARNING: 'const' methods are not available in C#:
//ORIGINAL LINE: virtual WalletTransactionWithTransfers getTransaction(const Crypto::Hash& transactionHash) const = 0;
        public abstract WalletTransactionWithTransfers getTransaction(Crypto.Hash transactionHash);
Exemple #30
0
//C++ TO C# CONVERTER WARNING: 'const' methods are not available in C#:
//ORIGINAL LINE: virtual ClassicVector<Crypto::Hash> getTransactionHashesByPaymentId(const Crypto::Hash& paymentId) const override
        public override List <Crypto.Hash> getTransactionHashesByPaymentId(Crypto.Hash paymentId)
        {
            return(transactionPool.getTransactionHashesByPaymentId(paymentId));
        }