diff options
| author | cyan <cyjan@mrcyjanek.net> | 2024-10-13 12:54:43 +0000 |
|---|---|---|
| committer | cyan <cyjan@mrcyjanek.net> | 2024-10-13 12:54:43 +0000 |
| commit | 6890bd648499094f1af3b6b964cfbf1e5beebd28 (patch) | |
| tree | b0294c8fdb62015912185c98517ff32670079876 /impls/monero.php/ffi.php | |
| parent | 44fd5e17bbce52caf681850ac79f463d9ce6bb31 (diff) | |
Draft PHP implementationphp
Diffstat (limited to 'impls/monero.php/ffi.php')
| -rw-r--r-- | impls/monero.php/ffi.php | 35 |
1 files changed, 35 insertions, 0 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 |
