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

consider sytactic suger for the activeInput #234

Open
mr-zwets opened this issue Nov 5, 2024 · 1 comment
Open

consider sytactic suger for the activeInput #234

mr-zwets opened this issue Nov 5, 2024 · 1 comment
Labels
cashc-compiler Relates to the cashc compiler

Comments

@mr-zwets
Copy link
Member

mr-zwets commented Nov 5, 2024

Rosco floated the idea that perhaps we could add syntactic sugar for the activeInput:

this.input (or this.activeInput) for tx.inputs[this.activeInputIndex] which would simplify common syntax

and to potentially do something similar for the corresponding output:

this.correspondingOutput for tx.outputs[this.activeInputIndex]

the drawback/danger of the syntax for the output is that it dilutes the meaning of this referring to the active script/input and is only slightly shorter (although no brackets)...

Example

With the new syntactic sugar, self-replicating covenants would then look like this:

    require(this.correspondingOutput.lockingBytecode == this.activeInput.lockingBytecode);
    require(this.correspondingOutput.tokenCategory == this.activeInput.tokenCategory);
    require(this.correspondingOutput.value == 1000);
    require(this.correspondingOutput.tokenAmount == this.activeInput.tokenAmount);
    require(this.correspondingOutput.nftCommitment == this.activeInput.nftCommitment);

whereas before:

    require(tx.outputs[this.activeInputIndex].lockingBytecode == tx.inputs[this.activeInputIndex].lockingBytecode);
    require(tx.outputs[this.activeInputIndex].tokenCategory == tx.inputs[this.activeInputIndex].tokenCategory);
    require(tx.outputs[this.activeInputIndex].value == 1000);
    require(tx.outputs[this.activeInputIndex].tokenAmount == tx.inputs[this.activeInputIndex].tokenAmount);
    require(tx.outputs[this.activeInputIndex].nftCommitment == tx.inputs[this.activeInputIndex].nftCommitment);
@SayoshiNakamario
Copy link

My first thought is it would be nice to simplify down to something like:

    function doThing() {  
        require(this.inputOutput == 1); //optional, reads more simply/makes sense with below terms
        
        require(this.output.lockingBytecode == this.input.lockingBytecode);
        require(this.output.tokenCategory == this.input.tokenCategory);
        require(this.output.value == 1000);
        require(this.output.tokenAmount == this.input.tokenAmount);
        require(this.output.nftCommitment == this.input.nftCommitment);
    }

When I look at contracts I'm already assuming the contract is only referring to the individual input being processed against it, and having checks done against other inputs/outputs always requires referring to them directly via tx.input/output[#]. I think the only time I ever use this. is specifying the activeInputIndex, so I feel the above would line up with that still.

@mr-zwets mr-zwets added the cashc-compiler Relates to the cashc compiler label Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cashc-compiler Relates to the cashc compiler
Projects
None yet
Development

No branches or pull requests

2 participants