Skip to content

Commit

Permalink
bindings updated
Browse files Browse the repository at this point in the history
  • Loading branch information
BitcoinZavior committed Nov 4, 2023
1 parent a475ad5 commit dccb768
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 52 deletions.
Binary file modified python/src/payjoin/libpayjoin_ffi.dylib
Binary file not shown.
87 changes: 47 additions & 40 deletions python/src/payjoin/payjoin_ffi.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,8 @@ def uniffi_check_api_checksums(lib):
raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
if lib.uniffi_payjoin_ffi_checksum_method_partiallysignedtransaction_as_string() != 32034:
raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
if lib.uniffi_payjoin_ffi_checksum_method_context_process_response() != 3341:
raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
if lib.uniffi_payjoin_ffi_checksum_method_amount_to_btc() != 39645:
raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
if lib.uniffi_payjoin_ffi_checksum_method_amount_to_sat() != 11749:
Expand Down Expand Up @@ -592,7 +594,7 @@ def uniffi_check_api_checksums(lib):
raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
if lib.uniffi_payjoin_ffi_checksum_method_provisionalproposal_try_preserving_privacy() != 18598:
raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
if lib.uniffi_payjoin_ffi_checksum_method_provisionalproposal_finalize_proposal() != 46915:
if lib.uniffi_payjoin_ffi_checksum_method_provisionalproposal_finalize_proposal() != 56758:
raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
if lib.uniffi_payjoin_ffi_checksum_method_payjoinproposal_utxos_to_be_locked() != 55131:
raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
Expand Down Expand Up @@ -622,9 +624,7 @@ def uniffi_check_api_checksums(lib):
raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
if lib.uniffi_payjoin_ffi_checksum_constructor_configuration_non_incentivizing() != 27440:
raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
if lib.uniffi_payjoin_ffi_checksum_constructor_partiallysignedtransaction_new() != 58526:
raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
if lib.uniffi_payjoin_ffi_checksum_constructor_partiallysignedtransaction_process_response() != 42239:
if lib.uniffi_payjoin_ffi_checksum_constructor_partiallysignedtransaction_from_string() != 53728:
raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
if lib.uniffi_payjoin_ffi_checksum_constructor_amount_from_sat() != 50973:
raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
Expand Down Expand Up @@ -807,17 +807,11 @@ def uniffi_check_api_checksums(lib):
ctypes.POINTER(RustCallStatus),
)
_UniFFILib.uniffi_payjoin_ffi_fn_free_partiallysignedtransaction.restype = None
_UniFFILib.uniffi_payjoin_ffi_fn_constructor_partiallysignedtransaction_new.argtypes = (
_UniFFILib.uniffi_payjoin_ffi_fn_constructor_partiallysignedtransaction_from_string.argtypes = (
RustBuffer,
ctypes.POINTER(RustCallStatus),
)
_UniFFILib.uniffi_payjoin_ffi_fn_constructor_partiallysignedtransaction_new.restype = ctypes.c_void_p
_UniFFILib.uniffi_payjoin_ffi_fn_constructor_partiallysignedtransaction_process_response.argtypes = (
ctypes.c_void_p,
RustBuffer,
ctypes.POINTER(RustCallStatus),
)
_UniFFILib.uniffi_payjoin_ffi_fn_constructor_partiallysignedtransaction_process_response.restype = ctypes.c_void_p
_UniFFILib.uniffi_payjoin_ffi_fn_constructor_partiallysignedtransaction_from_string.restype = ctypes.c_void_p
_UniFFILib.uniffi_payjoin_ffi_fn_method_partiallysignedtransaction_serialize.argtypes = (
ctypes.c_void_p,
ctypes.POINTER(RustCallStatus),
Expand All @@ -838,6 +832,12 @@ def uniffi_check_api_checksums(lib):
ctypes.POINTER(RustCallStatus),
)
_UniFFILib.uniffi_payjoin_ffi_fn_free_context.restype = None
_UniFFILib.uniffi_payjoin_ffi_fn_method_context_process_response.argtypes = (
ctypes.c_void_p,
RustBuffer,
ctypes.POINTER(RustCallStatus),
)
_UniFFILib.uniffi_payjoin_ffi_fn_method_context_process_response.restype = ctypes.c_void_p
_UniFFILib.uniffi_payjoin_ffi_fn_free_amount.argtypes = (
ctypes.c_void_p,
ctypes.POINTER(RustCallStatus),
Expand Down Expand Up @@ -1094,11 +1094,11 @@ def uniffi_check_api_checksums(lib):
ctypes.POINTER(RustCallStatus),
)
_UniFFILib.uniffi_payjoin_ffi_fn_init_callback_isoutputknown.restype = None
_UniFFILib.uniffi_payjoin_ffi_fn_init_callback_processpartiallysignedtransactioninterface.argtypes = (
_UniFFILib.uniffi_payjoin_ffi_fn_init_callback_processpartiallysignedtransaction.argtypes = (
FOREIGN_CALLBACK_T,
ctypes.POINTER(RustCallStatus),
)
_UniFFILib.uniffi_payjoin_ffi_fn_init_callback_processpartiallysignedtransactioninterface.restype = None
_UniFFILib.uniffi_payjoin_ffi_fn_init_callback_processpartiallysignedtransaction.restype = None
_UniFFILib.ffi_payjoin_ffi_rustbuffer_alloc.argtypes = (
ctypes.c_int32,
ctypes.POINTER(RustCallStatus),
Expand Down Expand Up @@ -1168,6 +1168,9 @@ def uniffi_check_api_checksums(lib):
_UniFFILib.uniffi_payjoin_ffi_checksum_method_partiallysignedtransaction_as_string.argtypes = (
)
_UniFFILib.uniffi_payjoin_ffi_checksum_method_partiallysignedtransaction_as_string.restype = ctypes.c_uint16
_UniFFILib.uniffi_payjoin_ffi_checksum_method_context_process_response.argtypes = (
)
_UniFFILib.uniffi_payjoin_ffi_checksum_method_context_process_response.restype = ctypes.c_uint16
_UniFFILib.uniffi_payjoin_ffi_checksum_method_amount_to_btc.argtypes = (
)
_UniFFILib.uniffi_payjoin_ffi_checksum_method_amount_to_btc.restype = ctypes.c_uint16
Expand Down Expand Up @@ -1270,12 +1273,9 @@ def uniffi_check_api_checksums(lib):
_UniFFILib.uniffi_payjoin_ffi_checksum_constructor_configuration_non_incentivizing.argtypes = (
)
_UniFFILib.uniffi_payjoin_ffi_checksum_constructor_configuration_non_incentivizing.restype = ctypes.c_uint16
_UniFFILib.uniffi_payjoin_ffi_checksum_constructor_partiallysignedtransaction_new.argtypes = (
_UniFFILib.uniffi_payjoin_ffi_checksum_constructor_partiallysignedtransaction_from_string.argtypes = (
)
_UniFFILib.uniffi_payjoin_ffi_checksum_constructor_partiallysignedtransaction_new.restype = ctypes.c_uint16
_UniFFILib.uniffi_payjoin_ffi_checksum_constructor_partiallysignedtransaction_process_response.argtypes = (
)
_UniFFILib.uniffi_payjoin_ffi_checksum_constructor_partiallysignedtransaction_process_response.restype = ctypes.c_uint16
_UniFFILib.uniffi_payjoin_ffi_checksum_constructor_partiallysignedtransaction_from_string.restype = ctypes.c_uint16
_UniFFILib.uniffi_payjoin_ffi_checksum_constructor_amount_from_sat.argtypes = (
)
_UniFFILib.uniffi_payjoin_ffi_checksum_constructor_amount_from_sat.restype = ctypes.c_uint16
Expand Down Expand Up @@ -1691,6 +1691,19 @@ def _make_instance_(cls, pointer):
return inst


def process_response(self, response: "str") -> "PartiallySignedTransaction":

return FfiConverterTypePartiallySignedTransaction.lift(
rust_call_with_error(
FfiConverterTypePayjoinError,_UniFFILib.uniffi_payjoin_ffi_fn_method_context_process_response,self._pointer,
FfiConverterString.lower(response))
)






class FfiConverterTypeContext:
@classmethod
def read(cls, buf):
Expand Down Expand Up @@ -2088,10 +2101,6 @@ def lower(value):

class PartiallySignedTransaction:
_pointer: ctypes.c_void_p
def __init__(self, psbt_base64: "str"):

self._pointer = rust_call_with_error(FfiConverterTypePayjoinError,_UniFFILib.uniffi_payjoin_ffi_fn_constructor_partiallysignedtransaction_new,
FfiConverterString.lower(psbt_base64))

def __del__(self):
# In case of partial initialization of instances.
Expand All @@ -2109,13 +2118,11 @@ def _make_instance_(cls, pointer):
return inst

@classmethod
def process_response(cls, context: "Context",response: "str"):

def from_string(cls, psbt_base64: "str"):

# Call the (fallible) function before creating any half-baked object instances.
pointer = rust_call_with_error(FfiConverterTypePayjoinError,_UniFFILib.uniffi_payjoin_ffi_fn_constructor_partiallysignedtransaction_process_response,
FfiConverterTypeContext.lower(context),
FfiConverterString.lower(response))
pointer = rust_call_with_error(FfiConverterTypePayjoinError,_UniFFILib.uniffi_payjoin_ffi_fn_constructor_partiallysignedtransaction_from_string,
FfiConverterString.lower(psbt_base64))
return cls._make_instance_(pointer)


Expand Down Expand Up @@ -2404,13 +2411,13 @@ def try_preserving_privacy(self, candidate_inputs: "dict") -> "OutPoint":



def finalize_proposal(self, process_psbt: "ProcessPartiallySignedTransactionInterface",min_feerate_sat_per_vb: "typing.Optional[FeeRate]") -> "PayjoinProposal":
def finalize_proposal(self, process_psbt: "ProcessPartiallySignedTransaction",min_feerate_sat_per_vb: "typing.Optional[FeeRate]") -> "PayjoinProposal":


return FfiConverterTypePayjoinProposal.lift(
rust_call_with_error(
FfiConverterTypePayjoinError,_UniFFILib.uniffi_payjoin_ffi_fn_method_provisionalproposal_finalize_proposal,self._pointer,
FfiConverterCallbackInterfaceProcessPartiallySignedTransactionInterface.lower(process_psbt),
FfiConverterCallbackInterfaceProcessPartiallySignedTransaction.lower(process_psbt),
FfiConverterOptionalTypeFeeRate.lower(min_feerate_sat_per_vb))
)

Expand Down Expand Up @@ -3593,15 +3600,15 @@ def makeCallAndHandleReturn():



# Declaration and FfiConverters for ProcessPartiallySignedTransactionInterface Callback Interface
# Declaration and FfiConverters for ProcessPartiallySignedTransaction Callback Interface

class ProcessPartiallySignedTransactionInterface:
class ProcessPartiallySignedTransaction:
def process_psbt(self, psbt: "PartiallySignedTransaction"):
raise NotImplementedError



def py_foreignCallbackCallbackInterfaceProcessPartiallySignedTransactionInterface(handle, method, args_data, args_len, buf_ptr):
def py_foreignCallbackCallbackInterfaceProcessPartiallySignedTransaction(handle, method, args_data, args_len, buf_ptr):

def invoke_process_psbt(python_callback, args_stream, buf_ptr):
def makeCall():return python_callback.process_psbt(
Expand All @@ -3611,7 +3618,7 @@ def makeCall():return python_callback.process_psbt(
def makeCallAndHandleReturn():
rval = makeCall()
with RustBuffer.allocWithBuilder() as builder:
FfiConverterTypePartiallySignedTransaction.write(rval, builder)
FfiConverterString.write(rval, builder)
buf_ptr[0] = builder.finalize()
return UNIFFI_CALLBACK_SUCCESS
try:
Expand All @@ -3625,12 +3632,12 @@ def makeCallAndHandleReturn():



cb = FfiConverterCallbackInterfaceProcessPartiallySignedTransactionInterface.lift(handle)
cb = FfiConverterCallbackInterfaceProcessPartiallySignedTransaction.lift(handle)
if not cb:
raise InternalError("No callback in handlemap; this is a Uniffi bug")

if method == IDX_CALLBACK_FREE:
FfiConverterCallbackInterfaceProcessPartiallySignedTransactionInterface.drop(handle)
FfiConverterCallbackInterfaceProcessPartiallySignedTransaction.drop(handle)
# Successfull return
# See docs of ForeignCallback in `uniffi_core/src/ffi/foreigncallbacks.rs`
return UNIFFI_CALLBACK_SUCCESS
Expand Down Expand Up @@ -3663,11 +3670,11 @@ def makeCallAndHandleReturn():
# if they get GC'd while in use then UniFFI internals could attempt to call a function
# that is in freed memory.
# That would be...uh...bad. Yeah, that's the word. Bad.
foreignCallbackCallbackInterfaceProcessPartiallySignedTransactionInterface = FOREIGN_CALLBACK_T(py_foreignCallbackCallbackInterfaceProcessPartiallySignedTransactionInterface)
rust_call(lambda err: _UniFFILib.uniffi_payjoin_ffi_fn_init_callback_processpartiallysignedtransactioninterface(foreignCallbackCallbackInterfaceProcessPartiallySignedTransactionInterface, err))
foreignCallbackCallbackInterfaceProcessPartiallySignedTransaction = FOREIGN_CALLBACK_T(py_foreignCallbackCallbackInterfaceProcessPartiallySignedTransaction)
rust_call(lambda err: _UniFFILib.uniffi_payjoin_ffi_fn_init_callback_processpartiallysignedtransaction(foreignCallbackCallbackInterfaceProcessPartiallySignedTransaction, err))

# The FfiConverter which transforms the Callbacks in to Handles to pass to Rust.
FfiConverterCallbackInterfaceProcessPartiallySignedTransactionInterface = FfiConverterCallbackInterface(foreignCallbackCallbackInterfaceProcessPartiallySignedTransactionInterface)
FfiConverterCallbackInterfaceProcessPartiallySignedTransaction = FfiConverterCallbackInterface(foreignCallbackCallbackInterfaceProcessPartiallySignedTransaction)



Expand Down Expand Up @@ -3922,6 +3929,6 @@ def read(cls, buf):
"CanBroadcast",
"IsScriptOwned",
"IsOutputKnown",
"ProcessPartiallySignedTransactionInterface",
"ProcessPartiallySignedTransaction",
]

8 changes: 3 additions & 5 deletions python/tests/regtest_payjoin_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def test_integration(self):
{"lockUnspents": True, "feeRate": 0.000020},
)["psbt"]
processed_psbt = sender._call("walletprocesspsbt", pre_processed_psbt)["psbt"]
psbt = PartiallySignedTransaction(processed_psbt)
psbt = PartiallySignedTransaction.from_string(processed_psbt)
pj_params = Configuration.with_fee_contribution(10000, None)
prj_uri_req = prj_uri.create_pj_request(psbt, pj_params)
req = prj_uri_req.request
Expand All @@ -74,9 +74,7 @@ def test_integration(self):
# **********************
# Inside the Sender:
# Sender checks, signs, finalizes, extracts, and broadcasts
checked_payjoin_proposal_psbt = PartiallySignedTransaction.process_response(
ctx, response
)
checked_payjoin_proposal_psbt = ctx.process_response(response)
payjoin_processed_psbt = sender._call(
"walletprocesspsbt",
checked_payjoin_proposal_psbt.as_string(),
Expand Down Expand Up @@ -161,7 +159,7 @@ def process_psbt(self, psbt: PartiallySignedTransaction):
"walletprocesspsbt",
psbt.as_string(),
)["psbt"]
return PartiallySignedTransaction(_psbt)
return _psbt


class BroadcastCallBack:
Expand Down
15 changes: 8 additions & 7 deletions src/payjoin_ffi.udl
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,17 @@ dictionary PrjUriRequest{
};

interface PartiallySignedTransaction{
[Throws=PayjoinError]
[Name=from_string,Throws=PayjoinError]
constructor(string psbt_base64);
[Name=process_response, Throws=PayjoinError]
constructor( Context context, string response);
sequence<u8> serialize();
Transaction extract_tx();
string as_string();
};

interface Context{};
interface Context{
[Throws=PayjoinError]
PartiallySignedTransaction process_response( string response);
};

interface Amount{
[Name=from_sat]
Expand Down Expand Up @@ -181,9 +182,9 @@ interface OutputsUnknown {
ProvisionalProposal identify_receiver_outputs(IsScriptOwned is_receiver_output);
};

callback interface ProcessPartiallySignedTransactionInterface {
callback interface ProcessPartiallySignedTransaction {
[Throws=PayjoinError]
PartiallySignedTransaction process_psbt(PartiallySignedTransaction psbt);
string process_psbt(PartiallySignedTransaction psbt);
};

interface FeeRate{
Expand All @@ -208,7 +209,7 @@ interface ProvisionalProposal{
[Throws=PayjoinError]
OutPoint try_preserving_privacy(record<u64, OutPoint> candidate_inputs);
[Throws=PayjoinError]
PayjoinProposal finalize_proposal(ProcessPartiallySignedTransactionInterface process_psbt, FeeRate? min_feerate_sat_per_vb);
PayjoinProposal finalize_proposal(ProcessPartiallySignedTransaction process_psbt, FeeRate? min_feerate_sat_per_vb);
};

interface PayjoinProposal{
Expand Down

0 comments on commit dccb768

Please sign in to comment.