@leocuvee/wrkzcoin-multi-hashing 0.0.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (314) hide show
  1. package/.travis.yml +5 -0
  2. package/LICENSE +674 -0
  3. package/README.md +87 -0
  4. package/appveyor.yml +12 -0
  5. package/argon2/.gitattributes +10 -0
  6. package/argon2/.travis.yml +25 -0
  7. package/argon2/Argon2.sln +160 -0
  8. package/argon2/CHANGELOG.md +32 -0
  9. package/argon2/CMakeLists.txt +87 -0
  10. package/argon2/LICENSE +314 -0
  11. package/argon2/Makefile +196 -0
  12. package/argon2/README.md +297 -0
  13. package/argon2/appveyor.yml +40 -0
  14. package/argon2/argon2-specs.pdf +0 -0
  15. package/argon2/export.sh +7 -0
  16. package/argon2/include/argon2.h +427 -0
  17. package/argon2/latex/CMakeLists.txt +34 -0
  18. package/argon2/latex/IEEEtran.cls +6347 -0
  19. package/argon2/latex/Makefile +18 -0
  20. package/argon2/latex/argon2-specs.tex +920 -0
  21. package/argon2/latex/pics/argon2-par.pdf +0 -0
  22. package/argon2/latex/pics/compression.pdf +0 -0
  23. package/argon2/latex/pics/generic.pdf +0 -0
  24. package/argon2/latex/pics/power-distribution.jpg +0 -0
  25. package/argon2/latex/tradeoff.bib +822 -0
  26. package/argon2/libargon2.pc +16 -0
  27. package/argon2/man/CMakeLists.txt +8 -0
  28. package/argon2/man/argon2.1 +57 -0
  29. package/argon2/meson.build +16 -0
  30. package/argon2/meson_options.txt +1 -0
  31. package/argon2/src/CMakeLists.txt +147 -0
  32. package/argon2/src/argon2.c +452 -0
  33. package/argon2/src/argon2.pc.in +11 -0
  34. package/argon2/src/blake2/blake2-impl.h +156 -0
  35. package/argon2/src/blake2/blake2.h +89 -0
  36. package/argon2/src/blake2/blake2b.c +390 -0
  37. package/argon2/src/blake2/blamka-round-opt.h +471 -0
  38. package/argon2/src/blake2/blamka-round-ref.h +56 -0
  39. package/argon2/src/core.c +634 -0
  40. package/argon2/src/core.h +228 -0
  41. package/argon2/src/encoding.c +467 -0
  42. package/argon2/src/encoding.h +57 -0
  43. package/argon2/src/genkat.h +51 -0
  44. package/argon2/src/meson.build +68 -0
  45. package/argon2/src/opt.c +283 -0
  46. package/argon2/src/optimization/CMakeLists.txt +10 -0
  47. package/argon2/src/ref.c +194 -0
  48. package/argon2/src/thread.c +57 -0
  49. package/argon2/src/thread.h +67 -0
  50. package/argon2/tests/CMakeLists.txt +43 -0
  51. package/argon2/tests/bench.c +111 -0
  52. package/argon2/tests/genkat.c +207 -0
  53. package/argon2/tests/kats/argon2d +12304 -0
  54. package/argon2/tests/kats/argon2d.shasum +1 -0
  55. package/argon2/tests/kats/argon2d_v16 +12304 -0
  56. package/argon2/tests/kats/argon2d_v16.shasum +1 -0
  57. package/argon2/tests/kats/argon2i +12304 -0
  58. package/argon2/tests/kats/argon2i.shasum +1 -0
  59. package/argon2/tests/kats/argon2i_v16 +12304 -0
  60. package/argon2/tests/kats/argon2i_v16.shasum +1 -0
  61. package/argon2/tests/kats/argon2id +12304 -0
  62. package/argon2/tests/kats/argon2id.shasum +1 -0
  63. package/argon2/tests/kats/argon2id_v16 +12304 -0
  64. package/argon2/tests/kats/argon2id_v16.shasum +1 -0
  65. package/argon2/tests/kats/check-sums.ps1 +48 -0
  66. package/argon2/tests/kats/check-sums.sh +16 -0
  67. package/argon2/tests/kats/test.ps1 +132 -0
  68. package/argon2/tests/kats/test.sh +117 -0
  69. package/argon2/tests/meson.build +34 -0
  70. package/argon2/tests/test.c +289 -0
  71. package/argon2/tool/CMakeLists.txt +7 -0
  72. package/argon2/tool/main.c +339 -0
  73. package/argon2/tool/meson.build +8 -0
  74. package/argon2/vs2015/Argon2Opt/Argon2Opt.vcxproj +226 -0
  75. package/argon2/vs2015/Argon2Opt/Argon2Opt.vcxproj.filters +69 -0
  76. package/argon2/vs2015/Argon2OptBench/Argon2OptBench.vcxproj +226 -0
  77. package/argon2/vs2015/Argon2OptBench/Argon2OptBench.vcxproj.filters +69 -0
  78. package/argon2/vs2015/Argon2OptDll/Argon2OptDll.vcxproj +225 -0
  79. package/argon2/vs2015/Argon2OptDll/Argon2OptDll.vcxproj.filters +66 -0
  80. package/argon2/vs2015/Argon2OptGenKAT/Argon2OptGenKAT.vcxproj +239 -0
  81. package/argon2/vs2015/Argon2OptGenKAT/Argon2OptGenKAT.vcxproj.filters +72 -0
  82. package/argon2/vs2015/Argon2OptTestCI/Argon2OptTestCI.vcxproj +227 -0
  83. package/argon2/vs2015/Argon2OptTestCI/Argon2OptTestCI.vcxproj.filters +69 -0
  84. package/argon2/vs2015/Argon2Ref/Argon2Ref.vcxproj +226 -0
  85. package/argon2/vs2015/Argon2Ref/Argon2Ref.vcxproj.filters +69 -0
  86. package/argon2/vs2015/Argon2RefBench/Argon2RefBench.vcxproj +226 -0
  87. package/argon2/vs2015/Argon2RefBench/Argon2RefBench.vcxproj.filters +69 -0
  88. package/argon2/vs2015/Argon2RefDll/Argon2RefDll.vcxproj +225 -0
  89. package/argon2/vs2015/Argon2RefDll/Argon2RefDll.vcxproj.filters +66 -0
  90. package/argon2/vs2015/Argon2RefGenKAT/Argon2RefGenKAT.vcxproj +227 -0
  91. package/argon2/vs2015/Argon2RefGenKAT/Argon2RefGenKAT.vcxproj.filters +72 -0
  92. package/argon2/vs2015/Argon2RefTestCI/Argon2RefTestCI.vcxproj +226 -0
  93. package/argon2/vs2015/Argon2RefTestCI/Argon2RefTestCI.vcxproj.filters +69 -0
  94. package/bcrypt.c +566 -0
  95. package/bcrypt.h +14 -0
  96. package/binding.gyp +93 -0
  97. package/blake.c +17 -0
  98. package/blake.h +16 -0
  99. package/boolberry.cc +11 -0
  100. package/boolberry.h +6 -0
  101. package/build/Makefile +354 -0
  102. package/build/Release/.deps/Release/multihashing.node.d +1 -0
  103. package/build/Release/.deps/Release/obj.target/multihashing/argon2/src/argon2.o.d +8 -0
  104. package/build/Release/.deps/Release/obj.target/multihashing/argon2/src/blake2/blake2b.o.d +8 -0
  105. package/build/Release/.deps/Release/obj.target/multihashing/argon2/src/core.o.d +10 -0
  106. package/build/Release/.deps/Release/obj.target/multihashing/argon2/src/encoding.o.d +8 -0
  107. package/build/Release/.deps/Release/obj.target/multihashing/argon2/src/ref.o.d +14 -0
  108. package/build/Release/.deps/Release/obj.target/multihashing/argon2/src/thread.o.d +5 -0
  109. package/build/Release/.deps/Release/obj.target/multihashing/bcrypt.o.d +4 -0
  110. package/build/Release/.deps/Release/obj.target/multihashing/blake.o.d +7 -0
  111. package/build/Release/.deps/Release/obj.target/multihashing/boolberry.o.d +12 -0
  112. package/build/Release/.deps/Release/obj.target/multihashing/c11.o.d +20 -0
  113. package/build/Release/.deps/Release/obj.target/multihashing/crypto/aesb.o.d +3 -0
  114. package/build/Release/.deps/Release/obj.target/multihashing/crypto/c_blake256.o.d +5 -0
  115. package/build/Release/.deps/Release/obj.target/multihashing/crypto/c_groestl.o.d +10 -0
  116. package/build/Release/.deps/Release/obj.target/multihashing/crypto/c_jh.o.d +9 -0
  117. package/build/Release/.deps/Release/obj.target/multihashing/crypto/c_keccak.o.d +7 -0
  118. package/build/Release/.deps/Release/obj.target/multihashing/crypto/c_skein.o.d +10 -0
  119. package/build/Release/.deps/Release/obj.target/multihashing/crypto/hash.o.d +7 -0
  120. package/build/Release/.deps/Release/obj.target/multihashing/crypto/oaes_lib.o.d +6 -0
  121. package/build/Release/.deps/Release/obj.target/multihashing/crypto/wild_keccak.o.d +8 -0
  122. package/build/Release/.deps/Release/obj.target/multihashing/cryptonight.o.d +18 -0
  123. package/build/Release/.deps/Release/obj.target/multihashing/cryptonight_dark.o.d +18 -0
  124. package/build/Release/.deps/Release/obj.target/multihashing/cryptonight_dark_lite.o.d +18 -0
  125. package/build/Release/.deps/Release/obj.target/multihashing/cryptonight_fast.o.d +18 -0
  126. package/build/Release/.deps/Release/obj.target/multihashing/cryptonight_lite.o.d +18 -0
  127. package/build/Release/.deps/Release/obj.target/multihashing/cryptonight_soft_shell.o.d +18 -0
  128. package/build/Release/.deps/Release/obj.target/multihashing/cryptonight_turtle.o.d +18 -0
  129. package/build/Release/.deps/Release/obj.target/multihashing/cryptonight_turtle_lite.o.d +18 -0
  130. package/build/Release/.deps/Release/obj.target/multihashing/fresh.o.d +10 -0
  131. package/build/Release/.deps/Release/obj.target/multihashing/fugue.o.d +7 -0
  132. package/build/Release/.deps/Release/obj.target/multihashing/groestl.o.d +8 -0
  133. package/build/Release/.deps/Release/obj.target/multihashing/hefty1.o.d +12 -0
  134. package/build/Release/.deps/Release/obj.target/multihashing/keccak.o.d +8 -0
  135. package/build/Release/.deps/Release/obj.target/multihashing/multihashing.o.d +155 -0
  136. package/build/Release/.deps/Release/obj.target/multihashing/nist5.o.d +12 -0
  137. package/build/Release/.deps/Release/obj.target/multihashing/quark.o.d +14 -0
  138. package/build/Release/.deps/Release/obj.target/multihashing/qubit.o.d +12 -0
  139. package/build/Release/.deps/Release/obj.target/multihashing/scryptjane.o.d +30 -0
  140. package/build/Release/.deps/Release/obj.target/multihashing/scryptn.o.d +6 -0
  141. package/build/Release/.deps/Release/obj.target/multihashing/sha1.o.d +24 -0
  142. package/build/Release/.deps/Release/obj.target/multihashing/sha3/aes_helper.o.d +5 -0
  143. package/build/Release/.deps/Release/obj.target/multihashing/sha3/hamsi.o.d +7 -0
  144. package/build/Release/.deps/Release/obj.target/multihashing/sha3/sph_blake.o.d +6 -0
  145. package/build/Release/.deps/Release/obj.target/multihashing/sha3/sph_bmw.o.d +6 -0
  146. package/build/Release/.deps/Release/obj.target/multihashing/sha3/sph_cubehash.o.d +6 -0
  147. package/build/Release/.deps/Release/obj.target/multihashing/sha3/sph_echo.o.d +7 -0
  148. package/build/Release/.deps/Release/obj.target/multihashing/sha3/sph_fugue.o.d +6 -0
  149. package/build/Release/.deps/Release/obj.target/multihashing/sha3/sph_groestl.o.d +6 -0
  150. package/build/Release/.deps/Release/obj.target/multihashing/sha3/sph_hefty1.o.d +5 -0
  151. package/build/Release/.deps/Release/obj.target/multihashing/sha3/sph_jh.o.d +6 -0
  152. package/build/Release/.deps/Release/obj.target/multihashing/sha3/sph_keccak.o.d +6 -0
  153. package/build/Release/.deps/Release/obj.target/multihashing/sha3/sph_luffa.o.d +6 -0
  154. package/build/Release/.deps/Release/obj.target/multihashing/sha3/sph_shabal.o.d +6 -0
  155. package/build/Release/.deps/Release/obj.target/multihashing/sha3/sph_shavite.o.d +7 -0
  156. package/build/Release/.deps/Release/obj.target/multihashing/sha3/sph_simd.o.d +6 -0
  157. package/build/Release/.deps/Release/obj.target/multihashing/sha3/sph_skein.o.d +6 -0
  158. package/build/Release/.deps/Release/obj.target/multihashing/sha3/sph_whirlpool.o.d +8 -0
  159. package/build/Release/.deps/Release/obj.target/multihashing/shavite3.o.d +7 -0
  160. package/build/Release/.deps/Release/obj.target/multihashing/skein.o.d +8 -0
  161. package/build/Release/.deps/Release/obj.target/multihashing/x11.o.d +20 -0
  162. package/build/Release/.deps/Release/obj.target/multihashing/x13.o.d +23 -0
  163. package/build/Release/.deps/Release/obj.target/multihashing/x15.o.d +26 -0
  164. package/build/Release/.deps/Release/obj.target/multihashing.node.d +1 -0
  165. package/build/Release/multihashing.node +0 -0
  166. package/build/binding.Makefile +6 -0
  167. package/build/multihashing.target.mk +255 -0
  168. package/c11.c +85 -0
  169. package/c11.h +17 -0
  170. package/crypto/aesb.c +177 -0
  171. package/crypto/c_blake256.c +326 -0
  172. package/crypto/c_blake256.h +43 -0
  173. package/crypto/c_groestl.c +360 -0
  174. package/crypto/c_groestl.h +56 -0
  175. package/crypto/c_jh.c +367 -0
  176. package/crypto/c_jh.h +20 -0
  177. package/crypto/c_keccak.c +112 -0
  178. package/crypto/c_keccak.h +26 -0
  179. package/crypto/c_skein.c +2036 -0
  180. package/crypto/c_skein.h +45 -0
  181. package/crypto/crypto.h +186 -0
  182. package/crypto/cryptonote_core/account.cpp +50 -0
  183. package/crypto/cryptonote_core/account.h +61 -0
  184. package/crypto/cryptonote_core/cryptonote_basic_impl.cpp +186 -0
  185. package/crypto/cryptonote_core/cryptonote_basic_impl.h +65 -0
  186. package/crypto/cryptonote_core/cryptonote_format_utils.cpp +766 -0
  187. package/crypto/cryptonote_core/cryptonote_format_utils.h +30 -0
  188. package/crypto/cryptonote_protocol/cryptonote_protocol_defs.h +152 -0
  189. package/crypto/groestl_tables.h +38 -0
  190. package/crypto/hash-ops.h +57 -0
  191. package/crypto/hash.c +24 -0
  192. package/crypto/hash.h +22 -0
  193. package/crypto/int-util.h +230 -0
  194. package/crypto/oaes_config.h +50 -0
  195. package/crypto/oaes_lib.c +1468 -0
  196. package/crypto/oaes_lib.h +215 -0
  197. package/crypto/skein_port.h +190 -0
  198. package/crypto/variant2_int_sqrt.h +168 -0
  199. package/crypto/wild_keccak.cpp +119 -0
  200. package/crypto/wild_keccak.h +168 -0
  201. package/cryptonight.c +300 -0
  202. package/cryptonight.h +17 -0
  203. package/cryptonight_dark.c +300 -0
  204. package/cryptonight_dark.h +17 -0
  205. package/cryptonight_dark_lite.c +300 -0
  206. package/cryptonight_dark_lite.h +17 -0
  207. package/cryptonight_fast.c +300 -0
  208. package/cryptonight_fast.h +17 -0
  209. package/cryptonight_lite.c +300 -0
  210. package/cryptonight_lite.h +17 -0
  211. package/cryptonight_soft_shell.c +298 -0
  212. package/cryptonight_soft_shell.h +17 -0
  213. package/cryptonight_turtle.c +300 -0
  214. package/cryptonight_turtle.h +17 -0
  215. package/cryptonight_turtle_lite.c +300 -0
  216. package/cryptonight_turtle_lite.h +17 -0
  217. package/fresh.c +42 -0
  218. package/fresh.h +16 -0
  219. package/fugue.c +12 -0
  220. package/fugue.h +16 -0
  221. package/groestl.c +40 -0
  222. package/groestl.h +17 -0
  223. package/hefty1.c +63 -0
  224. package/hefty1.h +16 -0
  225. package/index.js +1 -0
  226. package/keccak.c +14 -0
  227. package/keccak.h +16 -0
  228. package/leocuvee-wrkzcoin-multi-hashing-0.0.20.tgz +0 -0
  229. package/multihashing.cc +699 -0
  230. package/nist5.c +46 -0
  231. package/nist5.h +16 -0
  232. package/package.json +56 -0
  233. package/quark.c +210 -0
  234. package/quark.h +16 -0
  235. package/qubit.c +45 -0
  236. package/qubit.h +16 -0
  237. package/scryptjane/scrypt-jane-chacha.h +132 -0
  238. package/scryptjane/scrypt-jane-hash.h +48 -0
  239. package/scryptjane/scrypt-jane-hash_keccak.h +168 -0
  240. package/scryptjane/scrypt-jane-hash_sha256.h +135 -0
  241. package/scryptjane/scrypt-jane-mix_chacha-avx.h +340 -0
  242. package/scryptjane/scrypt-jane-mix_chacha-sse2.h +371 -0
  243. package/scryptjane/scrypt-jane-mix_chacha-ssse3.h +348 -0
  244. package/scryptjane/scrypt-jane-mix_chacha.h +69 -0
  245. package/scryptjane/scrypt-jane-mix_salsa-avx.h +381 -0
  246. package/scryptjane/scrypt-jane-mix_salsa-sse2.h +443 -0
  247. package/scryptjane/scrypt-jane-mix_salsa.h +70 -0
  248. package/scryptjane/scrypt-jane-pbkdf2.h +112 -0
  249. package/scryptjane/scrypt-jane-portable-x86.h +364 -0
  250. package/scryptjane/scrypt-jane-portable.h +281 -0
  251. package/scryptjane/scrypt-jane-romix-basic.h +67 -0
  252. package/scryptjane/scrypt-jane-romix-template.h +118 -0
  253. package/scryptjane/scrypt-jane-romix.h +27 -0
  254. package/scryptjane/scrypt-jane-salsa.h +106 -0
  255. package/scryptjane/scrypt-jane-test-vectors.h +261 -0
  256. package/scryptjane.c +223 -0
  257. package/scryptjane.h +36 -0
  258. package/scryptn.c +258 -0
  259. package/scryptn.h +16 -0
  260. package/sha1.c +65 -0
  261. package/sha1.h +16 -0
  262. package/sha256.h +440 -0
  263. package/sha3/aes_helper.c +392 -0
  264. package/sha3/hamsi.c +867 -0
  265. package/sha3/hamsi_helper.c +39648 -0
  266. package/sha3/md_helper.c +347 -0
  267. package/sha3/sph_blake.c +1114 -0
  268. package/sha3/sph_blake.h +327 -0
  269. package/sha3/sph_bmw.c +965 -0
  270. package/sha3/sph_bmw.h +328 -0
  271. package/sha3/sph_cubehash.c +723 -0
  272. package/sha3/sph_cubehash.h +292 -0
  273. package/sha3/sph_echo.c +1031 -0
  274. package/sha3/sph_echo.h +320 -0
  275. package/sha3/sph_fugue.c +1208 -0
  276. package/sha3/sph_fugue.h +81 -0
  277. package/sha3/sph_groestl.c +3119 -0
  278. package/sha3/sph_groestl.h +329 -0
  279. package/sha3/sph_hamsi.h +321 -0
  280. package/sha3/sph_hefty1.c +378 -0
  281. package/sha3/sph_hefty1.h +66 -0
  282. package/sha3/sph_jh.c +1116 -0
  283. package/sha3/sph_jh.h +298 -0
  284. package/sha3/sph_keccak.c +1824 -0
  285. package/sha3/sph_keccak.h +293 -0
  286. package/sha3/sph_luffa.c +1426 -0
  287. package/sha3/sph_luffa.h +296 -0
  288. package/sha3/sph_shabal.c +806 -0
  289. package/sha3/sph_shabal.h +344 -0
  290. package/sha3/sph_shavite.c +1764 -0
  291. package/sha3/sph_shavite.h +314 -0
  292. package/sha3/sph_simd.c +1799 -0
  293. package/sha3/sph_simd.h +309 -0
  294. package/sha3/sph_skein.c +1254 -0
  295. package/sha3/sph_skein.h +298 -0
  296. package/sha3/sph_types.h +1976 -0
  297. package/sha3/sph_whirlpool.c +3480 -0
  298. package/sha3/sph_whirlpool.h +209 -0
  299. package/shavite3.c +24 -0
  300. package/shavite3.h +16 -0
  301. package/skein.c +26 -0
  302. package/skein.h +16 -0
  303. package/stdint.h +259 -0
  304. package/tests/argon2-tests.js +16 -0
  305. package/tests/benchmark.js +36 -0
  306. package/tests/cryptonight-tests.js +189 -0
  307. package/tests/cryptonight_monero.js +53 -0
  308. package/tests/test.js +16 -0
  309. package/x11.c +85 -0
  310. package/x11.h +16 -0
  311. package/x13.c +97 -0
  312. package/x13.h +5 -0
  313. package/x15.c +106 -0
  314. package/x15.h +16 -0
@@ -0,0 +1,766 @@
1
+ // Copyright (c) 2012-2013 The Cryptonote developers
2
+ // Distributed under the MIT/X11 software license, see the accompanying
3
+ // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
+
5
+ #include "include_base_utils.h"
6
+ using namespace epee;
7
+
8
+ #include "cryptonote_format_utils.h"
9
+ #include <boost/foreach.hpp>
10
+ #include "cryptonote_config.h"
11
+ #include "miner.h"
12
+ #include "crypto/crypto.h"
13
+ #include "crypto/hash.h"
14
+
15
+ namespace cryptonote
16
+ {
17
+ //---------------------------------------------------------------
18
+ void get_transaction_prefix_hash(const transaction_prefix& tx, crypto::hash& h)
19
+ {
20
+ std::ostringstream s;
21
+ binary_archive<true> a(s);
22
+ ::serialization::serialize(a, const_cast<transaction_prefix&>(tx));
23
+ crypto::cn_fast_hash(s.str().data(), s.str().size(), h);
24
+ }
25
+ //---------------------------------------------------------------
26
+ crypto::hash get_transaction_prefix_hash(const transaction_prefix& tx)
27
+ {
28
+ crypto::hash h = null_hash;
29
+ get_transaction_prefix_hash(tx, h);
30
+ return h;
31
+ }
32
+ //---------------------------------------------------------------
33
+ bool parse_and_validate_tx_from_blob(const blobdata& tx_blob, transaction& tx)
34
+ {
35
+ std::stringstream ss;
36
+ ss << tx_blob;
37
+ binary_archive<false> ba(ss);
38
+ bool r = ::serialization::serialize(ba, tx);
39
+ CHECK_AND_ASSERT_MES(r, false, "Failed to parse transaction from blob");
40
+ return true;
41
+ }
42
+ //---------------------------------------------------------------
43
+ bool parse_and_validate_tx_from_blob(const blobdata& tx_blob, transaction& tx, crypto::hash& tx_hash, crypto::hash& tx_prefix_hash)
44
+ {
45
+ std::stringstream ss;
46
+ ss << tx_blob;
47
+ binary_archive<false> ba(ss);
48
+ bool r = ::serialization::serialize(ba, tx);
49
+ CHECK_AND_ASSERT_MES(r, false, "Failed to parse transaction from blob");
50
+ //TODO: validate tx
51
+
52
+ crypto::cn_fast_hash(tx_blob.data(), tx_blob.size(), tx_hash);
53
+ get_transaction_prefix_hash(tx, tx_prefix_hash);
54
+ return true;
55
+ }
56
+ //---------------------------------------------------------------
57
+ bool construct_miner_tx(size_t height, size_t median_size, uint64_t already_generated_coins, size_t current_block_size, uint64_t fee, const account_public_address &miner_address, transaction& tx, const blobdata& extra_nonce, size_t max_outs) {
58
+ tx.vin.clear();
59
+ tx.vout.clear();
60
+ tx.extra.clear();
61
+
62
+ keypair txkey = keypair::generate();
63
+ add_tx_pub_key_to_extra(tx, txkey.pub);
64
+ if(!extra_nonce.empty())
65
+ if(!add_extra_nonce_to_tx_extra(tx.extra, extra_nonce))
66
+ return false;
67
+
68
+ txin_gen in;
69
+ in.height = height;
70
+
71
+ uint64_t block_reward;
72
+ if(!get_block_reward(median_size, current_block_size, already_generated_coins, block_reward))
73
+ {
74
+ LOG_PRINT_L0("Block is too big");
75
+ return false;
76
+ }
77
+ #if defined(DEBUG_CREATE_BLOCK_TEMPLATE)
78
+ LOG_PRINT_L1("Creating block template: reward " << block_reward <<
79
+ ", fee " << fee)
80
+ #endif
81
+ block_reward += fee;
82
+
83
+ std::vector<uint64_t> out_amounts;
84
+ decompose_amount_into_digits(block_reward, DEFAULT_FEE,
85
+ [&out_amounts](uint64_t a_chunk) { out_amounts.push_back(a_chunk); },
86
+ [&out_amounts](uint64_t a_dust) { out_amounts.push_back(a_dust); });
87
+
88
+ CHECK_AND_ASSERT_MES(1 <= max_outs, false, "max_out must be non-zero");
89
+ while (max_outs < out_amounts.size())
90
+ {
91
+ out_amounts[out_amounts.size() - 2] += out_amounts.back();
92
+ out_amounts.resize(out_amounts.size() - 1);
93
+ }
94
+
95
+ uint64_t summary_amounts = 0;
96
+ for (size_t no = 0; no < out_amounts.size(); no++)
97
+ {
98
+ crypto::key_derivation derivation = AUTO_VAL_INIT(derivation);;
99
+ crypto::public_key out_eph_public_key = AUTO_VAL_INIT(out_eph_public_key);
100
+ bool r = crypto::generate_key_derivation(miner_address.m_view_public_key, txkey.sec, derivation);
101
+ CHECK_AND_ASSERT_MES(r, false, "while creating outs: failed to generate_key_derivation(" << miner_address.m_view_public_key << ", " << txkey.sec << ")");
102
+
103
+ r = crypto::derive_public_key(derivation, no, miner_address.m_spend_public_key, out_eph_public_key);
104
+ CHECK_AND_ASSERT_MES(r, false, "while creating outs: failed to derive_public_key(" << derivation << ", " << no << ", "<< miner_address.m_spend_public_key << ")");
105
+
106
+ txout_to_key tk;
107
+ tk.key = out_eph_public_key;
108
+
109
+ tx_out out;
110
+ summary_amounts += out.amount = out_amounts[no];
111
+ out.target = tk;
112
+ tx.vout.push_back(out);
113
+ }
114
+
115
+ CHECK_AND_ASSERT_MES(summary_amounts == block_reward, false, "Failed to construct miner tx, summary_amounts = " << summary_amounts << " not equal block_reward = " << block_reward);
116
+
117
+ tx.version = CURRENT_TRANSACTION_VERSION;
118
+ //lock
119
+ tx.unlock_time = height + CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW;
120
+ tx.vin.push_back(in);
121
+ //LOG_PRINT("MINER_TX generated ok, block_reward=" << print_money(block_reward) << "(" << print_money(block_reward - fee) << "+" << print_money(fee)
122
+ // << "), current_block_size=" << current_block_size << ", already_generated_coins=" << already_generated_coins << ", tx_id=" << get_transaction_hash(tx), LOG_LEVEL_2);
123
+ return true;
124
+ }
125
+ //---------------------------------------------------------------
126
+ bool generate_key_image_helper(const account_keys& ack, const crypto::public_key& tx_public_key, size_t real_output_index, keypair& in_ephemeral, crypto::key_image& ki)
127
+ {
128
+ crypto::key_derivation recv_derivation = AUTO_VAL_INIT(recv_derivation);
129
+ bool r = crypto::generate_key_derivation(tx_public_key, ack.m_view_secret_key, recv_derivation);
130
+ CHECK_AND_ASSERT_MES(r, false, "key image helper: failed to generate_key_derivation(" << tx_public_key << ", " << ack.m_view_secret_key << ")");
131
+
132
+ r = crypto::derive_public_key(recv_derivation, real_output_index, ack.m_account_address.m_spend_public_key, in_ephemeral.pub);
133
+ CHECK_AND_ASSERT_MES(r, false, "key image helper: failed to derive_public_key(" << recv_derivation << ", " << real_output_index << ", " << ack.m_account_address.m_spend_public_key << ")");
134
+
135
+ crypto::derive_secret_key(recv_derivation, real_output_index, ack.m_spend_secret_key, in_ephemeral.sec);
136
+
137
+ crypto::generate_key_image(in_ephemeral.pub, in_ephemeral.sec, ki);
138
+ return true;
139
+ }
140
+ //---------------------------------------------------------------
141
+ uint64_t power_integral(uint64_t a, uint64_t b)
142
+ {
143
+ if(b == 0)
144
+ return 1;
145
+ uint64_t total = a;
146
+ for(uint64_t i = 1; i != b; i++)
147
+ total *= a;
148
+ return total;
149
+ }
150
+ //---------------------------------------------------------------
151
+ bool parse_amount(uint64_t& amount, const std::string& str_amount_)
152
+ {
153
+ std::string str_amount = str_amount_;
154
+ boost::algorithm::trim(str_amount);
155
+
156
+ size_t point_index = str_amount.find_first_of('.');
157
+ size_t fraction_size;
158
+ if (std::string::npos != point_index)
159
+ {
160
+ fraction_size = str_amount.size() - point_index - 1;
161
+ while (CRYPTONOTE_DISPLAY_DECIMAL_POINT < fraction_size && '0' == str_amount.back())
162
+ {
163
+ str_amount.erase(str_amount.size() - 1, 1);
164
+ --fraction_size;
165
+ }
166
+ if (CRYPTONOTE_DISPLAY_DECIMAL_POINT < fraction_size)
167
+ return false;
168
+ str_amount.erase(point_index, 1);
169
+ }
170
+ else
171
+ {
172
+ fraction_size = 0;
173
+ }
174
+
175
+ if (str_amount.empty())
176
+ return false;
177
+
178
+ if (fraction_size < CRYPTONOTE_DISPLAY_DECIMAL_POINT)
179
+ {
180
+ str_amount.append(CRYPTONOTE_DISPLAY_DECIMAL_POINT - fraction_size, '0');
181
+ }
182
+
183
+ return string_tools::get_xtype_from_string(amount, str_amount);
184
+ }
185
+ //---------------------------------------------------------------
186
+ bool get_tx_fee(const transaction& tx, uint64_t & fee)
187
+ {
188
+ uint64_t amount_in = 0;
189
+ uint64_t amount_out = 0;
190
+ BOOST_FOREACH(auto& in, tx.vin)
191
+ {
192
+ CHECK_AND_ASSERT_MES(in.type() == typeid(txin_to_key), 0, "unexpected type id in transaction");
193
+ amount_in += boost::get<txin_to_key>(in).amount;
194
+ }
195
+ BOOST_FOREACH(auto& o, tx.vout)
196
+ amount_out += o.amount;
197
+
198
+ CHECK_AND_ASSERT_MES(amount_in >= amount_out, false, "transaction spend (" <<amount_in << ") more than it has (" << amount_out << ")");
199
+ fee = amount_in - amount_out;
200
+ return true;
201
+ }
202
+ //---------------------------------------------------------------
203
+ uint64_t get_tx_fee(const transaction& tx)
204
+ {
205
+ uint64_t r = 0;
206
+ if(!get_tx_fee(tx, r))
207
+ return 0;
208
+ return r;
209
+ }
210
+ //---------------------------------------------------------------
211
+ bool parse_tx_extra(const std::vector<uint8_t>& tx_extra, std::vector<tx_extra_field>& tx_extra_fields)
212
+ {
213
+ tx_extra_fields.clear();
214
+
215
+ if(tx_extra.empty())
216
+ return true;
217
+
218
+ std::string extra_str(reinterpret_cast<const char*>(tx_extra.data()), tx_extra.size());
219
+ std::istringstream iss(extra_str);
220
+ binary_archive<false> ar(iss);
221
+
222
+ bool eof = false;
223
+ while (!eof)
224
+ {
225
+ tx_extra_field field;
226
+ bool r = ::do_serialize(ar, field);
227
+ CHECK_AND_NO_ASSERT_MES(r, false, "failed to deserialize extra field. extra = " << string_tools::buff_to_hex_nodelimer(std::string(reinterpret_cast<const char*>(tx_extra.data()), tx_extra.size())));
228
+ tx_extra_fields.push_back(field);
229
+
230
+ std::ios_base::iostate state = iss.rdstate();
231
+ eof = (EOF == iss.peek());
232
+ iss.clear(state);
233
+ }
234
+ CHECK_AND_NO_ASSERT_MES(::serialization::check_stream_state(ar), false, "failed to deserialize extra field. extra = " << string_tools::buff_to_hex_nodelimer(std::string(reinterpret_cast<const char*>(tx_extra.data()), tx_extra.size())));
235
+
236
+ return true;
237
+ }
238
+ //---------------------------------------------------------------
239
+ crypto::public_key get_tx_pub_key_from_extra(const std::vector<uint8_t>& tx_extra)
240
+ {
241
+ std::vector<tx_extra_field> tx_extra_fields;
242
+ if (!parse_tx_extra(tx_extra, tx_extra_fields))
243
+ return null_pkey;
244
+
245
+ tx_extra_pub_key pub_key_field;
246
+ if(!find_tx_extra_field_by_type(tx_extra_fields, pub_key_field))
247
+ return null_pkey;
248
+
249
+ return pub_key_field.pub_key;
250
+ }
251
+ //---------------------------------------------------------------
252
+ crypto::public_key get_tx_pub_key_from_extra(const transaction& tx)
253
+ {
254
+ return get_tx_pub_key_from_extra(tx.extra);
255
+ }
256
+ //---------------------------------------------------------------
257
+ bool add_tx_pub_key_to_extra(transaction& tx, const crypto::public_key& tx_pub_key)
258
+ {
259
+ tx.extra.resize(tx.extra.size() + 1 + sizeof(crypto::public_key));
260
+ tx.extra[tx.extra.size() - 1 - sizeof(crypto::public_key)] = TX_EXTRA_TAG_PUBKEY;
261
+ *reinterpret_cast<crypto::public_key*>(&tx.extra[tx.extra.size() - sizeof(crypto::public_key)]) = tx_pub_key;
262
+ return true;
263
+ }
264
+ //---------------------------------------------------------------
265
+ bool add_extra_nonce_to_tx_extra(std::vector<uint8_t>& tx_extra, const blobdata& extra_nonce)
266
+ {
267
+ CHECK_AND_ASSERT_MES(extra_nonce.size() <= TX_EXTRA_NONCE_MAX_COUNT, false, "extra nonce could be 255 bytes max");
268
+ size_t start_pos = tx_extra.size();
269
+ tx_extra.resize(tx_extra.size() + 2 + extra_nonce.size());
270
+ //write tag
271
+ tx_extra[start_pos] = TX_EXTRA_NONCE;
272
+ //write len
273
+ ++start_pos;
274
+ tx_extra[start_pos] = static_cast<uint8_t>(extra_nonce.size());
275
+ //write data
276
+ ++start_pos;
277
+ memcpy(&tx_extra[start_pos], extra_nonce.data(), extra_nonce.size());
278
+ return true;
279
+ }
280
+ //---------------------------------------------------------------
281
+ void set_payment_id_to_tx_extra_nonce(blobdata& extra_nonce, const crypto::hash& payment_id)
282
+ {
283
+ extra_nonce.clear();
284
+ extra_nonce.push_back(TX_EXTRA_NONCE_PAYMENT_ID);
285
+ const uint8_t* payment_id_ptr = reinterpret_cast<const uint8_t*>(&payment_id);
286
+ std::copy(payment_id_ptr, payment_id_ptr + sizeof(payment_id), std::back_inserter(extra_nonce));
287
+ }
288
+ //---------------------------------------------------------------
289
+ bool get_payment_id_from_tx_extra_nonce(const blobdata& extra_nonce, crypto::hash& payment_id)
290
+ {
291
+ if(sizeof(crypto::hash) + 1 != extra_nonce.size())
292
+ return false;
293
+ if(TX_EXTRA_NONCE_PAYMENT_ID != extra_nonce[0])
294
+ return false;
295
+ payment_id = *reinterpret_cast<const crypto::hash*>(extra_nonce.data() + 1);
296
+ return true;
297
+ }
298
+ //---------------------------------------------------------------
299
+ bool construct_tx(const account_keys& sender_account_keys, const std::vector<tx_source_entry>& sources, const std::vector<tx_destination_entry>& destinations, std::vector<uint8_t> extra, transaction& tx, uint64_t unlock_time)
300
+ {
301
+ tx.vin.clear();
302
+ tx.vout.clear();
303
+ tx.signatures.clear();
304
+
305
+ tx.version = CURRENT_TRANSACTION_VERSION;
306
+ tx.unlock_time = unlock_time;
307
+
308
+ tx.extra = extra;
309
+ keypair txkey = keypair::generate();
310
+ add_tx_pub_key_to_extra(tx, txkey.pub);
311
+
312
+ struct input_generation_context_data
313
+ {
314
+ keypair in_ephemeral;
315
+ };
316
+ std::vector<input_generation_context_data> in_contexts;
317
+
318
+
319
+ uint64_t summary_inputs_money = 0;
320
+ //fill inputs
321
+ BOOST_FOREACH(const tx_source_entry& src_entr, sources)
322
+ {
323
+ if(src_entr.real_output >= src_entr.outputs.size())
324
+ {
325
+ LOG_ERROR("real_output index (" << src_entr.real_output << ")bigger than output_keys.size()=" << src_entr.outputs.size());
326
+ return false;
327
+ }
328
+ summary_inputs_money += src_entr.amount;
329
+
330
+ //key_derivation recv_derivation;
331
+ in_contexts.push_back(input_generation_context_data());
332
+ keypair& in_ephemeral = in_contexts.back().in_ephemeral;
333
+ crypto::key_image img;
334
+ if(!generate_key_image_helper(sender_account_keys, src_entr.real_out_tx_key, src_entr.real_output_in_tx_index, in_ephemeral, img))
335
+ return false;
336
+
337
+ //check that derivated key is equal with real output key
338
+ if( !(in_ephemeral.pub == src_entr.outputs[src_entr.real_output].second) )
339
+ {
340
+ LOG_ERROR("derived public key missmatch with output public key! "<< ENDL << "derived_key:"
341
+ << string_tools::pod_to_hex(in_ephemeral.pub) << ENDL << "real output_public_key:"
342
+ << string_tools::pod_to_hex(src_entr.outputs[src_entr.real_output].second) );
343
+ return false;
344
+ }
345
+
346
+ //put key image into tx input
347
+ txin_to_key input_to_key;
348
+ input_to_key.amount = src_entr.amount;
349
+ input_to_key.k_image = img;
350
+
351
+ //fill outputs array and use relative offsets
352
+ BOOST_FOREACH(const tx_source_entry::output_entry& out_entry, src_entr.outputs)
353
+ input_to_key.key_offsets.push_back(out_entry.first);
354
+
355
+ input_to_key.key_offsets = absolute_output_offsets_to_relative(input_to_key.key_offsets);
356
+ tx.vin.push_back(input_to_key);
357
+ }
358
+
359
+ // "Shuffle" outs
360
+ std::vector<tx_destination_entry> shuffled_dsts(destinations);
361
+ std::sort(shuffled_dsts.begin(), shuffled_dsts.end(), [](const tx_destination_entry& de1, const tx_destination_entry& de2) { return de1.amount < de2.amount; } );
362
+
363
+ uint64_t summary_outs_money = 0;
364
+ //fill outputs
365
+ size_t output_index = 0;
366
+ BOOST_FOREACH(const tx_destination_entry& dst_entr, shuffled_dsts)
367
+ {
368
+ CHECK_AND_ASSERT_MES(dst_entr.amount > 0, false, "Destination with wrong amount: " << dst_entr.amount);
369
+ crypto::key_derivation derivation;
370
+ crypto::public_key out_eph_public_key;
371
+ bool r = crypto::generate_key_derivation(dst_entr.addr.m_view_public_key, txkey.sec, derivation);
372
+ CHECK_AND_ASSERT_MES(r, false, "at creation outs: failed to generate_key_derivation(" << dst_entr.addr.m_view_public_key << ", " << txkey.sec << ")");
373
+
374
+ r = crypto::derive_public_key(derivation, output_index, dst_entr.addr.m_spend_public_key, out_eph_public_key);
375
+ CHECK_AND_ASSERT_MES(r, false, "at creation outs: failed to derive_public_key(" << derivation << ", " << output_index << ", "<< dst_entr.addr.m_spend_public_key << ")");
376
+
377
+ tx_out out;
378
+ out.amount = dst_entr.amount;
379
+ txout_to_key tk;
380
+ tk.key = out_eph_public_key;
381
+ out.target = tk;
382
+ tx.vout.push_back(out);
383
+ output_index++;
384
+ summary_outs_money += dst_entr.amount;
385
+ }
386
+
387
+ //check money
388
+ if(summary_outs_money > summary_inputs_money )
389
+ {
390
+ LOG_ERROR("Transaction inputs money ("<< summary_inputs_money << ") less than outputs money (" << summary_outs_money << ")");
391
+ return false;
392
+ }
393
+
394
+
395
+ //generate ring signatures
396
+ crypto::hash tx_prefix_hash;
397
+ get_transaction_prefix_hash(tx, tx_prefix_hash);
398
+
399
+ std::stringstream ss_ring_s;
400
+ size_t i = 0;
401
+ BOOST_FOREACH(const tx_source_entry& src_entr, sources)
402
+ {
403
+ ss_ring_s << "pub_keys:" << ENDL;
404
+ std::vector<const crypto::public_key*> keys_ptrs;
405
+ BOOST_FOREACH(const tx_source_entry::output_entry& o, src_entr.outputs)
406
+ {
407
+ keys_ptrs.push_back(&o.second);
408
+ ss_ring_s << o.second << ENDL;
409
+ }
410
+
411
+ tx.signatures.push_back(std::vector<crypto::signature>());
412
+ std::vector<crypto::signature>& sigs = tx.signatures.back();
413
+ sigs.resize(src_entr.outputs.size());
414
+ crypto::generate_ring_signature(tx_prefix_hash, boost::get<txin_to_key>(tx.vin[i]).k_image, keys_ptrs, in_contexts[i].in_ephemeral.sec, src_entr.real_output, sigs.data());
415
+ ss_ring_s << "signatures:" << ENDL;
416
+ std::for_each(sigs.begin(), sigs.end(), [&](const crypto::signature& s){ss_ring_s << s << ENDL;});
417
+ ss_ring_s << "prefix_hash:" << tx_prefix_hash << ENDL << "in_ephemeral_key: " << in_contexts[i].in_ephemeral.sec << ENDL << "real_output: " << src_entr.real_output;
418
+ i++;
419
+ }
420
+
421
+ LOG_PRINT2("construct_tx.log", "transaction_created: " << get_transaction_hash(tx) << ENDL << obj_to_json_str(tx) << ENDL << ss_ring_s.str() , LOG_LEVEL_3);
422
+
423
+ return true;
424
+ }
425
+ //---------------------------------------------------------------
426
+ bool get_inputs_money_amount(const transaction& tx, uint64_t& money)
427
+ {
428
+ money = 0;
429
+ BOOST_FOREACH(const auto& in, tx.vin)
430
+ {
431
+ CHECKED_GET_SPECIFIC_VARIANT(in, const txin_to_key, tokey_in, false);
432
+ money += tokey_in.amount;
433
+ }
434
+ return true;
435
+ }
436
+ //---------------------------------------------------------------
437
+ uint64_t get_block_height(const block& b)
438
+ {
439
+ CHECK_AND_ASSERT_MES(b.miner_tx.vin.size() == 1, 0, "wrong miner tx in block: " << get_block_hash(b) << ", b.miner_tx.vin.size() != 1");
440
+ CHECKED_GET_SPECIFIC_VARIANT(b.miner_tx.vin[0], const txin_gen, coinbase_in, 0);
441
+ return coinbase_in.height;
442
+ }
443
+ //---------------------------------------------------------------
444
+ bool check_inputs_types_supported(const transaction& tx)
445
+ {
446
+ BOOST_FOREACH(const auto& in, tx.vin)
447
+ {
448
+ CHECK_AND_ASSERT_MES(in.type() == typeid(txin_to_key), false, "wrong variant type: "
449
+ << in.type().name() << ", expected " << typeid(txin_to_key).name()
450
+ << ", in transaction id=" << get_transaction_hash(tx));
451
+
452
+ }
453
+ return true;
454
+ }
455
+ //-----------------------------------------------------------------------------------------------
456
+ bool check_outs_valid(const transaction& tx)
457
+ {
458
+ BOOST_FOREACH(const tx_out& out, tx.vout)
459
+ {
460
+ CHECK_AND_ASSERT_MES(out.target.type() == typeid(txout_to_key), false, "wrong variant type: "
461
+ << out.target.type().name() << ", expected " << typeid(txout_to_key).name()
462
+ << ", in transaction id=" << get_transaction_hash(tx));
463
+
464
+ CHECK_AND_NO_ASSERT_MES(0 < out.amount, false, "zero amount ouput in transaction id=" << get_transaction_hash(tx));
465
+
466
+ if(!check_key(boost::get<txout_to_key>(out.target).key))
467
+ return false;
468
+ }
469
+ return true;
470
+ }
471
+ //-----------------------------------------------------------------------------------------------
472
+ bool check_money_overflow(const transaction& tx)
473
+ {
474
+ return check_inputs_overflow(tx) && check_outs_overflow(tx);
475
+ }
476
+ //---------------------------------------------------------------
477
+ bool check_inputs_overflow(const transaction& tx)
478
+ {
479
+ uint64_t money = 0;
480
+ BOOST_FOREACH(const auto& in, tx.vin)
481
+ {
482
+ CHECKED_GET_SPECIFIC_VARIANT(in, const txin_to_key, tokey_in, false);
483
+ if(money > tokey_in.amount + money)
484
+ return false;
485
+ money += tokey_in.amount;
486
+ }
487
+ return true;
488
+ }
489
+ //---------------------------------------------------------------
490
+ bool check_outs_overflow(const transaction& tx)
491
+ {
492
+ uint64_t money = 0;
493
+ BOOST_FOREACH(const auto& o, tx.vout)
494
+ {
495
+ if(money > o.amount + money)
496
+ return false;
497
+ money += o.amount;
498
+ }
499
+ return true;
500
+ }
501
+ //---------------------------------------------------------------
502
+ uint64_t get_outs_money_amount(const transaction& tx)
503
+ {
504
+ uint64_t outputs_amount = 0;
505
+ BOOST_FOREACH(const auto& o, tx.vout)
506
+ outputs_amount += o.amount;
507
+ return outputs_amount;
508
+ }
509
+ //---------------------------------------------------------------
510
+ std::string short_hash_str(const crypto::hash& h)
511
+ {
512
+ std::string res = string_tools::pod_to_hex(h);
513
+ CHECK_AND_ASSERT_MES(res.size() == 64, res, "wrong hash256 with string_tools::pod_to_hex conversion");
514
+ auto erased_pos = res.erase(8, 48);
515
+ res.insert(8, "....");
516
+ return res;
517
+ }
518
+ //---------------------------------------------------------------
519
+ bool is_out_to_acc(const account_keys& acc, const txout_to_key& out_key, const crypto::public_key& tx_pub_key, size_t output_index)
520
+ {
521
+ crypto::key_derivation derivation;
522
+ generate_key_derivation(tx_pub_key, acc.m_view_secret_key, derivation);
523
+ crypto::public_key pk;
524
+ derive_public_key(derivation, output_index, acc.m_account_address.m_spend_public_key, pk);
525
+ return pk == out_key.key;
526
+ }
527
+ //---------------------------------------------------------------
528
+ bool lookup_acc_outs(const account_keys& acc, const transaction& tx, std::vector<size_t>& outs, uint64_t& money_transfered)
529
+ {
530
+ crypto::public_key tx_pub_key = get_tx_pub_key_from_extra(tx);
531
+ if(null_pkey == tx_pub_key)
532
+ return false;
533
+ return lookup_acc_outs(acc, tx, tx_pub_key, outs, money_transfered);
534
+ }
535
+ //---------------------------------------------------------------
536
+ bool lookup_acc_outs(const account_keys& acc, const transaction& tx, const crypto::public_key& tx_pub_key, std::vector<size_t>& outs, uint64_t& money_transfered)
537
+ {
538
+ money_transfered = 0;
539
+ size_t i = 0;
540
+ BOOST_FOREACH(const tx_out& o, tx.vout)
541
+ {
542
+ CHECK_AND_ASSERT_MES(o.target.type() == typeid(txout_to_key), false, "wrong type id in transaction out" );
543
+ if(is_out_to_acc(acc, boost::get<txout_to_key>(o.target), tx_pub_key, i))
544
+ {
545
+ outs.push_back(i);
546
+ money_transfered += o.amount;
547
+ }
548
+ i++;
549
+ }
550
+ return true;
551
+ }
552
+ //---------------------------------------------------------------
553
+ void get_blob_hash(const blobdata& blob, crypto::hash& res)
554
+ {
555
+ cn_fast_hash(blob.data(), blob.size(), res);
556
+ }
557
+ //---------------------------------------------------------------
558
+ std::string print_money(uint64_t amount)
559
+ {
560
+ std::string s = std::to_string(amount);
561
+ if(s.size() < CRYPTONOTE_DISPLAY_DECIMAL_POINT+1)
562
+ {
563
+ s.insert(0, CRYPTONOTE_DISPLAY_DECIMAL_POINT+1 - s.size(), '0');
564
+ }
565
+ s.insert(s.size() - CRYPTONOTE_DISPLAY_DECIMAL_POINT, ".");
566
+ return s;
567
+ }
568
+ //---------------------------------------------------------------
569
+ crypto::hash get_blob_hash(const blobdata& blob)
570
+ {
571
+ crypto::hash h = null_hash;
572
+ get_blob_hash(blob, h);
573
+ return h;
574
+ }
575
+ //---------------------------------------------------------------
576
+ crypto::hash get_transaction_hash(const transaction& t)
577
+ {
578
+ crypto::hash h = null_hash;
579
+ size_t blob_size = 0;
580
+ get_object_hash(t, h, blob_size);
581
+ return h;
582
+ }
583
+ //---------------------------------------------------------------
584
+ bool get_transaction_hash(const transaction& t, crypto::hash& res)
585
+ {
586
+ size_t blob_size = 0;
587
+ return get_object_hash(t, res, blob_size);
588
+ }
589
+
590
+ bool get_transaction_hash(const bb_transaction& t, crypto::hash& res)
591
+ {
592
+ size_t blob_size = 0;
593
+ return get_object_hash(t, res, blob_size);
594
+ }
595
+
596
+ //---------------------------------------------------------------
597
+ bool get_transaction_hash(const transaction& t, crypto::hash& res, size_t& blob_size)
598
+ {
599
+ return get_object_hash(t, res, blob_size);
600
+ }
601
+ //---------------------------------------------------------------
602
+ blobdata get_block_hashing_blob(const block& b)
603
+ {
604
+ blobdata blob = t_serializable_object_to_blob(static_cast<block_header>(b));
605
+ crypto::hash tree_root_hash = get_tx_tree_hash(b);
606
+ blob.append((const char*)&tree_root_hash, sizeof(tree_root_hash ));
607
+ blob.append(tools::get_varint_data(b.tx_hashes.size()+1));
608
+ return blob;
609
+ }
610
+ blobdata get_block_hashing_blob(const bb_block& b)
611
+ {
612
+ blobdata blob = t_serializable_object_to_blob(static_cast<bb_block_header>(b));
613
+ crypto::hash tree_root_hash = get_tx_tree_hash(b);
614
+ blob.append((const char*)&tree_root_hash, sizeof(tree_root_hash ));
615
+ blob.append(tools::get_varint_data(b.tx_hashes.size()+1));
616
+ return blob;
617
+ }
618
+ //---------------------------------------------------------------
619
+ bool get_block_hash(const block& b, crypto::hash& res)
620
+ {
621
+ return get_object_hash(get_block_hashing_blob(b), res);
622
+ }
623
+ //---------------------------------------------------------------
624
+ crypto::hash get_block_hash(const block& b)
625
+ {
626
+ crypto::hash p = null_hash;
627
+ get_block_hash(b, p);
628
+ return p;
629
+ }
630
+ //---------------------------------------------------------------
631
+ bool generate_genesis_block(block& bl)
632
+ {
633
+ //genesis block
634
+ bl = boost::value_initialized<block>();
635
+
636
+
637
+ account_public_address ac = boost::value_initialized<account_public_address>();
638
+ std::vector<size_t> sz;
639
+ construct_miner_tx(0, 0, 0, 0, 0, ac, bl.miner_tx); // zero fee in genesis
640
+ blobdata txb = tx_to_blob(bl.miner_tx);
641
+ std::string hex_tx_represent = string_tools::buff_to_hex_nodelimer(txb);
642
+
643
+ //hard code coinbase tx in genesis block, because "tru" generating tx use random, but genesis should be always the same
644
+ std::string genesis_coinbase_tx_hex = "013c01ff0001ffffffffffff03029b2e4c0281c0b02e7c53291a94d1d0cbff8883f8024f5142ee494ffbbd08807121017767aafcde9be00dcfd098715ebcf7f410daebc582fda69d24a28e9d0bc890d1";
645
+
646
+ blobdata tx_bl;
647
+ string_tools::parse_hexstr_to_binbuff(genesis_coinbase_tx_hex, tx_bl);
648
+ bool r = parse_and_validate_tx_from_blob(tx_bl, bl.miner_tx);
649
+ CHECK_AND_ASSERT_MES(r, false, "failed to parse coinbase tx from hard coded blob");
650
+ bl.major_version = CURRENT_BLOCK_MAJOR_VERSION;
651
+ bl.minor_version = CURRENT_BLOCK_MINOR_VERSION;
652
+ bl.timestamp = 0;
653
+ bl.nonce = 10000;
654
+ miner::find_nonce_for_given_block(bl, 1, 0);
655
+ return true;
656
+ }
657
+ //---------------------------------------------------------------
658
+ bool get_block_longhash(const block& b, crypto::hash& res, uint64_t height)
659
+ {
660
+ block b_local = b; //workaround to avoid const errors with do_serialize
661
+ blobdata bd = get_block_hashing_blob(b);
662
+ crypto::cn_slow_hash(bd.data(), bd.size(), res);
663
+ return true;
664
+ }
665
+ //---------------------------------------------------------------
666
+ std::vector<uint64_t> relative_output_offsets_to_absolute(const std::vector<uint64_t>& off)
667
+ {
668
+ std::vector<uint64_t> res = off;
669
+ for(size_t i = 1; i < res.size(); i++)
670
+ res[i] += res[i-1];
671
+ return res;
672
+ }
673
+ //---------------------------------------------------------------
674
+ std::vector<uint64_t> absolute_output_offsets_to_relative(const std::vector<uint64_t>& off)
675
+ {
676
+ std::vector<uint64_t> res = off;
677
+ if(!off.size())
678
+ return res;
679
+ std::sort(res.begin(), res.end());//just to be sure, actually it is already should be sorted
680
+ for(size_t i = res.size()-1; i != 0; i--)
681
+ res[i] -= res[i-1];
682
+
683
+ return res;
684
+ }
685
+ //---------------------------------------------------------------
686
+ crypto::hash get_block_longhash(const block& b, uint64_t height)
687
+ {
688
+ crypto::hash p = null_hash;
689
+ get_block_longhash(b, p, height);
690
+ return p;
691
+ }
692
+ //---------------------------------------------------------------
693
+ bool parse_and_validate_block_from_blob(const blobdata& b_blob, block& b)
694
+ {
695
+ std::stringstream ss;
696
+ ss << b_blob;
697
+ binary_archive<false> ba(ss);
698
+ bool r = ::serialization::serialize(ba, b);
699
+ CHECK_AND_ASSERT_MES(r, false, "Failed to parse block from blob");
700
+ return true;
701
+ }
702
+ bool parse_and_validate_block_from_blob(const blobdata& b_blob, bb_block& b)
703
+ {
704
+ std::stringstream ss;
705
+ ss << b_blob;
706
+ binary_archive<false> ba(ss);
707
+ bool r = ::serialization::serialize(ba, b);
708
+ CHECK_AND_ASSERT_MES(r, false, "Failed to parse block from blob");
709
+ return true;
710
+ }
711
+ //---------------------------------------------------------------
712
+ blobdata block_to_blob(const block& b)
713
+ {
714
+ return t_serializable_object_to_blob(b);
715
+ }
716
+ //---------------------------------------------------------------
717
+ bool block_to_blob(const block& b, blobdata& b_blob)
718
+ {
719
+ return t_serializable_object_to_blob(b, b_blob);
720
+ }
721
+ //---------------------------------------------------------------
722
+ blobdata tx_to_blob(const transaction& tx)
723
+ {
724
+ return t_serializable_object_to_blob(tx);
725
+ }
726
+ //---------------------------------------------------------------
727
+ bool tx_to_blob(const transaction& tx, blobdata& b_blob)
728
+ {
729
+ return t_serializable_object_to_blob(tx, b_blob);
730
+ }
731
+ //---------------------------------------------------------------
732
+ void get_tx_tree_hash(const std::vector<crypto::hash>& tx_hashes, crypto::hash& h)
733
+ {
734
+ tree_hash(tx_hashes.data(), tx_hashes.size(), h);
735
+ }
736
+ //---------------------------------------------------------------
737
+ crypto::hash get_tx_tree_hash(const std::vector<crypto::hash>& tx_hashes)
738
+ {
739
+ crypto::hash h = null_hash;
740
+ get_tx_tree_hash(tx_hashes, h);
741
+ return h;
742
+ }
743
+ //---------------------------------------------------------------
744
+ crypto::hash get_tx_tree_hash(const block& b)
745
+ {
746
+ std::vector<crypto::hash> txs_ids;
747
+ crypto::hash h = null_hash;
748
+ size_t bl_sz = 0;
749
+ get_transaction_hash(b.miner_tx, h, bl_sz);
750
+ txs_ids.push_back(h);
751
+ BOOST_FOREACH(auto& th, b.tx_hashes)
752
+ txs_ids.push_back(th);
753
+ return get_tx_tree_hash(txs_ids);
754
+ }
755
+ crypto::hash get_tx_tree_hash(const bb_block& b)
756
+ {
757
+ std::vector<crypto::hash> txs_ids;
758
+ crypto::hash h = null_hash;
759
+ get_transaction_hash(b.miner_tx, h);
760
+ txs_ids.push_back(h);
761
+ BOOST_FOREACH(auto& th, b.tx_hashes)
762
+ txs_ids.push_back(th);
763
+ return get_tx_tree_hash(txs_ids);
764
+ }
765
+ //---------------------------------------------------------------
766
+ }