예제 #1
0
        /// <summary>
        /// The main.
        /// </summary>
        /// <param name="args">
        /// The args.
        /// </param>
        private static void Main(string[] args)
        {
            var repository = new RestIotaRepository(new RestClient("https://field.deviota.com:443"), new PoWSrvService());

            var bundle = new Bundle();

            bundle.AddTransfer(new Transfer
            {
                Address   = new Address(Hash.Empty.Value),
                Tag       = new Tag("MYCSHARPPI"),
                Timestamp = Timestamp.UnixSecondsTimestamp,
                Message   = TryteString.FromUtf8String("Hello from PiDiver #1!")
            });

            bundle.AddTransfer(new Transfer
            {
                Address   = new Address(Hash.Empty.Value),
                Tag       = new Tag("MYCSHARPPI"),
                Timestamp = Timestamp.UnixSecondsTimestamp,
                Message   = TryteString.FromUtf8String("Hello from PiDiver #2!")
            });

            bundle.Finalize();
            bundle.Sign();

            repository.SendTrytes(bundle.Transactions);


            Console.WriteLine("Done");
            Console.ReadKey();
        }
        /// <summary>
        /// Uploads the object to the specified SendTo address inside the object
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static T Upload <T>(this T obj) where T : IDownloadable
        {
            if (!obj.IsFinalized)
            {
                throw new ArgumentException("object not finalized");
            }

            //prepare data
            var json = TangleNet::TryteString.FromUtf8String(Utils.ToJSON(obj));

            //send json to address
            var repository = new RestIotaRepository(new RestClient(obj.NodeAddress), new PoWService(new CpuPearlDiver()));

            var bundle = new TangleNet::Bundle();

            bundle.AddTransfer(
                new TangleNet::Transfer
            {
                Address   = new TangleNet::Address(obj.SendTo),
                Tag       = new TangleNet::Tag("TANGLECHAIN"),
                Message   = json,
                Timestamp = Timestamp.UnixSecondsTimestamp
            });

            bundle.Finalize();
            bundle.Sign();

            repository.SendTrytes(bundle.Transactions, 2, 14);

            return(obj);
        }
예제 #3
0
        /// <summary>
        /// The main.
        /// </summary>
        /// <param name="args">
        /// The args.
        /// </param>
        private static void Main(string[] args)
        {
            var repository = new RestIotaRepository(
                new FallbackIotaClient(
                    new List <string>
            {
                "https://invalid.node.com:443",
                "https://peanut.iotasalad.org:14265",
                "http://node04.iotatoken.nl:14265",
                "http://node05.iotatoken.nl:16265",
                "https://nodes.thetangle.org:443",
                "http://iota1.heidger.eu:14265",
                "https://nodes.iota.cafe:443",
                "https://potato.iotasalad.org:14265",
                "https://durian.iotasalad.org:14265",
                "https://turnip.iotasalad.org:14265",
                "https://nodes.iota.fm:443",
                "https://tuna.iotasalad.org:14265",
                "https://iotanode2.jlld.at:443",
                "https://node.iota.moe:443",
                "https://wallet1.iota.town:443",
                "https://wallet2.iota.town:443",
                "http://node03.iotatoken.nl:15265",
                "https://node.iota-tangle.io:14265",
                "https://pow4.iota.community:443",
                "https://dyn.tangle-nodes.com:443",
                "https://pow5.iota.community:443",
            },
                    5000),
                new PoWSrvService());

            var bundle = new Bundle();

            bundle.AddTransfer(
                new Transfer
            {
                Address   = new Address(Hash.Empty.Value),
                Tag       = new Tag("MYCSHARPPI"),
                Timestamp = Timestamp.UnixSecondsTimestamp,
                Message   = TryteString.FromUtf8String("Hello from PiDiver #1!")
            });

            bundle.AddTransfer(
                new Transfer
            {
                Address   = new Address(Hash.Empty.Value),
                Tag       = new Tag("MYCSHARPPI"),
                Timestamp = Timestamp.UnixSecondsTimestamp,
                Message   = TryteString.FromUtf8String("Hello from PiDiver #2!")
            });

            bundle.Finalize();
            bundle.Sign();

            repository.SendTrytes(bundle.Transactions, 1);

            Console.WriteLine("Done");
            Console.ReadKey();
        }
예제 #4
0
        public ActionResult SendMessage(string Message)
        {
            //connection to a iota node
            var repository = new RestIotaRepository(new RestClient("http://node04.iotatoken.nl:14265"), new PoWService(new CpuPowDiver()));

            User sender = HttpContext.Session.GetObjectFromJson <User>("User");

            Connections connection = HttpContext.Session.GetObjectFromJson <Connections>("SelectedConnection");

            //set refresh bools
            if (connection.UserA_.Name.Equals(sender.Name))
            {
                connection.Refresh_B = true;
            }
            else
            {
                connection.Refresh_A = true;
            }

            //updating entry
            _context.Connections.Update(connection);
            _context.SaveChanges();

            string sendingAddress = (connection.UserA_.UserID == sender.UserID) ? connection.AddressB : connection.AddressA;

            string encryptedMsg = Utility.EncryptString(Message, connection.EncryptionKey);

            Transfer trans = new Transfer()
            {
                Address = new Address(sendingAddress)
                {
                    Balance = 0
                },
                Message   = TryteString.FromAsciiString(encryptedMsg),
                Tag       = new Tag("CSHARP"),
                Timestamp = Timestamp.UnixSecondsTimestamp
            };

            Bundle bundle = new Bundle();

            bundle.AddTransfer(trans);

            bundle.Finalize();
            bundle.Sign();

            //sending the message to the tangle
            var resultTransactions = repository.SendTrytes(bundle.Transactions, 27, 14);

            return(RedirectToAction("ShowSpecificChat", new { connection = connection.ConnectionsID }));
        }
예제 #5
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            // Get needed parameters from payload.
            string  requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            dynamic data        = JsonConvert.DeserializeObject(requestBody);
            string  deviceId    = data?.device.deviceId;
            dynamic telemetry   = data?.device.measurements.telemetry;
            dynamic properties  = data?.device.properties;
            string  nprId       = properties.device.nprId_property.ToString();

            // Basic validation before proceeding.
            if (string.IsNullOrEmpty(nprId) || !(telemetry is JObject))
            {
                return(new BadRequestObjectResult("NprId not set on reporting device or reading invalid."));
            }

            // Connect to a node on one of the main networks.
            var repository = new RestIotaRepository(new RestClient("https://nodes.devnet.thetangle.org:443"));

            // Get addresses from the Tangle on behalf of the patient's wallet for generating new address for posting reading.
            // Would be an external trusted service.
            var tangleAddresses = NationalIdentityService.GetTangleAddressesFromNprId(repository, nprId, ((JObject)telemetry).Count);

            // Terminate if no addresses created.
            if (tangleAddresses.Count < 1)
            {
                return(new BadRequestObjectResult("NprId not found or no associated seed."));
            }

            // Create transactions for the Tangle for each type of reading in payload and bundle together.
            // Finalize and sign.
            var bundle = CreateTransaction(tangleAddresses, telemetry);

            // Send the complete transactions to the Tangle.
            repository.SendTrytes(bundle.Transactions, depth: 2, minWeightMagnitude: 9);

            string logMessage = $"NPRId: {nprId} - DeviceID: {deviceId} - reading: {telemetry.ToString()} - Bundle hash: {bundle.Hash.Value}";

            log.LogInformation(logMessage);

            return((ActionResult) new OkObjectResult(logMessage));
        }
예제 #6
0
        static Hash AttachChunk(byte[] chunk)
        {
            var bundle = new Bundle();

            bundle.AddTransfer(new Transfer
            {
                Address   = new Address(Hash.Empty.Value),
                Tag       = new Tag("MUTSI"),
                Timestamp = Timestamp.UnixSecondsTimestamp,
                Message   = TryteString.FromBytes(chunk)
            });

            bundle.Finalize();
            bundle.Sign();

            // see Getting Started to see how a repository is created
            var result = repository.SendTrytes(bundle.Transactions);

            return(bundle.Hash);
        }
예제 #7
0
        /// <summary>
        /// The main.
        /// </summary>
        /// <param name="args">
        /// The args.
        /// </param>
        private static void Main(string[] args)
        {
            var factory    = new RestIotaRepositoryFactory();
            var repo       = factory.CreateAsync(true).Result;
            var repository = new RestIotaRepository(new RestClient("http://localhost:14265"), new PoWService(new CpuPearlDiver()));
            var acc        = repository.GetAccountData(Seed.Random(), true, SecurityLevel.Medium, 0);

            var seed             = Seed.Random();
            var addressGenerator = new AddressGenerator(new Kerl(), new KeyGenerator(new Kerl(), new IssSigningHelper()));

            var addresses = addressGenerator.GetAddresses(seed, SecurityLevel.Medium, 0, 6);
            var addressesWithSpentInformation = repository.WereAddressesSpentFrom(addresses);

            var transactionStackCounter = 10;

            for (var i = 1; i <= transactionStackCounter; i++)
            {
                var stopwatch = new Stopwatch();
                stopwatch.Start();
                var transfers = new List <Transfer>();
                for (var j = 1; j <= i; j++)
                {
                    transfers.Add(new Transfer
                    {
                        Address =
                            new Address("YTXCUUWTXIXVRQIDSECVFRTKAFOEZITGDPLWYVUVFURMNVDPIRXEIQN9JHNFNVKVJMQVMA9GDZJROTSFZHIVJOVAEC")
                        {
                            Balance = 0
                        },
                        Message   = TryteString.FromAsciiString("Hello world! With " + i + " transactions."),
                        Tag       = new Tag("CSHARP"),
                        Timestamp = Timestamp.UnixSecondsTimestamp
                    });
                }

                var bundle = new Bundle();

                transfers.ForEach(bundle.AddTransfer);

                bundle.Finalize();
                bundle.Sign();

                var resultTransactions = repository.SendTrytes(bundle.Transactions, 27, 14);
                Console.WriteLine("Finished sending bundle with {0} transactions. Time elapsed: {1} seconds.", i, stopwatch.ElapsedMilliseconds / 1000);
            }


            var accountData = repository.GetAccountData(new Seed("SOMESEEDHERE"), true, SecurityLevel.Medium, 0);

            var latestInclusion =
                repository.GetLatestInclusion(
                    new List <Hash> {
                new Hash("HG9KCXQZGQDVTFGRHOZDZ99RMKGVRIQXEKXWXTPWYRGXQQVFVMTLQLUPJSIDONDEURVKHMBPRYGP99999")
            });

            var inputs = repository.GetInputs(new Seed("SOMESEEDHERE"), 99900000, SecurityLevel.Medium, 0);

            var newAddresses = repository.GetNewAddresses(Seed.Random(), 0, 5, SecurityLevel.Medium);

            var transactions =
                repository.FindTransactionsByAddresses(
                    new List <Address> {
                new Address("HHZSJANZQULQICZFXJHHAFJTWEITWKQYJKU9TYFA9AFJLVIYOUCFQRYTLKRGCVY9KPOCCHK99TTKQGXA9")
            });

            var tips             = repository.GetTips();
            var inclusionsStates =
                repository.GetInclusionStates(
                    new List <Hash> {
                new Hash("HG9KCXQZGQDVTFGRHOZDZ99RMKGVRIQXEKXWXTPWYRGXQQVFVMTLQLUPJSIDONDEURVKHMBPRYGP99999")
            },
                    tips.Hashes.GetRange(0, 10));

            var transactionTrytes =
                repository.GetTrytes(new List <Hash> {
                new Hash("HG9KCXQZGQDVTFGRHOZDZ99RMKGVRIQXEKXWXTPWYRGXQQVFVMTLQLUPJSIDONDEURVKHMBPRYGP99999")
            });

            var transactionData = transactionTrytes.Select(t => Transaction.FromTrytes(t)).ToList();

            var transactionsToApprove = repository.GetTransactionsToApprove();

            var balances =
                repository.GetBalances(
                    new List <Address>
            {
                new Address("GVZSJANZQULQICZFXJHHAFJTWEITWKQYJKU9TYFA9AFJLVIYOUCFQRYTLKRGCVY9KPOCCHK99TTKQGXA9"),
                new Address("HBBYKAKTILIPVUKFOTSLHGENPTXYBNKXZFQFR9VQFWNBMTQNRVOUKPVPRNBSZVVILMAFBKOTBLGLWLOHQ999999999")
            });

            var nodeInfo = repository.GetNodeInfo();

            var neighbours = repository.GetNeighbors();

            Console.WriteLine("Done");
            Console.ReadKey();
        }