Skip to content

Commit

Permalink
Merge pull request #2 from LtbLightning/send-receive
Browse files Browse the repository at this point in the history
Send and Receive
  • Loading branch information
BitcoinZavior authored Oct 2, 2023
2 parents 312b2df + 67610dd commit 2b9f118
Show file tree
Hide file tree
Showing 15 changed files with 1,138 additions and 346 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock


# These are backup files generated by rustfmt
**/*.rs.bk
.vscode/settings.json
30 changes: 23 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
[package]
name = "payjoin-ffi"
name = "pdk-ffi"
version = "0.1.0"
license = "MIT OR Apache-2.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
crate-type = ["lib", "staticlib", "cdylib"]
name = "pdk_ffi"

[build-dependencies]
uniffi = { version = "0.24.3", features = ["build"] }

[dev-dependencies]
uniffi = { version = "0.24.3", features = ["bindgen-tests"] }
assert_matches = "1.5.0"
env_logger = "0.10.0"
bitcoind = { version = "0.32.0", features = ["0_21_2"] }


[dependencies]
anyhow = "1.0.70"
Expand All @@ -19,10 +31,14 @@ reqwest = { version = "0.11.4", features = ["blocking"] }
rcgen = { version = "0.11.1", optional = true }
serde = { version = "1.0.160", features = ["derive"] }
payjoin = { version = "0.9.0", features = ["send", "receive", "rand"] }
bitcoin = "0.30.1"
serde_json = "1.0.103"
uniffi = "0.24.3"
hex = "0.4.3"
url = "2.4.0"

[profile.release]
panic = "abort"
[[bin]]
name = "uniffi-bindgen"
path = "uniffi-bindgen.rs"

[profile.dev]
panic = "abort"
[features]
default = ["uniffi/cli"]
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ With a commitment to collaboration and interoperability, this repository strives

**Current Status:**
This is a pre-alpha stage and is currently in the design phase. The first language bindings available will be for Android followed by Swift. The ultimate goal is to have Payjoin implementations for Android, iOS, Python, Java, React Native, Flutter, C# and Golang.

3 changes: 3 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
uniffi::generate_scaffolding("./src/pdk.udl").unwrap();
}
127 changes: 0 additions & 127 deletions src/bitcoind.rs

This file was deleted.

101 changes: 46 additions & 55 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,59 +1,50 @@
#[derive(Debug)]
pub struct ValidationError {
internal: InternalValidationError,
}
use std::fmt;

use payjoin::bitcoin::psbt::PsbtParseError;
use payjoin::receive::RequestError;

impl From<InternalValidationError> for ValidationError {
fn from(value: InternalValidationError) -> Self {
ValidationError { internal: value }
}
#[derive(Debug, PartialEq, Eq)]
pub enum Error {
/// Error encountered during PSBT decoding from Base64 string.
PsbtParseError(String),
ReceiveError(String),
///Error that may occur when the request from sender is malformed.
///This is currently opaque type because we aren’t sure which variants will stay. You can only display it.
RequestError(String),
///Error that may occur when coin selection fails.
SelectionError(String),
///Error returned when request could not be created.
///This error can currently only happen due to programmer mistake.
CreateRequestError(String),
PjParseError(String),
UnexpectedError(String),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::ReceiveError(e) => write!(f, "ReceiveError: {}", e),
Error::RequestError(e) => write!(f, "RequestError: {}", e),
Error::SelectionError(e) => write!(f, "SelectionError: {}", e),
Error::CreateRequestError(e) => write!(f, "CreateRequestError: {}", e),
Error::PjParseError(e) => write!(f, "PjParseError: {}", e),
Error::PsbtParseError(e) => write!(f, "PsbtParseError: {}", e),
Error::UnexpectedError(e) => write!(f, "UnexpectedError: {}", e),
}
}
}
impl std::error::Error for Error {}
impl From<RequestError> for Error {
fn from(value: RequestError) -> Self {
Error::RequestError(value.to_string())
}
}
impl From<InputTypeError> for InternalValidationError {
fn from(value: InputTypeError) -> Self {
InternalValidationError::InvalidInputType(value)
}
impl From<PsbtParseError> for Error {
fn from(value: PsbtParseError) -> Self {
Error::PsbtParseError(value.to_string())
}
}
#[derive(Debug)]
pub(crate) enum InternalValidationError {
Psbt(bitcoin::psbt::PsbtParseError),
Io(std::io::Error),
InvalidInput,
Type(InputTypeError),
InvalidProposedInput(crate::psbt::PrevTxOutError),
VersionsDontMatch {
proposed: i32,
original: i32,
},
LockTimesDontMatch {
proposed: LockTime,
original: LockTime,
},
SenderTxinSequenceChanged {
proposed: Sequence,
original: Sequence,
},
SenderTxinContainsNonWitnessUtxo,
SenderTxinContainsWitnessUtxo,
SenderTxinContainsFinalScriptSig,
SenderTxinContainsFinalScriptWitness,
TxInContainsKeyPaths,
ContainsPartialSigs,
ReceiverTxinNotFinalized,
ReceiverTxinMissingUtxoInfo,
MixedSequence,
MixedInputTypes {
proposed: InputType,
original: InputType,
},
MissingOrShuffledInputs,
TxOutContainsKeyPaths,
FeeContributionExceedsMaximum,
DisallowedOutputSubstitution,
OutputValueDecreased,
MissingOrShuffledOutputs,
Inflation,
AbsoluteFeeDecreased,
PayeeTookContributedFee,
FeeContributionPaysOutputSizeIncrease,
FeeRateBelowMinimum,
impl From<payjoin::Error> for Error {
fn from(value: payjoin::Error) -> Self {
Error::UnexpectedError(value.to_string())
}
}
Loading

0 comments on commit 2b9f118

Please sign in to comment.