From 14cbe7429339c84ecf78f2dcf0c96769a59682be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20D=C3=ADaz?= Date: Thu, 23 Nov 2023 20:45:02 +0100 Subject: [PATCH] feat: Witnet*.class(): string --- contracts/WitnetBytecodes.sol | 3 +++ contracts/WitnetRequestBoard.sol | 3 +++ contracts/WitnetRequestFactory.sol | 1 + contracts/WitnetRequestTemplate.sol | 1 + .../defaults/WitnetRequestFactoryDefault.sol | 17 +++++++++++++++++ 5 files changed, 25 insertions(+) diff --git a/contracts/WitnetBytecodes.sol b/contracts/WitnetBytecodes.sol index 0a79a627..6a123533 100644 --- a/contracts/WitnetBytecodes.sol +++ b/contracts/WitnetBytecodes.sol @@ -9,5 +9,8 @@ abstract contract WitnetBytecodes is IWitnetBytecodes { + function class() virtual external view returns (string memory) { + return type(WitnetBytecodes).name; + } function specs() virtual external view returns (bytes4); } \ No newline at end of file diff --git a/contracts/WitnetRequestBoard.sol b/contracts/WitnetRequestBoard.sol index 85953ad1..37fc92f9 100644 --- a/contracts/WitnetRequestBoard.sol +++ b/contracts/WitnetRequestBoard.sol @@ -12,6 +12,9 @@ abstract contract WitnetRequestBoard is IWitnetRequestBoard { + function class() virtual external view returns (string memory) { + return type(WitnetRequestBoard).name; + } function factory() virtual external view returns (WitnetRequestFactory); function registry() virtual external view returns (WitnetBytecodes); function specs() virtual external view returns (bytes4); diff --git a/contracts/WitnetRequestFactory.sol b/contracts/WitnetRequestFactory.sol index 7fb997b5..b6cf5c61 100644 --- a/contracts/WitnetRequestFactory.sol +++ b/contracts/WitnetRequestFactory.sol @@ -11,6 +11,7 @@ abstract contract WitnetRequestFactory is IWitnetRequestFactory { + function class() virtual external view returns (string memory); function registry() virtual external view returns (WitnetBytecodes); function specs() virtual external view returns (bytes4); function witnet() virtual external view returns (WitnetRequestBoard); diff --git a/contracts/WitnetRequestTemplate.sol b/contracts/WitnetRequestTemplate.sol index 9ad8835e..5a6b4793 100644 --- a/contracts/WitnetRequestTemplate.sol +++ b/contracts/WitnetRequestTemplate.sol @@ -11,6 +11,7 @@ abstract contract WitnetRequestTemplate { event WitnetRequestBuilt(address indexed request, bytes32 indexed radHash, string[][] args); + function class() virtual external view returns (string memory); function factory() virtual external view returns (WitnetRequestFactory); function registry() virtual external view returns (WitnetBytecodes); function specs() virtual external view returns (bytes4); diff --git a/contracts/core/defaults/WitnetRequestFactoryDefault.sol b/contracts/core/defaults/WitnetRequestFactoryDefault.sol index f333be97..a3ef1b11 100644 --- a/contracts/core/defaults/WitnetRequestFactoryDefault.sol +++ b/contracts/core/defaults/WitnetRequestFactoryDefault.sol @@ -184,6 +184,23 @@ contract WitnetRequestFactoryDefault ); } + function class() + virtual override(WitnetRequestFactory, WitnetRequestTemplate) + external view + returns (string memory) + { + if ( + address(this) == _SELF + || address(this) == __proxy() + ) { + return type(WitnetRequestFactory).name; + } else if (__witnetRequest().radHash != bytes32(0)) { + return type(WitnetRequest).name; + } else { + return type(WitnetRequestTemplate).name; + } + } + function specs() virtual override(WitnetRequestFactory, WitnetRequestTemplate) external view