Esempio n. 1
0
        public async Task <TupleValue <uint, Agenda[]> > AgendasAsync()
        {
            var client   = new AgendaService.AgendaServiceClient(_channel);
            var request  = new AgendasRequest();
            var response = await client.AgendasAsync(request, cancellationToken : _tokenSource.Token);

            var agendas = response.Agendas.Select(a => new Agenda
            {
                ID          = a.Id,
                Description = a.Description,
                Choices     = a.Choices.Select(c => new Agenda.Choice
                {
                    ID          = c.Id,
                    Description = c.Description,
                    Bits        = (ushort)c.Bits,
                    IsAbstain   = c.IsAbstain,
                    IsNo        = c.IsNo,
                }).ToArray(),
                Mask       = (ushort)a.Mask,
                StartTime  = DateTimeOffsetExtras.FromUnixTimeSeconds(a.StartTime),
                ExpireTime = DateTimeOffsetExtras.FromUnixTimeSeconds(a.ExpireTime),
            }).ToArray();

            return(TupleValue.Create(response.Version, agendas));
        }
Esempio n. 2
0
        public static UnspentOutput MarshalUnspentOutput(FundTransactionResponse.Types.PreviousOutput o)
        {
            var txHash         = new Sha256Hash(o.TransactionHash.ToByteArray());
            var outputIndex    = o.OutputIndex;
            var amount         = (Amount)o.Amount;
            var pkScript       = OutputScript.ParseScript(o.PkScript.ToByteArray());
            var seenTime       = DateTimeOffsetExtras.FromUnixTimeSeconds(o.ReceiveTime);
            var isFromCoinbase = o.FromCoinbase;

            return(new UnspentOutput(txHash, outputIndex, amount, pkScript, seenTime, isFromCoinbase));
        }
Esempio n. 3
0
        public Block(Sha256Hash hash, int height, long unixTime, List <WalletTransaction> transactions)
        {
            if (hash == null)
            {
                throw new ArgumentNullException(nameof(hash));
            }
            if (transactions == null)
            {
                throw new ArgumentNullException(nameof(transactions));
            }

            Identity     = new BlockIdentity(hash, height);
            Timestamp    = DateTimeOffsetExtras.FromUnixTimeSeconds(unixTime);
            Transactions = transactions;
        }
Esempio n. 4
0
        public static WalletTransaction MarshalWalletTransaction(TransactionDetails tx)
        {
            var transaction = Transaction.Deserialize(tx.Transaction.ToByteArray());
            var hash        = new Sha256Hash(tx.Hash.ToByteArray());
            var inputs      = tx.Debits
                              .Select(i => new WalletTransaction.Input(i.PreviousAmount, new Account(i.PreviousAccount)))
                              .ToArray();
            // There are two kinds of transactions to care about when choosing which outputs
            // should be created: transactions created by other wallets (inputs.Length == 0)
            // and those that spend controlled outputs from this wallet (inputs.Length != 0).
            // If the transaction was created by this wallet, then all outputs (both controlled
            // and uncontrolled) should be included.  Otherwise, uncontrolled outputs can be
            // ignored since they are not relevant (they could be change outputs for the other
            // wallet or outputs created for another unrelated wallet).
            var outputs = inputs.Length == 0
                ? tx.Credits.Select((o, i) => MarshalControlledOutput(o, transaction.Outputs[i])).ToArray()
                : MarshalCombinedOutputs(transaction, tx.Credits.GetEnumerator());
            var fee      = inputs.Length == transaction.Inputs.Length ? (Amount?)tx.Fee : null;
            var seenTime = DateTimeOffsetExtras.FromUnixTimeSeconds(tx.Timestamp);

            return(new WalletTransaction(transaction, hash, inputs, outputs, fee, seenTime));
        }