示例#1
0
        public void ScheduleGenericContainerJob <T, U>(T container, U value)
            where T : struct, INativeList <U>
            where U : struct
        {
            var j0     = new GenericContainerResizeJob <T, U>();
            var length = 5;

            j0.m_ListLength  = length;
            j0.m_GenericList = container;
            var handle0 = j0.Schedule();

            var j1 = new GenericContainerJobDefer <T, U>();

            j1.m_Value       = value;
            j1.m_GenericList = j0.m_GenericList;
            INativeList <U> iList = j0.m_GenericList;

            j1.Schedule((NativeList <U>)iList, 1, handle0).Complete();

            Assert.AreEqual(length, j1.m_GenericList.Length);
            for (int i = 0; i != j1.m_GenericList.Length; i++)
            {
                Assert.AreEqual(value, j1.m_GenericList[i]);
            }
        }
        private async Task GetTransactionPositionsBySingleAddress(string paymentAddress, SortedSet <Tuple <Int64, string> > txPositions, Stopwatch stopWatch)
        {
            Utils.CheckIfChainIsFresh(chain_, config_.AcceptStaleRequests);

            using (var address = new PaymentAddress(paymentAddress))
            {
                //Unconfirmed first
                GetUnconfirmedTransactionPositions(address, txPositions);
                //3
                statsGetTransactions.Add(stopWatch.ElapsedMilliseconds);

                using (var getTransactionResult = await chain_.FetchConfirmedTransactionsAsync(address, UInt64.MaxValue, 0))
                {
                    Utils.CheckBitprimApiErrorCode(getTransactionResult.ErrorCode, "FetchConfirmedTransactionsAsync(" + paymentAddress + ") failed, check error log.");

                    //4
                    statsGetTransactions.Add(stopWatch.ElapsedMilliseconds);

                    INativeList <byte[]> confirmedTxIds = getTransactionResult.Result;

                    //Confirmed
                    foreach (byte[] txHash in confirmedTxIds)
                    {
                        ApiCallResult <GetTxPositionResult> getTxPosResult = await chain_.FetchTransactionPositionAsync(txHash, true);

                        string txHashStr = Binary.ByteArrayToHexString(txHash);
                        Utils.CheckBitprimApiErrorCode(getTxPosResult.ErrorCode, "FetchTransactionPositionAsync(" + txHashStr + ") failed, check error log");
                        txPositions.Add(new Tuple <Int64, string>((Int64)getTxPosResult.Result.BlockHeight, txHashStr));
                    }

                    //5
                    statsGetTransactions.Add(stopWatch.ElapsedMilliseconds);
                }
            }
        }
        private static string[] BlockTxsToJSON(INativeList <byte[]> txHashes)
        {
            var txs = new List <string>();

            for (uint i = 0; i < txHashes.Count; i++)
            {
                txs.Add(Binary.ByteArrayToHexString(txHashes[i]));
            }
            return(txs.ToArray());
        }
        public static int[] ToArray(this INativeList <int> nativeList)
        {
            var array = new int[nativeList.Length];

            for (var i = 0; i < nativeList.Length; i++)
            {
                array[i] = nativeList[i];
            }
            return(array);
        }
示例#5
0
        public INativeList <ITransaction> GetMempoolTransactions(INativeList <PaymentAddress> addresses, bool useTestnetRules)
        {
            IntPtr txs = ChainNative.chain_get_mempool_transactions_from_wallets
                         (
                nativeInstance_,
                addresses.NativeInstance,
                useTestnetRules? 1 : 0
                         );

            return(new TransactionList(txs));
        }
示例#6
0
        internal static FixedString128 MessageObjectToString(object message)
        {
            FixedString128 result = default;

            if (message == null)
            {
                result.Append("(null)");
            }
            else if (message is string stringMessage)
            {
                result.Append(stringMessage);
            }
            else if (message is byte byteMessage)
            {
                result.Append(byteMessage);
            }
            else if (message is int intMessage)
            {
                result.Append(intMessage);
            }
            else if (message is short shortMessage)
            {
                result.Append(shortMessage);
            }
            else if (message is float floatMessage)
            {
                result.Append(floatMessage);
            }
            else if (message is double doubleMessage)
            {
                // TODO need double formatting
                result.Append((float)doubleMessage);
            }
            else if (message is bool boolMessage)
            {
                result.Append(boolMessage ? "true" : "false");
            }
            else if (message is char charMessage)
            {
                result.Append(charMessage);
            }
            else if (message is float2 f2Message)
            {
                result.Append("(");
                result.Append(f2Message.x);
                result.Append(", ");
                result.Append(f2Message.y);
                result.Append(")");
            }
            else if (message is float3 f3Message)
            {
                result.Append("(");
                result.Append(f3Message.x);
                result.Append(", ");
                result.Append(f3Message.y);
                result.Append(", ");
                result.Append(f3Message.z);
                result.Append(")");
            }
            else if (message is float4 f4Message)
            {
                result.Append("(");
                result.Append(f4Message.x);
                result.Append(", ");
                result.Append(f4Message.y);
                result.Append(", ");
                result.Append(f4Message.z);
                result.Append(", ");
                result.Append(f4Message.w);
                result.Append(")");
            }
            else if (message is Exception exc)
            {
                result.Append(exc.Message);
                result.Append("\n");
                result.Append(exc.StackTrace);
            }
            else if (message is IUTF8Bytes utf8BytesMessage)
            {
                INativeList <byte> nlb = (INativeList <byte>)utf8BytesMessage;
                unsafe
                {
                    result.Append(utf8BytesMessage.GetUnsafePtr(), nlb.Length);
                }
            }
            else
            {
                result.Append("[type not supported]");
            }

            return(result);
        }
        private static GetBlockByHashResponse BlockToJSON(IHeader blockHeader, UInt64 blockHeight, INativeList <byte[]> txHashes,
                                                          decimal blockReward, UInt64 currentHeight, byte[] nextBlockHash,
                                                          UInt64 serializedBlockSize, PoolInfo poolInfo, bool includeTransactionIds)
        {
            BigInteger.TryParse(blockHeader.ProofString, out var proof);
            var blockJson = new GetBlockByHashResponse
            {
                hash    = Binary.ByteArrayToHexString(blockHeader.Hash),
                size    = serializedBlockSize,
                height  = blockHeight,
                version = blockHeader.Version,
                // We reverse this field to match the way bitpay-insight displays it
                merkleroot        = Binary.ByteArrayToHexString(blockHeader.Merkle, reverse: true),
                tx                = includeTransactionIds ? BlockTxsToJSON(txHashes) : new string[0],
                txCount           = txHashes.Count,
                time              = blockHeader.Timestamp,
                nonce             = blockHeader.Nonce,
                bits              = blockHeader.Bits,
                difficulty        = Utils.BitsToDifficulty(blockHeader.Bits),
                chainwork         = (proof * 2).ToString("X64"),
                confirmations     = currentHeight - blockHeight + 1,
                previousblockhash = Binary.ByteArrayToHexString(blockHeader.PreviousBlockHash)
            };

            //TODO Use bitprim API when implemented
            //TODO Does not match Blockdozer value; check how bitpay calculates it
            if (nextBlockHash != null)
            {
                blockJson.nextblockhash = Binary.ByteArrayToHexString(nextBlockHash);
            }
            blockJson.reward      = blockReward;
            blockJson.isMainChain = true; //TODO Check value
            blockJson.poolInfo    = new DTOs.PoolInfo {
                poolName = poolInfo.Name, url = poolInfo.Url
            };
            return(blockJson);
        }