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 AllowedScriptTypesRuleTest() { this.network = new SmartContractsRegTest(); var loggerFactory = new Mock <ILoggerFactory>(); var dateTimeProvider = new Mock <IDateTimeProvider>(); var chain = new Mock <ConcurrentChain>(); var nodeDeployments = new Mock <NodeDeployments>(); var consensusSettings = new ConsensusSettings(NodeSettings.Default(this.network)); var checkpoints = new Mock <ICheckpoints>(); var coinView = new Mock <ICoinView>(); var chainState = new Mock <ChainState>(); var invalidBlockHashStore = new Mock <IInvalidBlockHashStore>(); this.rulesEngine = new TestContractRulesEngine(this.network, loggerFactory.Object, dateTimeProvider.Object, chain.Object, new NodeDeployments(this.network, chain.Object), consensusSettings, checkpoints.Object, coinView.Object, chainState.Object, invalidBlockHashStore.Object, new NodeStats(new DateTimeProvider()) ); this.rule = new AllowedScriptTypeRule { Parent = this.rulesEngine }; rule.Initialize(); }
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 OpSpendInput_OpInternalTransferOutput_Passes() { Transaction transaction = this.network.CreateTransaction(); transaction.Inputs.Add(new TxIn(new Script(new byte[] { (byte)ScOpcodeType.OP_SPEND }))); transaction.Outputs.Add(new TxOut(100, new Script(new byte[] { (byte)ScOpcodeType.OP_INTERNALCONTRACTTRANSFER }))); // No exception when checking AllowedScriptTypeRule.CheckTransaction(this.network, transaction); }
public void P2PKHInput_P2PKHOutput_Passes() { Transaction transaction = this.network.CreateTransaction(); transaction.Inputs.Add(GetP2PKHInput()); transaction.Outputs.Add(new TxOut(100, PayToPubkeyHashTemplate.Instance.GenerateScriptPubKey(new KeyId()))); // No exception when checking AllowedScriptTypeRule.CheckTransaction(this.network, transaction); }
public void P2PKHInput_SmartContractCreateOutput_Passes() { Transaction transaction = this.network.CreateTransaction(); transaction.Inputs.Add(GetP2PKHInput()); transaction.Outputs.Add(new TxOut(100, new Script(new byte[] { (byte)ScOpcodeType.OP_CREATECONTRACT, 1, 2, 3 }))); // No exception when checking AllowedScriptTypeRule.CheckTransaction(this.network, transaction); }
public void MultiSigInput_P2PKHOutput_Passes() { // This occurs when receiving funds from the federation on our sidechain Transaction transaction = this.network.CreateTransaction(); Script scriptSig = PayToMultiSigTemplate.Instance.GenerateScriptSig(new TransactionSignature[] { new Key().Sign(new uint256(0), SigHash.All), new Key().Sign(new uint256(0), SigHash.All) }); transaction.Inputs.Add(new TxIn(scriptSig)); transaction.Outputs.Add(new TxOut(100, PayToPubkeyHashTemplate.Instance.GenerateScriptPubKey(new KeyId()))); // No exception when checking AllowedScriptTypeRule.CheckTransaction(this.network, transaction); }
public void P2PKHInput_MultiSigOutput_Passes_With_Federation() { // This occurs when sending funds to the federation on our sidechain Transaction transaction = this.network.CreateTransaction(); transaction.Inputs.Add(GetP2PKHInput()); Script script = PayToFederationTemplate.Instance.GenerateScriptPubKey(new FederationId(new byte[10])); transaction.Outputs.Add(new TxOut(100, script)); // No exception when checking AllowedScriptTypeRule.CheckTransaction(this.network, 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 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 void Actual_Withdrawal_Passes() { Transaction withdrawal = new SmartContractsPoARegTest().CreateTransaction("01000000019eb9793f7c69bd31d4b03518f349e70384f8f20456556b4be0f941dbaebec9d400000000fdfe0000483045022100f6d3d20ebfe9b336a1432e06365c549a3dac5b411cb0fe2cd6dd46b09530adf202206e65df4c8f18f66f65409652463300c8b1b90ad69486c9ebabd58987baeeb7fd01483045022100e399eec964ccc1d99b1a0b285031284e7c4a4b0aa678dd52ea4698973c326622022011814dddddcd4a43fd4a223509de4815e2d687814c5fc5abde68ec3801026fe1014c69522102eef7619de25578c9717a289d08c61d4598b2bd81d2ee5db3072a07fa2d121e6521027ce19209dd1212a6a4fc2b7ddf678c6dea40b596457f934f73f3dcc5d0d9ee552103093239d5344ddb4c69c46c75bd629519e0b68d2cfc1a86cd63115fd068f202ba53aeffffffff03c0dc8743fd1a070017a91442938bb61378468a38629c4ffa1521759d0283578700e1f505000000001976a9148732134e7953ebfe51f65d455612a4245f9610ae88ac0000000000000000226a2009422af22360465d208f70e4c86284e538706db5db5dae1c2c4fcad5eef928eb00000000"); AllowedScriptTypeRule.CheckTransaction(this.network, withdrawal); }
public AllowedScriptTypesRuleTest() { this.network = new SmartContractsRegTest(); this.rule = new AllowedScriptTypeRule(this.network); }
/// <inheritdoc/> public override void CheckTransaction(MempoolValidationContext context) { AllowedScriptTypeRule.CheckTransaction(this.network, context.Transaction); }