Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 71bda2c8bb | |||
| 261c518133 | |||
| 2a1741ac52 | |||
| 1f59698bda | |||
| 3238964d2a | |||
| 85260f0281 | |||
| 8c944e469c | |||
| dae35d962a | |||
| 89fc132363 | |||
| af3cc3e902 | |||
| 4d8a30042e | |||
| a760b46501 | |||
| 9ef2d782c1 |
+1
-1
@@ -31,7 +31,7 @@
|
|||||||
"-fno-exceptions -std=gnu11 -march=native -fPIC -DNDEBUG -Ofast -funroll-loops -fvariable-expansion-in-unroller -ftree-loop-if-convert-stores -fmerge-all-constants -fbranch-target-load-optimize2"
|
"-fno-exceptions -std=gnu11 -march=native -fPIC -DNDEBUG -Ofast -funroll-loops -fvariable-expansion-in-unroller -ftree-loop-if-convert-stores -fmerge-all-constants -fbranch-target-load-optimize2"
|
||||||
],
|
],
|
||||||
"cflags_cc": [
|
"cflags_cc": [
|
||||||
"-fexceptions -frtti -std=c++14 -march=native -fPIC -DNDEBUG -Ofast -s -funroll-loops -fvariable-expansion-in-unroller -ftree-loop-if-convert-stores -fmerge-all-constants -fbranch-target-load-optimize2"
|
"-fexceptions -frtti -std=c++17 -march=native -fPIC -DNDEBUG -Ofast -s -funroll-loops -fvariable-expansion-in-unroller -ftree-loop-if-convert-stores -fmerge-all-constants -fbranch-target-load-optimize2"
|
||||||
],
|
],
|
||||||
"xcode_settings": {
|
"xcode_settings": {
|
||||||
"OTHER_CFLAGS": [ "-fexceptions -frtti" ]
|
"OTHER_CFLAGS": [ "-fexceptions -frtti" ]
|
||||||
|
|||||||
@@ -221,8 +221,20 @@ module.exports.convertRtmBlob = function(blobBuffer) {
|
|||||||
return header;
|
return header;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
module.exports.convertKcnBlob = function(blobBuffer) {
|
||||||
|
let header = blobBuffer.slice(0, 80);
|
||||||
|
update_merkle_root_hash(80, false, blobBuffer, header);
|
||||||
|
return header;
|
||||||
|
};
|
||||||
|
|
||||||
module.exports.constructNewRtmBlob = function(blockTemplate, nonceBuff) {
|
module.exports.constructNewRtmBlob = function(blockTemplate, nonceBuff) {
|
||||||
update_merkle_root_hash(80, true, blockTemplate, blockTemplate);
|
update_merkle_root_hash(80, true, blockTemplate, blockTemplate);
|
||||||
nonceBuff.copy(blockTemplate, 76, 0, 4);
|
nonceBuff.copy(blockTemplate, 76, 0, 4);
|
||||||
return blockTemplate;
|
return blockTemplate;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
module.exports.constructNewKcnBlob = function(blockTemplate, nonceBuff) {
|
||||||
|
update_merkle_root_hash(80, false, blockTemplate, blockTemplate);
|
||||||
|
nonceBuff.copy(blockTemplate, 76, 0, 4);
|
||||||
|
return blockTemplate;
|
||||||
|
};
|
||||||
|
|||||||
+2
-2
@@ -1,7 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "cryptoforknote-util",
|
"name": "cryptoforknote-util",
|
||||||
"version": "15.2.0",
|
"version": "15.3.8",
|
||||||
"main": "cryptoforknote-util",
|
|
||||||
"author": {
|
"author": {
|
||||||
"name": "LucasJones",
|
"name": "LucasJones",
|
||||||
"email": "lucasjonesdev@hotmail.co.uk"
|
"email": "lucasjonesdev@hotmail.co.uk"
|
||||||
@@ -17,6 +16,7 @@
|
|||||||
"bignum": "^0.13.1",
|
"bignum": "^0.13.1",
|
||||||
"sha3": "*",
|
"sha3": "*",
|
||||||
"base58-native": "*",
|
"base58-native": "*",
|
||||||
|
"bech32": "*",
|
||||||
"varuint-bitcoin": "^1.0.4",
|
"varuint-bitcoin": "^1.0.4",
|
||||||
"merkle-lib": "^2.0.10",
|
"merkle-lib": "^2.0.10",
|
||||||
"bitcoinjs-lib": "git+https://github.com/MoneroOcean/bitcoinjs-lib.git"
|
"bitcoinjs-lib": "git+https://github.com/MoneroOcean/bitcoinjs-lib.git"
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
const bignum = require('bignum');
|
const bignum = require('bignum');
|
||||||
const base58 = require('base58-native');
|
const base58 = require('base58-native');
|
||||||
|
const bech32 = require('bech32');
|
||||||
const bitcoin = require('bitcoinjs-lib');
|
const bitcoin = require('bitcoinjs-lib');
|
||||||
|
|
||||||
const diff1 = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;
|
const diff1 = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;
|
||||||
@@ -148,14 +149,20 @@ function getTransactionBuffers(txs) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function addressToScript(addr) {
|
function addressToScript(addr) {
|
||||||
const decoded = base58.decode(addr);
|
let decoded;
|
||||||
if (decoded.length != 25) throw new Error('Invalid address length for ' + addr);
|
try {
|
||||||
if (!decoded) throw new Error('Base58 decode failed for ' + addr);
|
decoded = base58.decode(addr);
|
||||||
|
} catch(err) {}
|
||||||
|
if (!decoded || decoded.length != 25) {
|
||||||
|
const decoded2 = Buffer.from(bech32.bech32.fromWords(bech32.bech32.decode(addr).words.slice(1)));
|
||||||
|
if (decoded2.length != 20) throw new Error('Invalid address ' + addr);
|
||||||
|
return Buffer.concat([Buffer.from([0x0, 0x14]), decoded2]);
|
||||||
|
}
|
||||||
const pubkey = decoded.slice(1, -4);
|
const pubkey = decoded.slice(1, -4);
|
||||||
return Buffer.concat([Buffer.from([0x76, 0xa9, 0x14]), pubkey, Buffer.from([0x88, 0xac])]);
|
return Buffer.concat([Buffer.from([0x76, 0xa9, 0x14]), pubkey, Buffer.from([0x88, 0xac])]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function createOutputTransaction(amount, payee, rewardToPool, reward, txOutputBuffers, payeeScript) {
|
function createTransactionOutput(amount, payee, rewardToPool, reward, txOutputBuffers, payeeScript) {
|
||||||
const payeeReward = amount;
|
const payeeReward = amount;
|
||||||
if (!payeeScript) payeeScript = addressToScript(payee);
|
if (!payeeScript) payeeScript = addressToScript(payee);
|
||||||
txOutputBuffers.push(Buffer.concat([
|
txOutputBuffers.push(Buffer.concat([
|
||||||
@@ -166,19 +173,25 @@ function createOutputTransaction(amount, payee, rewardToPool, reward, txOutputBu
|
|||||||
return { reward: reward - amount, rewardToPool: rewardToPool - amount };
|
return { reward: reward - amount, rewardToPool: rewardToPool - amount };
|
||||||
}
|
}
|
||||||
|
|
||||||
function generateOutputTransactions(rpcData, poolAddress) {
|
function generateTransactionOutputs(rpcData, poolAddress, is_witness) {
|
||||||
let reward = rpcData.coinbasevalue;
|
let reward = rpcData.coinbasevalue;
|
||||||
let rewardToPool = reward;
|
let rewardToPool = reward;
|
||||||
let txOutputBuffers = [];
|
let txOutputBuffers = [];
|
||||||
|
|
||||||
|
if (rpcData.coinbasedevreward) {
|
||||||
|
const rewards = createTransactionOutput(rpcData.coinbasedevreward.value, rpcData.coinbasedevreward.address, rewardToPool, reward, txOutputBuffers, Buffer.from(rpcData.coinbasedevreward.scriptpubkey, 'hex'));
|
||||||
|
reward = rewards.reward;
|
||||||
|
rewardToPool = rewards.rewardToPool;
|
||||||
|
}
|
||||||
|
|
||||||
if (rpcData.smartnode) {
|
if (rpcData.smartnode) {
|
||||||
if (rpcData.smartnode.payee) {
|
if (rpcData.smartnode.payee) {
|
||||||
const rewards = createOutputTransaction(rpcData.smartnode.amount, rpcData.smartnode.payee, rewardToPool, reward, txOutputBuffers);
|
const rewards = createTransactionOutput(rpcData.smartnode.amount, rpcData.smartnode.payee, rewardToPool, reward, txOutputBuffers);
|
||||||
reward = rewards.reward;
|
reward = rewards.reward;
|
||||||
rewardToPool = rewards.rewardToPool;
|
rewardToPool = rewards.rewardToPool;
|
||||||
} else if (Array.isArray(rpcData.smartnode)) {
|
} else if (Array.isArray(rpcData.smartnode)) {
|
||||||
for (let i in rpcData.smartnode) {
|
for (let i in rpcData.smartnode) {
|
||||||
const rewards = createOutputTransaction(rpcData.smartnode[i].amount, rpcData.smartnode[i].payee, rewardToPool, reward, txOutputBuffers);
|
const rewards = createTransactionOutput(rpcData.smartnode[i].amount, rpcData.smartnode[i].payee, rewardToPool, reward, txOutputBuffers);
|
||||||
reward = rewards.reward;
|
reward = rewards.reward;
|
||||||
rewardToPool = rewards.rewardToPool;
|
rewardToPool = rewards.rewardToPool;
|
||||||
}
|
}
|
||||||
@@ -187,7 +200,7 @@ function generateOutputTransactions(rpcData, poolAddress) {
|
|||||||
|
|
||||||
if (rpcData.superblock) {
|
if (rpcData.superblock) {
|
||||||
for (let i in rpcData.superblock) {
|
for (let i in rpcData.superblock) {
|
||||||
const rewards = createOutputTransaction(rpcData.superblock[i].amount, rpcData.superblock[i].payee, rewardToPool, reward, txOutputBuffers);
|
const rewards = createTransactionOutput(rpcData.superblock[i].amount, rpcData.superblock[i].payee, rewardToPool, reward, txOutputBuffers);
|
||||||
reward = rewards.reward;
|
reward = rewards.reward;
|
||||||
rewardToPool = rewards.rewardToPool;
|
rewardToPool = rewards.rewardToPool;
|
||||||
}
|
}
|
||||||
@@ -195,23 +208,23 @@ function generateOutputTransactions(rpcData, poolAddress) {
|
|||||||
|
|
||||||
if (rpcData.founder_payments_started && rpcData.founder) {
|
if (rpcData.founder_payments_started && rpcData.founder) {
|
||||||
const founderReward = rpcData.founder.amount || 0;
|
const founderReward = rpcData.founder.amount || 0;
|
||||||
const rewards = createOutputTransaction(founderReward, rpcData.founder.payee, rewardToPool, reward, txOutputBuffers);
|
const rewards = createTransactionOutput(founderReward, rpcData.founder.payee, rewardToPool, reward, txOutputBuffers);
|
||||||
reward = rewards.reward;
|
reward = rewards.reward;
|
||||||
rewardToPool = rewards.rewardToPool;
|
rewardToPool = rewards.rewardToPool;
|
||||||
}
|
}
|
||||||
|
|
||||||
createOutputTransaction(rewardToPool, null, rewardToPool, reward, txOutputBuffers, Buffer.from(addressToScript(poolAddress), "hex"));
|
createTransactionOutput(rewardToPool, null, rewardToPool, reward, txOutputBuffers, Buffer.from(addressToScript(poolAddress), "hex"));
|
||||||
|
|
||||||
if (rpcData.default_witness_commitment !== undefined) {
|
if (is_witness) {
|
||||||
const witness_commitment = Buffer.from(rpcData.default_witness_commitment, 'hex');
|
const witness_commitment = Buffer.from(rpcData.default_witness_commitment, 'hex');
|
||||||
txOutputBuffers.unshift(Buffer.concat([
|
txOutputBuffers.push(Buffer.concat([
|
||||||
packInt64LE(0),
|
varIntBuffer(1),
|
||||||
varIntBuffer(witness_commitment.length),
|
varIntBuffer(witness_commitment.length),
|
||||||
witness_commitment
|
witness_commitment
|
||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
return Buffer.concat([ varIntBuffer(txOutputBuffers.length), Buffer.concat(txOutputBuffers)]);
|
return Buffer.concat([ varIntBuffer(is_witness ? txOutputBuffers.length - 1 : txOutputBuffers.length), Buffer.concat(txOutputBuffers)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.RtmBlockTemplate = function(rpcData, poolAddress) {
|
module.exports.RtmBlockTemplate = function(rpcData, poolAddress) {
|
||||||
@@ -220,16 +233,19 @@ module.exports.RtmBlockTemplate = function(rpcData, poolAddress) {
|
|||||||
|
|
||||||
const scriptSigPart1 = Buffer.concat([
|
const scriptSigPart1 = Buffer.concat([
|
||||||
serializeNumber(rpcData.height),
|
serializeNumber(rpcData.height),
|
||||||
Buffer.from(rpcData.coinbaseaux.flags, 'hex'),
|
Buffer.from(rpcData.coinbaseaux.flags ? rpcData.coinbaseaux.flags : "", 'hex'),
|
||||||
serializeNumber(Date.now() / 1000 | 0),
|
serializeNumber(Date.now() / 1000 | 0),
|
||||||
Buffer.from([extraNoncePlaceholderLength])
|
Buffer.from([extraNoncePlaceholderLength])
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const scriptSigPart2 = serializeString('/nodeStratum/');
|
const scriptSigPart2 = serializeString('/nodeStratum/');
|
||||||
|
|
||||||
|
const is_witness = rpcData.default_witness_commitment !== undefined;
|
||||||
|
|
||||||
const blob1 = Buffer.concat([
|
const blob1 = Buffer.concat([
|
||||||
coinbaseVersion,
|
coinbaseVersion,
|
||||||
// transaction input
|
// transaction input
|
||||||
|
Buffer.from(is_witness ? "0001" : "", 'hex'),
|
||||||
varIntBuffer(1), // txInputsCount
|
varIntBuffer(1), // txInputsCount
|
||||||
uint256BufferFromHash(""), // txInPrevOutHash
|
uint256BufferFromHash(""), // txInPrevOutHash
|
||||||
packUInt32LE(Math.pow(2, 32) - 1), // txInPrevOutIndex
|
packUInt32LE(Math.pow(2, 32) - 1), // txInPrevOutIndex
|
||||||
@@ -242,13 +258,19 @@ module.exports.RtmBlockTemplate = function(rpcData, poolAddress) {
|
|||||||
packUInt32LE(0), // txInSequence
|
packUInt32LE(0), // txInSequence
|
||||||
// end transaction input
|
// end transaction input
|
||||||
// transaction output
|
// transaction output
|
||||||
generateOutputTransactions(rpcData, poolAddress),
|
generateTransactionOutputs(rpcData, poolAddress, is_witness),
|
||||||
// end transaction ouput
|
// end transaction ouput
|
||||||
packUInt32LE(0), // txLockTime
|
packUInt32LE(0) // txLockTime
|
||||||
varIntBuffer(rpcData.coinbase_payload.length / 2),
|
|
||||||
Buffer.from(rpcData.coinbase_payload, 'hex')
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
if (rpcData.coinbase_payload) {
|
||||||
|
blob2 = Buffer.concat([
|
||||||
|
blob2,
|
||||||
|
varIntBuffer(rpcData.coinbase_payload.length / 2),
|
||||||
|
Buffer.from(rpcData.coinbase_payload, 'hex')
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
const prev_hash = reverseBuffer(Buffer.from(rpcData.previousblockhash, 'hex')).toString('hex');
|
const prev_hash = reverseBuffer(Buffer.from(rpcData.previousblockhash, 'hex')).toString('hex');
|
||||||
const version = packInt32LE(rpcData.version).toString('hex');
|
const version = packInt32LE(rpcData.version).toString('hex');
|
||||||
const curtime = packUInt32LE(rpcData.curtime).toString('hex');
|
const curtime = packUInt32LE(rpcData.curtime).toString('hex');
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ template <>
|
|||||||
struct binary_archive<false> : public binary_archive_base<std::istream, false>
|
struct binary_archive<false> : public binary_archive_base<std::istream, false>
|
||||||
{
|
{
|
||||||
explicit binary_archive(stream_type &s) : base_type(s) {
|
explicit binary_archive(stream_type &s) : base_type(s) {
|
||||||
stream_type::streampos pos = stream_.tellg();
|
auto pos = stream_.tellg();
|
||||||
stream_.seekg(0, std::ios_base::end);
|
stream_.seekg(0, std::ios_base::end);
|
||||||
eof_pos_ = stream_.tellg();
|
eof_pos_ = stream_.tellg();
|
||||||
stream_.seekg(pos);
|
stream_.seekg(pos);
|
||||||
|
|||||||
Reference in New Issue
Block a user