Example #1
0
        public void UpdateContractInfo()
        {
            var contractCode = _ContractView.Code;

            _Code = Encoding.ASCII.GetBytes(contractCode);

            _Hash = Merkle.innerHash(Encoding.ASCII.GetBytes(contractCode));

            _ContractView.Hash         = _Hash;
            _ContractView.CostPerBlock = ActiveContractSet.KalapasPerBlock(contractCode);

            //new GetIsContractActiveAction(_Hash).Publish().Result
            // var isActive = new GetIsContractActiveAction(_Hash).Publish();
            //_ContractView.IsActive = ;
        }
        public void ShowDialog(byte[] hash, string code, ContractController contractController)
        {
            //UInt32 nextBlocks;
            _IsActive           = App.Instance.Wallet.IsContractActive(hash /*, out nextBlocks*/);
            _KalapasPerBlock    = code == null || code.Length == 0 ? 0 : ActiveContractSet.KalapasPerBlock(code);
            _Code               = Encoding.ASCII.GetBytes(code);
            _ContractController = contractController;

            if (_IsActive)
            {
//				labelHeader.Text = buttonApply.Label = "Extend a Contract";
//				txtContent.Buffer.Text = $"Contract active for the next {nextBlocks} blocks.\nCost to extend is {_KalapasPerBlock} Kalapas/block";
                txtContent.Buffer.Text = $"Contract active.\nCost to extend is {_KalapasPerBlock} Kalapas/block";
            }
            else
            {
//				labelHeader.Text = buttonApply.Label = "Contract Activation";
                txtContent.Buffer.Text = $"Contract is inactive.\nCost to activate is {_KalapasPerBlock} Kalapas/block";
            }

            UpdateZenAmount(spinBlocks);
            ShowDialog();
        }
Example #3
0
        void HandleTx(TransactionValidation.PointedTransaction ptx)
        {
            //TODO: try simplify using hash from message
            var txHash = Merkle.transactionHasher.Invoke(TransactionValidation.unpoint(ptx));

            var activationSacrifice = 0UL;

            for (var i = 0; i < ptx.outputs.Length; i++)
            {
                var output = ptx.outputs[i];

                if ([email protected])
                {
                    if (!output.spend.asset.SequenceEqual(Tests.zhash))
                    {
                        continue;                         // not Zen
                    }
                    var contractSacrificeLock = (Types.OutputLock.ContractSacrificeLock)output.@lock;

                    if (contractSacrificeLock.IsHighVLock)
                    {
                        continue;                         // not current version
                    }
                    if (contractSacrificeLock.Item.lockData.Length == 0)
                    {
                        activationSacrifice += output.spend.amount;
                    }
                }

                //todo: fix  to exclude CSLocks&FLocks, instead of including by locktype
                if ([email protected] || [email protected])
                {
                    var outpoint = new Types.Outpoint(txHash, (uint)i);
                    _UtxoSet.Add(new Tuple <Types.Outpoint, Types.Output>(outpoint, output));
                }
            }

            if (FSharpOption <Types.ExtendedContract> .get_IsSome(ptx.contract) && !ptx.contract.Value.IsHighVContract)
            {
                var codeBytes    = ((Types.ExtendedContract.Contract)ptx.contract.Value).Item.code;
                var contractHash = Merkle.innerHash(codeBytes);
                var contractCode = System.Text.Encoding.ASCII.GetString(codeBytes);

                if (!_ActiveContracts.Contains(contractHash))
                {
                    if (activationSacrifice > ActiveContractSet.KalapasPerBlock(contractCode))
                    {
                        try
                        {
                            var compiledCodeOpt = ContractExamples.FStarExecution.compile(contractCode);

                            if (FSharpOption <byte[]> .get_IsSome(compiledCodeOpt))
                            {
                                _ActiveContracts.Add(contractHash);
                            }
                        }
                        catch (Exception e)
                        {
                            MinerTrace.Error("Could not compile contract " + Convert.ToBase64String(contractHash), e);
                        }
                    }
                }
            }
        }