コード例 #1
0
        public async Task <ProtocolTransactionResponse> CreateTransaction(List <Common.RandomModels.SignedItem> items, ChaosProtocolSettings settings)
        {
            try
            {
                var rs = await api.ApiTransactionCommitPostWithHttpMessagesAsync(new ProtocolTransaction()
                {
                    Type           = "AggregatedCommit",
                    RandomSettings = settings.RandomSettings,
                    Items          = items.Select(x => new Sp8de.Protocol.Client.Models.SignedItem()
                    {
                        Type   = x.Type.ToString(),
                        Nonce  = x.Nonce,
                        PubKey = x.PubKey,
                        Sign   = x.Sign,
                    }).ToList()
                }, AuthHeaders);

                var result = (rs.Body as Sp8deTransaction);

                if (result != null)
                {
                    return(new ProtocolTransactionResponse()
                    {
                        Id = result.Id,
                        Items = result.InternalTransactions.Select(x => new Common.RandomModels.SignedItem()
                        {
                            Type = MapType(x.Type),
                            Nonce = x.Nonce,
                            PubKey = x.FromProperty,
                            Sign = x.Sign,
                        }).ToList()
                    });
                }
            }
            catch (Exception e)
            {
                throw;
            }


            return(null);
        }
コード例 #2
0
ファイル: DemoProtocolService.cs プロジェクト: SP8DE/protocol
        public async Task <ProtocolTransactionResponse> CreateTransaction(List <SignedItem> items, ChaosProtocolSettings settings)
        {
            var id = TxIdHelper.GenerateId();

            var revealItem = new RevealItem()
            {
                Type   = UserType.Validator,
                Seed   = random.NextLong().ToString(),
                Nonce  = DateTime.UtcNow.Ticks.ToString(),
                PubKey = keySecret.PublicAddress.ToLowerInvariant()
            };

            revealItem.Sign = cryptoService.SignMessage(revealItem.ToString(), keySecret.PrivateKey);

            await storage.Add(revealItem.Sign, revealItem);

            var commitItem = revealItem.ToCommitItem();

            items.Add(new SignedItem()
            {
                Type   = commitItem.Type,
                Nonce  = commitItem.Nonce,
                PubKey = commitItem.PubKey,
                Sign   = commitItem.Sign,
            });

            var tx = new ProtocolTransactionResponse()
            {
                Id     = id,
                Signer = keySecret.PublicAddress.ToLowerInvariant(),
                Items  = items
            };

            await AddAnchors(tx);

            await storage.Add(id, tx);

            return(tx);
        }