CashScript / cashscript

⚖️ Easily write and interact with Bitcoin Cash smart contracts
https://cashscript.org
MIT License
111 stars 77 forks source link

Consider syntactic sugar for "slice" functionality #170

Open mr-zwets opened 8 months ago

mr-zwets commented 8 months ago

We should consider adding syntactic sugar for "slice" functionality

so instead of bytes stateItem = fullState.split(4)[1].split(10)[0]; it would be bytes stateItem = fullState.slice(4,10);

suggesting the name slice because substr could be confusing working on bytes (and was previously the opcode name for OP_SPLIT)

mr-zwets commented 8 months ago

this would also simplify part of the anyhedge contract

        // Extract previous message's content sequence.
        int previousSequence = int(previousMessage.split(8)[1].split(4)[0]);

        // If the "content sequence" is negative it represents metadata rather than a price message
        // and cannot be used inside the contract.
        require(previousSequence > 0);

        // Extract settlement message's content sequence.
        int settlementSequence = int(settlementMessage.split(8)[1].split(4)[0]);