@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,40 @@
|
|
|
1
|
+
const assert = require('assert');
|
|
2
|
+
const TallyMap = require('./tallyMap.js');
|
|
3
|
+
|
|
4
|
+
describe('TallyMap', function() {
|
|
5
|
+
let tallyMap;
|
|
6
|
+
|
|
7
|
+
before(function() {
|
|
8
|
+
tallyMap = new TallyMap();
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('should update and retrieve balances', function() {
|
|
12
|
+
const testAddress = 'address1';
|
|
13
|
+
const propertyId = 1;
|
|
14
|
+
tallyMap.updateBalance(testAddress, propertyId, 100, 80, 20);
|
|
15
|
+
|
|
16
|
+
const balances = tallyMap.getAddressBalances(testAddress);
|
|
17
|
+
assert.strictEqual(balances.length, 1);
|
|
18
|
+
assert.strictEqual(balances[0].propertyId, propertyId.toString());
|
|
19
|
+
assert.strictEqual(balances[0].amount, 100);
|
|
20
|
+
assert.strictEqual(balances[0].available, 80);
|
|
21
|
+
assert.strictEqual(balances[0].reserved, 20);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('should not allow negative balances', function() {
|
|
25
|
+
const testAddress = 'address2';
|
|
26
|
+
const propertyId = 2;
|
|
27
|
+
|
|
28
|
+
assert.throws(() => {
|
|
29
|
+
tallyMap.updateBalance(testAddress, propertyId, -100, -50, -50);
|
|
30
|
+
}, /Balance cannot go negative/);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('should calculate total tokens correctly', function() {
|
|
34
|
+
const propertyId = 1;
|
|
35
|
+
const total = tallyMap.totalTokens(propertyId);
|
|
36
|
+
assert.strictEqual(total, 100); // Total from previous test
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// Additional tests for save, load, getTally, etc.
|
|
40
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
const assert = require('assert'); // Assertion library
|
|
2
|
+
const sinon = require('sinon'); // Mocking library (if needed)
|
|
3
|
+
const TradeLayerManager = require('./path/to/TradeLayerManager'); // The module under test
|
|
4
|
+
|
|
5
|
+
describe('TradeLayerManager', function() {
|
|
6
|
+
let tradeLayerManager;
|
|
7
|
+
let mockDependencies; // Mock any dependencies
|
|
8
|
+
|
|
9
|
+
beforeEach(function() {
|
|
10
|
+
// Set up for each test
|
|
11
|
+
tradeLayerManager = new TradeLayerManager();
|
|
12
|
+
mockDependencies = sinon.stub(/* ... */);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
afterEach(function() {
|
|
16
|
+
// Clean up after each test
|
|
17
|
+
sinon.restore();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
describe('performBuyback', function() {
|
|
21
|
+
it('should calculate buyback amount correctly based on order book', function() {
|
|
22
|
+
// Simulate fee cache and order book data
|
|
23
|
+
const feeCache = /* mock fee cache data */;
|
|
24
|
+
const orderBook = /* mock order book data */;
|
|
25
|
+
|
|
26
|
+
// Perform buyback
|
|
27
|
+
tradeLayerManager.performBuyback([feeCache]);
|
|
28
|
+
|
|
29
|
+
// Assert the buyback amount is calculated correctly
|
|
30
|
+
const expectedBuybackAmount = /* calculate expected buyback amount */;
|
|
31
|
+
assert.equal(tradeLayerManager.getBuybackAmount(), expectedBuybackAmount);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('should execute buyback transactions correctly', function() {
|
|
35
|
+
// Simulate fee cache and order book data
|
|
36
|
+
const feeCache = /* mock fee cache data */;
|
|
37
|
+
const orderBook = /* mock order book data */;
|
|
38
|
+
|
|
39
|
+
// Perform buyback
|
|
40
|
+
tradeLayerManager.performBuyback([feeCache]);
|
|
41
|
+
|
|
42
|
+
// Assert buyback transactions are executed as expected
|
|
43
|
+
// This may include checking the change in order book, token balances, etc.
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const crypto = require('crypto');
|
|
4
|
+
|
|
5
|
+
// Define file names
|
|
6
|
+
const jsFiles = [
|
|
7
|
+
'activation', 'amm', 'channels', 'clearing', 'clearlist', 'consensus', 'contractRegistry',
|
|
8
|
+
'insurance', 'logic', 'main', 'marginMap', 'options', 'oracle', 'orderbook',
|
|
9
|
+
'persistence', 'property', 'reOrg', 'tally', 'txDecoder', 'txIndex', 'types',
|
|
10
|
+
'validity', 'vaults', 'vesting', 'volumeIndex'
|
|
11
|
+
];
|
|
12
|
+
|
|
13
|
+
// Function to hash files in the specified folder
|
|
14
|
+
async function hashFiles(basePath) {
|
|
15
|
+
try {
|
|
16
|
+
let combinedContent = ''; // Initialize empty string to hold combined file content
|
|
17
|
+
|
|
18
|
+
// Loop through each file, read its content, and append to combinedContent
|
|
19
|
+
for (const file of jsFiles) {
|
|
20
|
+
const filePath = path.join(basePath, `../src/${file}.js`);
|
|
21
|
+
|
|
22
|
+
if (fs.existsSync(filePath)) {
|
|
23
|
+
const fileContent = fs.readFileSync(filePath, 'utf8');
|
|
24
|
+
combinedContent += fileContent; // Append file content
|
|
25
|
+
} else {
|
|
26
|
+
console.warn(`File not found: ${filePath}`); // Warn if the file is missing
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Stringify the combined content
|
|
31
|
+
const combinedContentString = JSON.stringify(combinedContent);
|
|
32
|
+
|
|
33
|
+
// Generate a SHA-256 hash of the combined content
|
|
34
|
+
const hash = crypto.createHash('sha256');
|
|
35
|
+
hash.update(combinedContentString);
|
|
36
|
+
const finalHash = hash.digest('hex');
|
|
37
|
+
|
|
38
|
+
console.log('Final SHA-256 Hash:', finalHash);
|
|
39
|
+
return finalHash;
|
|
40
|
+
} catch (err) {
|
|
41
|
+
console.error('Error reading or hashing files:', err);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Test the function
|
|
46
|
+
(async () => {
|
|
47
|
+
const projectPath = path.resolve(__dirname); // Specify path to the tradelayer project
|
|
48
|
+
await hashFiles(projectPath);
|
|
49
|
+
})();
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
const crypto = require('crypto');
|
|
2
|
+
const db = require('../src/db.js'); // Assuming db.js is correctly set up
|
|
3
|
+
const client = require('../src/client.js').getInstance()
|
|
4
|
+
|
|
5
|
+
class ConsensusDatabase {
|
|
6
|
+
// Function to generate SHA-256 hash
|
|
7
|
+
static generateHash(input) {
|
|
8
|
+
const hash = crypto.createHash('sha256');
|
|
9
|
+
hash.update(input);
|
|
10
|
+
return hash.digest('hex');
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// Function to get the latest instance of a DB
|
|
14
|
+
static async getLatestInstance(dbName) {
|
|
15
|
+
const base = await db.getDatabase(dbName)
|
|
16
|
+
const data = await base.findAsync({});
|
|
17
|
+
return data.length > 0 ? data[data.length - 1] : null; // Get the latest entry
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Function to get all instances from a DB
|
|
21
|
+
static async getAllInstances(dbName) {
|
|
22
|
+
const base = await db.getDatabase(dbName)
|
|
23
|
+
const data = await base.findAsync({});
|
|
24
|
+
return data; // Return all entries
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Function to generate stateConsensusHash based on various DBs
|
|
28
|
+
static async stateConsensusHash() {
|
|
29
|
+
try {
|
|
30
|
+
// Retrieve latest instance from tally.db and activations.db
|
|
31
|
+
const latestTally = await this.getLatestInstance('tallyMap');
|
|
32
|
+
const latestActivation = await this.getLatestInstance('activations');
|
|
33
|
+
|
|
34
|
+
// Retrieve everything from other specified DBs
|
|
35
|
+
const channels = await this.getAllInstances('channels');
|
|
36
|
+
const clearlists = await this.getAllInstances('clearlists');
|
|
37
|
+
const contractList = await this.getAllInstances('contractList');
|
|
38
|
+
const feeCache = await this.getAllInstances('feeCache');
|
|
39
|
+
const insurance = await this.getAllInstances('insurance');
|
|
40
|
+
const marginMaps = await this.getAllInstances('marginMaps');
|
|
41
|
+
const oracleData = await this.getAllInstances('oracleData');
|
|
42
|
+
const oracleList = await this.getAllInstances('oracleList');
|
|
43
|
+
const orderBooks = await this.getAllInstances('orderBooks');
|
|
44
|
+
const propertyList = await this.getAllInstances('propertyList');
|
|
45
|
+
const syntheticTokens = await this.getAllInstances('syntheticTokens');
|
|
46
|
+
const vaults = await this.getAllInstances('vaults');
|
|
47
|
+
const volumeIndex = await this.getAllInstances('volumeIndex');
|
|
48
|
+
const withdrawQueue = await this.getAllInstances('withdrawQueue');
|
|
49
|
+
|
|
50
|
+
// Combine all the retrieved data into a single structure
|
|
51
|
+
const combinedState = {
|
|
52
|
+
latestTally,
|
|
53
|
+
latestActivation,
|
|
54
|
+
channels,
|
|
55
|
+
clearlists,
|
|
56
|
+
contractList,
|
|
57
|
+
feeCache,
|
|
58
|
+
insurance,
|
|
59
|
+
marginMaps,
|
|
60
|
+
oracleData,
|
|
61
|
+
oracleList,
|
|
62
|
+
orderBooks,
|
|
63
|
+
propertyList,
|
|
64
|
+
syntheticTokens,
|
|
65
|
+
vaults,
|
|
66
|
+
volumeIndex,
|
|
67
|
+
withdrawQueue
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
// Convert combined data to string
|
|
71
|
+
const combinedStateString = JSON.stringify(combinedState);
|
|
72
|
+
|
|
73
|
+
// Generate and return the SHA-256 hash of the combined state
|
|
74
|
+
const hash = this.generateHash(combinedStateString);
|
|
75
|
+
console.log('stateConsensusHash:', hash);
|
|
76
|
+
return hash;
|
|
77
|
+
|
|
78
|
+
} catch (err) {
|
|
79
|
+
console.error('Error generating stateConsensus hash:', err);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Test the stateConsensusHash function
|
|
85
|
+
(async () => {
|
|
86
|
+
|
|
87
|
+
await db.init('ltc')
|
|
88
|
+
console.log('Generating stateConsensusHash...');
|
|
89
|
+
const stateHash = await ConsensusDatabase.stateConsensusHash();
|
|
90
|
+
console.log('Generated stateConsensusHash:', stateHash);
|
|
91
|
+
})();
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
function testDecode(opReturnData){
|
|
2
|
+
|
|
3
|
+
// Check if the hex contains the marker "746c" (which corresponds to "tl")
|
|
4
|
+
let markerHex = "746c"; // Hex for "tl"
|
|
5
|
+
let payloadStart = 8;
|
|
6
|
+
let markerPosition = opReturnData.indexOf(markerHex); // Check if the marker is anywhere in the string
|
|
7
|
+
if (markerPosition === -1 || markerPosition > 6) {
|
|
8
|
+
console.log('Marker "tl" not found or in an invalid position.');
|
|
9
|
+
return null;
|
|
10
|
+
} else if (markerHex === opReturnData.substring(4, 8)) {
|
|
11
|
+
payloadStart = 8;
|
|
12
|
+
} else if (markerHex === opReturnData.substring(5, 9)) {
|
|
13
|
+
payloadStart = 9;
|
|
14
|
+
} else if (markerHex === opReturnData.substring(6, 10)) {
|
|
15
|
+
payloadStart = 10;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Extract and log the actual payload
|
|
19
|
+
const payloadHex = opReturnData.substring(payloadStart);
|
|
20
|
+
const payload = Buffer.from(payloadHex, 'hex').toString();
|
|
21
|
+
console.log(`Marker: ${markerHex}, Payload: ${payload}`);
|
|
22
|
+
|
|
23
|
+
if (markerHex === '746c') {
|
|
24
|
+
console.log('Pre-decoded and Decoded Payload:', opReturnData + ' ' + payload);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return { marker: 'tl', payload, decodedTx };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
payload= ''
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
const axios = require('axios');
|
|
2
|
+
const baseConverter = require('bigint-base-converter');
|
|
3
|
+
let txCount = 0
|
|
4
|
+
|
|
5
|
+
// Litecoin Core RPC Config
|
|
6
|
+
const rpcConfig = {
|
|
7
|
+
url: 'http://127.0.0.1:18332',
|
|
8
|
+
auth: {
|
|
9
|
+
username: 'user', // Replace with your Litecoin Core RPC username
|
|
10
|
+
password: 'pass' // Replace with your Litecoin Core RPC password
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
// Base 94 and Base 128 Character Sets
|
|
15
|
+
const base94Chars = [...Array(94).keys()].map(i => String.fromCharCode(i + 33));
|
|
16
|
+
const base128Chars = Array.from({ length: 128 }, (_, i) => String.fromCharCode(i + 128));
|
|
17
|
+
|
|
18
|
+
// Define Custom Character Set, Filtering Out Problematic Characters
|
|
19
|
+
const allCharacters = [...Array(65536).keys()].map(i => String.fromCharCode(i));
|
|
20
|
+
const customBase256Chars = allCharacters.filter(
|
|
21
|
+
char => !/[\s\u0000-\u001F\u007F-\u00A0\u00AD\u2028\u2029]/.test(char)
|
|
22
|
+
).slice(0, 256);
|
|
23
|
+
|
|
24
|
+
// Check if the character set meets the base requirements
|
|
25
|
+
if (customBase256Chars.length !== 256) {
|
|
26
|
+
console.warn(`Character set only contains ${customBase256Chars.length} characters, switching to smaller base.`);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Encoding Functions
|
|
30
|
+
function hexToBase94(hex) {
|
|
31
|
+
const decimalString = BigInt(`0x${hex}`).toString(10);
|
|
32
|
+
return baseConverter(decimalString, 10, base94Chars.join(''));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function hexToBase128(hex) {
|
|
36
|
+
const decimalString = BigInt(`0x${hex}`).toString(10);
|
|
37
|
+
return baseConverter(decimalString, 10, base128Chars.join(''));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function hexToCustomBase256(hex) {
|
|
41
|
+
const decimalString = BigInt(`0x${hex}`).toString(10);
|
|
42
|
+
return baseConverter(decimalString, 10, customBase256Chars.join(''));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function fromCustomBase256(base256String) {
|
|
46
|
+
const result = baseConverter(base256String, customBase256Chars.join(''), 10);
|
|
47
|
+
return Array.isArray(result) ? result.join('') : result;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Helper to Detect Problematic Characters
|
|
51
|
+
function hasWhitespaceOrNonPrintable(str) {
|
|
52
|
+
return /[\s\u0000-\u001F\u007F-\u00A0\u00AD\u2028\u2029]/.test(str); // Common problematic characters
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Main Function to Test Encodings
|
|
56
|
+
async function testTxidEncodings(startBlock, endBlock) {
|
|
57
|
+
const results = {
|
|
58
|
+
base94: { lengths: [], problematicCount: 0 },
|
|
59
|
+
base128: { lengths: [], problematicCount: 0 },
|
|
60
|
+
customBase256: { lengths: [], problematicCount: 0 }
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
for (let block = startBlock; block <= endBlock; block++) {
|
|
64
|
+
if(block%1000==1){console.log(block)}
|
|
65
|
+
try {
|
|
66
|
+
// Fetch Block Hash and Block Data
|
|
67
|
+
const { data: blockHashRes } = await axios.post(rpcConfig.url, {
|
|
68
|
+
jsonrpc: '1.0',
|
|
69
|
+
id: 'curltext',
|
|
70
|
+
method: 'getblockhash',
|
|
71
|
+
params: [block]
|
|
72
|
+
}, { auth: rpcConfig.auth });
|
|
73
|
+
const blockHash = blockHashRes.result;
|
|
74
|
+
|
|
75
|
+
const { data: blockRes } = await axios.post(rpcConfig.url, {
|
|
76
|
+
jsonrpc: '1.0',
|
|
77
|
+
id: 'curltext',
|
|
78
|
+
method: 'getblock',
|
|
79
|
+
params: [blockHash, 2]
|
|
80
|
+
}, { auth: rpcConfig.auth });
|
|
81
|
+
|
|
82
|
+
const transactions = blockRes.result.tx;
|
|
83
|
+
transactions.forEach(tx => {
|
|
84
|
+
const txid = tx.txid;
|
|
85
|
+
txCount++
|
|
86
|
+
// Base 94 Encoding
|
|
87
|
+
const base94Encoded = hexToBase94(txid);
|
|
88
|
+
results.base94.lengths.push(base94Encoded.length);
|
|
89
|
+
if (hasWhitespaceOrNonPrintable(base94Encoded)) {
|
|
90
|
+
results.base94.problematicCount++;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Base 128 Encoding
|
|
94
|
+
const base128Encoded = hexToBase128(txid);
|
|
95
|
+
results.base128.lengths.push(base128Encoded.length);
|
|
96
|
+
if (hasWhitespaceOrNonPrintable(base128Encoded)) {
|
|
97
|
+
results.base128.problematicCount++;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Custom Base 256 Encoding
|
|
101
|
+
const customBase256Encoded = hexToCustomBase256(txid);
|
|
102
|
+
results.customBase256.lengths.push(customBase256Encoded.length);
|
|
103
|
+
if (hasWhitespaceOrNonPrintable(customBase256Encoded)) {
|
|
104
|
+
results.customBase256.problematicCount++;
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
} catch (error) {
|
|
108
|
+
console.error(`Error processing block ${block}:`, error.message);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Output Statistical Results
|
|
113
|
+
const avgLength = arr => arr.reduce((a, b) => a + b, 0) / arr.length;
|
|
114
|
+
console.log('--- Base 94 Results ---');
|
|
115
|
+
console.log(`Average Length: ${avgLength(results.base94.lengths)}`);
|
|
116
|
+
console.log(`Problematic Character Count: ${results.base94.problematicCount}`);
|
|
117
|
+
|
|
118
|
+
console.log('--- Base 128 Results ---');
|
|
119
|
+
console.log(`Average Length: ${avgLength(results.base128.lengths)}`);
|
|
120
|
+
console.log(`Problematic Character Count: ${results.base128.problematicCount}`);
|
|
121
|
+
|
|
122
|
+
console.log('--- Custom Base 256 Results ---');
|
|
123
|
+
console.log(`Average Length: ${avgLength(results.customBase256.lengths)}`);
|
|
124
|
+
console.log(`Problematic Character Count: ${results.customBase256.problematicCount}`);
|
|
125
|
+
console.log('Total transactions '+txCount)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Run Test on Blocks 100000 to 100010 (sample range)
|
|
129
|
+
testTxidEncodings(3100000, 3150010);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// testGetRawTransaction.js
|
|
2
|
+
const Litecoin = require('litecoin');
|
|
3
|
+
const util = require('util');
|
|
4
|
+
|
|
5
|
+
// Configuration for Litecoin RPC
|
|
6
|
+
const config = {
|
|
7
|
+
host: '127.0.0.1',
|
|
8
|
+
port: 18332,
|
|
9
|
+
user: 'user', // replace with actual RPC username
|
|
10
|
+
pass: 'pass', // replace with actual RPC password
|
|
11
|
+
timeout: 10000,
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
// Create Litecoin client instance
|
|
15
|
+
const client = new Litecoin.Client(config);
|
|
16
|
+
|
|
17
|
+
// Promisify getrawtransaction
|
|
18
|
+
const getRawTransaction = (txId, verbose = true) => {
|
|
19
|
+
return util.promisify(client.cmd.bind(client, 'getrawtransaction'))(txId, verbose);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// Test transaction ID (replace with a valid txId)
|
|
23
|
+
const testTxId = '763db4ffd18c7c0839b8e7532907db2b48e10da5c08b28874c249aa870a505aa';
|
|
24
|
+
|
|
25
|
+
(async () => {
|
|
26
|
+
try {
|
|
27
|
+
const transactionData = await getRawTransaction(testTxId, true);
|
|
28
|
+
console.log('Transaction Data:', transactionData);
|
|
29
|
+
} catch (error) {
|
|
30
|
+
console.error('Error retrieving transaction:', error);
|
|
31
|
+
}
|
|
32
|
+
})();
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// testGetRawTransaction.js
|
|
2
|
+
const Litecoin = require('litecoin');
|
|
3
|
+
const util = require('util');
|
|
4
|
+
|
|
5
|
+
// Configuration for Litecoin RPC
|
|
6
|
+
const config = {
|
|
7
|
+
host: '127.0.0.1',
|
|
8
|
+
port: 18332,
|
|
9
|
+
user: 'user', // replace with actual RPC username
|
|
10
|
+
pass: 'pass', // replace with actual RPC password
|
|
11
|
+
timeout: 10000,
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
// Create Litecoin client instance
|
|
15
|
+
const client = new Litecoin.Client(config);
|
|
16
|
+
|
|
17
|
+
// Promisify getrawtransaction
|
|
18
|
+
const getRawTransaction = (txId, verbose = true) => {
|
|
19
|
+
return util.promisify(client.cmd.bind(client, 'getrawtransaction'))(txId, verbose);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// Test transaction ID (replace with a valid txId)
|
|
23
|
+
const testTxId = '763db4ffd18c7c0839b8e7532907db2b48e10da5c08b28874c249aa870a505aa';
|
|
24
|
+
|
|
25
|
+
(async () => {
|
|
26
|
+
try {
|
|
27
|
+
const transactionData = await getRawTransaction(testTxId, true);
|
|
28
|
+
console.log('Transaction Data:', transactionData);
|
|
29
|
+
} catch (error) {
|
|
30
|
+
console.error('Error retrieving transaction:', error);
|
|
31
|
+
}
|
|
32
|
+
})();
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
function hexToBase36(hex) {
|
|
2
|
+
try {
|
|
3
|
+
const bigIntValue = BigInt('0x' + hex);
|
|
4
|
+
return bigIntValue.toString(36);
|
|
5
|
+
} catch (err) {
|
|
6
|
+
console.error('Error converting Hex to Base36:', err.message);
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// Test Function
|
|
12
|
+
function testHexToBase36Consistency() {
|
|
13
|
+
const testHex = '9dbe78a08985827d8ba2459466a770c831155cf5d3d03abf5e5e2cb2351103e6';
|
|
14
|
+
const expectedBase36 = '3xjcq2nduqyz7bey9tq9uqihxgyt15lomgapljtojujlj3tckm';
|
|
15
|
+
|
|
16
|
+
console.log('Original Hex:', testHex);
|
|
17
|
+
|
|
18
|
+
// Convert Hex to Base36
|
|
19
|
+
const base36Result = hexToBase36(testHex);
|
|
20
|
+
console.log('Base36 Result:', base36Result);
|
|
21
|
+
|
|
22
|
+
// Check Consistency
|
|
23
|
+
if (base36Result === expectedBase36) {
|
|
24
|
+
console.log('✅ Consistent Base36 conversion!');
|
|
25
|
+
} else {
|
|
26
|
+
console.error('❌ Base36 conversion mismatch!');
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Run the Test
|
|
31
|
+
console.log("=== Hex to Base36 Consistency Test ===");
|
|
32
|
+
testHexToBase36Consistency();
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// test-txIndexHash.js
|
|
2
|
+
|
|
3
|
+
const crypto = require('crypto');
|
|
4
|
+
const db = require('./db.js'); // Import the actual db.js file
|
|
5
|
+
|
|
6
|
+
// ConsensusDatabase class
|
|
7
|
+
class ConsensusDatabase {
|
|
8
|
+
// Function to generate SHA-256 hash
|
|
9
|
+
static generateHash(input) {
|
|
10
|
+
const hash = crypto.createHash('sha256');
|
|
11
|
+
hash.update(input);
|
|
12
|
+
return hash.digest('hex');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// 1. txIndexHash: Hash the filtered txIndex
|
|
16
|
+
static async txIndexHash() {
|
|
17
|
+
try {
|
|
18
|
+
const txIndex = await db.getDatabase('txIndex').findAsync({});
|
|
19
|
+
const filteredTxIndex = txIndex.filter(tx => tx._id.startsWith('tx'));
|
|
20
|
+
const filteredTxIndexString = JSON.stringify(filteredTxIndex);
|
|
21
|
+
const hash = this.generateHash(filteredTxIndexString);
|
|
22
|
+
console.log('txIndexHash:', hash);
|
|
23
|
+
return hash;
|
|
24
|
+
} catch (err) {
|
|
25
|
+
console.error('Error generating txIndex hash:', err);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Run the test
|
|
31
|
+
(async () => {
|
|
32
|
+
console.log('Running txIndexHash test...');
|
|
33
|
+
const result = await ConsensusDatabase.txIndexHash();
|
|
34
|
+
console.log('Test result:', result);
|
|
35
|
+
})();
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
const assert = require('assert'); // Assertion library
|
|
2
|
+
const sinon = require('sinon'); // Mocking library (if needed)
|
|
3
|
+
const TradeLayerManager = require('./path/to/TradeLayerManager'); // The module under test
|
|
4
|
+
|
|
5
|
+
describe('TradeLayerManager', function() {
|
|
6
|
+
let tradeLayerManager;
|
|
7
|
+
let mockDependencies; // Mock any dependencies
|
|
8
|
+
|
|
9
|
+
beforeEach(function() {
|
|
10
|
+
// Set up for each test
|
|
11
|
+
tradeLayerManager = new TradeLayerManager();
|
|
12
|
+
mockDependencies = sinon.stub(/* ... */);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
afterEach(function() {
|
|
16
|
+
// Clean up after each test
|
|
17
|
+
sinon.restore();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
// Assuming activation logic is in place to activate contract series
|
|
21
|
+
describe('initializeContractSeries', function() {
|
|
22
|
+
it('should create contract series correctly after activation', async function() {
|
|
23
|
+
// Simulate activation logic for contract series
|
|
24
|
+
await tradeLayerManager.activateContractSeries();
|
|
25
|
+
|
|
26
|
+
// Assert that the contract series are created with correct properties
|
|
27
|
+
const contractSeries = tradeLayerManager.getContractSeries();
|
|
28
|
+
assert.ok(contractSeries);
|
|
29
|
+
assert.equal(contractSeries.marginRequirement, expectedMarginRequirement);
|
|
30
|
+
assert.equal(contractSeries.expiry, expectedExpiry);
|
|
31
|
+
assert.equal(contractSeries.index, expectedIndex);
|
|
32
|
+
// Other assertions for contract properties
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
// Other tests...
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const expressInterface = require('./walletInterface.js')
|
|
2
|
+
|
|
3
|
+
async function someAsyncFunction() {
|
|
4
|
+
try {
|
|
5
|
+
const maxProcessedHeight = await expressInterface.getMaxProcessedHeight();
|
|
6
|
+
console.log("Max processed height:", maxProcessedHeight);
|
|
7
|
+
} catch (error) {
|
|
8
|
+
console.error("Error:", error);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
someAsyncFunction()
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// queryMaxSynth.js
|
|
2
|
+
// Usage: node queryMaxSynth.js
|
|
3
|
+
const http = require('http');
|
|
4
|
+
const querystring = require('querystring');
|
|
5
|
+
|
|
6
|
+
const HOST = process.env.HOST || 'localhost';
|
|
7
|
+
const PORT = Number(process.env.PORT || 3000);
|
|
8
|
+
|
|
9
|
+
// target params
|
|
10
|
+
const address = 'tltc1q89kkgaslk0lt8l90jkl3cgwg7dkkszn73u4d2t';
|
|
11
|
+
const propertyId = '1';
|
|
12
|
+
|
|
13
|
+
const qs = querystring.stringify({ address, propertyId });
|
|
14
|
+
|
|
15
|
+
const options = {
|
|
16
|
+
hostname: HOST,
|
|
17
|
+
port: PORT,
|
|
18
|
+
path: `/tl_getMaxSynth?${qs}`,
|
|
19
|
+
method: 'GET',
|
|
20
|
+
headers: { 'Accept': 'application/json' },
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const req = http.request(options, (res) => {
|
|
24
|
+
let body = '';
|
|
25
|
+
res.setEncoding('utf8');
|
|
26
|
+
res.on('data', (chunk) => (body += chunk));
|
|
27
|
+
res.on('end', () => {
|
|
28
|
+
try {
|
|
29
|
+
const json = JSON.parse(body);
|
|
30
|
+
console.log('Status:', res.statusCode);
|
|
31
|
+
console.dir(json, { depth: null });
|
|
32
|
+
} catch (e) {
|
|
33
|
+
console.error('Non-JSON response:', body);
|
|
34
|
+
process.exitCode = 1;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
req.on('error', (err) => {
|
|
40
|
+
console.error('Request error:', err.message);
|
|
41
|
+
process.exitCode = 1;
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
req.end();
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const txUtils = require('./txUtils'); // Make sure this path matches where txUtils.js is located
|
|
2
|
+
|
|
3
|
+
async function createMintTransaction() {
|
|
4
|
+
const thisAddress = 'tltc1qa0kd2d39nmeph3hvcx8ytv65ztcywg5sazhtw8'; // Replace with your address
|
|
5
|
+
const params = {
|
|
6
|
+
propertyIdUsed: 5, // Replace with the actual property ID
|
|
7
|
+
contractIdUsed: 4, // Replace with the actual contract ID
|
|
8
|
+
amount: 3, // Replace with the amount to mint
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
try {
|
|
12
|
+
const mintTransaction = await txUtils.createMintTransaction(thisAddress, params);
|
|
13
|
+
console.log('Mint Transaction Created:', mintTransaction);
|
|
14
|
+
// Here you would send the transaction using a web3 library or your preferred method
|
|
15
|
+
} catch (error) {
|
|
16
|
+
console.error('Error creating mint transaction:', error);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Call the function to create the transaction
|
|
21
|
+
createMintTransaction();
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const litecoin = require('litecoin');
|
|
2
|
+
const util = require('util');
|
|
3
|
+
|
|
4
|
+
// Litecoin client configuration
|
|
5
|
+
const clientConfig = {
|
|
6
|
+
host: '127.0.0.1', // Change to your Litecoin node IP if needed
|
|
7
|
+
port: 18332, // Default Litecoin RPC port
|
|
8
|
+
user: 'user', // Set your RPC username
|
|
9
|
+
pass: 'pass', // Set your RPC password
|
|
10
|
+
timeout: 10000
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// Create a Litecoin client
|
|
14
|
+
const client = new litecoin.Client(clientConfig);
|
|
15
|
+
|
|
16
|
+
// Promisify the RPC call for getnetworkinfo
|
|
17
|
+
const getNetworkInfoAsync = util.promisify(client.cmd.bind(client, 'getnetworkinfo'));
|
|
18
|
+
|
|
19
|
+
async function testNetworkInfo() {
|
|
20
|
+
try {
|
|
21
|
+
const result = await getNetworkInfoAsync();
|
|
22
|
+
console.log('Network Info:', result); // Log the network info if successful
|
|
23
|
+
} catch (error) {
|
|
24
|
+
if (error.code === -32601) {
|
|
25
|
+
console.error('Error: Method not found. Ensure that your Litecoin node supports the getnetworkinfo method.');
|
|
26
|
+
} else {
|
|
27
|
+
console.error('An unexpected error occurred:', error);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Call the test function
|
|
33
|
+
testNetworkInfo();
|