Example #1
0
        public static void Test()
        {
            timer.Interval = 5000;
            timer.Elapsed += Timer_Elapsed;
            timer.Start();
            var system = new BhpSystem(new LevelDBStore(dbPath));

            system.StartNode(10555, 11556);

            Console.WriteLine("block height : " + Blockchain.Singleton.Height);
            Console.WriteLine("Please input any key...");
            Console.ReadKey();

            SignDelegate2 sign = new SignDelegate2(SignWithoutWallet);
            //SignDelegate2 sign = new SignDelegate2(SignWithoutWallet2);

            var tx = CreateGlobalTransfer(sign);

            //var tx = CreateMinnerTransaction(sign);

            system.LocalNode.Tell(new LocalNode.Relay {
                Inventory = tx
            });

            Console.WriteLine("Transaction Replay. press any key...");
            timer.Stop();
            timer.Elapsed -= Timer_Elapsed;
            timer.Dispose();
            Console.ReadKey();
        }
Example #2
0
        public static Transaction CreateGlobalTransfer(SignDelegate2 sign)
        {
            CoinReference[] inputs = new CoinReference[]
            {
                new CoinReference()
                {
                    PrevHash  = new UInt256(preTxId.Remove(0, 2).HexToBytes().Reverse().ToArray()),
                    PrevIndex = prevIndex //vout n
                }
            }.ToArray();

            var outputs = new List <TransactionOutput>();
            var output1 = new TransactionOutput()
            {
                AssetId    = UInt256.Parse(assetid),
                ScriptHash = tansferAddress.ToScriptHash(),
                Value      = tansferValue
            };

            outputs.Add(output1);

            var tx = new ContractTransaction()
            {
                Outputs    = outputs.ToArray(),
                Inputs     = inputs,
                Attributes = new TransactionAttribute[0],
                Witnesses  = new Witness[0]
            };

            return(sign.Invoke(tx));
        }
Example #3
0
        public static Transaction CreateGlobalTransfer(SignDelegate2 sign)
        {
            //utxo txid
            string      preTxId = "0x1db3ae57b5f3fda94aa6a81add07a70fc38f0eae9e26f39d7d51183fad0c849f";
            UInt256     hash    = UInt256.Parse(preTxId);
            Transaction tx1     = Blockchain.Singleton.GetTransaction(hash);

            Fixed8 preOutVal     = tx1.Outputs[100].Value;
            Fixed8 currentOutVal = new Fixed8(1 * (long)Math.Pow(10, 8));

            if (preOutVal < currentOutVal)
            {
                Console.WriteLine("insufficient fund");
                return(null);
            }

            var inputs = new List <CoinReference>
            {
                new CoinReference()
                {
                    PrevHash  = new UInt256(preTxId.Remove(0, 2).HexToBytes().Reverse().ToArray()),
                    PrevIndex = 440
                }
            }.ToArray();

            var outputs = new List <TransactionOutput>();

            var output1 = new TransactionOutput()
            {
                AssetId    = UInt256.Parse(assetid),
                ScriptHash = "AbUAKqt8crJQnhDJWQtFGHT7Pgv9ABnQE6".ToScriptHash(),
                Value      = currentOutVal
            };

            outputs.Add(output1);
            //if (preOutVal > currentOutVal)
            //{
            //    var output2 = new TransactionOutput()
            //    {
            //        AssetId = UInt256.Parse(assetid),
            //        ScriptHash = "AZi4EzuSSp4kiWCUvLZcWo8daymKf53ez6".ToScriptHash(),
            //        Value = preOutVal - currentOutVal
            //    };
            //    outputs.Add(output2);
            //}

            var tx = new ContractTransaction()
            {
                Outputs    = outputs.ToArray(),
                Inputs     = inputs,
                Attributes = new TransactionAttribute[0],
                Witnesses  = new Witness[0]
            };

            return(sign.Invoke(tx));
        }
Example #4
0
        public static void Test(string[] args)
        {
            timer.Interval = 15000;
            timer.Elapsed += Timer_Elapsed;
            timer.Start();
            var system = new BhpSystem(new LevelDBStore(@"D:\BHP-Project\TestBhp\bin\Debug\db"));

            system.StartNode(10555, 10556);

            Console.ReadKey();
            SignDelegate2 sign = new SignDelegate2(SignWithoutWallet);
            var           tx   = CreateGlobalTransfer(sign); // CreateMinnerTransaction(sign);

            system.LocalNode.Tell(new LocalNode.Relay {
                Inventory = tx
            });

            Console.WriteLine("The End. Please press any key...");
            timer.Stop();
            timer.Elapsed -= Timer_Elapsed;
            timer.Dispose();
            Console.ReadKey();
        }
Example #5
0
        public static Transaction CreateMinnerTransaction(SignDelegate2 sign)
        {
            // d55ccd8b368aca2402003f39549ad7b75385c226009b3080e0d886959b75b5ce
            TransactionOutput[] outputs = new TransactionOutput[]
            {
                new TransactionOutput
                {
                    AssetId    = Blockchain.GoverningToken.Hash,
                    Value      = Fixed8.FromDecimal(444),
                    ScriptHash = currentAddress.ToScriptHash()
                }
            };
            ulong            nonce = GetNonce();
            MinerTransaction tx    = new MinerTransaction
            {
                Nonce      = (uint)(nonce % (uint.MaxValue + 1ul)),
                Attributes = new TransactionAttribute[0],
                Inputs     = new CoinReference[0],
                Outputs    = outputs,
                Witnesses  = new Witness[0]
            };

            return(sign.Invoke(tx));
        }