cashscript
cashscript copied to clipboard
Investigate compilation of 'cashscript snippets' to CashASM
@jimtendo started a convestion on telegram (https://t.me/bch_compilers/7955) to ask
Might it be feasible in future to have some kind of
compileScriptfunction that allows CashScript to compile a short segment of CashScript into CashASM? Something like:// First arg is the script // Second arg is the named values and their type compileScript('a + b', { a: 'int', b: 'int', }) // outputs: // <a> <b> OP_ADD
Rosco replied (https://t.me/bch_compilers/8000) that we could try to support the following:
compileScript(`function x(int a, int b) { return a + b }`);
// or
const requireLockscriptP2PKH = compileScript(`
function checkLockingBytecode(bytes lockingBytecode) {
require(lockingBytecode.length == 25);
require(lockingBytecode.split(3)[0] == 0x76a914);
require(lockingBytecode.split(23)[1] == 0x88ac);
}`);
That way we skip the contract overhead, but keep the function definition that has parameter data
Creating self-contained "functions" is something that is on the roadmap (although specifics are yet to be defined), but when we implement that, we could try to ensure that they could be compiled by themselves so they could be used for use cases like yours
adding a "target" for CashASM (besides "regular" hex bytecode / asm) should be doable as well.