コード例 #1
0
ファイル: OrderManager.cs プロジェクト: aosrul/AbacasX
        private string HashOrder(BlockChainData blockRecord)
        {
            var jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(blockRecord);

            var resultHash = ComputeHashCode(Encoding.UTF8.GetBytes(jsonString));

            return(Convert.ToBase64String(resultHash));
        }
コード例 #2
0
        protected async Task <BlockChainResponse> StratisMineBlock(string stratisMineUrl, StratisBlockData blockData)
        {
            var            jsonMediaTypeFormatter = new JsonMediaTypeFormatter();
            BlockChainData request = new BlockChainData {
                blockCount = blockData.blockCount, description = blockData
            };

            var httpResponse = await HttpClient.PostAsJsonAsync <BlockChainData>(stratisMineUrl, request);

            return(JsonConvert.DeserializeObject <BlockChainResponse>(httpResponse.Content.ReadAsStringAsync().Result));
        }
コード例 #3
0
ファイル: OrderManager.cs プロジェクト: aosrul/AbacasX
        private void addTransferToBlockChain(AssetTransferData transferRequest)
        {
            BlockChainData blockChainRecord = new BlockChainData();
            KeyPairData    KeyPair          = new KeyPairData();

            lock (BlockChainTransactionsLock)
            {
                blockChainRecord = new BlockChainData();

                blockChainRecord.Date        = DateTime.Now.ToShortDateString();
                blockChainRecord.BlockNumber = blockCount++;
                blockChainRecord.OrderId     = orderCount++;
                blockChainRecord.clientId    = transferRequest.clientId;

                if (transferRequest.transferType == TransferTypeEnum.Deposit)
                {
                    blockChainRecord.PayReceive  = "Receive";
                    blockChainRecord.TokenAmount = transferRequest.tokenAmount;
                    blockChainRecord.TokenId     = transferRequest.tokenId;
                }
                else
                {
                    blockChainRecord.PayReceive  = "Pay";
                    blockChainRecord.TokenAmount = transferRequest.tokenAmount;
                    blockChainRecord.TokenId     = transferRequest.tokenId;
                }

                if (KeyPairs.TryGetValue(1, out KeyPair) == true)
                {
                    blockChainRecord.Address = KeyPair.publicKey;
                }

                blockChainRecord.TransactionHash = HashOrder(blockChainRecord);
                BlockChainTransactions.TryAdd(blockChainRecord.BlockNumber, blockChainRecord);
            }
        }
コード例 #4
0
ファイル: OrderManager.cs プロジェクト: aosrul/AbacasX
        private void UpdateBlockChain(OrderLeg orderLegRecord, OrderFilledData orderFilledData)
        {
            BlockChainData blockChainRecord = new BlockChainData();
            KeyPairData    KeyPair          = new KeyPairData();

            //Console.WriteLine("Writing Order Flows to blockchain");

            lock (BlockChainTransactionsLock)
            {
                if (orderLegRecord.BuySellType == OrderLegBuySellEnum.Buy)
                {
                    blockChainRecord = new BlockChainData();

                    blockChainRecord.clientId = orderLegRecord.Order.ClientId;

                    blockChainRecord.Date        = orderFilledData.FilledDateTime.ToShortDateString();
                    blockChainRecord.BlockNumber = blockCount++;
                    blockChainRecord.OrderId     = orderLegRecord.OrderId;
                    blockChainRecord.PayReceive  = "Receive";
                    blockChainRecord.TokenAmount = orderFilledData.Token1Amount;
                    blockChainRecord.TokenId     = orderFilledData.Token1Id;

                    if (KeyPairs.TryGetValue(1, out KeyPair) == true)
                    {
                        blockChainRecord.Address = KeyPair.publicKey;
                    }
                    else
                    {
                        //blockChainRecord.Address = GenerateNewClientKey(orderLegRecord.Order.ClientId);
                    }

                    blockChainRecord.TransactionHash = HashOrder(blockChainRecord);
                    BlockChainTransactions.TryAdd(blockChainRecord.BlockNumber, blockChainRecord);


                    blockChainRecord             = new BlockChainData();
                    blockChainRecord.clientId    = orderLegRecord.Order.ClientId;
                    blockChainRecord.Date        = DateTime.Now.ToShortDateString();
                    blockChainRecord.BlockNumber = blockCount++;
                    blockChainRecord.OrderId     = orderFilledData.OrderLegId;
                    blockChainRecord.PayReceive  = "Pay";
                    blockChainRecord.TokenAmount = orderFilledData.Token2Amount;
                    blockChainRecord.TokenId     = orderFilledData.Token2Id;

                    if (KeyPairs.TryGetValue(0, out KeyPair) == true)
                    {
                        blockChainRecord.Address = KeyPair.publicKey;
                    }
                    else
                    {
                        //blockChainRecord.Address = GenerateNewClientKey(orderLegRecord.Order.ClientId);
                    }

                    blockChainRecord.TransactionHash = HashOrder(blockChainRecord);
                    BlockChainTransactions.TryAdd(blockChainRecord.BlockNumber, blockChainRecord);
                }
                else
                {
                    blockChainRecord      = new BlockChainData();
                    blockChainRecord.Date = DateTime.Now.ToShortDateString();

                    blockChainRecord.clientId    = orderLegRecord.Order.ClientId;
                    blockChainRecord.BlockNumber = blockCount++;
                    blockChainRecord.OrderId     = orderLegRecord.OrderId;
                    blockChainRecord.PayReceive  = "Pay";
                    blockChainRecord.TokenAmount = orderFilledData.Token1Amount;
                    blockChainRecord.TokenId     = orderFilledData.Token1Id;

                    if (KeyPairs.TryGetValue(0, out KeyPair) == true)
                    {
                        blockChainRecord.Address = KeyPair.publicKey;
                    }
                    else
                    {
                    }

                    blockChainRecord.TransactionHash = HashOrder(blockChainRecord);
                    BlockChainTransactions.TryAdd(blockChainRecord.BlockNumber, blockChainRecord);

                    blockChainRecord      = new BlockChainData();
                    blockChainRecord.Date = DateTime.Now.ToShortDateString();

                    blockChainRecord.clientId    = orderLegRecord.Order.ClientId;
                    blockChainRecord.BlockNumber = blockCount++;
                    blockChainRecord.OrderId     = orderLegRecord.OrderId;
                    blockChainRecord.PayReceive  = "Receive";
                    blockChainRecord.TokenAmount = orderFilledData.Token2Amount;
                    blockChainRecord.TokenId     = orderFilledData.Token2Id;
                    if (KeyPairs.TryGetValue(1, out KeyPair) == true)
                    {
                        blockChainRecord.Address = KeyPair.publicKey;
                    }
                    else
                    {
                    }

                    blockChainRecord.TransactionHash = HashOrder(blockChainRecord);
                    BlockChainTransactions.TryAdd(blockChainRecord.BlockNumber, blockChainRecord);
                }
            }
        }