@tradelayerprotocol/tradelayer 1.9.1

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 (249) hide show
  1. package/.claude/settings.local.json +13 -0
  2. package/.claude/skills/tl-algo/SKILL.md +255 -0
  3. package/.gitattributes +2 -0
  4. package/.github/workflows/publish.yaml +26 -0
  5. package/4mm.js +163 -0
  6. package/LICENSE +21 -0
  7. package/NPMSwapRefactor.zip +0 -0
  8. package/README.md +217 -0
  9. package/address.sh +26 -0
  10. package/algoAPI.js +581 -0
  11. package/analyzepsbt.js +92 -0
  12. package/apiEx.js +99 -0
  13. package/bb_hyperscalper.js +290 -0
  14. package/bbo_demo.js +111 -0
  15. package/buyer.js +622 -0
  16. package/client.js +50 -0
  17. package/createTxTest.js +26 -0
  18. package/createWallet.js +75 -0
  19. package/daytrader.js +531 -0
  20. package/decodeTest.js +69 -0
  21. package/fundingManager.js +144 -0
  22. package/index.js +4 -0
  23. package/listener.js +27 -0
  24. package/litecoreTxBuilder.js +1128 -0
  25. package/mmEx.js +356 -0
  26. package/networks.js +51 -0
  27. package/orderbook.js +200 -0
  28. package/package.json +34 -0
  29. package/perTradeQueue.js +36 -0
  30. package/projectsTLNPMTLNPM/package-lock.json +162 -0
  31. package/projectsTLNPMTLNPM/package.json +5 -0
  32. package/quick.js +32 -0
  33. package/quickFut.js +37 -0
  34. package/quickSell.js +37 -0
  35. package/relayerClient.js +117 -0
  36. package/run4mm.js +80 -0
  37. package/run_bbo_tracker.js +241 -0
  38. package/seller.js +443 -0
  39. package/session.js +45 -0
  40. package/setup-lin-ltc.sh +139 -0
  41. package/setup-lin.sh +203 -0
  42. package/setup-win-ltc.bat +108 -0
  43. package/setup-win.bat +167 -0
  44. package/spam_screamer_futures.js +222 -0
  45. package/tradelayer.js/.gitattributes +2 -0
  46. package/tradelayer.js/README.md +2 -0
  47. package/tradelayer.js/oldTests/activationTest.js +6 -0
  48. package/tradelayer.js/oldTests/base58.test.js +23 -0
  49. package/tradelayer.js/oldTests/base64Decode.test.js +16 -0
  50. package/tradelayer.js/oldTests/blocksRefactor.js +140 -0
  51. package/tradelayer.js/oldTests/checkVestBalance.js +25 -0
  52. package/tradelayer.js/oldTests/consensusHashProto.js +151 -0
  53. package/tradelayer.js/oldTests/contractOrderbook.js +243 -0
  54. package/tradelayer.js/oldTests/createPayload.js +0 -0
  55. package/tradelayer.js/oldTests/createTestnetAddr.js +43 -0
  56. package/tradelayer.js/oldTests/decode.js +205 -0
  57. package/tradelayer.js/oldTests/decodeTest.js +50 -0
  58. package/tradelayer.js/oldTests/displayTallyMap.js +19 -0
  59. package/tradelayer.js/oldTests/encodeDecode.js +340 -0
  60. package/tradelayer.js/oldTests/expressTest.js +29 -0
  61. package/tradelayer.js/oldTests/extractBlocksVanilla.js +214 -0
  62. package/tradelayer.js/oldTests/extractBlocksVanillaa.js +179 -0
  63. package/tradelayer.js/oldTests/extractPubkeyTest.js +60 -0
  64. package/tradelayer.js/oldTests/fillInputCacheProto.js +111 -0
  65. package/tradelayer.js/oldTests/getRawTxTest.js +22 -0
  66. package/tradelayer.js/oldTests/indexTest.js +26 -0
  67. package/tradelayer.js/oldTests/initTokensTest.js +32 -0
  68. package/tradelayer.js/oldTests/interfaceChild.js +129 -0
  69. package/tradelayer.js/oldTests/listenerChild.js +112 -0
  70. package/tradelayer.js/oldTests/opdecode.js +26 -0
  71. package/tradelayer.js/oldTests/options.js +79 -0
  72. package/tradelayer.js/oldTests/optxtest.js +116 -0
  73. package/tradelayer.js/oldTests/optxtest1.js +64 -0
  74. package/tradelayer.js/oldTests/oracle.test.js +32 -0
  75. package/tradelayer.js/oldTests/orderbook.test.js +36 -0
  76. package/tradelayer.js/oldTests/parsing.js +93 -0
  77. package/tradelayer.js/oldTests/payload.js +13 -0
  78. package/tradelayer.js/oldTests/persistenceUnitTest.js +23 -0
  79. package/tradelayer.js/oldTests/property.test.js +53 -0
  80. package/tradelayer.js/oldTests/propertyLevel.js +75 -0
  81. package/tradelayer.js/oldTests/propertyTest.js +32 -0
  82. package/tradelayer.js/oldTests/queryAddressTest.js +17 -0
  83. package/tradelayer.js/oldTests/salter.js +14 -0
  84. package/tradelayer.js/oldTests/tally.js +81 -0
  85. package/tradelayer.js/oldTests/tally.test.js +48 -0
  86. package/tradelayer.js/oldTests/tally2.js +124 -0
  87. package/tradelayer.js/oldTests/tally3.js +142 -0
  88. package/tradelayer.js/oldTests/tallyDiag.js +38 -0
  89. package/tradelayer.js/oldTests/testGetRaw.js +40 -0
  90. package/tradelayer.js/oldTests/testHexConvert.js +47 -0
  91. package/tradelayer.js/oldTests/testNewEncoding.js +96 -0
  92. package/tradelayer.js/oldTests/testNewEncoding2.js +113 -0
  93. package/tradelayer.js/oldTests/testNewEncoding3 +112 -0
  94. package/tradelayer.js/oldTests/testNewEncoding3.js +168 -0
  95. package/tradelayer.js/oldTests/testOPReturn.js +102 -0
  96. package/tradelayer.js/oldTests/testPayload.js +23 -0
  97. package/tradelayer.js/oldTests/testRaw.js +50 -0
  98. package/tradelayer.js/oldTests/testSendTooMuch.js +20 -0
  99. package/tradelayer.js/oldTests/testTxBuild +28 -0
  100. package/tradelayer.js/oldTests/testTxBuild.js +42 -0
  101. package/tradelayer.js/oldTests/tokenOrderbook.js +243 -0
  102. package/tradelayer.js/oldTests/txUtilsA.js +515 -0
  103. package/tradelayer.js/oldTests/validityUnitTest.js +53 -0
  104. package/tradelayer.js/oldTests/vaults.js +72 -0
  105. package/tradelayer.js/oldTests/volumeIndex.js +117 -0
  106. package/tradelayer.js/oldTests/volumeIndex2.js +88 -0
  107. package/tradelayer.js/output_base64.txt +1 -0
  108. package/tradelayer.js/package-lock.json +9967 -0
  109. package/tradelayer.js/package.json +61 -0
  110. package/tradelayer.js/server/index.js +88 -0
  111. package/tradelayer.js/server/litecoind.exe +0 -0
  112. package/tradelayer.js/src/activation.js +303 -0
  113. package/tradelayer.js/src/adjuster.js +77 -0
  114. package/tradelayer.js/src/amm.js +400 -0
  115. package/tradelayer.js/src/base256.js +55 -0
  116. package/tradelayer.js/src/base94.js +79 -0
  117. package/tradelayer.js/src/channels.js +1163 -0
  118. package/tradelayer.js/src/clearing.js +3109 -0
  119. package/tradelayer.js/src/clearlist.js +364 -0
  120. package/tradelayer.js/src/client.js +295 -0
  121. package/tradelayer.js/src/consensus.js +613 -0
  122. package/tradelayer.js/src/contractRegistry.js +964 -0
  123. package/tradelayer.js/src/db.js +89 -0
  124. package/tradelayer.js/src/init.js +24 -0
  125. package/tradelayer.js/src/insurance.js +347 -0
  126. package/tradelayer.js/src/interface.js +218 -0
  127. package/tradelayer.js/src/interfaceExpress.js +178 -0
  128. package/tradelayer.js/src/iou.js +509 -0
  129. package/tradelayer.js/src/listener.js +226 -0
  130. package/tradelayer.js/src/logic.js +1702 -0
  131. package/tradelayer.js/src/main.js +927 -0
  132. package/tradelayer.js/src/marginMap.js +2165 -0
  133. package/tradelayer.js/src/options.js +126 -0
  134. package/tradelayer.js/src/oracle.js +394 -0
  135. package/tradelayer.js/src/orderbook.js +4123 -0
  136. package/tradelayer.js/src/persistence.js +554 -0
  137. package/tradelayer.js/src/property.js +411 -0
  138. package/tradelayer.js/src/reOrg.js +41 -0
  139. package/tradelayer.js/src/scaling.js +145 -0
  140. package/tradelayer.js/src/tally.js +1275 -0
  141. package/tradelayer.js/src/tradeHistoryManager.js +552 -0
  142. package/tradelayer.js/src/txDecoder.js +584 -0
  143. package/tradelayer.js/src/txEncoder.js +610 -0
  144. package/tradelayer.js/src/txIndex.js +502 -0
  145. package/tradelayer.js/src/txUtils.js +1392 -0
  146. package/tradelayer.js/src/types.js +429 -0
  147. package/tradelayer.js/src/validity.js +3077 -0
  148. package/tradelayer.js/src/vaults.js +430 -0
  149. package/tradelayer.js/src/vesting.js +491 -0
  150. package/tradelayer.js/src/volumeIndex.js +618 -0
  151. package/tradelayer.js/src/walletInterface.js +220 -0
  152. package/tradelayer.js/src/walletListener.js +665 -0
  153. package/tradelayer.js/tests/256decode.js +82 -0
  154. package/tradelayer.js/tests/UTXOracle.js +205 -0
  155. package/tradelayer.js/tests/base94test.js +23 -0
  156. package/tradelayer.js/tests/cancelTxTest.js +62 -0
  157. package/tradelayer.js/tests/contractInterfaceTest.js +48 -0
  158. package/tradelayer.js/tests/decimalTest.js +65 -0
  159. package/tradelayer.js/tests/decoderTest.js +100 -0
  160. package/tradelayer.js/tests/deltaCount.js +47 -0
  161. package/tradelayer.js/tests/deltaCount2.js +60 -0
  162. package/tradelayer.js/tests/interfaceTest.js +37 -0
  163. package/tradelayer.js/tests/mainTest.js +53 -0
  164. package/tradelayer.js/tests/makeActivationTest.js +24 -0
  165. package/tradelayer.js/tests/maxHeightTest.js +49 -0
  166. package/tradelayer.js/tests/reverseHash.js +72 -0
  167. package/tradelayer.js/tests/sensitiveConsoleOutput.txt +267 -0
  168. package/tradelayer.js/tests/tallyTest.js +40 -0
  169. package/tradelayer.js/tests/testBuybacks.js +46 -0
  170. package/tradelayer.js/tests/testCodeHash.js +49 -0
  171. package/tradelayer.js/tests/testConsensusHash.js +91 -0
  172. package/tradelayer.js/tests/testDecode.js +30 -0
  173. package/tradelayer.js/tests/testEncodingLengths.js +129 -0
  174. package/tradelayer.js/tests/testGetTx +32 -0
  175. package/tradelayer.js/tests/testGetTx.js +32 -0
  176. package/tradelayer.js/tests/testHexHash.js +32 -0
  177. package/tradelayer.js/tests/testIndexHash.js +35 -0
  178. package/tradelayer.js/tests/testInitContracts.js +38 -0
  179. package/tradelayer.js/tests/testMaxConsensus.js +12 -0
  180. package/tradelayer.js/tests/testMaxSynth.js +44 -0
  181. package/tradelayer.js/tests/testMint.js +21 -0
  182. package/tradelayer.js/tests/testNetwork.js +33 -0
  183. package/tradelayer.js/tests/testOrderbookLoad.js +62 -0
  184. package/tradelayer.js/tests/testRebates.js +32 -0
  185. package/tradelayer.js/tests/testRedeem.js +22 -0
  186. package/tradelayer.js/tests/testTokenTrade.js +39 -0
  187. package/tradelayer.js/tests/testTxBuild.js +42 -0
  188. package/tradelayer.js/tests/testUTXOTrade.js +27 -0
  189. package/tradelayer.js/tests/tokenTradeHistory.js +27 -0
  190. package/tradelayer.js/tests/tradeFutures.js +40 -0
  191. package/tradelayer.js/tests/tradeHistoryExample.js +35 -0
  192. package/tradelayer.js/tests/tradeHistoryLoad.js +15 -0
  193. package/tradelayer.js/tests/txScanTest.js +134 -0
  194. package/tradelayer.js/tests/validateTest.js +136 -0
  195. package/tradelayer.js/tests/vestingTest.js +37 -0
  196. package/tradelayer.js/utils/activateMainnet.js +59 -0
  197. package/tradelayer.js/utils/activateMainnetDoge.js +63 -0
  198. package/tradelayer.js/utils/autocompactdb.js +23 -0
  199. package/tradelayer.js/utils/base64toHex.js +32 -0
  200. package/tradelayer.js/utils/broadcastDoge.js +38 -0
  201. package/tradelayer.js/utils/calcRedeem.js +19 -0
  202. package/tradelayer.js/utils/checkNetwork.js +27 -0
  203. package/tradelayer.js/utils/createAddress.js +48 -0
  204. package/tradelayer.js/utils/createAttestation.js +133 -0
  205. package/tradelayer.js/utils/createContract.js +118 -0
  206. package/tradelayer.js/utils/createOracle.js +94 -0
  207. package/tradelayer.js/utils/createwallet.js +20 -0
  208. package/tradelayer.js/utils/crossFuturesTrades.js +57 -0
  209. package/tradelayer.js/utils/crossTokenTrades.js +62 -0
  210. package/tradelayer.js/utils/dumpPriv.js +29 -0
  211. package/tradelayer.js/utils/generateChannel.js +34 -0
  212. package/tradelayer.js/utils/getInfo.js +21 -0
  213. package/tradelayer.js/utils/hardWipe.js +20 -0
  214. package/tradelayer.js/utils/hexTo64.js +16 -0
  215. package/tradelayer.js/utils/importAddress.js +28 -0
  216. package/tradelayer.js/utils/importpriv.js +20 -0
  217. package/tradelayer.js/utils/issueOracleContract.js +67 -0
  218. package/tradelayer.js/utils/issueTokens.js +41 -0
  219. package/tradelayer.js/utils/listunspent.js +66 -0
  220. package/tradelayer.js/utils/litecoinClient.js +30 -0
  221. package/tradelayer.js/utils/loadwallet.js +20 -0
  222. package/tradelayer.js/utils/publishOracle.js +113 -0
  223. package/tradelayer.js/utils/sendActivation.js +21 -0
  224. package/tradelayer.js/utils/sendChannelContractTrade.js +34 -0
  225. package/tradelayer.js/utils/sendChannelTokenTrade.js +34 -0
  226. package/tradelayer.js/utils/sendCommit.js +24 -0
  227. package/tradelayer.js/utils/sendDoge.js +62 -0
  228. package/tradelayer.js/utils/sendDogeMain.js +67 -0
  229. package/tradelayer.js/utils/sendDogeTx.js +46 -0
  230. package/tradelayer.js/utils/sendLTC.js +63 -0
  231. package/tradelayer.js/utils/sendMainnet.js +62 -0
  232. package/tradelayer.js/utils/sendTransfer.js +19 -0
  233. package/tradelayer.js/utils/sendVestTest.js +88 -0
  234. package/tradelayer.js/utils/sendWithdrawal.js +26 -0
  235. package/tradelayer.js/utils/simpleStart.js +8 -0
  236. package/tradelayer.js/utils/startStop.js +27 -0
  237. package/tradelayer.js/utils/structuredTrades.js +136 -0
  238. package/tradelayer.js/utils/verifySignature.js +90 -0
  239. package/tradelayer.js/utils/verifyWitnessAndScriptPubkey.js +41 -0
  240. package/tradelayer.js/utils/walletCache.js +172 -0
  241. package/tradelayer.js/utils/walletContractInterface.js +48 -0
  242. package/tradelayer.js/utils/walletFetchTxs.js +66 -0
  243. package/tradelayer.js/utils/walletUtils.js +97 -0
  244. package/tradelayer.js/utils/wipeDB.js +55 -0
  245. package/tradelayer.js/utils/wipeDBNotTx.js +50 -0
  246. package/txEncoder.js +529 -0
  247. package/utility.js +28 -0
  248. package/verifymessage.js +38 -0
  249. package/ws-transport.js +311 -0
@@ -0,0 +1,26 @@
1
+ const hexString = "808479860";
2
+
3
+ function hexToBytes(hex) {
4
+ let bytes = [];
5
+ for (let i = 0; i < hex.length; i += 2) {
6
+ bytes.push(parseInt(hex.substr(i, 2), 16));
7
+ }
8
+ return bytes;
9
+ }
10
+
11
+ function bytesToInteger(bytes) {
12
+ return bytes.reduce((total, currentByte) => total * 256 + currentByte, 0);
13
+ }
14
+
15
+ function integerToBase36(integer) {
16
+ return integer.toString(36);
17
+ }
18
+
19
+ const bytes = hexToBytes(hexString);
20
+ const integer = bytesToInteger(bytes);
21
+ const base36String = integerToBase36(integer);
22
+
23
+ console.log("Hex:", hexString);
24
+ console.log("Bytes:", bytes);
25
+ console.log("Integer:", integer);
26
+ console.log("Base36 String:", base36String);
@@ -0,0 +1,79 @@
1
+ class OptionChain {
2
+ constructor() {
3
+ this.optionChains = new Map(); // Stores all option chains
4
+ }
5
+
6
+ createOptionChain(contractSeriesId, strikeInterval, europeanStyle) {
7
+ const optionChainKey = `optionChain-${contractSeriesId}`;
8
+ let optionChain = this.optionChains.get(optionChainKey) || [];
9
+
10
+ // Assuming we have a method to get the current block height and expiry intervals
11
+ const currentBlockHeight = this.getCurrentBlockHeight();
12
+ const expiryIntervals = this.getExpiryIntervals(contractSeriesId);
13
+
14
+ expiryIntervals.forEach(expiryBlock => {
15
+ // Generate Puts and Calls for each strike price
16
+ const strikePrices = this.calculateStrikePrices(contractSeriesId, strikeInterval);
17
+ strikePrices.forEach(strikePrice => {
18
+ ['P', 'C'].forEach(optionType => {
19
+ const contractId = `${contractSeriesId}-${expiryBlock}-${optionType}-${strikePrice}`;
20
+ optionChain.push({
21
+ contractId,
22
+ contractSeriesId,
23
+ expiryBlock,
24
+ optionType,
25
+ strikePrice,
26
+ europeanStyle
27
+ });
28
+ });
29
+ });
30
+ });
31
+
32
+ // Update the option chain in the map
33
+ this.optionChains.set(optionChainKey, optionChain);
34
+
35
+ console.log(`Option chain created for contract series ID ${contractSeriesId}`);
36
+ return optionChain;
37
+ }
38
+
39
+ // Helper method to calculate strike prices based on the interval
40
+ calculateStrikePrices(contractSeriesId, strikeInterval) {
41
+ // Placeholder for logic to calculate strike prices
42
+ // This might involve fetching the current price of the underlying asset and calculating strikes around it
43
+ return []; // Return an array of strike prices
44
+ }
45
+
46
+ // Placeholder method to get current block height
47
+ getCurrentBlockHeight() {
48
+ // Logic to fetch the current block height from the blockchain
49
+ return 0; // Replace with actual implementation
50
+ }
51
+
52
+ // Placeholder method to get expiry intervals for a contract series
53
+ getExpiryIntervals(contractSeriesId) {
54
+ // Logic to fetch expiry intervals for the given contract series
55
+ return []; // Replace with actual implementation
56
+ },
57
+
58
+ async storeOptionChain(optionChain) {
59
+ // Placeholder for logic to store the option chain in the blockchain or database
60
+ // Implement as per your system's requirements
61
+ // This might involve creating transactions, interacting with a smart contract, or simply storing in a database
62
+ },
63
+
64
+ isValidSeriesId(seriesId) {
65
+ // Placeholder for series ID validation logic
66
+ // Implement as per your system's requirements
67
+ return true; // Replace with actual validation logic
68
+ }
69
+ }
70
+
71
+ // Example usage
72
+ const optionChainManager = new OptionChainManager();
73
+ const contractSeriesId = 1; // Example series ID
74
+ const strikeInterval = 5; // Example strike interval
75
+ const europeanStyle = true; // European style option
76
+ const optionChainz = optionChainManager.createOptionChain(contractSeriesId, strikeInterval, europeanStyle);
77
+ console.log(optionChainz);
78
+
79
+ module.exports = optionChain
@@ -0,0 +1,116 @@
1
+ const Litecoin = require('litecoin'); // Replace with actual library import
2
+ const util = require('util');
3
+ const bitcore = require('bitcore-lib-ltc');
4
+
5
+ const client = new Litecoin.Client({
6
+ host: '127.0.0.1',
7
+ port: 18332,
8
+ user: 'user',
9
+ pass: 'pass',
10
+ timeout: 10000
11
+ });
12
+
13
+ const STANDARD_FEE = 10000; // Standard fee in LTC
14
+ const DUST_THRESHOLD = 54600; // Dust threshold in LTC
15
+
16
+ const decoderawtransactionAsync = util.promisify(client.cmd.bind(client, 'decoderawtransaction'));
17
+ const getrawtransactionAsync = util.promisify(client.cmd.bind(client, 'getrawtransaction'));
18
+ const dumpprivkeyAsync = util.promisify(client.cmd.bind(client, 'dumpprivkey'));
19
+ const sendrawtransactionAsync = util.promisify(client.cmd.bind(client, 'sendrawtransaction'));
20
+ const listUnspentAsync = util.promisify(client.cmd.bind(client, 'listunspent'))
21
+
22
+ const scriptPubKey= "0014ebecd536259ef21bc6ecc18e45b35412f0472290"
23
+
24
+ async function main() {
25
+
26
+ // Dump private key
27
+ const privateKey = await dumpprivkeyAsync('tltc1qa0kd2d39nmeph3hvcx8ytv65ztcywg5sazhtw8');
28
+ console.log(privateKey);
29
+
30
+ // Get raw transaction
31
+ const rawTx = await getrawtransactionAsync('57dbb47d8db6249b720421d78052e6f168664f3c062f1fbe187270ff5edd4dc5');
32
+ console.log(rawTx);
33
+
34
+ // Extract scriptPubKey
35
+ const scriptPubKey = await getScriptPubKeyFromRawTx(rawTx, 'tltc1qa0kd2d39nmeph3hvcx8ytv65ztcywg5sazhtw8', 1);
36
+ console.log(scriptPubKey);
37
+
38
+ // Create UTXO object
39
+ var utxo = {
40
+ "txId": "57dbb47d8db6249b720421d78052e6f168664f3c062f1fbe187270ff5edd4dc5",
41
+ "outputIndex": 1,
42
+ "address": "tltc1qa0kd2d39nmeph3hvcx8ytv65ztcywg5sazhtw8",
43
+ "script": scriptPubKey,
44
+ "satoshis": 50000 // This should be the actual amount in satoshis
45
+ };
46
+
47
+ // Get the UTXO from the blockchain (I assume you have the txid and vout)
48
+ const utxoTxId = '57dbb47d8db6249b720421d78052e6f168664f3c062f1fbe187270ff5edd4dc5';
49
+ const utxoVout = 1; // or the appropriate vout index
50
+
51
+ const blockchainUtxo = await getrawtransactionAsync(utxoTxId, true);
52
+ const blockchainScriptPubKey = blockchainUtxo.vout[utxoVout].scriptPubKey.hex;
53
+
54
+ // Compare with the script you have in your UTXO object
55
+ if (utxo.script !== blockchainScriptPubKey) {
56
+ console.error("Script mismatch: UTXO script does not match blockchain data.");
57
+ }
58
+
59
+ // Check if the UTXO is unspent
60
+ const utxos = await listUnspentAsync(0, 9999999, ["tltc1qa0kd2d39nmeph3hvcx8ytv65ztcywg5sazhtw8"]);
61
+
62
+ let utxoFound = false;
63
+ utxos.forEach(utxo => {
64
+ if (utxo.txid === utxoTxId && utxo.vout === utxoVout) {
65
+ utxoFound = true;
66
+ // Validate the satoshis (amount in satoshis) as well
67
+ if (utxo.satoshis !== 50000) { // Replace 50000 with the correct amount
68
+ console.error("Incorrect UTXO amount.");
69
+ }
70
+ }
71
+ });
72
+
73
+ if (!utxoFound) {
74
+ console.error("UTXO not found or already spent.");
75
+ }
76
+
77
+ try {
78
+ // Create and sign transaction
79
+ var transaction = new bitcore.Transaction()
80
+ .from(utxo) // Make sure this UTXO is unspent
81
+ .addData('litecore rocks') // OP_RETURN data
82
+ .change('tltc1qa0kd2d39nmeph3hvcx8ytv65ztcywg5sazhtw8') // Change address
83
+ .sign(privateKey);
84
+
85
+ // Check if transaction is valid before serialization
86
+ if (transaction.getSerializationError()) {
87
+ const error = transaction.getSerializationError().message;
88
+ throw new Error(`Transaction serialization failed: ${error}`);
89
+ }
90
+
91
+ const serializedTx = transaction.serialize();
92
+ console.log(`Serialized Transaction: ${serializedTx}`);
93
+
94
+ // Broadcast the transaction
95
+ const txid = await sendrawtransactionAsync(serializedTx);
96
+ console.log(`Transaction ID: ${txid}`);
97
+ } catch (error) {
98
+ console.error(`Error:`, error);
99
+ }
100
+ }
101
+
102
+ // Execute the main function
103
+ main();
104
+
105
+ async function getScriptPubKeyFromRawTx(rawTx, address, vout) {
106
+ try {
107
+ // Decode the raw transaction
108
+ const decodedTx = await decoderawtransactionAsync(rawTx);
109
+
110
+ // Find the output with the matching address
111
+ return decodedTx.vout[vout].scriptPubKey.hex;
112
+ } catch (error) {
113
+ console.error(`Error retrieving scriptPubKey:`, error);
114
+ throw error;
115
+ }
116
+ }
@@ -0,0 +1,64 @@
1
+ const Litecoin = require('litecoin'); // Replace with actual library import
2
+ const async = require('async')
3
+ const util = require('util');
4
+ const bitcore = require('bitcore-lib-ltc');
5
+
6
+ const STANDARD_FEE = 0.0001; // Standard fee in LTC
7
+ const client = new Litecoin.Client({
8
+ host: '127.0.0.1',
9
+ port: 18332,
10
+ user: 'user',
11
+ pass: 'pass',
12
+ timeout: 10000
13
+ });
14
+
15
+
16
+ var privateKey =''
17
+
18
+ client.cmd('dumpprivkey','tltc1qa0kd2d39nmeph3hvcx8ytv65ztcywg5sazhtw8',function(err,data){
19
+ if(err){console.log(err)}
20
+ privateKey = data
21
+ console.log(privateKey)
22
+ });
23
+
24
+
25
+
26
+ const decoderawtransactionAsync = util.promisify(client.cmd.bind(client, 'decoderawtransaction'));
27
+ const getrawtransactionAsync = util.promisify(client.cmd.bind(client, 'getrawtransaction'));
28
+
29
+ const rawTx = await getrawtransactionAsync('57dbb47d8db6249b720421d78052e6f168664f3c062f1fbe187270ff5edd4dc5')
30
+
31
+ console.log(rawTx)
32
+
33
+ async function getScriptPubKeyFromRawTx(rawTx, address, vout) {
34
+ try {
35
+ // Decode the raw transaction
36
+ const decodedTx = await decoderawtransactionAsync('decoderawtransaction', rawTx);
37
+
38
+ // Find the output with the matching address
39
+ return decodedTx.vout[vout].scriptPubKey.hex;
40
+
41
+ } catch (error) {
42
+ console.error(`Error retrieving scriptPubKey:`, error);
43
+ throw error;
44
+ }
45
+ }
46
+
47
+ const scriptPubKey = getScriptPubKeyFromRawTx()
48
+
49
+ console.log(scriptPubKey)
50
+
51
+ var utxo = {
52
+ "txId" : "57dbb47d8db6249b720421d78052e6f168664f3c062f1fbe187270ff5edd4dc5",
53
+ "outputIndex" : `1`,
54
+ "address" : "tltc1qa0kd2d39nmeph3hvcx8ytv65ztcywg5sazhtw8",
55
+ "script" : "0014ebecd536259ef21bc6ecc18e45b35412f0472290",
56
+ "satoshis" : 50000
57
+ };
58
+
59
+ var transaction = new bitcore.Transaction()
60
+ .from(utxo)
61
+ .addData('litecore rocks') // Add OP_RETURN data
62
+ .sign(privateKey);
63
+
64
+ console.log(transaction)
@@ -0,0 +1,32 @@
1
+ const OR = require('../oracle')
2
+
3
+ describe('=== ORACLE TESTs ===', () => {
4
+ path = './dbOR'
5
+ or = null
6
+
7
+ beforeAll(async () => {
8
+ //console.log('--beforeAll');
9
+ })
10
+
11
+ beforeEach(async () => {
12
+ //console.log('--beforeEach');
13
+ or = new OR(path)
14
+ await or.load()
15
+ });
16
+
17
+ test('PUT', async () => {
18
+ })
19
+
20
+ test('GET', async () => {
21
+ })
22
+
23
+ afterEach(async () => {
24
+ //console.log('--afterEach');
25
+ //await or.save()
26
+ await or.close()
27
+ })
28
+
29
+ afterAll(async () => {
30
+ //console.log('--afterAll');
31
+ })
32
+ })
@@ -0,0 +1,36 @@
1
+ const OB = require('../orderbook')
2
+
3
+ describe('=== OB TESTS ===', () => {
4
+ path = './dbOB'
5
+ ob = null
6
+
7
+ beforeAll(async () => {
8
+ //console.log('--beforeAll');
9
+ })
10
+
11
+ beforeEach(async () => {
12
+ //console.log('--beforeEach');
13
+ ob = new OB(path)
14
+ await ob.load()
15
+ });
16
+
17
+ test('PUT', async () => {
18
+ ob.addTokenOrder({ propertyIdNumber : 1, propertyIdNumberDesired : 1, amountOffered : 100, amountExpected : 100, time : 123456789 })
19
+ })
20
+
21
+ test('GET', async () => {
22
+ })
23
+
24
+ afterEach(async () => {
25
+ //console.log('--afterEach');
26
+ //await ob.save(null)
27
+ await ob.close()
28
+ })
29
+
30
+ afterAll(async () => {
31
+ //console.log('--afterAll');
32
+ ob = new OB(path)
33
+ await ob.clear()
34
+ await ob.close()
35
+ })
36
+ })
@@ -0,0 +1,93 @@
1
+ const { CSHA256 } = require('sha2');
2
+
3
+ function isBigEndian() {
4
+ const bint = { i: 0x01020304 };
5
+ const byteArray = new Uint8Array(new Uint32Array([bint.i]).buffer);
6
+ return byteArray[0] === 1;
7
+ }
8
+
9
+ function swapByteOrder16(us) {
10
+ if (isBigEndian()) return us;
11
+ return ((us >> 8) & 0x00ff) | ((us << 8) & 0xff00);
12
+ }
13
+
14
+ function swapByteOrder32(ui) {
15
+ if (isBigEndian()) return ui;
16
+ return (
17
+ ((ui >> 24) & 0x000000ff) |
18
+ ((ui << 8) & 0x00ff0000) |
19
+ ((ui >> 8) & 0x0000ff00) |
20
+ ((ui << 24) & 0xff000000)
21
+ );
22
+ }
23
+ function swapByteOrder64(ull) {
24
+ if (isBigEndian()) return;
25
+ ull = (
26
+ ((ull >> BigInt(56)) & BigInt(0x00000000000000ff)) |
27
+ ((ull << BigInt(40)) & BigInt(0x00ff000000000000)) |
28
+ ((ull << BigInt(24)) & BigInt(0x0000ff0000000000)) |
29
+ ((ull << BigInt(8)) & BigInt(0x000000ff00000000)) |
30
+ ((ull >> BigInt(8)) & BigInt(0x00000000ff000000)) |
31
+ ((ull >> BigInt(24)) & BigInt(0x0000000000ff0000)) |
32
+ ((ull >> BigInt(40)) & BigInt(0x000000000000ff00)) |
33
+ ((ull << BigInt(56)) & BigInt(0xff00000000000000))
34
+ );
35
+
36
+ // Note: The result `ull` will be a BigInt type.
37
+ }
38
+
39
+ function hashToAddress(version, hash) {
40
+ const Base58 = require('base-58');
41
+ const { CKeyID, CScriptID, Params } = require('bitcoinjs-lib');
42
+
43
+ const base58PrefixPubKeyAddress = Params().base58Prefixes.pubkeyhash;
44
+ const base58PrefixScriptAddress = Params().base58Prefixes.scripthash;
45
+
46
+ if (version === base58PrefixPubKeyAddress[0]) {
47
+ const keyId = new CKeyID(hash);
48
+ return Base58.encode(keyId);
49
+ } else if (version === base58PrefixScriptAddress[0]) {
50
+ const scriptId = new CScriptID(hash);
51
+ return Base58.encode(scriptId);
52
+ }
53
+
54
+ return '';
55
+ }
56
+
57
+ function prepareObfuscatedHashes(strSeed, hashCount) {
58
+ const MAX_SHA256_OBFUSCATION_TIMES = 255;
59
+ const sha_input = Buffer.alloc(128);
60
+ const sha_result = Buffer.alloc(32);
61
+ const vstrHashes = [];
62
+
63
+ if (strSeed.length >= sha_input.length) {
64
+ throw new Error('Seed length exceeds the maximum allowed size');
65
+ }
66
+
67
+ sha_input.write(strSeed);
68
+
69
+ if (hashCount > MAX_SHA256_OBFUSCATION_TIMES) {
70
+ hashCount = MAX_SHA256_OBFUSCATION_TIMES;
71
+ }
72
+
73
+ for (let j = 1; j <= hashCount; ++j) {
74
+ const sha256 = new CSHA256();
75
+ sha256.update(sha_input);
76
+ sha256.finalize(sha_result);
77
+ const hexStr = sha_result.toString('hex').toUpperCase();
78
+ vstrHashes[j] = hexStr;
79
+
80
+ sha_input.fill(0);
81
+ sha_input.write(hexStr);
82
+ }
83
+
84
+ return vstrHashes;
85
+ }
86
+
87
+ module.exports = {
88
+ swapByteOrder16,
89
+ swapByteOrder32,
90
+ swapByteOrder64,
91
+ hashToAddress,
92
+ prepareObfuscatedHashes,
93
+ };
@@ -0,0 +1,13 @@
1
+ const tokenIdentifier = 2;
2
+ const amount = "0.1";
3
+
4
+ // Convert the token identifier to a 4-byte hexadecimal string
5
+ const tokenIdentifierHex = tokenIdentifier.toString(16).padStart(8, "0");
6
+
7
+ // Convert the amount to a 8-byte hexadecimal string (assuming 8 bytes for the amount)
8
+ const amountHex = (Math.floor(parseFloat(amount) * 1e8)).toString(16).padStart(16, "0");
9
+
10
+ // Combine the token identifier and amount as a payload
11
+ const payload = tokenIdentifierHex + amountHex;
12
+
13
+ console.log(payload);
@@ -0,0 +1,23 @@
1
+ const BlockchainPersistence = require('./BlockchainPersistence');
2
+
3
+ describe('BlockchainPersistence', () => {
4
+ let blockchainPersistence;
5
+
6
+ beforeEach(() => {
7
+ blockchainPersistence = new BlockchainPersistence();
8
+ // Setup for test database connection
9
+ });
10
+
11
+ afterEach(() => {
12
+ // Clean up database or mock after each test
13
+ });
14
+
15
+ test('should update last known block hash', async () => {
16
+ const testBlockHash = '000000testhash';
17
+ await blockchainPersistence.updateLastKnownBlock(testBlockHash);
18
+ const storedHash = await blockchainPersistence.getLastKnownBlock();
19
+ expect(storedHash).toBe(testBlockHash);
20
+ });
21
+
22
+ // Add more tests for other methods
23
+ });
@@ -0,0 +1,53 @@
1
+ const PM = require('../property')
2
+
3
+ describe('=== PM TEST ===', () => {
4
+ path = './dbPM'
5
+ pm = null
6
+
7
+ beforeAll(async () => {
8
+ //console.log('--beforeAll');
9
+ })
10
+
11
+ beforeEach(async () => {
12
+ //console.log('--beforeEach');
13
+ pm = new PM(path)
14
+ await pm.load()
15
+ });
16
+
17
+ test('PUT1', async () => {
18
+ pm.addProperty(1, 'PROP1', 1000000, 'Fixed')
19
+ })
20
+
21
+ test('ID1', async () => {
22
+ let p = pm.getPropertyData(1)
23
+ expect(p != null).toBe(true)
24
+ expect(p.ticker).toBe('PROP1')
25
+ expect(p.type).toBe(1)
26
+ expect(p.totalInCirculation).toBe(1000000)
27
+ })
28
+
29
+ test('PUT2', async () => {
30
+ pm.addProperty(2, 'PROP2', 500000, 'Managed')
31
+ })
32
+
33
+ test('ID2', async () => {
34
+ let p = pm.getPropertyData(2)
35
+ expect(p != null).toBe(true)
36
+ expect(p.ticker).toBe('PROP2')
37
+ expect(p.type).toBe(2)
38
+ expect(p.totalInCirculation).toBe(500000)
39
+ })
40
+
41
+ afterEach(async () => {
42
+ //console.log('--afterEach');
43
+ await pm.save()
44
+ await pm.close()
45
+ })
46
+
47
+ afterAll(async () => {
48
+ //console.log('--afterAll');
49
+ pm = new PM(path)
50
+ await pm.save()
51
+ await pm.close()
52
+ })
53
+ })
@@ -0,0 +1,75 @@
1
+ // PropertyManager
2
+
3
+ const level = require('level');
4
+ const db = level('properties');
5
+
6
+ // ...existing code
7
+
8
+ loadPropertyIndexFromDb() {
9
+ return new Promise((resolve, reject) => {
10
+ db.get('propertyIndex', (err, value) => {
11
+ if (err) return reject(err);
12
+ if (!value) return resolve();
13
+
14
+ this.propertyIndex = new Map(Object.entries(JSON.parse(value)));
15
+ resolve();
16
+ });
17
+ });
18
+ }
19
+
20
+ savePropertyIndexToDb() {
21
+ const indexJson = JSON.stringify(Object.fromEntries(this.propertyIndex));
22
+
23
+ return new Promise((resolve, reject) => {
24
+ db.put('propertyIndex', indexJson, err => {
25
+ if (err) return reject(err);
26
+ resolve();
27
+ });
28
+ });
29
+ }
30
+
31
+ // TallyMap
32
+
33
+ const db = level('balances');
34
+
35
+ // ...existing code
36
+
37
+ loadBalancesFromDb() {
38
+ return new Promise((resolve, reject) => {
39
+ db.createReadStream()
40
+ .on('data', ({key, value}) => {
41
+ const { address, propertyId } = JSON.parse(key);
42
+ const balance = JSON.parse(value);
43
+
44
+ this.updateBalance(
45
+ address,
46
+ propertyId,
47
+ balance.amount,
48
+ balance.available,
49
+ balance.reserved
50
+ );
51
+ })
52
+ .on('error', reject)
53
+ .on('end', resolve);
54
+ });
55
+ }
56
+
57
+ saveBalancesToDb() {
58
+ const batch = [];
59
+
60
+ for (let [address, balances] of this.addresses) {
61
+ for (let [propertyId, balance] of Object.entries(balances)) {
62
+ const key = JSON.stringify({ address, propertyId });
63
+ const value = JSON.stringify(balance);
64
+
65
+ batch.push({ type: 'put', key, value });
66
+ }
67
+ }
68
+
69
+ return new Promise((resolve, reject) => {
70
+ db.batch(batch, err => {
71
+ if (err) return reject(err);
72
+ resolve();
73
+ });
74
+ });
75
+ }
@@ -0,0 +1,32 @@
1
+ const PropertyManager = require('./property.js'); // Adjust the path to the PropertyManager class file
2
+
3
+ async function addRandomTokensAndDisplay(count) {
4
+ const propertyManager = PropertyManager.getInstance();
5
+ const propertyTypes = ['Fixed', 'Managed', 'Native', 'Vesting', 'Synthetic', 'Non-Fungible'];
6
+
7
+
8
+ for (let i = 0; i < count; i++) {
9
+ const ticker = 'TK' + Math.random().toString(36).substring(2, 7).toUpperCase();
10
+ const type = propertyTypes[Math.floor(Math.random() * propertyTypes.length)];
11
+ const totalInCirculation = Math.floor(Math.random() * 1000000);
12
+
13
+ try {
14
+ const propertyId = await propertyManager.createToken(ticker, totalInCirculation, type);
15
+ console.log(`Added token with ID: ${propertyId}, Ticker: ${ticker}, Type: ${type}`);
16
+ } catch (error) {
17
+ console.error('Error adding token:', error);
18
+ }
19
+ }
20
+
21
+ try {
22
+ propertyManager.inspectPropertyIndex()
23
+
24
+ const properties = await PropertyManager.getPropertyIndex();
25
+ console.log('Current Properties:', properties);
26
+ } catch (error) {
27
+ console.error('Error retrieving properties:', error);
28
+ }
29
+ }
30
+
31
+ // Call the function to add 5 random tokens and display the list
32
+ addRandomTokensAndDisplay(5);
@@ -0,0 +1,17 @@
1
+ const TallyMap = require('./tally.js'); // Adjust the path
2
+
3
+ async function queryAddressBalances(address) {
4
+ try {
5
+ console.log(`Querying balances for address: ${address}`);
6
+ //const tallyMapInstance = await TallyMap.getInstance();
7
+ //await tallyMapInstance.loadFromDB();
8
+
9
+ const balances = await TallyMap.getAddressBalances(address);
10
+ console.log(`Balances for address ${address}:`, balances);
11
+ } catch (error) {
12
+ console.error('Error querying address balances:', error);
13
+ }
14
+ }
15
+
16
+ const addressToQuery = 'test-address' //'tltc1qa0kd2d39nmeph3hvcx8ytv65ztcywg5sazhtw8';
17
+ queryAddressBalances(addressToQuery);
@@ -0,0 +1,14 @@
1
+ const bcrypt = require('bcrypt');
2
+
3
+ const saltRounds = 10; // Number of salt rounds (adjust as needed)
4
+ const password = 'pass'; // Replace with your actual password
5
+
6
+ bcrypt.genSalt(saltRounds, function(err, salt) {
7
+ bcrypt.hash(password, salt, function(err, hash) {
8
+ if (!err) {
9
+ console.log(`Salted Hash Password: ${hash}`);
10
+ } else {
11
+ console.error('Error generating salted hash:', err);
12
+ }
13
+ });
14
+ });