From 8fd35468a63dd0a7ce103cee9b83055fc539ae5b Mon Sep 17 00:00:00 2001 From: Kapten boneng Date: Sat, 8 Feb 2025 21:44:48 +0700 Subject: [PATCH] Update .env(Indodax) Perbaikan Utama dalam Kode Ini 1. Meningkatkan Keamanan Menambahkan Content-Type: application/json dalam header request API. Memastikan error handling lebih baik untuk mencegah kebocoran informasi sensitif. Tidak menampilkan private key di log (pastikan .env aman). 2. Menggunakan API dengan Pendekatan Lebih Realistis recordTransactionOnPiNetwork() memproses transaksi di Pi Network, tetapi perlu konfirmasi apakah API ini mendukung transaksi langsung atau harus menggunakan Pi SDK. requestListingOnIndodax() menggunakan endpoint yang lebih realistis, tetapi pastikan endpoint ini benar-benar ada. 3. Memisahkan Fungsi dengan Baik Setiap operasi memiliki fungsinya sendiri, sehingga lebih mudah di-maintain. Fungsi utama integratePiWithIndodax() mengatur alur kerja dengan log yang lebih jelas. --- .env(Indodax) | 66 +++++++++++++++++++++++++++++++++++---------------- 1 file changed, 45 insertions(+), 21 deletions(-) diff --git a/.env(Indodax) b/.env(Indodax) index 15adefe..a05d100 100644 --- a/.env(Indodax) +++ b/.env(Indodax) @@ -1,46 +1,70 @@ -PI_NETWORK_API_URL=https://api.minepi.com -PI_PRIVATE_KEY=your-private-key -INDODAX_API_URL=https://api.indodax.com - -const axios = require("axios"); require("dotenv").config(); +const axios = require("axios"); const piApiUrl = process.env.PI_NETWORK_API_URL; const indodaxApiUrl = process.env.INDODAX_API_URL; const privateKey = process.env.PI_PRIVATE_KEY; -// Fungsi untuk mencatat aktivitas listing ke Pi Network -async function recordListingOnPiNetwork() { +// Fungsi untuk mencatat aktivitas transaksi Pi Network +async function recordTransactionOnPiNetwork(sender, receiver, amount) { try { - // Data transaksi simulasi const transactionData = { - sender: "PiWalletAddressSender", - receiver: "IndodaxWalletAddress", - amount: 1000, // Jumlah token Pi yang ditransfer + sender: sender, + receiver: receiver, + amount: amount, message: "Listing Pi Network on Indodax", }; - // Mengirim data transaksi ke Pi Network - const piResponse = await axios.post(`${piApiUrl}/transactions`, transactionData, { + const response = await axios.post(`${piApiUrl}/transactions`, transactionData, { headers: { "Authorization": `Bearer ${privateKey}`, + "Content-Type": "application/json", }, }); - console.log("Transaction recorded on Pi Network:", piResponse.data); + console.log("Pi Network Transaction Response:", response.data); + return response.data; + } catch (error) { + console.error("Error in Pi Network transaction:", error.response ? error.response.data : error.message); + throw error; + } +} - // Mencatat aktivitas listing ke Indodax - const indodaxResponse = await axios.post(`${indodaxApiUrl}/listing`, { +// Fungsi untuk mencatat permintaan listing di Indodax +async function requestListingOnIndodax() { + try { + const response = await axios.post(`${indodaxApiUrl}/market_info`, { token: "Pi Network Token", symbol: "PI", - message: "Listing Pi Network on Indodax", + message: "Request listing Pi Network on Indodax", }); - console.log("Response from Indodax API:", indodaxResponse.data); + console.log("Indodax API Response:", response.data); + return response.data; + } catch (error) { + console.error("Error in Indodax listing request:", error.response ? error.response.data : error.message); + throw error; + } +} + +// Fungsi utama untuk menjalankan integrasi +async function integratePiWithIndodax() { + try { + const senderWallet = "PiWalletAddressSender"; // Ubah dengan alamat dompet asli + const receiverWallet = "IndodaxWalletAddress"; // Ubah dengan alamat dompet tujuan di Indodax + const amount = 1000; // Jumlah token yang akan ditransfer + + console.log("Initiating transaction on Pi Network..."); + await recordTransactionOnPiNetwork(senderWallet, receiverWallet, amount); + + console.log("Requesting listing on Indodax..."); + await requestListingOnIndodax(); + + console.log("Integration successful."); } catch (error) { - console.error("Error during integration:", error.response ? error.response.data : error.message); + console.error("Integration failed:", error.message); } } -// Run Integration -recordListingOnPiNetwork(); +// Jalankan fungsi integrasi +integratePiWithIndodax();