Пример #1
0
 public void SetOperationResult(FakeOperationResult operationResult)
 {
     _operationResult = operationResult;
     Header           = new OperationHeader
     {
         Status = operationResult.Status,
         Cas    = operationResult.Cas
     };
 }
Пример #2
0
 public FakeOperation(OpCode operationCode, ResponseStatus status) : base()
 {
     Key            = "hi";
     _operationCode = operationCode;
     Header         = new OperationHeader
     {
         Status = status,
         OpCode = _operationCode
     };
 }
Пример #3
0
 public FakeOperation(OperationCode operationCode, ResponseStatus status, ErrorCode errorCode = null)
     : base("hello", null, new DefaultTranscoder(), 0)
 {
     _operationCode = operationCode;
     Header         = new OperationHeader
     {
         Status        = status,
         OperationCode = _operationCode
     };
     ErrorCode = errorCode;
 }
 /// <summary>
 /// Sets all values back to their defaults, so this object can be reused.
 /// </summary>
 public void Reset()
 {
     if (Data != null)
     {
         Data.Dispose();
     }
     Buffer        = new byte[512];
     Data          = new MemoryStream();
     BytesReceived = 0;
     Header        = new OperationHeader();
     Body          = new OperationBody();
 }
Пример #5
0
        private IEnumerable <IBlockchainTransaction> TxsFromOperation(
            OperationHeader <OperationType <Operation> > operationHeader)
        {
            var txs = new List <IBlockchainTransaction>();

            var internalCounters = new Dictionary <string, int>();

            foreach (var operation in operationHeader.Type.Operations)
            {
                try
                {
                    if (operation.Kind != OperationType.Transaction)
                    {
                        Log.Debug("Skip {@kind} operation", operation.Kind);
                        continue;
                    }

                    var internalIndex = 0;

                    if (operation.Internal)
                    {
                        if (internalCounters.TryGetValue(operationHeader.Hash, out var index))
                        {
                            internalIndex = ++index;
                            internalCounters[operationHeader.Hash] = internalIndex;
                        }
                        else
                        {
                            internalCounters.Add(operationHeader.Hash, internalIndex);
                        }
                    }

                    txs.Add(new TezosTransaction(_currency)
                    {
                        Id           = operationHeader.Hash,
                        From         = operation.Source.Tz,
                        To           = operation.Destination.Tz,
                        Amount       = decimal.Parse(operation.Amount),
                        Fee          = operation.Fee,
                        GasLimit     = decimal.Parse(operation.GasLimit),
                        StorageLimit = decimal.Parse(operation.StorageLimit),
                        Burn         = operation.Burn,
                        Params       = operation.Parameters != null
                            ? JObject.Parse(operation.Parameters)
                            : null,
                        Type          = TezosTransaction.UnknownTransaction,
                        IsInternal    = operation.Internal,
                        InternalIndex = internalIndex,

                        BlockInfo = new BlockInfo
                        {
                            Fees          = operation.Fee,
                            FirstSeen     = operation.TimeStamp,
                            BlockTime     = operation.TimeStamp,
                            BlockHeight   = operation.OpLevel,
                            Confirmations = operation.Failed ? 0 : 1
                        }
                    });
                }
                catch (Exception e)
                {
                    Log.Error(e, "Operation parse error");
                }
            }

            return(txs);
        }