/* * [TestMethod] * public void WhenBuildSmartContractTransaction() * { * var code = @" * using System; * public class SimpleTest * { * private string y {get; set;} * private string z; * public string Test2(string parameter) * { * return parameter; * } * private string Test() * { * return ""1""; * } * }"; * var compiler = new DotnetCompiler(); * var smartContract = compiler.Compile(code); * var ba = BuildBlockChainAddress(); * var builder = new TransactionBuilder(); * var script = Script.CreateP2PKHScript(ba.PublicKeyHash); * var nonce = BitConverter.GetBytes(NonceHelper.GetNonceUInt64()); * var transaction = builder * .NewSmartContractTransaction().CreateSmartContract(smartContract, script, "thabart", "test", 0, nonce) * .Build(); * var serializedTransaction = transaction.Serialize(); * var deserializedTx = BaseTransaction.Deserialize(serializedTransaction, TransactionTypes.SmartContract); * string s = ""; * } */ private static BlockChainAddress BuildBlockChainAddress() { var network = Networks.MainNet; var key = Key.Genererate(); var blockChainAddress = new BlockChainAddress(ScriptTypes.P2PKH, network, key); var hash = blockChainAddress.GetSerializedHash(); var deserializedBA = BlockChainAddress.Deserialize(hash); return(deserializedBA); }
private static BlockChainAddress BuildBlockChainAddress() { var network = Networks.MainNet; var key = Key.Deserialize(new BigInteger("66661394595692466950200829442443674598224300882267065208709422638481412972116609477112206002430829808784107536250360432119209033266013484787698545014625057"), new BigInteger("43102461949956883352376427470284148089747996528740865531180015053863743793176")); //Key.Genererate(); var k2 = Key.Genererate(); var publicKey = new BigInteger(k2.GetPublicKey().ToArray()); var privateKey = k2.GetPrivateKey(); var keyHash = new BigInteger(k2.GetPublicKeyHashed().ToArray()); var blockChainAddress2 = new BlockChainAddress(ScriptTypes.P2PKH, network, k2); var hh = blockChainAddress2.GetSerializedHash(); var h = new BigInteger(key.GetPublicKeyHashed()); var blockChainAddress = new BlockChainAddress(ScriptTypes.P2PKH, network, key); var s = blockChainAddress.GetJson().ToString(); var hash = blockChainAddress.GetSerializedHash(); var deserializedBA = BlockChainAddress.Deserialize(hash); return(deserializedBA); }
public Key CreateNewAddress() { var walletStore = WalletStore.Instance(); var authenticatedWallet = walletStore.GetAuthenticatedWallet(); if (authenticatedWallet == null) { return(null); } var key = Key.Genererate(); var blockChainAdr = new BlockChainAddress(ScriptTypes.P2PKH, authenticatedWallet.Network, key); authenticatedWallet.Addresses.Add(new WalletAggregateAddress { Hash = blockChainAdr.GetSerializedHash(), Key = key, Network = authenticatedWallet.Network }); var password = walletStore.GetPassword(); _walletRepository.Update(authenticatedWallet, walletStore.GetPassword()); return(key); }
private static void ExecuteConnectedWallet(int number) { if (number < 0 && number > 6) { MenuHelper.DisplayError("Please enter an option between [1-6]"); } switch (number) { case 1: // BROADCAST A UTXO TRANSACTION. Console.WriteLine("Please enter the address"); var receivedHash = Console.ReadLine(); var deserializedAdr = BlockChainAddress.Deserialize(receivedHash); Console.WriteLine("How much do-you want to send ?"); var value = MenuHelper.EnterNumber(); var blockChain = BlockChainStore.Instance().GetBlockChain(); var builder = new TransactionBuilder(); var transaction = builder.NewNoneCoinbaseTransaction() // .Spend(0, ) .AddOutput(value, Script.CreateP2PKHScript(deserializedAdr.PublicKeyHash)) .Build(); var serializedTransaction = transaction.Serialize(); // SEND UTXO. _nodeLauncher.Broadcast(transaction); ExecuteMenu(); return; case 2: // GENERATE A NEW BITCOIN ADDRESS. var key = Key.Genererate(); var h = new BigInteger(key.GetPublicKeyHashed()); var blockChainAddress = new BlockChainAddress(ScriptTypes.P2PKH, _nodeLauncher.GetNetwork(), key); var hash = blockChainAddress.GetSerializedHash(); Console.WriteLine($"Give the bitcoin address to the person {hash}"); Console.WriteLine("Please enter a password to protect your wallet"); var password = Console.ReadLine(); _keyRepository.Load(password); _keyRepository.Keys.Add(key); _keyRepository.Save(password); break; case 3: DisplayWalletInformation(); ExecuteMenu(); return; case 4: _nodeLauncher.RefreshBlockChain(); ExecuteMenu(); break; case 5: _nodeLauncher.RefreshConnectedPeers(); ExecuteMenu(); break; case 6: Console.WriteLine("Bye bye"); Console.ReadLine(); return; } ExecuteMenu(); }