solidity中`this`对象的类型是什么

What is the type of `this` object in solidity

在下面的 claimPayment 函数中,该函数用于索取之前对该合同支付的款项,行 bytes32 message = prefixed(keccak256(abi.encodePacked(msg.sender, amount, nonce, this)));this 作为签名消息的一部分。这让我想知道 this 是什么以及 this 的类型是什么。如果我在函数中返回 this,它使用什么类型?谢谢。

    function claimPayment(uint256 amount, uint256 nonce, bytes memory signature) public {
        require(!usedNonces[nonce]);
        usedNonces[nonce] = true;

        // this recreates the message that was signed on the client
        bytes32 message = prefixed(keccak256(abi.encodePacked(msg.sender, amount, nonce, this)));

        require(recoverSigner(message, signature) == owner);

        payable(msg.sender).transfer(amount);
    }

this 是指向当前 class 实例的指针,与许多其他编程语言一样。例如,您可以指向 public 方法:

pragma solidity ^0.8.0;

contract MyContract {
    function foo() external {
        this.bar();
    }
    
    function bar() public {
    }
}

this 被类型转换时,它采用地址形式,即当前实例部署的位置。

pragma solidity ^0.8.0;

contract MyContract {
    function foo() external view returns (bytes memory) {
        return abi.encodePacked(this);
    }
    
    function bar() external view returns (address) {
        return address(this);
    }
}