Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[alstr] Fix diff template #47

Open
github-actions bot opened this issue Sep 14, 2024 · 0 comments
Open

[alstr] Fix diff template #47

github-actions bot opened this issue Sep 14, 2024 · 0 comments
Assignees
Labels

Comments

@github-actions
Copy link

Only use this slower method for coins that need it

emitLog('miner ' + JSON.stringify(template.miner));

emitLog('founder ' + JSON.stringify(template.founders));

emitLog('miner ' + JSON.stringify(template.miner));

emitLog('founder ' + JSON.stringify(template.founders));

//TODO(alstr): Fix diff template

    function GetBlockTemplate(callback) {
        function getBlockSubsidyandTemplate() {
            _this.daemon.cmd('getblocktemplate',
                             [ { "capabilities": ["coinbasetxn", "workid", "coinbase/append"] }],
            function (result) {
                if (result.error) {
                    emitErrorLog('getblocktemplate call failed for daemon instance ' + result.instance.index + ' with error ' + JSON.stringify(result.error));
                    callback(result.error);
                } else if (result[0].response == null) {
                    emitErrorLog('getblocktemplate call failed because daemon template code is still fucked up');
                    getBlockSubsidyandTemplate()
                } else if (result[0].response.coinbasetxn == null) {
                    emitErrorLog('getblocktemplate call failed for daemon with error 2 ' + JSON.stringify(result));
                    getBlockSubsidyandTemplate()
                } else if (typeof result[0].response === 'undefined') {
                    emitErrorLog('getblocktemplate call failed for daemon with error 3 ' + JSON.stringify(result));
                    getBlockSubsidyandTemplate()
                } else if (typeof result[0].response.coinbasetxn === 'undefined') {
                    emitErrorLog('getblocktemplate call failed for daemon with error 4 ' + JSON.stringify(result));
                    getBlockSubsidyandTemplate()
                } else {
                    getRawTransaction(result[0].response)
                }
            }
                            )
        }
        //TODO(alstr): Fix diff template
        //Only use this slower method for coins that need it
        function getRawTransaction(template) {
            template.miner = template.coinbasetxn.coinbasevalue;
            template.miner = (template.miner / Math.pow(10, 8));
            template.miner = parseFloat(template.miner.toFixed(8));
            _this.daemon.cmd('decoderawtransaction',
                             [template.coinbasetxn.data],
            function (result) {
                if (result.error) {
                    emitErrorLog('decoderawtransaction call failed for daemon instance ' +
                                 result.instance.index + ' with error ' + JSON.stringify(result.error));
                    callback(result.error);
                } else {
                    template.vouts = result.response.vout;
                    //emitErrorLog('total vouts: ' + JSON.stringify(result.response.vout.length));
                    //emitLog('miner ' + JSON.stringify(template.miner));
                    //emitLog('founder ' + JSON.stringify(template.founders));
                    var processedNewBlock = _this.jobManager.processTemplate(template);
                    callback(null, template, processedNewBlock);
                    callback = function () {
                    };
                }
            }, true
                            );
        }

        function getNextBlockHeight() {
            _this.daemon.cmd(
                'getblockcount',
                [],
            function (result) {
                "response" in result[0] ? console.log(result[0].response) : console.log(result)
            }
            )
        }

        if (options.coin.symbol == "MCL") {
            getNextBlockHeight();

        }
        getBlockSubsidyandTemplate();
    }
    function CheckBlockAccepted(blockHash, callback) {
        _this.daemon.cmd('getblock', [blockHash],
        function (results) {
            var validResults = results.filter(function (result) { return result.response && (result.response.hash === blockHash) });
            validResults.length >= 1 ? callback(true, validResults[0].response.tx[0]) : callback(false)
        }
                        );
    }
    /**
     * This method is being called from the blockNotify so that when a new block is discovered by the daemon
     * We can inform our miners about the newly found block
     **/
     //TODO(alstr): Fix height print
    this.processBlockNotify = function (blockHash, sourceTrigger) {
        if (!process.env.forkId || process.env.forkId === '0') {
            //console.log(_this.jobManager.meh);
            //var logheight = JSON.stringify(_this.jobManager.currentJob.rpcData.height);
            emitLog('Block notification via ' + sourceTrigger + ' -->> Block: ' + _this.jobManager.currentJob.rpcData.height);
        }
        if (typeof (_this.jobManager) !== 'undefined' && typeof (_this.jobManager.currentJob) !== 'undefined' &&
                                          typeof (_this.jobManager.currentJob.rpcData.previousblockhash) !== 'undefined' &&
                                                  blockHash !== _this.jobManager.currentJob.rpcData.previousblockhash) {
            GetBlockTemplate(function (error, result) {
                if (error)
                { emitErrorLog('Block notify error getting block template for ' + options.coin.name); }
            })
        }
    };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant