Skip to content

Commit

Permalink
Draft PHP implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
MrCyjaneK committed Oct 13, 2024
1 parent 44fd5e1 commit 6890bd6
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
35 changes: 35 additions & 0 deletions impls/monero.php/ffi.php
Original file line number Diff line number Diff line change
@@ -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;
2 changes: 1 addition & 1 deletion monero_libwallet2_api_c/src/main/cpp/wallet2_api_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 6890bd6

Please sign in to comment.