Skip to content

consider sytactic suger for the activeInput #234

Open
@mr-zwets

Description

@mr-zwets

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);

Metadata

Metadata

Assignees

No one assigned

    Labels

    cashc-compilerRelates to the cashc compilerenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions