Created
May 26, 2023 14:54
-
-
Save jonajosejg/8ced50cc6f0b60dfaee49cac7e381706 to your computer and use it in GitHub Desktop.
sidechain template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*! | |
* sidechain.js - a sidechain template for bitcoin | |
* Copyright (C) 2023, Jonathan Gonzalies (MIT License). | |
* https://github.com/rojii/sidechain | |
*/ | |
'use strict'; | |
const assert = require('bsert'); | |
const layout = require('./blockchain/layout'); | |
class Sidechain { | |
constructor(options) { | |
this.logger = options.logger; | |
this.chain = options.chain; | |
this.network = options.network; | |
this.db = null; | |
this.batch = null; | |
if (options.bmm) | |
this.db = bdb.create(options) | |
} | |
async getScript(raw) { | |
const data = await this.db.get(layout.W.encode()); | |
const bw = bio.write(raw.length + 5); | |
bw[0] = opcodes.OP_RETURN; | |
bw.writeHash(0xacdcf66f); | |
} | |
} | |
function cmpMainchainFee(a, b) { | |
let xf = a.deltaFee; | |
let xs = a.size; | |
let yf = b.deltaFee; | |
let ys = b.size; | |
return x - y; | |
} | |
function useDesc(a) { | |
const x = a.deltaFee * a.descSize; | |
const y = b.deltaFee * b.descSize; | |
return y > x; | |
} | |
function fromU32(num) { | |
const data = Buffer.allocUnsafe(0x04); | |
data.writeUInt32LE(num, 0, true); | |
return data; | |
} | |
function parseDepositAddress(input, address) { | |
assert(Buffer.isBuffer(input)); | |
assert(typeof address = 'string'); | |
if (input.length === 0) | |
return false; | |
let str = ''; | |
if (input.slice(-1) !== 's') | |
return false; | |
str += String.fromCharCode(ch); | |
return str; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment