aboutsummaryrefslogtreecommitdiff
path: root/build_msvc/testconsensus/testconsensus.cpp
diff options
context:
space:
mode:
authorAaron Clauson <aaron@sipsorcery.com>2018-08-10 09:19:00 +0200
committerAaron Clauson <aaron@sipsorcery.com>2018-08-10 09:19:00 +0200
commitef7beaea6abcaab389ccb486a8f25bc4512b99ed (patch)
tree86223ae2f6c0eb342bc03bf1b5e77cbeb5ecb0be /build_msvc/testconsensus/testconsensus.cpp
parentf66e1c793eda7a6143fd03400c98512a9b6f00c7 (diff)
Visual Studio build configuration for Bitcoin Core
Diffstat (limited to 'build_msvc/testconsensus/testconsensus.cpp')
-rw-r--r--build_msvc/testconsensus/testconsensus.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/build_msvc/testconsensus/testconsensus.cpp b/build_msvc/testconsensus/testconsensus.cpp
new file mode 100644
index 0000000000..0068f588cc
--- /dev/null
+++ b/build_msvc/testconsensus/testconsensus.cpp
@@ -0,0 +1,50 @@
+#include <iostream>
+
+// bitcoin includes.
+#include <..\src\script\bitcoinconsensus.h>
+#include <..\src\primitives\transaction.h>
+#include <..\src\script\script.h>
+#include <..\src\streams.h>
+#include <..\src\version.h>
+
+CMutableTransaction BuildSpendingTransaction(const CScript& scriptSig, const CScriptWitness& scriptWitness, int nValue = 0)
+{
+ CMutableTransaction txSpend;
+ txSpend.nVersion = 1;
+ txSpend.nLockTime = 0;
+ txSpend.vin.resize(1);
+ txSpend.vout.resize(1);
+ txSpend.vin[0].scriptWitness = scriptWitness;
+ txSpend.vin[0].prevout.hash = uint256();
+ txSpend.vin[0].prevout.n = 0;
+ txSpend.vin[0].scriptSig = scriptSig;
+ txSpend.vin[0].nSequence = CTxIn::SEQUENCE_FINAL;
+ txSpend.vout[0].scriptPubKey = CScript();
+ txSpend.vout[0].nValue = nValue;
+
+ return txSpend;
+}
+
+int main()
+{
+ std::cout << "bitcoinconsensus version: " << bitcoinconsensus_version() << std::endl;
+
+ CScript pubKeyScript;
+ pubKeyScript << OP_1 << OP_0 << OP_1;
+
+ int amount = 0; // 600000000;
+
+ CScript scriptSig;
+ CScriptWitness scriptWitness;
+ CTransaction vanillaSpendTx = BuildSpendingTransaction(scriptSig, scriptWitness, amount);
+ CDataStream stream(SER_NETWORK, PROTOCOL_VERSION);
+ stream << vanillaSpendTx;
+
+ bitcoinconsensus_error err;
+ auto op0Result = bitcoinconsensus_verify_script_with_amount(pubKeyScript.data(), pubKeyScript.size(), amount, (const unsigned char*)&stream[0], stream.size(), 0, bitcoinconsensus_SCRIPT_FLAGS_VERIFY_ALL, &err);
+ std::cout << "Op0 result: " << op0Result << ", error code " << err << std::endl;
+
+ getchar();
+
+ return 0;
+}