Skip to content

Commit

Permalink
trial solution
Browse files Browse the repository at this point in the history
  • Loading branch information
OsauravO committed Apr 23, 2024
1 parent 8701272 commit fa1106f
Show file tree
Hide file tree
Showing 14 changed files with 4,141 additions and 1 deletion.
639 changes: 639 additions & 0 deletions final.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions finallyTxidsSelected.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions mempoolTempFinalArray/considerationArray.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions mempoolTempFinalArray/fileArray.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions mempoolTempFinalArray/serializedArrayFileName.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions mempoolTempFinalArray/txidArrayReversed.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions mempoolTempFinalArray/txids.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions mempoolTempFinalArray/wTxidArray.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions mempoolTempFinalArray/weightArray.json

Large diffs are not rendered by default.

3,355 changes: 3,355 additions & 0 deletions output.txt

Large diffs are not rendered by default.

51 changes: 51 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"dependencies": {
"bs58": "^5.0.0",
"js-sha256": "^0.11.0"
}
}
7 changes: 6 additions & 1 deletion run.sh
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
# Update this file to run your own code
# Update this file to run your own code
node final.js > output.txt

sed -i '' -e '${/^$/d;}' output.txt

echo "Script execution completed. Output saved in output.txt"
76 changes: 76 additions & 0 deletions utils/utilFunctions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
const crypto = require('crypto');

// utils functions:
function reversedBytes(bytes) {
const reversed = Buffer.alloc(bytes.length);
for (let i = 0; i < bytes.length; i++) {
reversed[i] = bytes[bytes.length - 1 - i];
}
return [...reversed];
}

function uint16ToBytes(n) {
const bytes = Buffer.alloc(2);
bytes.writeUInt16LE(Number(n) & 0xffff, 0); // Convert n to a number explicitly
return [...bytes];
}

function uint32ToBytes(n) {
const bytes = Buffer.alloc(4);
bytes.writeUInt32LE(Number(n) & 0xffffffff, 0); // Mask with 0xffffffff to ensure it fits within 32 bits
return [...bytes];
}

function uint64ToBytes(n) {
const lower = n & 0xffffffff; // Mask the lower 32 bits
const upper = (n - lower) / 2 ** 32; // Get the upper 32 bits
const bytes = Buffer.alloc(8);
bytes.writeUInt32LE(lower, 0); // Write lower 32 bits
bytes.writeUInt32LE(upper, 4); // Write upper 32 bits
return [...bytes];
}

function singleSHA256(data) {
const buffer = Buffer.from(data, 'hex');
const hash = crypto.createHash('sha256').update(buffer).digest();
return hash.toString('hex');
}

function doubleSHA256(data) {
const buffer = Buffer.from(data, 'hex');
const hash1 = crypto.createHash('sha256').update(buffer).digest();
const hash2 = crypto.createHash('sha256').update(hash1).digest();
return hash2.toString('hex');
}

function reverseHex(hexString) {
let result = '';
for (let i = hexString.length - 2; i >= 0; i -= 2) {
result += hexString.substr(i, 2);
}
return result;
}

function serializeVarInt(n) {
if (n < 0xfd) {
return [n];
} else if (n <= 0xffff) {
return [0xfd, ...uint16ToBytes(n)];
} else if (n <= 0xffffffff) {
return [0xfe, ...uint32ToBytes(n)];
} else {
return [0xff, ...uint64ToBytes(n)];
}
}

// export all the above functions
module.exports = {
reversedBytes,
uint16ToBytes,
uint32ToBytes,
uint64ToBytes,
singleSHA256,
doubleSHA256,
reverseHex,
serializeVarInt
};

0 comments on commit fa1106f

Please sign in to comment.