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

[Bug] python call transfer error #927

Open
zhp1254 opened this issue Sep 17, 2024 · 1 comment
Open

[Bug] python call transfer error #927

zhp1254 opened this issue Sep 17, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@zhp1254
Copy link

zhp1254 commented Sep 17, 2024

🐛 Bug Report

1、add rust func transfer_tx
2、build so cargo build --release
3、python ctypes call transfer_tx
import ctypes lib = ctypes.CDLL('./target/release/libaleo_wasm.so') kPtr = lib.transfer_tx(b'{"private_key":"APrivateKey1zkpAUbZDoVZBj4xDhD1q5bpR9Lq11QQKd58HcgszW6aLJ8b","amount":0.01,"fee":0.06,"receiver":"aleo12m2q0y4d84vcf5alul2v2q9q3layxgsezxpyxn06gk95zpk3j5rsr4tn4r","state_root":"sr154fn2fz057zm49yk90pdlet883dsj7nsah2reg3hlfqlsvnpdypse92gak"}')

Steps to Reproduce

Code snippet to reproduce

#[no_mangle]
pub extern "C" fn transfer_tx(json_c_char: *const c_char) -> *const c_char {
      let json_cstr = unsafe {
         assert!(!json_c_char.is_null());
         CStr::from_ptr(json_c_char)
     };

     let json_str = match json_cstr.to_str() {
         Ok(v) => v,
         Err(e) => {
             panic!("json ptr to json string err: {:?}", e);
         }
     };

      let data: TransferInfo = match serde_json::from_str(json_str) {
         Ok(v) => v,
         Err(e) => {
            panic!("json to transferInfo struct err: {:?}", e);
         }
     };

     let offline_query = OfflineQuery::new(&data.state_root);
     let private_key = match PrivateKey::from_string(&data.private_key) {
                 Ok(v) => v,
                 Err(e) => {
                     panic!("parse key err: {:?}", e);
                 }
             };

       let ret = block_on(ProgramManager::transfer(
             &private_key,
             data.amount,
             &data.receiver,
             "public",
             None,
             data.fee,
             None,
             None,
             None,
             None,
             None,
             None,
             Some(offline_query.expect("offline query init error")),
         ));

         let transfer = match ret {
                  Ok(v) => v,
                  Err(e) => {
                     panic!("ProgramManager create transfer err: {:?}", e);
                  }
              };

         let resp_json = transfer.to_string();
         let resp_data = CString::new(resp_json).unwrap();
         resp_data.into_raw()
}

Stack trace & error message

thread '<unnamed>' panicked at /root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wasm-bindgen-0.2.92/src/lib.rs:1017:1:
function not implemented on non-wasm32 targets
stack backtrace:
   0: rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::panicking::panic
   3: wasm_bindgen::__wbindgen_describe
   4: aleo_wasm::programs::manager::transfer::<impl aleo_wasm::programs::manager::ProgramManager>::transfer::{{closure}}
   5: transfer_tx
   6: <unknown>
   7: <unknown>
   8: <unknown>
   9: <unknown>
  10: _PyObject_MakeTpCall
  11: _PyEval_EvalFrameDefault
  12: <unknown>
  13: _PyEval_EvalCodeWithName
  14: PyEval_EvalCode
  15: <unknown>
  16: <unknown>
  17: <unknown>
  18: PyRun_InteractiveLoopFlags
  19: PyRun_AnyFileExFlags
  20: <unknown>
  21: Py_BytesMain
  22: __libc_start_main
  23: _start

Expected Behavior

(Write what you expected to happen here)

Your Environment

  • branch testnet3
  • cargo 1.80.0-nightly (4de0094ac 2024-05-09)

5.4.0-153-generic #170-Ubuntu

@zhp1254 zhp1254 added the bug Something isn't working label Sep 17, 2024
@zhp1254
Copy link
Author

zhp1254 commented Sep 17, 2024

#[no_mangle] pub extern "C" fn new_private() -> *const c_char { let key = PrivateKey::new(); let key_str = key.to_string(); let c_key = CString::new(key_str).unwrap(); c_key.into_raw() }
new_private call success by python and i got an right private key with lib.so

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant