Skip to content

Commit

Permalink
Bindings dirs (#124)
Browse files Browse the repository at this point in the history
* bindings dir for python

* rpc/wrpc/wasm -> rpc/wrpc/bindings/wasm

* wallet/core/src/wasm -> wallet/core/src/bindings/wasm/

* crypto/txscript/src/wasm -> crypto/txscript/src/bindings/wasm

* rpc/core/src/wasm -> rpc/core/src/bindings/wasm
  • Loading branch information
smartgoo authored Nov 16, 2024
1 parent 8d563a1 commit 6e2c380
Show file tree
Hide file tree
Showing 74 changed files with 76 additions and 71 deletions.
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ members = [
"rpc/wrpc/server",
"rpc/wrpc/client",
"rpc/wrpc/proxy",
"rpc/wrpc/python",
"rpc/wrpc/wasm",
"rpc/wrpc/bindings/python",
"rpc/wrpc/bindings/wasm",
"rpc/wrpc/examples/subscriber",
"rpc/wrpc/examples/simple_client",
"mining",
Expand Down Expand Up @@ -137,9 +137,9 @@ kaspa-wasm = { version = "0.15.2", path = "wasm" }
kaspa-wasm-core = { version = "0.15.2", path = "wasm/core" }
kaspa-wrpc-client = { version = "0.15.2", path = "rpc/wrpc/client" }
kaspa-wrpc-proxy = { version = "0.15.2", path = "rpc/wrpc/proxy" }
kaspa-wrpc-python = { version = "0.15.2", path = "rpc/wrpc/python" }
kaspa-wrpc-python = { version = "0.15.2", path = "rpc/wrpc/bindings/python" }
kaspa-wrpc-server = { version = "0.15.2", path = "rpc/wrpc/server" }
kaspa-wrpc-wasm = { version = "0.15.2", path = "rpc/wrpc/wasm" }
kaspa-wrpc-wasm = { version = "0.15.2", path = "rpc/wrpc/bindings/wasm" }
kaspa-wrpc-example-subscriber = { version = "0.15.2", path = "rpc/wrpc/examples/subscriber" }
kaspad = { version = "0.15.2", path = "kaspad" }
kaspa-alloc = { version = "0.15.2", path = "utils/alloc" }
Expand Down
7 changes: 7 additions & 0 deletions crypto/txscript/src/bindings/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pub mod opcodes;

#[cfg(feature = "py-sdk")]
pub mod python;

#[cfg(any(feature = "wasm32-core", feature = "wasm32-sdk"))]
pub mod wasm;
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::wasm::opcodes::Opcodes;
use crate::bindings::opcodes::Opcodes;
use crate::{script_builder as native, standard};
use kaspa_consensus_core::tx::ScriptPublicKey;
use kaspa_python_core::types::PyBinary;
Expand Down
2 changes: 2 additions & 0 deletions crypto/txscript/src/bindings/python/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod builder;
pub use self::builder::*;
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ use cfg_if::cfg_if;

cfg_if! {
if #[cfg(any(feature = "wasm32-sdk", feature = "wasm32-core"))] {
pub mod opcodes;
// pub mod opcodes;
pub mod builder;

pub use self::opcodes::*;
pub use crate::bindings::opcodes::*;
pub use self::builder::*;
} else if #[cfg(feature = "py-sdk")] {
pub mod opcodes;
}
}
6 changes: 2 additions & 4 deletions crypto/txscript/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
extern crate alloc;
extern crate core;

#[cfg(any(feature = "wasm32-sdk", feature = "py-sdk", feature = "py-sdk"))]
pub mod bindings;
pub mod caches;
mod data_stack;
pub mod error;
pub mod opcodes;
#[cfg(feature = "py-sdk")]
pub mod python;
pub mod result;
pub mod script_builder;
pub mod script_class;
pub mod standard;
#[cfg(any(feature = "wasm32-sdk", feature = "py-sdk"))]
pub mod wasm;

use crate::caches::Cache;
use crate::data_stack::{DataStack, Stack};
Expand Down
9 changes: 0 additions & 9 deletions crypto/txscript/src/python/mod.rs

This file was deleted.

34 changes: 17 additions & 17 deletions python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,24 @@ cfg_if::cfg_if! {
m.add_class::<kaspa_bip32::Language>()?;
m.add_class::<kaspa_bip32::Mnemonic>()?;

m.add_class::<kaspa_txscript::python::ScriptBuilder>()?;
m.add_class::<kaspa_txscript::wasm::opcodes::Opcodes>()?;
m.add_class::<kaspa_txscript::bindings::python::ScriptBuilder>()?;
m.add_class::<kaspa_txscript::bindings::opcodes::Opcodes>()?;

m.add_function(wrap_pyfunction!(kaspa_wallet_core::python::message::py_sign_message, m)?)?;
m.add_function(wrap_pyfunction!(kaspa_wallet_core::python::message::py_verify_message, m)?)?;
m.add_function(wrap_pyfunction!(kaspa_wallet_core::python::signer::py_sign_transaction, m)?)?;
m.add_class::<kaspa_wallet_core::python::tx::generator::generator::Generator>()?;
m.add_class::<kaspa_wallet_core::python::tx::generator::pending::PendingTransaction>()?;
m.add_class::<kaspa_wallet_core::python::tx::generator::summary::GeneratorSummary>()?;
m.add_function(wrap_pyfunction!(kaspa_wallet_core::python::tx::mass::calculate_unsigned_transaction_fee, m)?)?;
m.add_function(wrap_pyfunction!(kaspa_wallet_core::python::tx::mass::calculate_unsigned_transaction_mass, m)?)?;
m.add_function(wrap_pyfunction!(kaspa_wallet_core::python::tx::mass::update_unsigned_transaction_mass, m)?)?;
m.add_function(wrap_pyfunction!(kaspa_wallet_core::python::tx::utils::create_transaction_py, m)?)?;
m.add_function(wrap_pyfunction!(kaspa_wallet_core::python::tx::utils::create_transactions_py, m)?)?;
m.add_function(wrap_pyfunction!(kaspa_wallet_core::python::tx::utils::estimate_transactions_py, m)?)?;
m.add_function(wrap_pyfunction!(kaspa_wallet_core::python::utils::kaspa_to_sompi, m)?)?;
m.add_function(wrap_pyfunction!(kaspa_wallet_core::python::utils::sompi_to_kaspa, m)?)?;
m.add_function(wrap_pyfunction!(kaspa_wallet_core::python::utils::sompi_to_kaspa_string_with_suffix, m)?)?;
m.add_function(wrap_pyfunction!(kaspa_wallet_core::bindings::python::message::py_sign_message, m)?)?;
m.add_function(wrap_pyfunction!(kaspa_wallet_core::bindings::python::message::py_verify_message, m)?)?;
m.add_function(wrap_pyfunction!(kaspa_wallet_core::bindings::python::signer::py_sign_transaction, m)?)?;
m.add_class::<kaspa_wallet_core::bindings::python::tx::generator::generator::Generator>()?;
m.add_class::<kaspa_wallet_core::bindings::python::tx::generator::pending::PendingTransaction>()?;
m.add_class::<kaspa_wallet_core::bindings::python::tx::generator::summary::GeneratorSummary>()?;
m.add_function(wrap_pyfunction!(kaspa_wallet_core::bindings::python::tx::mass::calculate_unsigned_transaction_fee, m)?)?;
m.add_function(wrap_pyfunction!(kaspa_wallet_core::bindings::python::tx::mass::calculate_unsigned_transaction_mass, m)?)?;
m.add_function(wrap_pyfunction!(kaspa_wallet_core::bindings::python::tx::mass::update_unsigned_transaction_mass, m)?)?;
m.add_function(wrap_pyfunction!(kaspa_wallet_core::bindings::python::tx::utils::create_transaction_py, m)?)?;
m.add_function(wrap_pyfunction!(kaspa_wallet_core::bindings::python::tx::utils::create_transactions_py, m)?)?;
m.add_function(wrap_pyfunction!(kaspa_wallet_core::bindings::python::tx::utils::estimate_transactions_py, m)?)?;
m.add_function(wrap_pyfunction!(kaspa_wallet_core::bindings::python::utils::kaspa_to_sompi, m)?)?;
m.add_function(wrap_pyfunction!(kaspa_wallet_core::bindings::python::utils::sompi_to_kaspa, m)?)?;
m.add_function(wrap_pyfunction!(kaspa_wallet_core::bindings::python::utils::sompi_to_kaspa_string_with_suffix, m)?)?;
m.add_class::<kaspa_wallet_core::tx::payment::PaymentOutput>()?;

m.add_class::<kaspa_wallet_keys::derivation_path::DerivationPath>()?;
Expand Down
5 changes: 5 additions & 0 deletions rpc/core/src/bindings/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#[cfg(feature = "py-sdk")]
pub mod python;

#[cfg(feature = "wasm32-sdk")]
pub mod wasm;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions rpc/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
#![recursion_limit = "256"]

pub mod api;
#[cfg(any(feature = "wasm32-sdk", feature = "py-sdk"))]
pub mod bindings;
pub mod convert;
pub mod error;
pub mod model;
pub mod notify;
#[cfg(feature = "py-sdk")]
pub mod python;
pub mod wasm;
// pub mod wasm;

pub mod prelude {
pub use super::api::notifications::*;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use kaspa_notify::events::EventType;
use kaspa_notify::listener;
use kaspa_notify::notification::Notification as NotificationT;
use kaspa_rpc_core::api::ctl;
pub use kaspa_rpc_core::wasm::message::*;
pub use kaspa_rpc_core::bindings::wasm::message::*;
pub use kaspa_rpc_macros::{
build_wrpc_wasm_bindgen_interface, build_wrpc_wasm_bindgen_subscriptions, declare_typescript_wasm_interface as declare,
};
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions wallet/core/src/bindings/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#[cfg(feature = "py-sdk")]
pub mod python;

#[cfg(any(feature = "wasm32-sdk", feature = "wasm32-core"))]
pub mod wasm;
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::bindings::wasm::signer::{sign_hash, sign_transaction};
use crate::imports::*;
use crate::wasm::signer::{sign_hash, sign_transaction};
use kaspa_consensus_client::Transaction;
use kaspa_consensus_core::hashing::wasm::SighashType;
use kaspa_consensus_core::sign::sign_input;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::bindings::python::tx::generator::pending::PendingTransaction;
use crate::bindings::python::tx::generator::summary::GeneratorSummary;
use crate::imports::*;
use crate::python::tx::generator::pending::PendingTransaction;
use crate::python::tx::generator::summary::GeneratorSummary;
use crate::tx::{generator as native, Fees, PaymentDestination, PaymentOutput, PaymentOutputs};

pub struct PyUtxoEntries {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::bindings::python::tx::generator::{Generator, GeneratorSummary, PendingTransaction, PyOutputs, PyUtxoEntries};
use crate::imports::*;
use crate::python::tx::generator::{Generator, GeneratorSummary, PendingTransaction, PyOutputs, PyUtxoEntries};
use kaspa_consensus_client::*;
use kaspa_consensus_core::subnets::SUBNETWORK_ID_NATIVE;

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
use super::extensions::*;
use crate::account::descriptor::IAccountDescriptor;
use crate::api::message::*;
use crate::bindings::wasm::tx::fees::IFees;
use crate::bindings::wasm::tx::GeneratorSummary;
use crate::imports::*;
use crate::tx::{Fees, PaymentDestination, PaymentOutputs};
use crate::wasm::tx::fees::IFees;
use crate::wasm::tx::GeneratorSummary;
use js_sys::Array;
use serde_wasm_bindgen::from_value;
use workflow_wasm::serde::to_value;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::bindings::wasm::tx::generator::*;
use crate::bindings::wasm::tx::IFees;
use crate::imports::*;
use crate::result::Result;
use crate::tx::{generator as native, Fees, PaymentDestination, PaymentOutputs};
use crate::utxo::{TryIntoUtxoEntryReferences, UtxoEntryReference};
use crate::wasm::tx::generator::*;
use crate::wasm::tx::IFees;
// use crate::wasm::wallet::Account;
use crate::wasm::UtxoContext;
use crate::bindings::wasm::UtxoContext;

// TODO-WASM fix outputs
#[wasm_bindgen(typescript_custom_section)]
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::bindings::wasm::PrivateKeyArrayT;
use crate::imports::*;
use crate::result::Result;
use crate::tx::generator as native;
use crate::wasm::PrivateKeyArrayT;
use kaspa_consensus_client::{numeric, string};
use kaspa_consensus_client::{Transaction, TransactionT};
use kaspa_consensus_core::hashing::wasm::SighashType;
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::bindings::wasm::tx::generator::*;
use crate::imports::*;
use crate::result::Result;
use crate::tx::{IPaymentOutputArray, PaymentOutputs};
use crate::wasm::tx::generator::*;
use kaspa_consensus_client::*;
use kaspa_consensus_core::subnets::SUBNETWORK_ID_NATIVE;
use kaspa_wallet_macros::declare_typescript_wasm_interface as declare;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::bindings::wasm::utxo::UtxoProcessor;
use crate::bindings::wasm::{Balance, BalanceStrings};
use crate::imports::*;
use crate::result::Result;
use crate::utxo as native;
use crate::utxo::{UtxoContextBinding, UtxoContextId};
use crate::wasm::utxo::UtxoProcessor;
use crate::wasm::{Balance, BalanceStrings};
use kaspa_addresses::AddressOrStringArrayT;
use kaspa_consensus_client::UtxoEntryReferenceArrayT;
use kaspa_hashes::Hash;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use crate::bindings::wasm::notify::{
UtxoProcessorEventTarget, UtxoProcessorNotificationCallback, UtxoProcessorNotificationTypeOrCallback,
};
use crate::error::Error;
use crate::events::{EventKind, Events};
use crate::imports::*;
use crate::result::Result;
use crate::utxo as native;
use crate::wasm::notify::{UtxoProcessorEventTarget, UtxoProcessorNotificationCallback, UtxoProcessorNotificationTypeOrCallback};
use kaspa_consensus_core::network::NetworkIdT;
use kaspa_wallet_macros::declare_typescript_wasm_interface as declare;
use kaspa_wasm_core::events::{get_event_targets, Sink};
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::bindings::wasm::notify::{WalletEventTarget, WalletNotificationCallback, WalletNotificationTypeOrCallback};
use crate::imports::*;
use crate::storage::local::interface::LocalStore;
use crate::storage::WalletDescriptor;
use crate::wallet as native;
use crate::wasm::notify::{WalletEventTarget, WalletNotificationCallback, WalletNotificationTypeOrCallback};
use kaspa_wallet_macros::declare_typescript_wasm_interface as declare;
use kaspa_wasm_core::events::{get_event_targets, Sink};
use kaspa_wrpc_wasm::{IConnectOptions, Resolver, RpcClient, RpcConfig, WrpcEncoding};
Expand Down
7 changes: 2 additions & 5 deletions wallet/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,8 @@ pub mod wallet;

// }

#[cfg(any(feature = "wasm32-sdk", feature = "wasm32-core"))]
pub mod wasm;

#[cfg(feature = "py-sdk")]
pub mod python;
#[cfg(any(feature = "wasm32-sdk", feature = "wasm32-core", feature = "py-sdk"))]
pub mod bindings;

/// Returns the version of the Wallet framework.
pub fn version() -> String {
Expand Down
16 changes: 8 additions & 8 deletions wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ cfg_if::cfg_if! {
pub use kaspa_addresses::{Address, Version as AddressVersion};
pub use kaspa_consensus_core::tx::{ScriptPublicKey, Transaction, TransactionInput, TransactionOutpoint, TransactionOutput};
pub use kaspa_pow::wasm::*;
pub use kaspa_txscript::wasm::*;
pub use kaspa_txscript::bindings::wasm::*;

pub mod rpc {
//! Kaspa RPC interface
Expand All @@ -156,7 +156,7 @@ cfg_if::cfg_if! {
pub use kaspa_rpc_core::model::message::*;
}
pub use kaspa_rpc_core::api::rpc::RpcApi;
pub use kaspa_rpc_core::wasm::message::*;
pub use kaspa_rpc_core::bindings::wasm::message::*;

pub use kaspa_wrpc_wasm::client::*;
pub use kaspa_wrpc_wasm::resolver::*;
Expand All @@ -165,14 +165,14 @@ cfg_if::cfg_if! {

pub use kaspa_consensus_wasm::*;
pub use kaspa_wallet_keys::prelude::*;
pub use kaspa_wallet_core::wasm::*;
pub use kaspa_wallet_core::bindings::wasm::*;

} else if #[cfg(feature = "wasm32-core")] {

pub use kaspa_addresses::{Address, Version as AddressVersion};
pub use kaspa_consensus_core::tx::{ScriptPublicKey, Transaction, TransactionInput, TransactionOutpoint, TransactionOutput};
pub use kaspa_pow::wasm::*;
pub use kaspa_txscript::wasm::*;
pub use kaspa_txscript::bindings::wasm::*;

pub mod rpc {
//! Kaspa RPC interface
Expand All @@ -183,7 +183,7 @@ cfg_if::cfg_if! {
pub use kaspa_rpc_core::model::message::*;
}
pub use kaspa_rpc_core::api::rpc::RpcApi;
pub use kaspa_rpc_core::wasm::message::*;
pub use kaspa_rpc_core::bindings::wasm::message::*;

pub use kaspa_wrpc_wasm::client::*;
pub use kaspa_wrpc_wasm::resolver::*;
Expand All @@ -192,13 +192,13 @@ cfg_if::cfg_if! {

pub use kaspa_consensus_wasm::*;
pub use kaspa_wallet_keys::prelude::*;
pub use kaspa_wallet_core::wasm::*;
pub use kaspa_wallet_core::bindings::wasm::*;

} else if #[cfg(feature = "wasm32-rpc")] {

pub use kaspa_rpc_core::api::rpc::RpcApi;
pub use kaspa_rpc_core::wasm::message::*;
pub use kaspa_rpc_core::wasm::message::IPingRequest;
pub use kaspa_rpc_core::bindings::wasm::message::*;
pub use kaspa_rpc_core::bindings::wasm::message::IPingRequest;
pub use kaspa_wrpc_wasm::client::*;
pub use kaspa_wrpc_wasm::resolver::*;
pub use kaspa_wrpc_wasm::notify::*;
Expand Down

0 comments on commit 6e2c380

Please sign in to comment.