zig-bitcoin / btczee

Bitcoin protocol implementation in Zig.
https://zig-bitcoin.github.io/btczee/
MIT License
38 stars 26 forks source link

feat: create a script generator #65

Open tdelabro opened 3 weeks ago

tdelabro commented 3 weeks ago

Currently we create scripts in order to test our opcodes implementation. It is done with a []u8 looking like this:

const bytes: [?]u8 = [_]u8{ 0x12, 0x34, 0x56, 0x78 };

Where everything (opcode and data) is written as u8. This is unreadable and unmaintainable.

I want it to look like this:

const my_script = ScriptBuilder.new().pushOpcode(Opcode.OP_ADD).pushInt(1).pushInt(1).addOpcode(Opcode.OP_NUMEQUAL).addInt(2).build();

Create in as an independent lib, script/

89oso commented 3 weeks ago

Hello, can i do this?

onlydustapp[bot] commented 3 weeks ago

Hey @89oso! Thanks for showing interest. We've created an application for you to contribute to btczee. Go check it out on OnlyDust!

varun-doshi commented 3 weeks ago

Hey @tdelabro I can take this up. Been working with Zig the past few weeks. I probably have a good idea how to get this done

onlydustapp[bot] commented 3 weeks ago

Hey @varun-doshi! Thanks for showing interest. We've created an application for you to contribute to btczee. Go check it out on OnlyDust!

tdelabro commented 3 weeks ago

Hey @89oso, as this is an advanced issue and you have not contributed yet to the project, I will assign it to @varun-doshi and ask you to start with an easier, smaller issue.

varun-doshi commented 3 weeks ago

I see this https://github.com/zig-bitcoin/btczee/blob/d11b780ea999e3fbb38b689f05b2d832706750a0/src/script/lib.zig#L11

Would it be right to assume our ScriptBuilder will only hold max of 201 opcodes at any given time?

varun-doshi commented 3 weeks ago

Also something to note @tdelabro Zig seems to have an inherent issue with function chaining: https://github.com/ziglang/zig/issues/5705

I've come up with 2 ways to use the ScriptBuilder. Will clarify in my PR. We can choose whichever seems to be simpler syntax wise