Skip to content

Commit

Permalink
Updated to 0.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
i5hi committed Apr 18, 2024
1 parent f1a753e commit a30f124
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 61 deletions.
2 changes: 1 addition & 1 deletion assets/release.config.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
TAG_VERSION=0.1.2
TAG_VERSION=0.1.3
REPOSITORY_URL=https://github.com/SatoshiPortal/boltz-dart/releases/download
13 changes: 4 additions & 9 deletions lib/src/generated/bindings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -757,18 +757,18 @@ class BoltzDartWire implements FlutterRustBridgeWireBase {
: _lookup = lookup;

void store_dart_post_cobject(
DartPostCObjectFnType ptr,
int ptr,
) {
return _store_dart_post_cobject(
ptr,
);
}

late final _store_dart_post_cobjectPtr =
_lookup<ffi.NativeFunction<ffi.Void Function(DartPostCObjectFnType)>>(
_lookup<ffi.NativeFunction<ffi.Void Function(ffi.Int)>>(
'store_dart_post_cobject');
late final _store_dart_post_cobject = _store_dart_post_cobjectPtr
.asFunction<void Function(DartPostCObjectFnType)>();
late final _store_dart_post_cobject =
_store_dart_post_cobjectPtr.asFunction<void Function(int)>();

Object get_dart_object(
int ptr,
Expand Down Expand Up @@ -1337,8 +1337,3 @@ final class wire_LbtcLnSwap extends ffi.Struct {

external ffi.Pointer<wire_uint_8_list> boltz_url;
}

typedef DartPostCObjectFnType = ffi.Pointer<
ffi.NativeFunction<
ffi.Bool Function(DartPort port_id, ffi.Pointer<ffi.Void> message)>>;
typedef DartPort = ffi.Int64;
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: boltz_dart
description: A dart/flutter library for boltz swaps
version: 0.1.0
version: 0.1.3
homepage: https://github.com/SatoshiPortal/boltz-dart

environment:
Expand Down
12 changes: 5 additions & 7 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
[package]
name = "boltz-dart"
authors = ["i5hi <[email protected]>, mocodesmo <[email protected]>"]
version = "0.1.2"
version = "0.1.3"
edition = "2021"

[lib]
name = "boltzclient"
doctest = false
crate-type = ["staticlib", "cdylib", "lib"]

#Needed to build linux bin without docker
#[target.x86_64-unknown-linux-gnu]
#linker = "x86_64-unknown-linux-gnu-gcc"


[dependencies]
boltz-client = { version = "0.1.2"}
boltz-client = { git = "https://github.com/SatoshiPortal/boltz-rust.git", rev = "ee97d929aec403142fdbba4303bda3e33f3e8822" }
flutter_rust_bridge = "1.82.2"
anyhow = "1.0.68"
serde = "1.0.89"
serde_json = "1.0.96"

[patch.crates-io]
secp256k1-zkp = {git = "https://github.com/BlockstreamResearch/rust-secp256k1-zkp.git", rev = "60e631c24588a0c9e271badd61959294848c665d"}

[build-dependencies]
flutter_rust_bridge_codegen = { version = "= 1.82.6" }

Expand Down
4 changes: 2 additions & 2 deletions rust/android.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
`#!/bin/bash
# Setup jniLibs directory
ROOT="target"
VERSION=$1
Expand All @@ -22,4 +22,4 @@ cargo ndk -o $JNI_DIR \
-t arm64-v8a \
-t x86 \
-t x86_64 \
build --release
build --release`
2 changes: 1 addition & 1 deletion rust/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ PROJECTNAME=$(shell basename "$(PWD)")
# ##############################################################################
# # GENERAL
# ##############################################################################
VERSION="0.1.2"
VERSION="0.1.3"
.PHONY: help
help: makefile
@echo
Expand Down
73 changes: 36 additions & 37 deletions rust/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ use boltz_client::{network::electrum::ElectrumConfig, swaps::bitcoin::BtcSwapScr
use boltz_client::swaps::boltz::BoltzApiClient;
use boltz_client::swaps::boltz::CreateSwapRequest;
use boltz_client::swaps::boltz::SwapStatusRequest;
use boltz_client::util::error::ErrorKind;
use boltz_client::util::error::S5Error;
// use boltz_client::error::Error;
use boltz_client::util::secrets::Preimage;

use crate::types::BoltzError;
Expand All @@ -33,35 +32,35 @@ impl Api {
Ok(result) => result,
Err(e) => return Err(e.into()),
};
let btc_pair = boltz_pairs.get_btc_pair()?;
let btc_pair = boltz_pairs.get_btc_pair().unwrap();
let btc_limits = Limits {
minimal: btc_pair.limits.minimal as u64,
maximal: btc_pair.limits.maximal as u64,
};
let btc_submarine = SubmarineSwapFees {
boltz_fees: btc_pair.fees.submarine_boltz(output_amount)?,
boltz_fees: btc_pair.fees.submarine_boltz(output_amount),
lockup_fees_estimate: btc_pair.fees.submarine_lockup_estimate(),
claim_fees: btc_pair.fees.submarine_claim()?,
claim_fees: btc_pair.fees.submarine_claim(),
};
let btc_reverse = ReverseSwapFees {
boltz_fees: btc_pair.fees.reverse_boltz(output_amount)?,
lockup_fees: btc_pair.fees.reverse_lockup()?,
boltz_fees: btc_pair.fees.reverse_boltz(output_amount),
lockup_fees: btc_pair.fees.reverse_lockup(),
claim_fees_estimate: btc_pair.fees.reverse_claim_estimate(),
};

let lbtc_pair = boltz_pairs.get_lbtc_pair()?;
let lbtc_pair = boltz_pairs.get_lbtc_pair().unwrap();
let lbtc_limits = Limits {
minimal: lbtc_pair.limits.minimal as u64,
maximal: lbtc_pair.limits.maximal as u64,
};
let lbtc_submarine = SubmarineSwapFees {
boltz_fees: lbtc_pair.fees.submarine_boltz(output_amount)?,
boltz_fees: lbtc_pair.fees.submarine_boltz(output_amount),
lockup_fees_estimate: lbtc_pair.fees.submarine_lockup_estimate(),
claim_fees: lbtc_pair.fees.submarine_claim()?,
claim_fees: lbtc_pair.fees.submarine_claim(),
};
let lbtc_reverse = ReverseSwapFees {
boltz_fees: lbtc_pair.fees.reverse_boltz(output_amount)?,
lockup_fees: lbtc_pair.fees.reverse_lockup()?,
boltz_fees: lbtc_pair.fees.reverse_boltz(output_amount),
lockup_fees: lbtc_pair.fees.reverse_lockup(),
claim_fees_estimate: lbtc_pair.fees.reverse_claim_estimate(),
};
let btc_pair_hash = btc_pair.hash;
Expand Down Expand Up @@ -99,10 +98,10 @@ impl Api {
Ok(result) => result,
Err(e) => return Err(e.into()),
};
let btc_pair = boltz_pairs.get_btc_pair()?;
let btc_pair = boltz_pairs.get_btc_pair().unwrap();
if btc_pair.hash != pair_hash {
return Err(BoltzError{
kind: ErrorKind::Input.to_string(),
kind: "Input".to_string(),
message: "Pair hash has updated. Check fees with boltz and use updated hash.".to_string()
});
}
Expand Down Expand Up @@ -166,10 +165,10 @@ impl Api {
Err(e) => return Err(e.into()),
};

let btc_pair = boltz_pairs.get_btc_pair()?;
let btc_pair = boltz_pairs.get_btc_pair().unwrap();
if btc_pair.hash != pair_hash {
return Err(BoltzError{
kind: ErrorKind::Input.to_string(),
kind: "Input".to_string(),
message: "Pair hash has updated. Check fees with boltz and use updated hash.".to_string()
});
}
Expand Down Expand Up @@ -208,7 +207,7 @@ impl Api {

pub fn btc_ln_tx_size(swap: BtcLnSwap) -> anyhow::Result<usize, BoltzError> {
if swap.kind == SwapType::Submarine {
return Err(S5Error::new(ErrorKind::Input, "Submarine swaps are not claimable").into());
return Err(BoltzError{kind: "Input".to_string(), message: "Submarine swaps are not claimable".to_string()});
} else {
()
}
Expand All @@ -225,7 +224,7 @@ impl Api {
};
let ckp: Keypair = swap.keys.into();

let size = match tx.size(&ckp, &swap.preimage.try_into().unwrap()) {
let size = match tx.unwrap().size(&ckp, &swap.preimage.try_into().unwrap()) {
Ok(result) => result,
Err(e) => return Err(e.into()),
};
Expand All @@ -238,7 +237,7 @@ impl Api {
abs_fee: u64,
) -> anyhow::Result<String, BoltzError> {
if swap.kind == SwapType::Submarine {
return Err(S5Error::new(ErrorKind::Input, "Submarine swaps are not claimable").into());
return Err(BoltzError{kind: "Input".to_string(),message: "Submarine swaps are not claimable".to_string()});
} else {
()
}
Expand All @@ -256,7 +255,7 @@ impl Api {

if script_balance.0 > 0 || script_balance.1 > 0 {
let tx = match BtcSwapTx::new_claim(script, out_address, &network_config) {
Ok(result) => result,
Ok(result) => result.unwrap(),
Err(e) => return Err(e.into()),
};
let ckp: Keypair = swap.keys.into();
Expand All @@ -268,9 +267,9 @@ impl Api {
Ok(result) => result,
Err(e) => return Err(e.into()),
};
Ok(txid)
Ok(txid.to_string())
} else {
return Err(S5Error::new(ErrorKind::Script, "Script is not funded yet!").into());
return Err(BoltzError{kind: "Script".to_string(), message: "Script is not funded yet!".to_string()});
}
}

Expand All @@ -280,7 +279,7 @@ impl Api {
abs_fee: u64,
) -> anyhow::Result<String, BoltzError> {
if swap.kind == SwapType::Reverse {
return Err(S5Error::new(ErrorKind::Input, "Reverse swaps are not refundable").into());
return Err(BoltzError{kind: "Input".to_string(), message: "Reverse swaps are not refundable".to_string()});
} else {
()
}
Expand All @@ -298,7 +297,7 @@ impl Api {

if script_balance.0 > 0 || script_balance.1 > 0 {
let tx = match BtcSwapTx::new_refund(script, out_address, &network_config) {
Ok(result) => result,
Ok(result) => result.unwrap(),
Err(e) => return Err(e.into()),
};
let ckp: Keypair = swap.keys.into();
Expand All @@ -310,9 +309,9 @@ impl Api {
Ok(result) => result,
Err(e) => return Err(e.into()),
};
Ok(txid)
Ok(txid.to_string())
} else {
return Err(S5Error::new(ErrorKind::Script, "Script is not funded yet!").into());
return Err(BoltzError{kind: "Script".to_string(), message:"Script is not funded yet!".to_string()});
}
}

Expand All @@ -337,10 +336,10 @@ impl Api {
Err(e) => return Err(e.into()),
};

let lbtc_pair = boltz_pairs.get_lbtc_pair()?;
let lbtc_pair = boltz_pairs.get_lbtc_pair().unwrap();
if lbtc_pair.hash != pair_hash {
return Err(BoltzError{
kind: ErrorKind::Input.to_string(),
kind: "Input".to_string(),
message: "Pair hash has updated. Check fees with boltz and use updated hash.".to_string()
});
}
Expand Down Expand Up @@ -373,7 +372,7 @@ impl Api {
// };

// if &payment_address != &response.clone().address.unwrap(){
// return Err(S5Error::new(ErrorKind::BoltzApi, "Payment address in response does not match constructed script! Report to support!").into());
// return Err(BoltzError{kind: ErrorKind::BoltzApi, "Payment address in response does not match constructed script! Report to support!").into());
// }

Ok(LbtcLnSwap::new(
Expand Down Expand Up @@ -414,10 +413,10 @@ impl Api {
Err(e) => return Err(e.into()),
};

let lbtc_pair = boltz_pairs.get_lbtc_pair()?;
let lbtc_pair = boltz_pairs.get_lbtc_pair().unwrap();
if lbtc_pair.hash != pair_hash {
return Err(BoltzError{
kind: ErrorKind::Input.to_string(),
kind: "Input".to_string(),
message: "Pair hash has updated. Check fees with boltz and use updated hash.".to_string()
});
}
Expand Down Expand Up @@ -445,7 +444,7 @@ impl Api {
// };

// if &payment_address != &response.clone().address.unwrap(){
// return Err(S5Error::new(ErrorKind::BoltzApi, "Payment address in response does not match constructed script! Report to support!").into());
// return Err(BoltzError{kind: ErrorKind::BoltzApi, "Payment address in response does not match constructed script! Report to support!").into());
// }

Ok(LbtcLnSwap::new(
Expand All @@ -466,7 +465,7 @@ impl Api {

pub fn lbtc_ln_tx_size(swap: LbtcLnSwap) -> anyhow::Result<usize, BoltzError> {
if swap.kind == SwapType::Submarine {
return Err(S5Error::new(ErrorKind::Input, "Submarine swaps are not claimable").into());
return Err(BoltzError{kind: "Input".to_string(), message: "Submarine swaps are not claimable".to_string()});
} else {
()
}
Expand Down Expand Up @@ -494,7 +493,7 @@ impl Api {
abs_fee: u64,
) -> anyhow::Result<String, BoltzError> {
if swap.kind == SwapType::Submarine {
return Err(S5Error::new(ErrorKind::Input, "Submarine swaps are not claimable").into());
return Err(BoltzError{kind: "Input".to_string(), message: "Submarine swaps are not claimable".to_string()});
} else {
()
}
Expand Down Expand Up @@ -527,7 +526,7 @@ impl Api {
Ok(txid)
// }
// else{
// return Err(S5Error::new(ErrorKind::Script, "Script is not funded yet!").into());
// return Err(BoltzError{kind: ErrorKind::Script, "Script is not funded yet!").into());
// }
}

Expand All @@ -537,7 +536,7 @@ impl Api {
abs_fee: u64,
) -> anyhow::Result<String, BoltzError> {
if swap.kind == SwapType::Reverse {
return Err(S5Error::new(ErrorKind::Input, "Reverse swaps are not refundable").into());
return Err(BoltzError{kind: "Input".to_string(), message: "Reverse swaps are not refundable".to_string()});
} else {
()
}
Expand Down Expand Up @@ -578,7 +577,7 @@ impl Api {
pub fn decode_invoice(invoice_str: String)->anyhow::Result<DecodedInvoice, BoltzError>{
let invoice = match Bolt11Invoice::from_str(&invoice_str){
Ok(result)=>result,
Err(e) => return Err(BoltzError{kind: ErrorKind::Input.to_string(), message: e.to_string()})
Err(e) => return Err(BoltzError{kind: "Input".to_string(), message: e.to_string()})
};
Ok(invoice.into())
}
Expand Down
8 changes: 5 additions & 3 deletions rust/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
//
use serde::{Serialize,Deserialize};
use boltz_client::{
network::Chain as BChain, swaps::boltz::SwapType as BoltzSwapType, util::{error::{ErrorKind, S5Error}, secrets::{Preimage as BoltzPreImage, SwapKey}}, Bolt11Invoice, Keypair, Secp256k1, ZKKeyPair, ZKSecp256k1
network::Chain as BChain, swaps::boltz::SwapType as BoltzSwapType, util::{secrets::{Preimage as BoltzPreImage, SwapKey}}, Bolt11Invoice, Keypair, Secp256k1, ZKKeyPair, ZKSecp256k1
};
use boltz_client::error::Error as S5Error;

// use crate::types::{KeyPair, PreImage, Network, SwapType};

#[frb(dart_metadata=("freezed"))]
Expand Down Expand Up @@ -313,8 +315,8 @@ impl BoltzError {
impl From<S5Error> for BoltzError {
fn from(value: S5Error) -> Self {
BoltzError {
kind: value.kind.to_string(),
message: value.message,
kind: value.name(),
message: value.message(),
}
}
}
Expand Down

0 comments on commit a30f124

Please sign in to comment.