summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcyan <cyjan@mrcyjanek.net>2024-10-13 12:54:43 +0000
committercyan <cyjan@mrcyjanek.net>2024-10-13 12:54:43 +0000
commit6890bd648499094f1af3b6b964cfbf1e5beebd28 (patch)
treeb0294c8fdb62015912185c98517ff32670079876
parent44fd5e17bbce52caf681850ac79f463d9ce6bb31 (diff)
Draft PHP implementationphp
-rw-r--r--impls/monero.php/ffi.php35
-rw-r--r--monero_libwallet2_api_c/src/main/cpp/wallet2_api_c.h2
2 files changed, 36 insertions, 1 deletions
diff --git a/impls/monero.php/ffi.php b/impls/monero.php/ffi.php
new file mode 100644
index 0000000..5ab35b3
--- /dev/null
+++ b/impls/monero.php/ffi.php
@@ -0,0 +1,35 @@
+<?php
+
+$content = file_get_contents("../../monero_libwallet2_api_c/src/main/cpp/wallet2_api_c.h");
+$lines = explode("\n", $content);
+$exclude = array();
+$i = 0;
+foreach ($lines as $line) {
+ if (!str_starts_with($line, " ")) {
+ if (strpos($line, 'MONERO_') == FALSE) {
+ continue;
+ }
+ }
+ $i++;
+ $line = str_replace("extern ADDAPI ", "", $line);
+ $exclude[] = $line;
+ // echo "$i: $line\n";
+}
+$content = implode("\n", $exclude);
+// echo $content;
+$ffi = FFI::cdef($content, "../../release/monero/x86_64-linux-gnu_libwallet2_api_c.so");
+
+$wmPtr = $ffi->MONERO_WalletManagerFactory_getWalletManager();
+$exists = $ffi->MONERO_WalletManager_walletExists($wmPtr, "test_wallet");
+if ($exists) {
+ $wPtr = $ffi->MONERO_WalletManager_openWallet($wmPtr, "test_wallet", "test_password", 0);
+} else {
+ $wPtr = $ffi->MONERO_WalletManager_createWallet($wmPtr, "test_wallet", "test_password", "English", 0);
+}
+$status = $ffi->MONERO_Wallet_status($wPtr);
+if ($status != 0) {
+ $error = $ffi->MONERO_Wallet_errorString($wPtr);
+ echo "Unable to create wallet: $error".PHP_EOL;
+ exit(1);
+}
+echo $ffi->MONERO_Wallet_address($wPtr, 0, 0).PHP_EOL; \ No newline at end of file
diff --git a/monero_libwallet2_api_c/src/main/cpp/wallet2_api_c.h b/monero_libwallet2_api_c/src/main/cpp/wallet2_api_c.h
index 6e691c8..6cd4e3b 100644
--- a/monero_libwallet2_api_c/src/main/cpp/wallet2_api_c.h
+++ b/monero_libwallet2_api_c/src/main/cpp/wallet2_api_c.h
@@ -948,7 +948,7 @@ extern ADDAPI bool MONERO_WalletManager_walletExists(void* wm_ptr, const char* p
// virtual bool verifyWalletPassword(const std::string &keys_file_name, const std::string &password, bool no_spend_key, uint64_t kdf_rounds = 1) const = 0;
extern ADDAPI bool MONERO_WalletManager_verifyWalletPassword(void* wm_ptr, const char* keys_file_name, const char* password, bool no_spend_key, uint64_t kdf_rounds);
// virtual bool queryWalletDevice(Wallet::Device& device_type, const std::string &keys_file_name, const std::string &password, uint64_t kdf_rounds = 1) const = 0;
-extern ADDAPI bool MONERO_WalletManager_queryWalletDevice(int device_type, const char* keys_file_name, const char* password, uint64_t kdf_rounds);
+// extern ADDAPI bool MONERO_WalletManager_queryWalletDevice(int device_type, const char* keys_file_name, const char* password, uint64_t kdf_rounds);
// virtual std::vector<std::string> findWallets(const std::string &path) = 0;
extern ADDAPI const char* MONERO_WalletManager_findWallets(void* wm_ptr, const char* path, const char* separator);
// virtual std::string errorString() const = 0;