public void Reset() { var keypair = KeyPair.FromWIF(InitialPrivateWIF); int amount = 10000; var balances = new Dictionary <string, decimal>(); balances["NEO"] = amount; balances["GAS"] = amount; _accounts.Clear(); _accounts.Add(new Account() { name = "Genesis", balances = balances, byteCode = null, keys = keypair, storage = null }); _blocks.Clear(); var block = GenerateBlock(); var hash = new UInt160(CryptoUtils.AddressToScriptHash(keypair.address)); var tx = new Transaction(block); foreach (var entry in balances) { BigInteger total = (BigInteger)amount * Asset.Decimals; tx.outputs.Add(new TransactionOutput(Asset.GetAssetId(entry.Key), total, hash)); } ConfirmBlock(block); }
private void SendAssetPrompt(Account from, Account to, string symbol) { string input = "1"; if (InputUtils.ShowInputDialog("Insert amount of ", ref input) == DialogResult.OK) { BigInteger amount; if (BigInteger.TryParse(input, out amount) && amount > 0) { var block = _blockchain.GenerateBlock(); var assetID = Asset.GetAssetId(symbol); var bytes = CryptoUtils.AddressToScriptHash(to.keys.address); var hash = new UInt160(bytes); var tx = new Transaction(block); tx.outputs.Add(new TransactionOutput(assetID, amount, hash)); if (_blockchain.ConfirmBlock(block)) { _blockchain.Save(); Reload(); } } else { MessageBox.Show("Invalid amount"); } } }
public void SetTransaction(byte[] assetID, BigInteger amount) { var key = Runtime.invokerKeys; var bytes = key != null?CryptoUtils.AddressToScriptHash(key.address) : new byte[20]; var src_hash = new UInt160(bytes); var dst_hash = CryptoUtils.ToScriptHash(ContractByteCode); //var dst_hash = new UInt160(LuxUtils.ReverseHex(LuxUtils.ByteToHex(CryptoUtils.ToScriptHash(ContractByteCode).ToArray())).HexToBytes()); //new UInt160(CryptoUtils.AddressToScriptHash(this.currentAccount.keys.address)); this.currentHash = dst_hash; var block = blockchain.GenerateBlock(); var tx = new API.Transaction(block); BigInteger asset_decimals = 100000000; tx.outputs.Add(new API.TransactionOutput(assetID, amount * asset_decimals, src_hash)); tx.outputs.Add(new API.TransactionOutput(assetID, amount * asset_decimals, dst_hash)); blockchain.ConfirmBlock(block); this.currentTransaction = tx; }
public void SetTransaction(byte[] assetID, BigInteger amount) { var key = Runtime.invokerKeys; var bytes = key != null?CryptoUtils.AddressToScriptHash(key.address) : new byte[20]; var src_hash = new UInt160(bytes); var dst_hash = new UInt160(CryptoUtils.AddressToScriptHash(this.currentAccount.keys.address)); this.currentHash = dst_hash; BigInteger asset_decimals = 100000000; BigInteger total_amount = (amount * 10) * asset_decimals; // FIXME instead of (amount * 10) we should take balance from virtual blockchain var block = blockchain.GenerateBlock(); var tx = new API.Transaction(block); //tx.inputs.Add(new TransactionInput(-1, src_hash)); tx.outputs.Add(new API.TransactionOutput(assetID, amount, dst_hash)); tx.outputs.Add(new API.TransactionOutput(assetID, total_amount - amount, src_hash)); blockchain.ConfirmBlock(block); this.currentTransaction = tx; }
public Account FindAccountByHash(UInt160 hash) { foreach (var entry in _accounts) { var bytes = CryptoUtils.AddressToScriptHash(entry.keys.address); var temp = new UInt160(bytes); if (temp.Equals(hash)) { return(entry); } } return(null); }