@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.
- package/.claude/settings.local.json +13 -0
- package/.claude/skills/tl-algo/SKILL.md +255 -0
- package/.gitattributes +2 -0
- package/.github/workflows/publish.yaml +26 -0
- package/4mm.js +163 -0
- package/LICENSE +21 -0
- package/NPMSwapRefactor.zip +0 -0
- package/README.md +217 -0
- package/address.sh +26 -0
- package/algoAPI.js +581 -0
- package/analyzepsbt.js +92 -0
- package/apiEx.js +99 -0
- package/bb_hyperscalper.js +290 -0
- package/bbo_demo.js +111 -0
- package/buyer.js +622 -0
- package/client.js +50 -0
- package/createTxTest.js +26 -0
- package/createWallet.js +75 -0
- package/daytrader.js +531 -0
- package/decodeTest.js +69 -0
- package/fundingManager.js +144 -0
- package/index.js +4 -0
- package/listener.js +27 -0
- package/litecoreTxBuilder.js +1128 -0
- package/mmEx.js +356 -0
- package/networks.js +51 -0
- package/orderbook.js +200 -0
- package/package.json +34 -0
- package/perTradeQueue.js +36 -0
- package/projectsTLNPMTLNPM/package-lock.json +162 -0
- package/projectsTLNPMTLNPM/package.json +5 -0
- package/quick.js +32 -0
- package/quickFut.js +37 -0
- package/quickSell.js +37 -0
- package/relayerClient.js +117 -0
- package/run4mm.js +80 -0
- package/run_bbo_tracker.js +241 -0
- package/seller.js +443 -0
- package/session.js +45 -0
- package/setup-lin-ltc.sh +139 -0
- package/setup-lin.sh +203 -0
- package/setup-win-ltc.bat +108 -0
- package/setup-win.bat +167 -0
- package/spam_screamer_futures.js +222 -0
- package/tradelayer.js/.gitattributes +2 -0
- package/tradelayer.js/README.md +2 -0
- package/tradelayer.js/oldTests/activationTest.js +6 -0
- package/tradelayer.js/oldTests/base58.test.js +23 -0
- package/tradelayer.js/oldTests/base64Decode.test.js +16 -0
- package/tradelayer.js/oldTests/blocksRefactor.js +140 -0
- package/tradelayer.js/oldTests/checkVestBalance.js +25 -0
- package/tradelayer.js/oldTests/consensusHashProto.js +151 -0
- package/tradelayer.js/oldTests/contractOrderbook.js +243 -0
- package/tradelayer.js/oldTests/createPayload.js +0 -0
- package/tradelayer.js/oldTests/createTestnetAddr.js +43 -0
- package/tradelayer.js/oldTests/decode.js +205 -0
- package/tradelayer.js/oldTests/decodeTest.js +50 -0
- package/tradelayer.js/oldTests/displayTallyMap.js +19 -0
- package/tradelayer.js/oldTests/encodeDecode.js +340 -0
- package/tradelayer.js/oldTests/expressTest.js +29 -0
- package/tradelayer.js/oldTests/extractBlocksVanilla.js +214 -0
- package/tradelayer.js/oldTests/extractBlocksVanillaa.js +179 -0
- package/tradelayer.js/oldTests/extractPubkeyTest.js +60 -0
- package/tradelayer.js/oldTests/fillInputCacheProto.js +111 -0
- package/tradelayer.js/oldTests/getRawTxTest.js +22 -0
- package/tradelayer.js/oldTests/indexTest.js +26 -0
- package/tradelayer.js/oldTests/initTokensTest.js +32 -0
- package/tradelayer.js/oldTests/interfaceChild.js +129 -0
- package/tradelayer.js/oldTests/listenerChild.js +112 -0
- package/tradelayer.js/oldTests/opdecode.js +26 -0
- package/tradelayer.js/oldTests/options.js +79 -0
- package/tradelayer.js/oldTests/optxtest.js +116 -0
- package/tradelayer.js/oldTests/optxtest1.js +64 -0
- package/tradelayer.js/oldTests/oracle.test.js +32 -0
- package/tradelayer.js/oldTests/orderbook.test.js +36 -0
- package/tradelayer.js/oldTests/parsing.js +93 -0
- package/tradelayer.js/oldTests/payload.js +13 -0
- package/tradelayer.js/oldTests/persistenceUnitTest.js +23 -0
- package/tradelayer.js/oldTests/property.test.js +53 -0
- package/tradelayer.js/oldTests/propertyLevel.js +75 -0
- package/tradelayer.js/oldTests/propertyTest.js +32 -0
- package/tradelayer.js/oldTests/queryAddressTest.js +17 -0
- package/tradelayer.js/oldTests/salter.js +14 -0
- package/tradelayer.js/oldTests/tally.js +81 -0
- package/tradelayer.js/oldTests/tally.test.js +48 -0
- package/tradelayer.js/oldTests/tally2.js +124 -0
- package/tradelayer.js/oldTests/tally3.js +142 -0
- package/tradelayer.js/oldTests/tallyDiag.js +38 -0
- package/tradelayer.js/oldTests/testGetRaw.js +40 -0
- package/tradelayer.js/oldTests/testHexConvert.js +47 -0
- package/tradelayer.js/oldTests/testNewEncoding.js +96 -0
- package/tradelayer.js/oldTests/testNewEncoding2.js +113 -0
- package/tradelayer.js/oldTests/testNewEncoding3 +112 -0
- package/tradelayer.js/oldTests/testNewEncoding3.js +168 -0
- package/tradelayer.js/oldTests/testOPReturn.js +102 -0
- package/tradelayer.js/oldTests/testPayload.js +23 -0
- package/tradelayer.js/oldTests/testRaw.js +50 -0
- package/tradelayer.js/oldTests/testSendTooMuch.js +20 -0
- package/tradelayer.js/oldTests/testTxBuild +28 -0
- package/tradelayer.js/oldTests/testTxBuild.js +42 -0
- package/tradelayer.js/oldTests/tokenOrderbook.js +243 -0
- package/tradelayer.js/oldTests/txUtilsA.js +515 -0
- package/tradelayer.js/oldTests/validityUnitTest.js +53 -0
- package/tradelayer.js/oldTests/vaults.js +72 -0
- package/tradelayer.js/oldTests/volumeIndex.js +117 -0
- package/tradelayer.js/oldTests/volumeIndex2.js +88 -0
- package/tradelayer.js/output_base64.txt +1 -0
- package/tradelayer.js/package-lock.json +9967 -0
- package/tradelayer.js/package.json +61 -0
- package/tradelayer.js/server/index.js +88 -0
- package/tradelayer.js/server/litecoind.exe +0 -0
- package/tradelayer.js/src/activation.js +303 -0
- package/tradelayer.js/src/adjuster.js +77 -0
- package/tradelayer.js/src/amm.js +400 -0
- package/tradelayer.js/src/base256.js +55 -0
- package/tradelayer.js/src/base94.js +79 -0
- package/tradelayer.js/src/channels.js +1163 -0
- package/tradelayer.js/src/clearing.js +3109 -0
- package/tradelayer.js/src/clearlist.js +364 -0
- package/tradelayer.js/src/client.js +295 -0
- package/tradelayer.js/src/consensus.js +613 -0
- package/tradelayer.js/src/contractRegistry.js +964 -0
- package/tradelayer.js/src/db.js +89 -0
- package/tradelayer.js/src/init.js +24 -0
- package/tradelayer.js/src/insurance.js +347 -0
- package/tradelayer.js/src/interface.js +218 -0
- package/tradelayer.js/src/interfaceExpress.js +178 -0
- package/tradelayer.js/src/iou.js +509 -0
- package/tradelayer.js/src/listener.js +226 -0
- package/tradelayer.js/src/logic.js +1702 -0
- package/tradelayer.js/src/main.js +927 -0
- package/tradelayer.js/src/marginMap.js +2165 -0
- package/tradelayer.js/src/options.js +126 -0
- package/tradelayer.js/src/oracle.js +394 -0
- package/tradelayer.js/src/orderbook.js +4123 -0
- package/tradelayer.js/src/persistence.js +554 -0
- package/tradelayer.js/src/property.js +411 -0
- package/tradelayer.js/src/reOrg.js +41 -0
- package/tradelayer.js/src/scaling.js +145 -0
- package/tradelayer.js/src/tally.js +1275 -0
- package/tradelayer.js/src/tradeHistoryManager.js +552 -0
- package/tradelayer.js/src/txDecoder.js +584 -0
- package/tradelayer.js/src/txEncoder.js +610 -0
- package/tradelayer.js/src/txIndex.js +502 -0
- package/tradelayer.js/src/txUtils.js +1392 -0
- package/tradelayer.js/src/types.js +429 -0
- package/tradelayer.js/src/validity.js +3077 -0
- package/tradelayer.js/src/vaults.js +430 -0
- package/tradelayer.js/src/vesting.js +491 -0
- package/tradelayer.js/src/volumeIndex.js +618 -0
- package/tradelayer.js/src/walletInterface.js +220 -0
- package/tradelayer.js/src/walletListener.js +665 -0
- package/tradelayer.js/tests/256decode.js +82 -0
- package/tradelayer.js/tests/UTXOracle.js +205 -0
- package/tradelayer.js/tests/base94test.js +23 -0
- package/tradelayer.js/tests/cancelTxTest.js +62 -0
- package/tradelayer.js/tests/contractInterfaceTest.js +48 -0
- package/tradelayer.js/tests/decimalTest.js +65 -0
- package/tradelayer.js/tests/decoderTest.js +100 -0
- package/tradelayer.js/tests/deltaCount.js +47 -0
- package/tradelayer.js/tests/deltaCount2.js +60 -0
- package/tradelayer.js/tests/interfaceTest.js +37 -0
- package/tradelayer.js/tests/mainTest.js +53 -0
- package/tradelayer.js/tests/makeActivationTest.js +24 -0
- package/tradelayer.js/tests/maxHeightTest.js +49 -0
- package/tradelayer.js/tests/reverseHash.js +72 -0
- package/tradelayer.js/tests/sensitiveConsoleOutput.txt +267 -0
- package/tradelayer.js/tests/tallyTest.js +40 -0
- package/tradelayer.js/tests/testBuybacks.js +46 -0
- package/tradelayer.js/tests/testCodeHash.js +49 -0
- package/tradelayer.js/tests/testConsensusHash.js +91 -0
- package/tradelayer.js/tests/testDecode.js +30 -0
- package/tradelayer.js/tests/testEncodingLengths.js +129 -0
- package/tradelayer.js/tests/testGetTx +32 -0
- package/tradelayer.js/tests/testGetTx.js +32 -0
- package/tradelayer.js/tests/testHexHash.js +32 -0
- package/tradelayer.js/tests/testIndexHash.js +35 -0
- package/tradelayer.js/tests/testInitContracts.js +38 -0
- package/tradelayer.js/tests/testMaxConsensus.js +12 -0
- package/tradelayer.js/tests/testMaxSynth.js +44 -0
- package/tradelayer.js/tests/testMint.js +21 -0
- package/tradelayer.js/tests/testNetwork.js +33 -0
- package/tradelayer.js/tests/testOrderbookLoad.js +62 -0
- package/tradelayer.js/tests/testRebates.js +32 -0
- package/tradelayer.js/tests/testRedeem.js +22 -0
- package/tradelayer.js/tests/testTokenTrade.js +39 -0
- package/tradelayer.js/tests/testTxBuild.js +42 -0
- package/tradelayer.js/tests/testUTXOTrade.js +27 -0
- package/tradelayer.js/tests/tokenTradeHistory.js +27 -0
- package/tradelayer.js/tests/tradeFutures.js +40 -0
- package/tradelayer.js/tests/tradeHistoryExample.js +35 -0
- package/tradelayer.js/tests/tradeHistoryLoad.js +15 -0
- package/tradelayer.js/tests/txScanTest.js +134 -0
- package/tradelayer.js/tests/validateTest.js +136 -0
- package/tradelayer.js/tests/vestingTest.js +37 -0
- package/tradelayer.js/utils/activateMainnet.js +59 -0
- package/tradelayer.js/utils/activateMainnetDoge.js +63 -0
- package/tradelayer.js/utils/autocompactdb.js +23 -0
- package/tradelayer.js/utils/base64toHex.js +32 -0
- package/tradelayer.js/utils/broadcastDoge.js +38 -0
- package/tradelayer.js/utils/calcRedeem.js +19 -0
- package/tradelayer.js/utils/checkNetwork.js +27 -0
- package/tradelayer.js/utils/createAddress.js +48 -0
- package/tradelayer.js/utils/createAttestation.js +133 -0
- package/tradelayer.js/utils/createContract.js +118 -0
- package/tradelayer.js/utils/createOracle.js +94 -0
- package/tradelayer.js/utils/createwallet.js +20 -0
- package/tradelayer.js/utils/crossFuturesTrades.js +57 -0
- package/tradelayer.js/utils/crossTokenTrades.js +62 -0
- package/tradelayer.js/utils/dumpPriv.js +29 -0
- package/tradelayer.js/utils/generateChannel.js +34 -0
- package/tradelayer.js/utils/getInfo.js +21 -0
- package/tradelayer.js/utils/hardWipe.js +20 -0
- package/tradelayer.js/utils/hexTo64.js +16 -0
- package/tradelayer.js/utils/importAddress.js +28 -0
- package/tradelayer.js/utils/importpriv.js +20 -0
- package/tradelayer.js/utils/issueOracleContract.js +67 -0
- package/tradelayer.js/utils/issueTokens.js +41 -0
- package/tradelayer.js/utils/listunspent.js +66 -0
- package/tradelayer.js/utils/litecoinClient.js +30 -0
- package/tradelayer.js/utils/loadwallet.js +20 -0
- package/tradelayer.js/utils/publishOracle.js +113 -0
- package/tradelayer.js/utils/sendActivation.js +21 -0
- package/tradelayer.js/utils/sendChannelContractTrade.js +34 -0
- package/tradelayer.js/utils/sendChannelTokenTrade.js +34 -0
- package/tradelayer.js/utils/sendCommit.js +24 -0
- package/tradelayer.js/utils/sendDoge.js +62 -0
- package/tradelayer.js/utils/sendDogeMain.js +67 -0
- package/tradelayer.js/utils/sendDogeTx.js +46 -0
- package/tradelayer.js/utils/sendLTC.js +63 -0
- package/tradelayer.js/utils/sendMainnet.js +62 -0
- package/tradelayer.js/utils/sendTransfer.js +19 -0
- package/tradelayer.js/utils/sendVestTest.js +88 -0
- package/tradelayer.js/utils/sendWithdrawal.js +26 -0
- package/tradelayer.js/utils/simpleStart.js +8 -0
- package/tradelayer.js/utils/startStop.js +27 -0
- package/tradelayer.js/utils/structuredTrades.js +136 -0
- package/tradelayer.js/utils/verifySignature.js +90 -0
- package/tradelayer.js/utils/verifyWitnessAndScriptPubkey.js +41 -0
- package/tradelayer.js/utils/walletCache.js +172 -0
- package/tradelayer.js/utils/walletContractInterface.js +48 -0
- package/tradelayer.js/utils/walletFetchTxs.js +66 -0
- package/tradelayer.js/utils/walletUtils.js +97 -0
- package/tradelayer.js/utils/wipeDB.js +55 -0
- package/tradelayer.js/utils/wipeDBNotTx.js +50 -0
- package/txEncoder.js +529 -0
- package/utility.js +28 -0
- package/verifymessage.js +38 -0
- package/ws-transport.js +311 -0
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
// encodeDecode.js
|
|
2
|
+
|
|
3
|
+
// Function to encode "Simple Token Issue" transaction (Type 1)
|
|
4
|
+
function encodeSimpleTokenIssue(type, params) {
|
|
5
|
+
const payload = [type, params.initialAmount, params.ticker, params.whitelists || 0];
|
|
6
|
+
return payload.join(',');
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// Function to decode "Simple Token Issue" transaction (Type 1)
|
|
10
|
+
function decodeSimpleTokenIssue(encodedPayload) {
|
|
11
|
+
const parts = encodedPayload.split(',');
|
|
12
|
+
const type = parseInt(parts[0], 10);
|
|
13
|
+
const params = {
|
|
14
|
+
initialAmount: parseInt(parts[1], 10),
|
|
15
|
+
ticker: parts[2],
|
|
16
|
+
whitelists: parseInt(parts[3], 10),
|
|
17
|
+
};
|
|
18
|
+
return { type, params };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Function to encode "Simple Send" transaction (Type 2)
|
|
22
|
+
function encodeSimpleSend(type, params) {
|
|
23
|
+
const payload = [type, params.propertyId, params.amount];
|
|
24
|
+
return payload.join(',');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Function to decode "Simple Send" transaction (Type 2)
|
|
28
|
+
function decodeSimpleSend(encodedPayload) {
|
|
29
|
+
const parts = encodedPayload.split(',');
|
|
30
|
+
const type = parseInt(parts[0], 10);
|
|
31
|
+
const params = {
|
|
32
|
+
propertyId: parseInt(parts[1], 10),
|
|
33
|
+
amount: parseInt(parts[2], 10),
|
|
34
|
+
};
|
|
35
|
+
return { type, params };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Encode and decode functions for remaining transaction types (3 to 16).
|
|
39
|
+
|
|
40
|
+
// Function to encode "Trade Token for UTXO" transaction (Type 3)
|
|
41
|
+
function encodeTradeTokenForUTXO(type, params) {
|
|
42
|
+
const payload = [type, params.propertyId, params.amount, params.satsExpected];
|
|
43
|
+
return payload.join(',');
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Function to decode "Trade Token for UTXO" transaction (Type 3)
|
|
47
|
+
function decodeTradeTokenForUTXO(encodedPayload) {
|
|
48
|
+
const parts = encodedPayload.split(',');
|
|
49
|
+
const type = parseInt(parts[0], 10);
|
|
50
|
+
const params = {
|
|
51
|
+
propertyId: parseInt(parts[1], 10),
|
|
52
|
+
amount: parseInt(parts[2], 10),
|
|
53
|
+
satsExpected: parseInt(parts[3], 10),
|
|
54
|
+
};
|
|
55
|
+
return { type, params };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Function to encode "Commit Token" transaction (Type 4)
|
|
59
|
+
function encodeCommitToken(type, params) {
|
|
60
|
+
const payload = [type, params.propertyId, params.amount];
|
|
61
|
+
return payload.join(',');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Function to decode "Commit Token" transaction (Type 4)
|
|
65
|
+
function decodeCommitToken(encodedPayload) {
|
|
66
|
+
const parts = encodedPayload.split(',');
|
|
67
|
+
const type = parseInt(parts[0], 10);
|
|
68
|
+
const params = {
|
|
69
|
+
propertyId: parseInt(parts[1], 10),
|
|
70
|
+
amount: parseInt(parts[2], 10),
|
|
71
|
+
};
|
|
72
|
+
return { type, params };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Function to encode "On-chain Token for Token" transaction (Type 5)
|
|
76
|
+
function encodeOnChainTokenForToken(type, params) {
|
|
77
|
+
const payload = [type, params.propertyId, params.propertyIdDesired, params.amountOffered, params.amountExpected];
|
|
78
|
+
return payload.join(',');
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Function to decode "On-chain Token for Token" transaction (Type 5)
|
|
82
|
+
function decodeOnChainTokenForToken(encodedPayload) {
|
|
83
|
+
const parts = encodedPayload.split(',');
|
|
84
|
+
const type = parseInt(parts[0], 10);
|
|
85
|
+
const params = {
|
|
86
|
+
propertyId: parseInt(parts[1], 10),
|
|
87
|
+
propertyIdDesired: parseInt(parts[2], 10),
|
|
88
|
+
amountOffered: parseInt(parts[3], 10),
|
|
89
|
+
amountExpected: parseInt(parts[4], 10),
|
|
90
|
+
};
|
|
91
|
+
return { type, params };
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Continue by adding functions for transaction types 6 to 16.
|
|
95
|
+
|
|
96
|
+
// Function to encode "Create Whitelist" transaction (Type 6)
|
|
97
|
+
function encodeCreateWhitelist(type, params) {
|
|
98
|
+
const payload = [type, params.backupAddress];
|
|
99
|
+
return payload.join(',');
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Function to decode "Create Whitelist" transaction (Type 6)
|
|
103
|
+
function decodeCreateWhitelist(encodedPayload) {
|
|
104
|
+
const parts = encodedPayload.split(',');
|
|
105
|
+
const type = parseInt(parts[0], 10);
|
|
106
|
+
const params = {
|
|
107
|
+
backupAddress: parts[1],
|
|
108
|
+
};
|
|
109
|
+
return { type, params };
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Function to encode "Update Whitelist Admin" transaction (Type 7)
|
|
113
|
+
function encodeUpdateWhitelistAdmin(type, params) {
|
|
114
|
+
const payload = [type, params.newAddress];
|
|
115
|
+
return payload.join(',');
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Function to decode "Update Whitelist Admin" transaction (Type 7)
|
|
119
|
+
function decodeUpdateWhitelistAdmin(encodedPayload) {
|
|
120
|
+
const parts = encodedPayload.split(',');
|
|
121
|
+
const type = parseInt(parts[0], 10);
|
|
122
|
+
const params = {
|
|
123
|
+
newAddress: parts[1],
|
|
124
|
+
};
|
|
125
|
+
return { type, params };
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Function to encode "Issue Attestation" transaction (Type 8)
|
|
129
|
+
function encodeIssueAttestation(type, params) {
|
|
130
|
+
const payload = [type, params.targetAddress];
|
|
131
|
+
return payload.join(',');
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Function to decode "Issue Attestation" transaction (Type 8)
|
|
135
|
+
function decodeIssueAttestation(encodedPayload) {
|
|
136
|
+
const parts = encodedPayload.split(',');
|
|
137
|
+
const type = parseInt(parts[0], 10);
|
|
138
|
+
const params = {
|
|
139
|
+
targetAddress: parts[1],
|
|
140
|
+
};
|
|
141
|
+
return { type, params };
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Function to encode "Revoke Attestation" transaction (Type 9)
|
|
145
|
+
function encodeRevokeAttestation(type, params) {
|
|
146
|
+
const payload = [type, params.targetAddress];
|
|
147
|
+
return payload.join(',');
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// Function to decode "Revoke Attestation" transaction (Type 9)
|
|
151
|
+
function decodeRevokeAttestation(encodedPayload) {
|
|
152
|
+
const parts = encodedPayload.split(',');
|
|
153
|
+
const type = parseInt(parts[0], 10);
|
|
154
|
+
const params = {
|
|
155
|
+
targetAddress: parts[1],
|
|
156
|
+
};
|
|
157
|
+
return { type, params };
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// Function to encode "Create Managed Token" transaction (Type 10)
|
|
161
|
+
function encodeCreateManagedToken(type, params) {
|
|
162
|
+
const payload = [
|
|
163
|
+
type,
|
|
164
|
+
params.initialAmount,
|
|
165
|
+
params.ticker,
|
|
166
|
+
params.url,
|
|
167
|
+
params.whitelists.join(','),
|
|
168
|
+
params.backupAddress,
|
|
169
|
+
];
|
|
170
|
+
return payload.join(',');
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// Function to decode "Create Managed Token" transaction (Type 10)
|
|
174
|
+
function decodeCreateManagedToken(encodedPayload) {
|
|
175
|
+
const parts = encodedPayload.split(',');
|
|
176
|
+
const type = parseInt(parts[0], 10);
|
|
177
|
+
const params = {
|
|
178
|
+
initialAmount: parseInt(parts[1], 10),
|
|
179
|
+
ticker: parts[2],
|
|
180
|
+
url: parts[3],
|
|
181
|
+
whitelists: parts[4].split(',').map(value => parseInt(value, 10)),
|
|
182
|
+
backupAddress: parts[5],
|
|
183
|
+
};
|
|
184
|
+
return { type, params };
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// Continue by adding functions for transaction types 11 to 16.
|
|
188
|
+
|
|
189
|
+
// ... Functions for transaction types 11 to 16
|
|
190
|
+
|
|
191
|
+
// Function to encode "Grant Managed Token" transaction (Type 11)
|
|
192
|
+
function encodeGrantManagedToken(type, params) {
|
|
193
|
+
const payload = [type, params.amountGranted, params.addressToGrant];
|
|
194
|
+
return payload.join(',');
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// Function to decode "Grant Managed Token" transaction (Type 11)
|
|
198
|
+
function decodeGrantManagedToken(encodedPayload) {
|
|
199
|
+
const parts = encodedPayload.split(',');
|
|
200
|
+
const type = parseInt(parts[0], 10);
|
|
201
|
+
const params = {
|
|
202
|
+
amountGranted: parseInt(parts[1], 10),
|
|
203
|
+
addressToGrant: parts[2],
|
|
204
|
+
};
|
|
205
|
+
return { type, params };
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// Function to encode "Redeem Managed Token" transaction (Type 12)
|
|
209
|
+
function encodeRedeemManagedToken(type, params) {
|
|
210
|
+
const payload = [type, params.amountDestroyed];
|
|
211
|
+
return payload.join(',');
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// Function to decode "Redeem Managed Token" transaction (Type 12)
|
|
215
|
+
function decodeRedeemManagedToken(encodedPayload) {
|
|
216
|
+
const parts = encodedPayload.split(',');
|
|
217
|
+
const type = parseInt(parts[0], 10);
|
|
218
|
+
const params = {
|
|
219
|
+
amountDestroyed: parseInt(parts[1], 10),
|
|
220
|
+
};
|
|
221
|
+
return { type, params };
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// Function to encode "Update Managed Token Admin" transaction (Type 13)
|
|
225
|
+
function encodeUpdateManagedTokenAdmin(type, params) {
|
|
226
|
+
const payload = [type, params.newAddress];
|
|
227
|
+
return payload.join(',');
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// Function to decode "Update Managed Token Admin" transaction (Type 13)
|
|
231
|
+
function decodeUpdateManagedTokenAdmin(encodedPayload) {
|
|
232
|
+
const parts = encodedPayload.split(',');
|
|
233
|
+
const type = parseInt(parts[0], 10);
|
|
234
|
+
const params = {
|
|
235
|
+
newAddress: parts[1],
|
|
236
|
+
};
|
|
237
|
+
return { type, params };
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// Function to encode "Create Oracle" transaction (Type 14)
|
|
241
|
+
function encodeCreateOracle(type, params) {
|
|
242
|
+
const payload = [
|
|
243
|
+
type,
|
|
244
|
+
params.ticker,
|
|
245
|
+
params.url,
|
|
246
|
+
params.backupAddress,
|
|
247
|
+
params.whitelists.join(','),
|
|
248
|
+
params.lag,
|
|
249
|
+
];
|
|
250
|
+
return payload.join(',');
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// Function to decode "Create Oracle" transaction (Type 14)
|
|
254
|
+
function decodeCreateOracle(encodedPayload) {
|
|
255
|
+
const parts = encodedPayload.split(',');
|
|
256
|
+
const type = parseInt(parts[0], 10);
|
|
257
|
+
const params = {
|
|
258
|
+
ticker: parts[1],
|
|
259
|
+
url: parts[2],
|
|
260
|
+
backupAddress: parts[3],
|
|
261
|
+
whitelists: parts[4].split(',').map(value => parseInt(value, 10)),
|
|
262
|
+
lag: parseInt(parts[5], 10),
|
|
263
|
+
};
|
|
264
|
+
return { type, params };
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// Function to encode "Publish Oracle Data" transaction (Type 15)
|
|
268
|
+
function encodePublishOracleData(type, params) {
|
|
269
|
+
const payload = [type, params.price];
|
|
270
|
+
if (params.high) payload.push(params.high);
|
|
271
|
+
if (params.low) payload.push(params.low);
|
|
272
|
+
if (params.close) payload.push(params.close);
|
|
273
|
+
return payload.join(',');
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// Function to decode "Publish Oracle Data" transaction (Type 15)
|
|
277
|
+
function decodePublishOracleData(encodedPayload) {
|
|
278
|
+
const parts = encodedPayload.split(',');
|
|
279
|
+
const type = parseInt(parts[0], 10);
|
|
280
|
+
const params = {
|
|
281
|
+
price: parseInt(parts[1], 10),
|
|
282
|
+
};
|
|
283
|
+
if (parts[2]) params.high = parseInt(parts[2], 10);
|
|
284
|
+
if (parts[3]) params.low = parseInt(parts[3], 10);
|
|
285
|
+
if (parts[4]) params.close = parseInt(parts[4], 10);
|
|
286
|
+
return { type, params };
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
// Function to encode "Update Oracle Admin" transaction (Type 16)
|
|
290
|
+
function encodeUpdateOracleAdmin(type, params) {
|
|
291
|
+
const payload = [type, params.newAddress];
|
|
292
|
+
return payload.join(',');
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// Function to decode "Update Oracle Admin" transaction (Type 16)
|
|
296
|
+
function decodeUpdateOracleAdmin(encodedPayload) {
|
|
297
|
+
const parts = encodedPayload.split(',');
|
|
298
|
+
const type = parseInt(parts[0], 10);
|
|
299
|
+
const params = {
|
|
300
|
+
newAddress: parts[1],
|
|
301
|
+
};
|
|
302
|
+
return { type, params };
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
module.exports = {
|
|
306
|
+
// Previous functions for transaction types 1 to 5
|
|
307
|
+
encodeSimpleTokenIssue,
|
|
308
|
+
decodeSimpleTokenIssue,
|
|
309
|
+
encodeSimpleSend,
|
|
310
|
+
decodeSimpleSend,
|
|
311
|
+
encodeTradeTokenForUTXO,
|
|
312
|
+
decodeTradeTokenForUTXO,
|
|
313
|
+
encodeCommitToken,
|
|
314
|
+
decodeCommitToken,
|
|
315
|
+
encodeOnChainTokenForToken,
|
|
316
|
+
decodeOnChainTokenForToken,
|
|
317
|
+
encodeCreateWhitelist,
|
|
318
|
+
decodeCreateWhitelist,
|
|
319
|
+
encodeUpdateWhitelistAdmin,
|
|
320
|
+
decodeUpdateWhitelistAdmin,
|
|
321
|
+
encodeIssueAttestation,
|
|
322
|
+
decodeIssueAttestation,
|
|
323
|
+
encodeRevokeAttestation,
|
|
324
|
+
decodeRevokeAttestation,
|
|
325
|
+
encodeCreateManagedToken,
|
|
326
|
+
decodeCreateManagedToken,
|
|
327
|
+
encodeGrantManagedToken,
|
|
328
|
+
decodeGrantManagedToken,
|
|
329
|
+
encodeRedeemManagedToken,
|
|
330
|
+
decodeRedeemManagedToken,
|
|
331
|
+
encodeUpdateManagedTokenAdmin,
|
|
332
|
+
decodeUpdateManagedTokenAdmin,
|
|
333
|
+
encodeCreateOracle,
|
|
334
|
+
decodeCreateOracle,
|
|
335
|
+
encodePublishOracleData,
|
|
336
|
+
decodePublishOracleData,
|
|
337
|
+
encodeUpdateOracleAdmin,
|
|
338
|
+
decodeUpdateOracleAdmin,
|
|
339
|
+
// Continue adding functions for other transaction types (11 to 16).
|
|
340
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const InterfaceChild = require('./interfaceChild.js');
|
|
2
|
+
const adminAddress = "tltc1qa0kd2d39nmeph3hvcx8ytv65ztcywg5sazhtw8"; // Replace with your admin address
|
|
3
|
+
|
|
4
|
+
async function testInterfaceChild() {
|
|
5
|
+
try {
|
|
6
|
+
|
|
7
|
+
const interfaceChild = new InterfaceChild();
|
|
8
|
+
interfaceChild.initMain().then(() => {
|
|
9
|
+
console.log("initMain command sent.");
|
|
10
|
+
}).catch((error) => {
|
|
11
|
+
console.error("Error sending initMain command:", error);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
// Query for balance on the admin address
|
|
15
|
+
const adminBalance = await tradeLayerInterfaceChild.getAllBalancesForAddress(adminAddress);
|
|
16
|
+
console.log(`Balance for admin address (${adminAddress}):`, adminBalance);
|
|
17
|
+
|
|
18
|
+
// Query for the property list
|
|
19
|
+
const propertyList = await tradeLayerInterfaceChild.listProperties();
|
|
20
|
+
console.log("Property List:", propertyList);
|
|
21
|
+
|
|
22
|
+
// ... additional queries as needed ...
|
|
23
|
+
|
|
24
|
+
} catch (error) {
|
|
25
|
+
console.error("Error during test:", error);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
testInterfaceChild();
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
const litecoin = require('litecoin');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const json = require('big-json');
|
|
4
|
+
const blockData = [];
|
|
5
|
+
var chainHeight = 0
|
|
6
|
+
var protocolBlocks=[{height:0,omTx:[],tlTx:[]}]
|
|
7
|
+
var txIndexomni=[]
|
|
8
|
+
var indexPlaceholder = 0
|
|
9
|
+
var thisBlockOm = []
|
|
10
|
+
var thisBlockTl = []
|
|
11
|
+
var omniTxCount = 0
|
|
12
|
+
var totalBlocks = 20
|
|
13
|
+
|
|
14
|
+
const client = new litecoin.Client({
|
|
15
|
+
host: '127.0.0.1',
|
|
16
|
+
port: 8332,
|
|
17
|
+
user: 'user',
|
|
18
|
+
pass: 'pass',
|
|
19
|
+
timeout: 10000
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
function decodeOPReturnPayload(hexPayload) {
|
|
23
|
+
// Decode the payload and return the decoded data
|
|
24
|
+
// ...
|
|
25
|
+
|
|
26
|
+
// Example code
|
|
27
|
+
const decodedData = Buffer.from(hexPayload, 'hex').toString('utf8');
|
|
28
|
+
return decodedData;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function extractBlockData(startHeight) {
|
|
32
|
+
client.getBlockCount(function (error, chainTip) {
|
|
33
|
+
if (error) {
|
|
34
|
+
console.error('Error retrieving chain tip:', error);
|
|
35
|
+
return;
|
|
36
|
+
}else{chainHeight=chainTip}
|
|
37
|
+
|
|
38
|
+
getBlockData(startHeight);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
function getBlockData(height) {
|
|
45
|
+
console.log(height)
|
|
46
|
+
client.getBlockHash(height, function (error, blockHash) {
|
|
47
|
+
if (error) {
|
|
48
|
+
console.error('Error retrieving block hash:', error);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
client.getBlock(blockHash, function (error, currentBlock) {
|
|
53
|
+
if (error) {
|
|
54
|
+
console.error('Error retrieving block data:', error);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
blockData.push(currentBlock);
|
|
59
|
+
|
|
60
|
+
if (currentBlock.height === startHeight+totalBlocks) {
|
|
61
|
+
console.log('Block data extraction completed.');
|
|
62
|
+
extractProtocolTx(startHeight,false)
|
|
63
|
+
} else {
|
|
64
|
+
getBlockData(height + 1);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function makeFile(filename, pojo){
|
|
71
|
+
|
|
72
|
+
const stringifyStream = json.createStringifyStream({
|
|
73
|
+
body: pojo
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
stringifyStream.on('data', function(strChunk) {
|
|
77
|
+
fs.appendFile(filename, strChunk, function (err) {
|
|
78
|
+
if (err) throw err;
|
|
79
|
+
})
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Example usage
|
|
85
|
+
const startHeight = 2093623;
|
|
86
|
+
extractBlockData(startHeight);
|
|
87
|
+
|
|
88
|
+
function extractProtocolTx(start,finishBlock){
|
|
89
|
+
//console.log(blockData)
|
|
90
|
+
if(finishBlock==true){
|
|
91
|
+
if(protocolBlocks.omTx!=[]||tlTx!=[]){
|
|
92
|
+
protocolBlocks.push({height:start,omTx:thisBlockOm,tlTX:thisBlockTl})
|
|
93
|
+
thisBlockOm=[]
|
|
94
|
+
thisBlockTl=[]
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
indexPlaceholder=start
|
|
98
|
+
var placement = start-startHeight
|
|
99
|
+
console.log("getting ready to loop through a new block: "+placement+" "+start)
|
|
100
|
+
var thisBlock = blockData[placement]
|
|
101
|
+
/*try{
|
|
102
|
+
if(thisBlock.tx.length=undefined){thisBlock=blockData[placement+1]}else{indexPlaceholder=start}
|
|
103
|
+
}catch{
|
|
104
|
+
console.log('block is apparently undefined')
|
|
105
|
+
}*/
|
|
106
|
+
|
|
107
|
+
if(start>=startHeight+totalBlocks){
|
|
108
|
+
var obj = JSON.stringify(protocolBlocks)
|
|
109
|
+
makeFile('protocolTxIndex.json',protocolBlocks)
|
|
110
|
+
console.log("ta da!!")
|
|
111
|
+
return true
|
|
112
|
+
}
|
|
113
|
+
loopThroughBlock(thisBlock,0)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function loopThroughBlock(block,i) {
|
|
117
|
+
if(block!=undefined){
|
|
118
|
+
console.log("block not undefined: "+block.height, i, block.tx.length);
|
|
119
|
+
}else{extractProtocolTx(null,true) }
|
|
120
|
+
|
|
121
|
+
if (block === undefined) {
|
|
122
|
+
console.log("Jim, abort! Block undefined");
|
|
123
|
+
return extractProtocolTx(indexPlaceholder+1,true)
|
|
124
|
+
}else if(i>=block.tx.length){
|
|
125
|
+
var newBlock = block.height+1
|
|
126
|
+
console.log("i>tx.length block done!... now:"+newBlock);
|
|
127
|
+
return extractProtocolTx(block.height+1,false)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
var tx = block.tx[i];
|
|
131
|
+
|
|
132
|
+
if (tx === undefined || tx === '') {
|
|
133
|
+
console.log("Jim, abort!");
|
|
134
|
+
return loopThroughBlock(block,i+1)
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
try{
|
|
138
|
+
console.log(tx);
|
|
139
|
+
client.getRawTransaction(tx,true,function(err,rawtx){
|
|
140
|
+
|
|
141
|
+
if (rawtx === undefined) {
|
|
142
|
+
console.log("raw tx undefined")
|
|
143
|
+
return loopThroughBlock(block, i + 1);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
let confirmations;
|
|
147
|
+
try {
|
|
148
|
+
confirmations = rawtx.confirmations;
|
|
149
|
+
} catch {
|
|
150
|
+
return loopThroughBlock(block, i + 1);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
var thisConfirmations = confirmations;
|
|
154
|
+
|
|
155
|
+
for (let v = 0; v < rawtx.vout.length; v++) {
|
|
156
|
+
console.log(v)
|
|
157
|
+
var vout = rawtx.vout[v];
|
|
158
|
+
var ASMstring = vout.scriptPubKey.asm.slice(0,9);
|
|
159
|
+
console.log(ASMstring)
|
|
160
|
+
if (ASMstring === "OP_RETURN" && confirmations >= 1) {
|
|
161
|
+
|
|
162
|
+
var payload = vout.scriptPubKey.asm.slice(11,vout.scriptPubKey.asm.length);
|
|
163
|
+
console.log(payload)
|
|
164
|
+
var marker =decode(payload.slice(0,1))
|
|
165
|
+
|
|
166
|
+
var txObj = { tx: tx, payload: payload, marker: marker };
|
|
167
|
+
console.log(decodedPayload,marker,txObj)
|
|
168
|
+
if (marker === "om") {
|
|
169
|
+
marker = payload.slice(0,3)
|
|
170
|
+
txObj.marker=marker
|
|
171
|
+
payload=payload.slice(4,payload.length)
|
|
172
|
+
txObj.payload=payload
|
|
173
|
+
omniTxCount+=1
|
|
174
|
+
console.log("Omni tx "+omniTxCount)
|
|
175
|
+
thisBlockOm.push(txObj);
|
|
176
|
+
}
|
|
177
|
+
if (marker === "tl") {
|
|
178
|
+
payload=payload.slice(2,payload.length)
|
|
179
|
+
txObj.payload=payload
|
|
180
|
+
thisBlockTl.push(txObj);
|
|
181
|
+
}
|
|
182
|
+
} else if (ASMstring === "OP_RETURN" && confirmations === 0) {
|
|
183
|
+
var payload = vout.scriptPubKey.asm.split(' ');
|
|
184
|
+
var decodedPayload = decodeOPReturnPayload(payload);
|
|
185
|
+
var marker = decodedPayload.slice(0, 1);
|
|
186
|
+
var txObj = { tx: tx, payload: payload, decode: decode, marker: marker };
|
|
187
|
+
if (marker === "om" || marker === "tl") {
|
|
188
|
+
memPool.push(tx);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return loopThroughBlock(block,i+1)
|
|
193
|
+
})
|
|
194
|
+
}catch{
|
|
195
|
+
console.log("is rawtx undefined", rawtx);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
function decodeOmniPayload(hexPayload) {
|
|
202
|
+
const marker = hexPayload.slice(0, 4);
|
|
203
|
+
|
|
204
|
+
if (marker === '6f6d') {
|
|
205
|
+
// Decode 'om' marker
|
|
206
|
+
return "omni"
|
|
207
|
+
} else if (marker === '746c') {
|
|
208
|
+
// Decode 'tl' marker
|
|
209
|
+
return "tl"
|
|
210
|
+
} else {
|
|
211
|
+
// Unknown marker
|
|
212
|
+
return { error: 'Unknown marker' };
|
|
213
|
+
}
|
|
214
|
+
}
|