bitcoin-sv / sol2scrypt

Solidity to sCrypt Transplier
BSD 3-Clause "New" or "Revised" License
1 stars 0 forks source link

rewrite contract SimpleStorage in sCrypt #28

Closed xhliu closed 2 years ago

xhliu commented 2 years ago
contract SimpleStorage {
    @state
    int storedData;

    public function set(int x, SigHashPreimage preimage)  {
        this.storedData = x;

        //this.get()

        // inserted code
        require(Tx.checkPreimage(preimage));
        bytes outputScript = this.getStateScript();
        bytes output = Utils.buildOutput(outputScript, SigHash.value(preimage));
        require(hash256(output) == SigHash.hashOutputs(preimage));
    }

    function get(): int {
        return this.storedData;
    }

    // public function getVerify(int x) {
    //     require(this.get() == x);
    // }
}