Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            var path = Path.Combine(Directory.GetCurrentDirectory());

            path = Path.GetFullPath(path) + "/.env";
            DotEnv.Config(true, path);
            DotEnv.Config(true, path, Encoding.Unicode, false);
            EnvReader envReader = new EnvReader();

            BlockIo blockIo = new BlockIo(envReader.GetStringValue("API_KEY"), envReader.GetStringValue("PIN"));

            var balance = blockIo.GetBalance().Data.available_balance;

            Console.WriteLine("Balance: " + balance);

            while (true)
            {
                var    res         = blockIo.Withdraw(new { to_address = envReader.GetStringValue("TO_ADDRESS"), amount = balance.ToString() });
                double maxWithdraw = res.Data.max_withdrawal_available;

                Console.WriteLine("Max Withdraw Available: " + maxWithdraw.ToString());

                if (maxWithdraw == 0)
                {
                    break;
                }
                blockIo.Withdraw(new { to_address = envReader.GetStringValue("TO_ADDRESS"), amount = maxWithdraw.ToString() });
            }

            balance = blockIo.GetBalance().Data.available_balance;

            Console.WriteLine("Final Balance: " + balance);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            var path = Path.Combine(Directory.GetCurrentDirectory());

            path = Path.GetFullPath(path) + "/.env";
            DotEnv.Config(true, path);
            DotEnv.Config(true, path, Encoding.Unicode, false);
            EnvReader envReader = new EnvReader();

            BlockIo blockIo = new BlockIo(envReader.GetStringValue("API_KEY"));

            var res = blockIo.SweepFromAddress(new
            {
                to_address   = envReader.GetStringValue("TO_ADDRESS"),
                private_key  = envReader.GetStringValue("PRIVATE_KEY_FROM_ADDRESS"),
                from_address = envReader.GetStringValue("FROM_ADDRESS")
            });

            if (res.Status == "success")
            {
                Console.WriteLine("Sweep Res: " + res.Data);
                return;
            }

            Console.WriteLine("Error occurred: " + res.Data);
        }
Ejemplo n.º 3
0
        public void Sweep()
        {
            blockIo = new BlockIo(api_key, null, 2, new Options(baseUrl));
            var response = blockIo.SweepFromAddress(sweepRequestBodyContent);

            Assert.AreEqual("success", response.Status);
            Assert.IsNotNull(response.Data);
        }
Ejemplo n.º 4
0
        public void Dtrust()
        {
            pin     = "blockiotestpininsecure";
            blockIo = new BlockIo(api_key, pin, 2, new Options(baseUrl));
            var response = blockIo.WithdrawFromDtrustAddress(dTrustRequestBodyContent);

            Assert.AreEqual("success", response.Status);
            Assert.IsNotNull(response.Data);
        }
Ejemplo n.º 5
0
        public MaxWithdrawal()
        {
            var path = Path.Combine(Directory.GetCurrentDirectory(), @"..\..\..");

            path = Path.GetFullPath(path) + "\\.env";
            DotEnv.Config(true, path);
            DotEnv.Config(true, path, Encoding.Unicode, false);
            envReader = new EnvReader();

            blockIo = new BlockIo(envReader.GetStringValue("API_KEY"), envReader.GetStringValue("PIN"));
        }
Ejemplo n.º 6
0
        public Proxy()
        {
            var path = Path.Combine(Directory.GetCurrentDirectory(), @"..\..\..");

            path = Path.GetFullPath(path) + "\\.env";
            DotEnv.Config(true, path);
            DotEnv.Config(true, path, Encoding.Unicode, false);
            var envReader = new EnvReader();

            blockIo = new BlockIo(envReader.GetStringValue("API_KEY"), envReader.GetStringValue("PIN"), 2,
                                  "{proxy: {" +
                                  "  hostname: '" + envReader.GetStringValue("PROXY_HOST") +
                                  "', port: '" + envReader.GetStringValue("PROXY_PORT") +
                                  "', username: '******', password: '******'}}");
        }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            var path = Path.Combine(Directory.GetCurrentDirectory());

            path = Path.GetFullPath(path) + "/.env";
            DotEnv.Config(true, path);
            DotEnv.Config(true, path, Encoding.Unicode, false);
            var envReader = new EnvReader();

            BlockIo blockIo = new BlockIo(envReader.GetStringValue("API_KEY"), envReader.GetStringValue("PIN"));

            Console.WriteLine("Get New Address: " + blockIo.GetNewAddress(new { label = "testDest2" }).Data);
            Console.WriteLine("Withdraw from labels: " + blockIo.WithdrawFromLabels(new { from_labels = "testDest2", to_label = "default", amount = "0.00061440" }).Data);
            Console.WriteLine("Get Address Balance: " + blockIo.GetAddressBalance(new { labels = "default,testDest2" }).Data);
            Console.WriteLine("Get Sent Transactions: " + blockIo.GetTransactions(new { type = "sent" }).Data);
            Console.WriteLine("Get Received Transactions: " + blockIo.GetTransactions(new { type = "received" }).Data);
            Console.WriteLine("Get Current Price: " + blockIo.GetCurrentPrice(new { base_price = "BTC" }).Data);
        }
Ejemplo n.º 8
0
        private void InitializeOptimal(AILBlock[] Graph, AILBlock Root)
        {
            //This will go through all possible paths on the graph,
            //and store all inputs/outputs for each block. A register
            //that was previously written to already is not considered an input.
            //When a block can be reached by more than one path, then the
            //output from all paths needs to be set for this block, and
            //only outputs present in all of the parent blocks can be considered
            //when doing input elimination. Each block chain have a root, that's where
            //the code starts executing. They are present on the subroutine start point,
            //and on call return points too (address written to X30 by BL).
            HashSet <BlockIo> Visited = new HashSet <BlockIo>();

            Queue <BlockIo> Unvisited = new Queue <BlockIo>();

            void Enqueue(BlockIo Block)
            {
                if (!Visited.Contains(Block))
                {
                    Unvisited.Enqueue(Block);

                    Visited.Add(Block);
                }
            }

            Enqueue(new BlockIo()
            {
                Block = Root,
                Entry = Root
            });

            while (Unvisited.Count > 0)
            {
                BlockIo Current = Unvisited.Dequeue();

                Current.IntInputs  |= Current.Block.IntInputs & ~Current.IntOutputs;
                Current.VecInputs  |= Current.Block.VecInputs & ~Current.VecOutputs;
                Current.IntOutputs |= Current.Block.IntOutputs;
                Current.VecOutputs |= Current.Block.VecOutputs;

                //Check if this is a exit block
                //(a block that returns or calls another sub).
                if ((Current.Block.Next == null &&
                     Current.Block.Branch == null) || Current.Block.HasStateStore)
                {
                    if (!IntPaths.TryGetValue(Current.Block, out PathIo IntPath))
                    {
                        IntPaths.Add(Current.Block, IntPath = new PathIo());
                    }

                    if (!VecPaths.TryGetValue(Current.Block, out PathIo VecPath))
                    {
                        VecPaths.Add(Current.Block, VecPath = new PathIo());
                    }

                    IntPath.Set(Current.Entry, Current.IntInputs, Current.IntOutputs);
                    VecPath.Set(Current.Entry, Current.VecInputs, Current.VecOutputs);
                }

                void EnqueueFromCurrent(AILBlock Block, bool RetTarget)
                {
                    BlockIo BlkIO = new BlockIo()
                    {
                        Block = Block
                    };

                    if (RetTarget)
                    {
                        BlkIO.Entry = Block;
                    }
                    else
                    {
                        BlkIO.Entry      = Current.Entry;
                        BlkIO.IntInputs  = Current.IntInputs;
                        BlkIO.VecInputs  = Current.VecInputs;
                        BlkIO.IntOutputs = Current.IntOutputs;
                        BlkIO.VecOutputs = Current.VecOutputs;
                    }

                    Enqueue(BlkIO);
                }

                if (Current.Block.Next != null)
                {
                    EnqueueFromCurrent(Current.Block.Next, Current.Block.HasStateStore);
                }

                if (Current.Block.Branch != null)
                {
                    EnqueueFromCurrent(Current.Block.Branch, false);
                }
            }
        }
Ejemplo n.º 9
0
        public void BuildUses(ILBlock entry)
        {
            //This will go through all possible paths on the graph,
            //and store all inputs/outputs for each block. A register
            //that was previously written to already is not considered an input.
            //When a block can be reached by more than one path, then the
            //output from all paths needs to be set for this block, and
            //only outputs present in all of the parent blocks can be considered
            //when doing input elimination. Each block chain has a entry, that's where
            //the code starts executing. They are present on the subroutine start point,
            //and on call return points too (address written to X30 by BL).
            HashSet <BlockIo> visited = new HashSet <BlockIo>();

            Queue <BlockIo> unvisited = new Queue <BlockIo>();

            void Enqueue(BlockIo block)
            {
                if (visited.Add(block))
                {
                    unvisited.Enqueue(block);
                }
            }

            Enqueue(new BlockIo(entry, entry));

            while (unvisited.Count > 0)
            {
                BlockIo current = unvisited.Dequeue();

                current.IntInputs  |= current.Block.IntInputs & ~current.IntOutputs;
                current.VecInputs  |= current.Block.VecInputs & ~current.VecOutputs;
                current.IntOutputs |= current.Block.IntOutputs;
                current.VecOutputs |= current.Block.VecOutputs;

                //Check if this is a exit block
                //(a block that returns or calls another sub).
                if ((current.Block.Next == null &&
                     current.Block.Branch == null) || current.Block.HasStateStore)
                {
                    if (!_intPaths.TryGetValue(current.Block, out PathIo intPath))
                    {
                        _intPaths.Add(current.Block, intPath = new PathIo());
                    }

                    if (!_vecPaths.TryGetValue(current.Block, out PathIo vecPath))
                    {
                        _vecPaths.Add(current.Block, vecPath = new PathIo());
                    }

                    intPath.Set(current.Entry, current.IntInputs, current.IntOutputs);
                    vecPath.Set(current.Entry, current.VecInputs, current.VecOutputs);
                }

                void EnqueueFromCurrent(ILBlock block, bool retTarget)
                {
                    BlockIo blockIo;

                    if (retTarget)
                    {
                        blockIo = new BlockIo(block, block);
                    }
                    else
                    {
                        blockIo = new BlockIo(
                            block,
                            current.Entry,
                            current.IntInputs,
                            current.VecInputs,
                            current.IntOutputs,
                            current.VecOutputs);
                    }

                    Enqueue(blockIo);
                }

                if (current.Block.Next != null)
                {
                    EnqueueFromCurrent(current.Block.Next, current.Block.HasStateStore);
                }

                if (current.Block.Branch != null)
                {
                    EnqueueFromCurrent(current.Block.Branch, false);
                }
            }
        }
Ejemplo n.º 10
0
        static void Main(string[] args)
        {
            var path = Path.Combine(Directory.GetCurrentDirectory());

            path = Path.GetFullPath(path) + "/.env";
            DotEnv.Config(true, path);
            DotEnv.Config(true, path, Encoding.Unicode, false);
            var envReader = new EnvReader();

            string     DtrustAddress      = null;
            string     DtrustAddressLabel = "dTrust1_witness_v0";
            BlockIo    blockIo            = new BlockIo(envReader.GetStringValue("API_KEY"), envReader.GetStringValue("PIN"));
            List <Key> PrivKeys           = new List <Key>()
            {
                new Key().ExtractKeyFromPassphraseString("verysecretkey1"),
                new Key().ExtractKeyFromPassphraseString("verysecretkey2"),
                new Key().ExtractKeyFromPassphraseString("verysecretkey3"),
                new Key().ExtractKeyFromPassphraseString("verysecretkey4")
            };
            List <string> PublicKeys = new List <string>()
            {
                PrivKeys[0].PubKey.ToHex(),
                PrivKeys[1].PubKey.ToHex(),
                PrivKeys[2].PubKey.ToHex(),
                PrivKeys[3].PubKey.ToHex()
            };

            string signers = string.Join(",", PublicKeys);
            var    res     = blockIo.GetNewDtrustAddress(new { label = DtrustAddressLabel, public_keys = signers, required_signatures = "3", address_type = "witness_v0" });

            if (res.Status != "success")
            {
                Console.WriteLine("Error: " + res.Data);
                // if this failed, we probably created the same label before. let's fetch the address then

                res           = blockIo.GetDtrustAddressByLabel(new { label = DtrustAddressLabel });
                DtrustAddress = res.Data.address;
            }
            else
            {
                DtrustAddress = res.Data.address;
            }
            Console.WriteLine("Our dTrust Address: " + DtrustAddress);

            res = blockIo.WithdrawFromLabels(new { from_labels = "default", to_address = DtrustAddress, amounts = "0.0002" });
            Console.WriteLine("Withdrawal Response: " + res.Data);

            res = blockIo.GetDtrustAddressBalance(new { label = DtrustAddressLabel });
            Console.WriteLine("Dtrust address label Balance: " + res.Data);

            var normalAddress = blockIo.GetAddressByLabel(new { label = "default" }).Data.address.ToString();

            Console.WriteLine("Withdrawing from dtrust_address_label to the 'default' label in normal multisig");

            res = blockIo.WithdrawFromDtrustAddress(new { from_labels = DtrustAddressLabel, to_address = normalAddress, amounts = "0.0002" });

            Console.WriteLine("Withdraw from Dtrust Address response: " + res.Data);

            int keyIte;

            foreach (dynamic input in res.Data.inputs)
            {
                keyIte = 0;
                foreach (dynamic signer in input.signers)
                {
                    signer.signed_data = Helper.SignInputs(PrivKeys[keyIte++], input.data_to_sign.ToString(), signer.signer_public_key.ToString());
                }
            }
            Console.WriteLine("Our Signed Request: " + res.Data);
            Console.WriteLine("Finalize Withdrawal: ");
            Console.WriteLine(blockIo.SignAndFinalizeWithdrawal(res.Data.ToString()).Data);
            Console.WriteLine("Get transactions sent by our dtrust_address_label address: ");
            Console.WriteLine(blockIo.GetDtrustTransactions(new { type = "sent", labels = DtrustAddressLabel }).Data);
        }