Example #1
0
 public ExecutionStatus Deploy(byte[] byteCode, SystemContractExecutionFrame frame)
 {
     if (HardforkHeights.IsHardfork_2Active(frame.InvocationContext.Snapshot.Blocks.GetTotalBlockHeight()))
     {
         return(DeployV2(byteCode, frame));
     }
     return(DeployV1(byteCode, frame));
 }
Example #2
0
        private JObject DeployContract(string byteCodeInHex, string input, ulong gasLimit)
        {
            var ecdsaKeyPair = _privateWallet.GetWalletInstance()?.EcdsaKeyPair;

            if (ecdsaKeyPair == null)
            {
                throw new Exception("Wallet is locked");
            }
            if (string.IsNullOrEmpty(byteCodeInHex))
            {
                throw new ArgumentException("Invalid byteCode specified", nameof(byteCodeInHex));
            }
            var from  = ecdsaKeyPair.PublicKey.GetAddress();
            var nonce = _stateManager.LastApprovedSnapshot.Transactions.GetTotalTransactionCount(from);
            /* calculate contract hash */
            var hash = from.ToBytes().Concat(nonce.ToBytes()).Ripemd();

            Console.WriteLine("Contract Hash: " + hash.ToHex());
            var byteCode = byteCodeInHex.HexToBytes();

            if (!VirtualMachine.VerifyContract(byteCode,
                                               HardforkHeights.IsHardfork_2Active(_stateManager.LastApprovedSnapshot.Blocks.GetTotalBlockHeight())))
            {
                throw new ArgumentException("Unable to validate smart-contract code");
            }
            // TODO: use deploy abi if required
            var tx       = _transactionBuilder.DeployTransaction(from, byteCode);
            var signedTx = _transactionSigner.Sign(tx, ecdsaKeyPair, HardforkHeights.IsHardfork_9Active(_stateManager.LastApprovedSnapshot.Blocks.GetTotalBlockHeight() + 1));
            var error    = _transactionPool.Add(signedTx);

            return(new JObject
            {
                ["status"] = signedTx.Status.ToString(),
                ["gasLimit"] = gasLimit,
                ["gasUsed"] = signedTx.GasUsed,
                ["ok"] = error == OperatingError.Ok,
                ["result"] = hash.ToHex()
            });
        }