private static async Task Download(
            ITransferClient client,
            AutoDeleteDirectory directory,
            TransferContext context,
            IList <TransferPath> localSourcePaths,
            string uploadTargetPath,
            SampleRunner sampleRunner,
            CancellationToken token)
        {
            // Create a job-based download transfer request.
            Console2.WriteStartHeader("Transfer - Download");
            string          downloadTargetPath = directory.Path;
            TransferRequest downloadJobRequest = TransferRequest.ForDownloadJob(downloadTargetPath, context);

            downloadJobRequest.Application = "Github Sample";
            downloadJobRequest.Name        = "Download Sample";
            Console2.WriteLine("Download started.");

            // Create a transfer job to download the sample dataset to the target local path.
            using (ITransferJob job = await client.CreateJobAsync(downloadJobRequest, token).ConfigureAwait(false))
            {
                IEnumerable <TransferPath> remotePaths = localSourcePaths.Select(
                    localPath => new TransferPath
                {
                    SourcePath     = uploadTargetPath + "\\" + Path.GetFileName(localPath.SourcePath),
                    PathAttributes = TransferPathAttributes.File,
                    TargetPath     = downloadTargetPath
                });

                await job.AddPathsAsync(remotePaths, token).ConfigureAwait(false);

                await sampleRunner.ChangeDataRateAsync(job, token).ConfigureAwait(false);

                // Await completion of the job.
                ITransferResult result = await job.CompleteAsync(token).ConfigureAwait(false);

                Console2.WriteLine("Download completed.");
                sampleRunner.DisplayTransferResult(result);
                Console2.WriteEndHeader();
            }
        }
Exemple #2
0
 // Used by each of the owners to request a withdrawal from the multisig to an external address
 public void Send(Address requestedAddress, ulong requestedAmount)
 {
     LogMessage("Send request from " + Message.Sender + " for amount " + requestedAmount + " to address " + requestedAddress);
     if (Message.Sender != Owner1 && Message.Sender != Owner2)
     {
         LogMessage("Rejecting non-owner request.");
         return;
     }
     Assert(Message.Sender == Owner1 || Message.Sender == Owner2);
     Assert(requestedAmount > 0);
     RequestedAmounts[Message.Sender.Value]   = requestedAmount;
     RequestedAddresses[Message.Sender.Value] = requestedAddress;
     if (RequestedAmounts[Owner1.Value] == RequestedAmounts[Owner2.Value] && RequestedAddresses[Owner1.Value] == RequestedAddresses[Owner2.Value])
     {
         LogMessage("Both owners agree.");
         LogMessage("Approved send request for amount " + requestedAmount + " to address " + requestedAddress);
         ITransferResult transferResult = TransferFunds(requestedAddress, requestedAmount);
         if (transferResult.Success)
         {
             LogMessage("Transfer Succesful");
             RequestedAmounts[Owner1.Value] = 0;
             RequestedAmounts[Owner2.Value] = 0;
         }
         else
         {
             LogMessage("Transfer failed. Reason: " + transferResult.ThrownException);
         }
     }
     else
     {
         LogMessage("Both owners do not yet agree. No transfer yet.");
         if (RequestedAmounts[Owner1.Value] > 0)
         {
             LogMessage("Owner1 wants to send " + RequestedAmounts[Owner1.Value] + " to " + RequestedAddresses[Owner1.Value]);
         }
         if (RequestedAmounts[Owner2.Value] > 0)
         {
             LogMessage("Owner2 wants to send " + RequestedAmounts[Owner2.Value] + " to " + RequestedAddresses[Owner2.Value]);
         }
     }
 }
        public void Transfer_StateTransition_Error()
        {
            ulong amount = 100UL;
            var   to     = new Address("Sj2p6ZRHdLvywyi43HYoE4bu2TF1nvavjR");

            var fixture = new InternalExecutorTestFixture();

            fixture.SetGasMeterLimitAbove((Gas)InternalExecutor.DefaultGasLimit);

            StateTransitionResult stateTransitionResult = StateTransitionResult.Fail((Gas)1000, new ContractErrorMessage("Error"));

            fixture.StateProcessor
            .Setup(sp => sp.Apply(It.IsAny <IState>(), It.IsAny <ContractTransferMessage>()))
            .Returns(stateTransitionResult);

            var internalExecutor = new InternalExecutor(
                fixture.LoggerFactory,
                fixture.Network,
                fixture.State.Object,
                fixture.StateProcessor.Object);

            ITransferResult result = internalExecutor.Transfer(fixture.SmartContractState, to, amount);

            fixture.State.Verify(s => s.Snapshot(), Times.Once);

            fixture.StateProcessor.Verify(sp =>
                                          sp.Apply(fixture.Snapshot, It.Is <ContractTransferMessage>(m =>
                                                                                                     m.Amount == amount &&
                                                                                                     m.GasLimit == InternalExecutor.DefaultGasLimit &&
                                                                                                     m.From == fixture.FromAddress &&
                                                                                                     m.To == to.ToUint160(fixture.Network)
                                                                                                     )));

            fixture.State.Verify(s => s.TransitionTo(fixture.Snapshot), Times.Never);

            fixture.GasMeter.Verify(g => g.Spend(stateTransitionResult.GasConsumed), Times.Once);

            Assert.False(result.Success);
            Assert.Null(result.ReturnValue);
        }
        public void Transfer_StateTransition_Error()
        {
            var fixture = new InternalExecutorTestFixture();

            ulong amount = 100UL;
            var   to     = "0x95D34980095380851902ccd9A1Fb4C813C2cb639".HexToAddress();

            fixture.SetGasMeterLimitAbove((Gas)InternalExecutor.DefaultGasLimit);

            StateTransitionResult stateTransitionResult = StateTransitionResult.Fail((Gas)1000, StateTransitionErrorKind.VmError);

            fixture.StateProcessor
            .Setup(sp => sp.Apply(It.IsAny <IState>(), It.IsAny <ContractTransferMessage>()))
            .Returns(stateTransitionResult);

            var internalExecutor = new InternalExecutor(
                fixture.LoggerFactory,
                fixture.State.Object,
                fixture.StateProcessor.Object);

            ITransferResult result = internalExecutor.Transfer(fixture.SmartContractState, to, amount);

            fixture.State.Verify(s => s.Snapshot(), Times.Once);

            fixture.StateProcessor.Verify(sp =>
                                          sp.Apply(fixture.Snapshot, It.Is <ContractTransferMessage>(m =>
                                                                                                     m.Amount == amount &&
                                                                                                     m.GasLimit == InternalExecutor.DefaultGasLimit &&
                                                                                                     m.From == fixture.FromAddress &&
                                                                                                     m.To == to.ToUint160()
                                                                                                     )));

            fixture.State.Verify(s => s.TransitionTo(fixture.Snapshot), Times.Never);

            fixture.GasMeter.Verify(g => g.Spend(stateTransitionResult.GasConsumed), Times.Once);

            Assert.False(result.Success);
            Assert.Null(result.ReturnValue);
        }
 public void DisplayTransferResult(ITransferResult result)
 {
     this._consolePrinter.DisplayTransferResult(result);
 }
    public bool CallOther(string addressString)
    {
        ITransferResult result = Call(new Address(addressString), 100, "IncrementCount");

        return(result.Success);
    }
Exemple #7
0
            private async Task UploadMultipleDocumentsAsync(IRelativityTransferHost relativityTransferHost, CancellationToken cancellationToken)
            {
                // Search for the first logical file share.
                const int           logicalFileShareNumber = 1;
                RelativityFileShare fileShare = await GetFileShareAsync(relativityTransferHost, logicalFileShareNumber, cancellationToken).ConfigureAwait(false);

                // Configure an Aspera specific transfer.
                AsperaClientConfiguration configuration = CreateAsperaClientConfiguration();

                // Assigning the file share bypasses auto-configuration that will normally use the default workspace repository.
                configuration.TargetFileShare = fileShare;
                using (ITransferClient client = await CreateClientAsync(relativityTransferHost, configuration, cancellationToken).ConfigureAwait(false))
                    using (AutoDeleteDirectory directory = new AutoDeleteDirectory())
                    {
                        // Create a job-based upload transfer request.
                        Console2.WriteTapiStartHeader("Advanced Transfer - Upload");
                        string uploadTargetPath = GetUniqueRemoteTargetPath(fileShare);
                        IList <TransferPath> localSourcePaths = await SearchLocalSourcePathsAsync(client, uploadTargetPath, cancellationToken).ConfigureAwait(false);

                        TransferContext context          = CreateTransferContext();
                        TransferRequest uploadJobRequest = TransferRequest.ForUploadJob(uploadTargetPath, context);
                        uploadJobRequest.Application = "Github Sample";
                        uploadJobRequest.Name        = "Advanced Upload Sample";

                        // Create a transfer job to upload the local sample data set to the target remote path.
                        using (ITransferJob job = await client.CreateJobAsync(uploadJobRequest, cancellationToken).ConfigureAwait(false))
                        {
                            Console2.WriteDebugLine("Advanced upload started.");

                            // Paths added to the async job are transferred immediately.
                            await job.AddPathsAsync(localSourcePaths, cancellationToken).ConfigureAwait(false);

                            // Await completion of the job.
                            ITransferResult result = await job.CompleteAsync(cancellationToken).ConfigureAwait(false);

                            Console2.WriteDebugLine("Advanced upload completed.");
                            DisplayTransferResult(result);
                            Console2.WriteTapiEndHeader();
                        }

                        // Create a job-based download transfer request.
                        Console2.WriteTapiStartHeader("Advanced Transfer - Download");
                        string          downloadTargetPath = directory.Path;
                        TransferRequest downloadJobRequest = TransferRequest.ForDownloadJob(downloadTargetPath, context);
                        downloadJobRequest.Application = "Github Sample";
                        downloadJobRequest.Name        = "Advanced Download Sample";
                        Console2.WriteDebugLine("Advanced download started.");

                        // Create a transfer job to download the sample data set to the target local path.
                        using (ITransferJob job = await client.CreateJobAsync(downloadJobRequest, cancellationToken).ConfigureAwait(false))
                        {
                            IEnumerable <TransferPath> remotePaths = localSourcePaths.Select(localPath => new TransferPath
                            {
                                SourcePath     = uploadTargetPath + "\\" + Path.GetFileName(localPath.SourcePath),
                                PathAttributes = TransferPathAttributes.File,
                                TargetPath     = downloadTargetPath
                            });

                            await job.AddPathsAsync(remotePaths, cancellationToken).ConfigureAwait(false);
                            await ChangeDataRateAsync(job, cancellationToken).ConfigureAwait(false);

                            // Await completion of the job.
                            ITransferResult result = await job.CompleteAsync(cancellationToken).ConfigureAwait(false);

                            Console2.WriteDebugLine("Advanced download completed.");
                            DisplayTransferResult(result);
                            Console2.WriteTapiEndHeader();
                        }
                    }
            }
    public bool CallInfiniteLoop(string addressString)
    {
        ITransferResult result = Call(new Address(addressString), 100, "Loop", null, 10_000);

        return(result.Success);
    }
 public void ContractTransfer(string addressString)
 {
     ITransferResult result = Call(new Address(addressString), 100, "ReturnInt");
 }
Exemple #10
0
    public bool ContractTransferWithFail(string addressString)
    {
        ITransferResult result = Call(new Address(addressString), 100, "ThrowException");

        return(result.Success);
    }
Exemple #11
0
    public bool CallInfiniteLoop(Address address)
    {
        ITransferResult result = Call(address, 100, "Loop", null, 10_000);

        return(result.Success);
    }
Exemple #12
0
    public bool CallOther(Address address)
    {
        ITransferResult result = Call(address, 100, "IncrementCount");

        return(result.Success);
    }
Exemple #13
0
 public void ContractTransfer(Address address)
 {
     ITransferResult result = Call(address, 100, "ReturnInt");
 }
Exemple #14
0
    public bool ContractTransferWithFail(Address address)
    {
        ITransferResult result = Call(address, 100, "ThrowException");

        return(result.Success);
    }