Beispiel #1
0
        public string StartValidator()
        {
            if (_privateWallet.GetWalletInstance() is null)
            {
                return("wallet_locked");
            }

            Logger.LogDebug("validator start command received");
            if (_validatorStatusManager.IsStarted())
            {
                return("withdraw previous stake first");
            }

            _validatorStatusManager.Start(false);

            return("validator_started");
        }
Beispiel #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()
            });
        }