public SmartContractMempoolValidator(ITxMempool memPool, MempoolSchedulerLock mempoolLock, IDateTimeProvider dateTimeProvider, MempoolSettings mempoolSettings, ConcurrentChain chain, ICoinView coinView, ILoggerFactory loggerFactory, NodeSettings nodeSettings, IConsensusRuleEngine consensusRules, ICallDataSerializer callDataSerializer) : base(memPool, mempoolLock, dateTimeProvider, mempoolSettings, chain, coinView, loggerFactory, nodeSettings, consensusRules) { this.callDataSerializer = callDataSerializer; var p2pkhRule = new P2PKHNotContractRule(); p2pkhRule.Parent = (ConsensusRuleEngine)consensusRules; p2pkhRule.Initialize(); var scriptTypeRule = new AllowedScriptTypeRule(); scriptTypeRule.Parent = (ConsensusRuleEngine)consensusRules; scriptTypeRule.Initialize(); this.preTxRules = new List <ISmartContractMempoolRule> { new MempoolOpSpendRule(), new TxOutSmartContractExecRule(), scriptTypeRule, p2pkhRule }; this.feeTxRules = new List <ISmartContractMempoolRule>() { new SmartContractFormatRule(callDataSerializer) }; }
public SmartContractMempoolValidator(ITxMempool memPool, MempoolSchedulerLock mempoolLock, IDateTimeProvider dateTimeProvider, MempoolSettings mempoolSettings, ConcurrentChain chain, ICoinView coinView, ILoggerFactory loggerFactory, NodeSettings nodeSettings, IConsensusRuleEngine consensusRules, ICallDataSerializer callDataSerializer) : base(memPool, mempoolLock, dateTimeProvider, mempoolSettings, chain, coinView, loggerFactory, nodeSettings, consensusRules) { // Dirty hack, but due to AllowedScriptTypeRule we don't need to check for standard scripts on any network, even live. // TODO: Remove ASAP. Ensure RequireStandard isn't used on SC mainnets, or the StandardScripts check is modular. mempoolSettings.RequireStandard = false; this.callDataSerializer = callDataSerializer; var p2pkhRule = new P2PKHNotContractRule(); p2pkhRule.Parent = (ConsensusRuleEngine)consensusRules; p2pkhRule.Initialize(); var scriptTypeRule = new AllowedScriptTypeRule(); scriptTypeRule.Parent = (ConsensusRuleEngine)consensusRules; scriptTypeRule.Initialize(); this.preTxRules = new List <ISmartContractMempoolRule> { new MempoolOpSpendRule(), new TxOutSmartContractExecRule(), scriptTypeRule, p2pkhRule }; this.feeTxRules = new List <ISmartContractMempoolRule>() { new SmartContractFormatRule(callDataSerializer) }; }
public void SendTo_Contract_Fails() { var contractAddress = new uint160(123); var state = new Mock <IStateRepositoryRoot>(); state.Setup(x => x.GetAccountState(contractAddress)).Returns(new AccountState()); // not null Transaction transaction = this.network.CreateTransaction(); transaction.Outputs.Add(new TxOut(100, PayToPubkeyHashTemplate.Instance.GenerateScriptPubKey(new KeyId(contractAddress)))); Assert.Throws <ConsensusErrorException>(() => P2PKHNotContractRule.CheckTransaction(state.Object, transaction)); }
public void SendTo_NotAContract_Success() { var walletAddress = new uint160(321); var state = new Mock <IStateRepositoryRoot>(); state.Setup(x => x.GetAccountState(walletAddress)).Returns <AccountState>(null); Transaction transaction = this.network.CreateTransaction(); transaction.Outputs.Add(new TxOut(100, PayToPubkeyHashTemplate.Instance.GenerateScriptPubKey(new KeyId(walletAddress)))); P2PKHNotContractRule.CheckTransaction(state.Object, transaction); }
public SmartContractMempoolValidator(ITxMempool memPool, MempoolSchedulerLock mempoolLock, IDateTimeProvider dateTimeProvider, MempoolSettings mempoolSettings, ConcurrentChain chain, ICoinView coinView, ILoggerFactory loggerFactory, NodeSettings nodeSettings, IConsensusRuleEngine consensusRules, ICallDataSerializer callDataSerializer, Network network, IStateRepositoryRoot stateRepositoryRoot) : base(memPool, mempoolLock, dateTimeProvider, mempoolSettings, chain, coinView, loggerFactory, nodeSettings, consensusRules) { // Dirty hack, but due to AllowedScriptTypeRule we don't need to check for standard scripts on any network, even live. // TODO: Remove ASAP. Ensure RequireStandard isn't used on SC mainnets, or the StandardScripts check is modular. mempoolSettings.RequireStandard = false; this.callDataSerializer = callDataSerializer; this.stateRepositoryRoot = stateRepositoryRoot; var p2pkhRule = new P2PKHNotContractRule(stateRepositoryRoot); var scriptTypeRule = new AllowedScriptTypeRule(network); scriptTypeRule.Initialize(); this.preTxRules = new List <ISmartContractMempoolRule> { new MempoolOpSpendRule(), new TxOutSmartContractExecRule(), scriptTypeRule, p2pkhRule }; // TODO: Tidy this up. Rules should be injected? Shouldn't be generating here based on Network. var txChecks = new List <IContractTransactionValidationLogic> { new SmartContractFormatLogic() }; if (network is ISignedCodePubKeyHolder holder) { txChecks.Add(new ContractSignedCodeLogic(new ContractSigner(), holder.SigningContractPubKey)); } this.feeTxRules = new List <ISmartContractMempoolRule>() { new ContractTransactionValidationRule(this.callDataSerializer, txChecks) }; }
public void SendTo_Contract_Fails() { uint160 contractAddress = new uint160(123); var state = new Mock <IStateRepositoryRoot>(); state.Setup(x => x.GetAccountState(contractAddress)).Returns(new AccountState()); // not null this.rulesEngine.OriginalStateRoot = state.Object; var rule = new P2PKHNotContractRule(); rule.Parent = this.rulesEngine; rule.Initialize(); Transaction transaction = this.network.CreateTransaction(); transaction.Outputs.Add(new TxOut(100, PayToPubkeyHashTemplate.Instance.GenerateScriptPubKey(new KeyId(contractAddress)))); Assert.Throws <ConsensusErrorException>(() => rule.CheckTransaction(new MempoolValidationContext(transaction, null))); }
public void SendTo_NotAContract_Success() { uint160 walletAddress = new uint160(321); var state = new Mock <IStateRepositoryRoot>(); state.Setup(x => x.GetAccountState(walletAddress)).Returns <AccountState>(null); this.rulesEngine.OriginalStateRoot = state.Object; var rule = new P2PKHNotContractRule(); rule.Parent = this.rulesEngine; rule.Initialize(); Transaction transaction = this.network.CreateTransaction(); transaction.Outputs.Add(new TxOut(100, PayToPubkeyHashTemplate.Instance.GenerateScriptPubKey(new KeyId(walletAddress)))); rule.CheckTransaction(new MempoolValidationContext(transaction, null)); }
public SmartContractMempoolValidator(ITxMempool memPool, MempoolSchedulerLock mempoolLock, IDateTimeProvider dateTimeProvider, MempoolSettings mempoolSettings, ConcurrentChain chain, ICoinView coinView, ILoggerFactory loggerFactory, NodeSettings nodeSettings, IConsensusRules consensusRules) : base(memPool, mempoolLock, dateTimeProvider, mempoolSettings, chain, coinView, loggerFactory, nodeSettings, consensusRules) { var p2pkhRule = new P2PKHNotContractRule(); p2pkhRule.Parent = (ConsensusRules)consensusRules; p2pkhRule.Initialize(); this.preTxRules = new List <ISmartContractMempoolRule> { new MempoolOpSpendRule(), new TxOutSmartContractExecRule(), p2pkhRule }; this.feeTxRules = new List <ISmartContractMempoolRule>() { new SmartContractFormatRule(), }; }
public SmartContractMempoolValidator(ITxMempool memPool, MempoolSchedulerLock mempoolLock, IDateTimeProvider dateTimeProvider, MempoolSettings mempoolSettings, ChainIndexer chainIndexer, ICoinView coinView, ILoggerFactory loggerFactory, NodeSettings nodeSettings, IConsensusRuleEngine consensusRules, ICallDataSerializer callDataSerializer, Network network, IStateRepositoryRoot stateRepositoryRoot, IEnumerable <IContractTransactionFullValidationRule> txFullValidationRules) : base(memPool, mempoolLock, dateTimeProvider, mempoolSettings, chainIndexer, coinView, loggerFactory, nodeSettings, consensusRules) { // Dirty hack, but due to AllowedScriptTypeRule we don't need to check for standard scripts on any network, even live. // TODO: Remove ASAP. Ensure RequireStandard isn't used on SC mainnets, or the StandardScripts check is modular. mempoolSettings.RequireStandard = false; this.callDataSerializer = callDataSerializer; this.stateRepositoryRoot = stateRepositoryRoot; var p2pkhRule = new P2PKHNotContractRule(stateRepositoryRoot); var scriptTypeRule = new AllowedScriptTypeRule(network); scriptTypeRule.Initialize(); this.preTxRules = new List <ISmartContractMempoolRule> { new MempoolOpSpendRule(), new TxOutSmartContractExecRule(), scriptTypeRule, p2pkhRule }; var txChecks = new List <IContractTransactionPartialValidationRule>() { new SmartContractFormatLogic() }; this.feeTxRules = new List <ISmartContractMempoolRule>() { new ContractTransactionPartialValidationRule(this.callDataSerializer, txChecks), new ContractTransactionFullValidationRule(this.callDataSerializer, txFullValidationRules) }; }
public override void CheckTransaction(MempoolValidationContext context) { P2PKHNotContractRule.CheckTransaction(this.stateRepositoryRoot, context.Transaction); }