From 20a253aebdbef68da05a66971f909aa57e546a98 Mon Sep 17 00:00:00 2001 From: JeremyHD <10832016+jeremyHD@users.noreply.github.com> Date: Wed, 24 Jan 2024 16:08:20 +0800 Subject: [PATCH] fix: get nonce without override pending txs --- src/BatchScript.sol | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/BatchScript.sol b/src/BatchScript.sol index feb7fe7..303fb47 100644 --- a/src/BatchScript.sol +++ b/src/BatchScript.sol @@ -433,14 +433,16 @@ abstract contract BatchScript is Script, DelegatePrank { function _getNonce(address safe_) internal returns (uint256) { string memory endpoint = string.concat( - SAFE_API_BASE_URL, - vm.toString(safe_), - "/" + _getSafeAPIEndpoint(safe_), + "?limit=1" ); (uint256 status, bytes memory data) = endpoint.get(); if (status == 200) { - string memory result = string(data); - return result.readUint(".nonce"); + string memory resp = string(data); + string[] memory results; + results = resp.readStringArray(".results"); + if (results.length == 0) return 0; + return resp.readUint(".results[0].nonce") + 1; } else { revert("Get nonce failed!"); }