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 void Reset(byte[] inputScript, ABI ABI, string methodName) { if (ContractByteCode == null || ContractByteCode.Length == 0) { throw new Exception("Contract bytecode is not set yet!"); } if (lastState.state == DebuggerState.State.Reset) { return; } if (currentTransaction == null) { //throw new Exception("Transaction not set"); currentTransaction = new API.Transaction(this.blockchain.currentBlock); } usedGas = 0; usedOpcodeCount = 0; currentTransaction.emulator = this; engine = new ExecutionEngine(currentTransaction, null, interop); engine.LoadScript(ContractByteCode); engine.LoadScript(inputScript); this.currentMethod = methodName; /*foreach (var output in currentTransaction.outputs) * { * if (output.hash == this.currentHash) * { * output.hash = engine.CurrentContext.ScriptHash; * } * }*/ foreach (var pos in _breakpoints) { engine.AddBreakPoint((uint)pos); } //engine.Reset(); lastState = new DebuggerState(DebuggerState.State.Reset, 0); currentTransaction = null; _variables.Clear(); this._ABI = ABI; }