From 793e805af06d5a8684fce1d1ecf0ef61923f842d Mon Sep 17 00:00:00 2001 From: Raul Bernal Date: Fri, 18 Oct 2024 09:44:05 +0200 Subject: [PATCH 1/2] Update validation.php with SDK checker Check SDK version to determine what endpoint query --- controllers/front/validation.php | 40 +++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/controllers/front/validation.php b/controllers/front/validation.php index ef6b1e5..d3a4565 100644 --- a/controllers/front/validation.php +++ b/controllers/front/validation.php @@ -191,14 +191,38 @@ public function checkByTxHash() { } } public function checkByMemo() { - header('Content-Type: application/json'); - $cart = $this->context->cart; - $returnTrans = cosmosSql::getTransaction($cart->id); - - $json = file_get_contents($returnTrans[0]['lcd_pay'].'/cosmos/tx/v1beta1/txs?events=message.action=%27/cosmos.bank.v1beta1.MsgSend%27&order_by=ORDER_BY_DESC&pagination.limit=10'); - $obj = json_decode($json); - - echo $json; + header('Content-Type: application/json'); + $cart = $this->context->cart; + $returnTrans = cosmosSql::getTransaction($cart->id); + + // Get the LCD URL from the transaction data + $lcdPay = $returnTrans[0]['lcd_pay']; + + // Obtain node information to determine the Cosmos SDK version + $nodeInfoJson = file_get_contents($lcdPay.'/cosmos/base/tendermint/v1beta1/node_info'); + $nodeInfo = json_decode($nodeInfoJson, true); + + // Check if the node information was obtained successfully + if ($nodeInfo !== null && isset($nodeInfo['application_version']['cosmos_sdk_version'])) { + // Extract the Cosmos SDK version and remove the 'v' prefix if it exists + $cosmosSdkVersion = ltrim($nodeInfo['application_version']['cosmos_sdk_version'], 'v'); + + // Decide which endpoint to use based on the SDK version + if (version_compare($cosmosSdkVersion, '0.50.0', '>=')) { + // Use the endpoint for SDK v0.50.x + $json = file_get_contents($lcdPay.'/cosmos/tx/v1beta1/txs?query=message.action=%27/cosmos.bank.v1beta1.MsgSend%27&order_by=ORDER_BY_DESC&pagination.limit=10'); + } else { + // Use the endpoint for SDK v0.47.x + $json = file_get_contents($lcdPay.'/cosmos/tx/v1beta1/txs?events=message.action=%27/cosmos.bank.v1beta1.MsgSend%27&order_by=ORDER_BY_DESC&pagination.limit=10'); + } + } else { + // If unable to determine the SDK version, default to the endpoint for SDK v0.50.x + $json = file_get_contents($lcdPay.'/cosmos/tx/v1beta1/txs?query=message.action=%27/cosmos.bank.v1beta1.MsgSend%27&order_by=ORDER_BY_DESC&pagination.limit=10'); + } + + $obj = json_decode($json); + + echo $json; } public function postProcess() { From 2b2ae19cfe597b49de3ff48ca00f04a99b82cf84 Mon Sep 17 00:00:00 2001 From: Raul Bernal Date: Thu, 7 Nov 2024 14:09:25 +0100 Subject: [PATCH 2/2] fix version selector doing by CometBFT version & updating the checking URL params --- controllers/front/validation.php | 62 +++++++++++++++++--------------- 1 file changed, 34 insertions(+), 28 deletions(-) diff --git a/controllers/front/validation.php b/controllers/front/validation.php index d3a4565..fbac25a 100644 --- a/controllers/front/validation.php +++ b/controllers/front/validation.php @@ -191,39 +191,45 @@ public function checkByTxHash() { } } public function checkByMemo() { - header('Content-Type: application/json'); - $cart = $this->context->cart; - $returnTrans = cosmosSql::getTransaction($cart->id); - - // Get the LCD URL from the transaction data - $lcdPay = $returnTrans[0]['lcd_pay']; - - // Obtain node information to determine the Cosmos SDK version - $nodeInfoJson = file_get_contents($lcdPay.'/cosmos/base/tendermint/v1beta1/node_info'); - $nodeInfo = json_decode($nodeInfoJson, true); - - // Check if the node information was obtained successfully - if ($nodeInfo !== null && isset($nodeInfo['application_version']['cosmos_sdk_version'])) { - // Extract the Cosmos SDK version and remove the 'v' prefix if it exists - $cosmosSdkVersion = ltrim($nodeInfo['application_version']['cosmos_sdk_version'], 'v'); - - // Decide which endpoint to use based on the SDK version - if (version_compare($cosmosSdkVersion, '0.50.0', '>=')) { - // Use the endpoint for SDK v0.50.x - $json = file_get_contents($lcdPay.'/cosmos/tx/v1beta1/txs?query=message.action=%27/cosmos.bank.v1beta1.MsgSend%27&order_by=ORDER_BY_DESC&pagination.limit=10'); + header('Content-Type: application/json'); + $cart = $this->context->cart; + $returnTrans = cosmosSql::getTransaction($cart->id); + + // Get info from LCD Node to get the Tendermint/CometBFT version + // example $getTx = file_get_contents($lcdUrl . '/cosmos/tx/v1beta1/txs/' . $getTxVar); + $nodeInfoJson = file_get_contents($lcdUrl.'/cosmos/base/tendermint/v1beta1/node_info'); + $nodeInfo = json_decode($nodeInfoJson, true); + if ($nodeInfo !== null && isset($nodeInfo['default_node_info']['version'])) { + // Get the string + $versionString = $nodeInfo['default_node_info']['version']; + // Split the string '.' => "v0" "38" "11" + $versionParts = explode('.', $versionString); + + if (isset($versionParts[1])) { + // Get the minor version and convert to integer + $minorVersion = intval($versionParts[1]); + + // Check the minor version and apply the proper endpoint fix + if ($minorVersion >= 38) { + $paramName = 'query'; } else { - // Use the endpoint for SDK v0.47.x - $json = file_get_contents($lcdPay.'/cosmos/tx/v1beta1/txs?events=message.action=%27/cosmos.bank.v1beta1.MsgSend%27&order_by=ORDER_BY_DESC&pagination.limit=10'); + $paramName = 'events'; } } else { - // If unable to determine the SDK version, default to the endpoint for SDK v0.50.x - $json = file_get_contents($lcdPay.'/cosmos/tx/v1beta1/txs?query=message.action=%27/cosmos.bank.v1beta1.MsgSend%27&order_by=ORDER_BY_DESC&pagination.limit=10'); + // If something fails getting the version.. use "query" as default + $paramName = 'query'; } - - $obj = json_decode($json); - - echo $json; + } else { + // If something fails querying the node.. use "query" as default + $paramName = 'query'; + } + + $json = file_get_contents($returnTrans[0]['lcd_pay'].'/cosmos/tx/v1beta1/txs?'. $paramName .'=message.action=%27/cosmos.bank.v1beta1.MsgSend%27&pagination.limit=10&order_by=2&limit=10'); + $obj = json_decode($json); + + echo $json; } + public function postProcess() { if (isset($_GET['check'])) {