From d3b592ba434cecbaebdae10011378863e9223d3f Mon Sep 17 00:00:00 2001 From: Vicente Dragicevic <3252614+vdrg@users.noreply.github.com> Date: Fri, 22 Nov 2024 10:35:16 +0900 Subject: [PATCH] Add callAsRoot and callAsRootFrom --- .../world/ts/node/render-solidity/renderSystemLibrary.ts | 8 ++++++-- .../src/namespaces/a/codegen/libraries/ASystemLib.sol | 8 ++++++-- .../src/namespaces/b/codegen/libraries/BSystemLib.sol | 8 ++++++-- test/system-libraries/src/namespaces/root/RootSystem.sol | 2 +- .../namespaces/root/codegen/libraries/RootSystemLib.sol | 8 ++++++-- 5 files changed, 25 insertions(+), 9 deletions(-) diff --git a/packages/world/ts/node/render-solidity/renderSystemLibrary.ts b/packages/world/ts/node/render-solidity/renderSystemLibrary.ts index cfd468e947..dfa8301a46 100644 --- a/packages/world/ts/node/render-solidity/renderSystemLibrary.ts +++ b/packages/world/ts/node/render-solidity/renderSystemLibrary.ts @@ -91,8 +91,12 @@ export function renderSystemLibrary(options: RenderSystemLibraryOptions) { return CallWrapper(self.toResourceId(), from); } - function asRoot(${userTypeName} self) internal pure returns (RootCallWrapper memory) { - return RootCallWrapper(self.toResourceId(), address(0)); + function callAsRoot(${userTypeName} self) internal view returns (RootCallWrapper memory) { + return RootCallWrapper(self.toResourceId(), msg.sender); + } + + function callAsRootFrom(${userTypeName} self, address from) internal pure returns (RootCallWrapper memory) { + return RootCallWrapper(self.toResourceId(), from); } function toResourceId(${userTypeName} self) internal pure returns (ResourceId) { diff --git a/test/system-libraries/src/namespaces/a/codegen/libraries/ASystemLib.sol b/test/system-libraries/src/namespaces/a/codegen/libraries/ASystemLib.sol index 6759b52831..eaa2a0b4c5 100644 --- a/test/system-libraries/src/namespaces/a/codegen/libraries/ASystemLib.sol +++ b/test/system-libraries/src/namespaces/a/codegen/libraries/ASystemLib.sol @@ -109,8 +109,12 @@ library ASystemLib { return CallWrapper(self.toResourceId(), from); } - function asRoot(ASystemType self) internal pure returns (RootCallWrapper memory) { - return RootCallWrapper(self.toResourceId(), address(0)); + function callAsRoot(ASystemType self) internal view returns (RootCallWrapper memory) { + return RootCallWrapper(self.toResourceId(), msg.sender); + } + + function callAsRootFrom(ASystemType self, address from) internal pure returns (RootCallWrapper memory) { + return RootCallWrapper(self.toResourceId(), from); } function toResourceId(ASystemType self) internal pure returns (ResourceId) { diff --git a/test/system-libraries/src/namespaces/b/codegen/libraries/BSystemLib.sol b/test/system-libraries/src/namespaces/b/codegen/libraries/BSystemLib.sol index 246b4fbfd2..d51e2177a9 100644 --- a/test/system-libraries/src/namespaces/b/codegen/libraries/BSystemLib.sol +++ b/test/system-libraries/src/namespaces/b/codegen/libraries/BSystemLib.sol @@ -72,8 +72,12 @@ library BSystemLib { return CallWrapper(self.toResourceId(), from); } - function asRoot(BSystemType self) internal pure returns (RootCallWrapper memory) { - return RootCallWrapper(self.toResourceId(), address(0)); + function callAsRoot(BSystemType self) internal view returns (RootCallWrapper memory) { + return RootCallWrapper(self.toResourceId(), msg.sender); + } + + function callAsRootFrom(BSystemType self, address from) internal pure returns (RootCallWrapper memory) { + return RootCallWrapper(self.toResourceId(), from); } function toResourceId(BSystemType self) internal pure returns (ResourceId) { diff --git a/test/system-libraries/src/namespaces/root/RootSystem.sol b/test/system-libraries/src/namespaces/root/RootSystem.sol index 45149421ef..d2c28c0d23 100644 --- a/test/system-libraries/src/namespaces/root/RootSystem.sol +++ b/test/system-libraries/src/namespaces/root/RootSystem.sol @@ -6,6 +6,6 @@ import { aSystem } from "../a/codegen/libraries/ASystemLib.sol"; contract RootSystem is System { function setValueInA(uint256 value) external { - aSystem.asRoot().setValue(value); + aSystem.callAsRoot().setValue(value); } } diff --git a/test/system-libraries/src/namespaces/root/codegen/libraries/RootSystemLib.sol b/test/system-libraries/src/namespaces/root/codegen/libraries/RootSystemLib.sol index 441452f4f7..f0be5f46a8 100644 --- a/test/system-libraries/src/namespaces/root/codegen/libraries/RootSystemLib.sol +++ b/test/system-libraries/src/namespaces/root/codegen/libraries/RootSystemLib.sol @@ -55,8 +55,12 @@ library RootSystemLib { return CallWrapper(self.toResourceId(), from); } - function asRoot(RootSystemType self) internal pure returns (RootCallWrapper memory) { - return RootCallWrapper(self.toResourceId(), address(0)); + function callAsRoot(RootSystemType self) internal view returns (RootCallWrapper memory) { + return RootCallWrapper(self.toResourceId(), msg.sender); + } + + function callAsRootFrom(RootSystemType self, address from) internal pure returns (RootCallWrapper memory) { + return RootCallWrapper(self.toResourceId(), from); } function toResourceId(RootSystemType self) internal pure returns (ResourceId) {