Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SDK version checker to api-cosmos.php #13

Open
wants to merge 3 commits into
base: next
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 46 additions & 10 deletions api-cosmos.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,50 @@

echo '{ "return": "canceled" }';

} elseif ( isset($_GET['check']) && isset( $_GET['order_id'] ) ) {
} elseif (isset($_GET['check']) && isset($_GET['order_id'])) {

$orderId = sanitize_text_field($_GET['order_id']);
$getLcdPay = wc_get_order_item_meta($orderId, '_cosmos_lcd_pay', true);

// Get info from LCD Node to get the Tendermint/CometBFT version
$nodeInfoJson = file_get_contents($getLcdPay . '/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 {
$paramName = 'events';
}
} else {
// If something fails getting the version.. use "query" as default
$paramName = 'query';
}
} else {
// If something fails querying the node.. use "query" as default
$paramName = 'query';
}

// Build the proper Query
// BCNA: https://lcd.bitcanna.io/cosmos/tx/v1beta1/txs?events=message.action=%27/cosmos.bank.v1beta1.MsgSend%27&pagination.limit=10&order_by=0&limit=10
// OSMOSIS: https://rest.cosmos.directory/osmosis/cosmos/tx/v1beta1/txs?query=message.action=%27/cosmos.bank.v1beta1.MsgSend%27&pagination.limit=10&order_by=2&limit=10
// COSMOS: https://rest.cosmos.directory/cosmoshub/cosmos/tx/v1beta1/txs?query=message.action=%27/cosmos.bank.v1beta1.MsgSend%27&pagination.limit=10&order_by=2&limit=10
$json = file_get_contents($getLcdPay . '/cosmos/tx/v1beta1/txs?' . $paramName . '=message.sender=%27/cosmos.bank.v1beta1.MsgSend%27&pagination.limit=10&order_by=2&limit=10');

$obj = json_decode($json);

echo $json;
} else {
echo 'Incorrect parameters';
}

$orderId = sanitize_text_field( $_GET['order_id'] );
$getLcdPay = wc_get_order_item_meta( $orderId , '_cosmos_lcd_pay', true );
$json = file_get_contents($getLcdPay.'/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;
} else
echo 'Bad parameters';