Skip to content
This repository has been archived by the owner on Feb 8, 2024. It is now read-only.

Commit

Permalink
Debugging payments with custom amounts
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Mar 7, 2021
1 parent 2acee16 commit 1e6381b
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 7 deletions.
1 change: 1 addition & 0 deletions libmycitadel/libmycitadel.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ const char *mycitadel_address_pay(struct mycitadel_client_t *client,
struct prepared_transfer_t mycitadel_invoice_pay(struct mycitadel_client_t *client,
const char *contract_id,
const char *invoice,
uint64_t amount,
uint64_t fee,
uint64_t giveaway);

Expand Down
4 changes: 3 additions & 1 deletion libmycitadel/src/capi/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ pub extern "C" fn mycitadel_address_pay(
client,
ptr::null(),
invoice.as_ptr() as *const c_char,
amount,
fee,
0,
)
Expand All @@ -357,6 +358,7 @@ pub extern "C" fn mycitadel_invoice_pay(
client: *mut mycitadel_client_t,
contract_id: *const c_char,
invoice: *const c_char,
amount: u64,
fee: u64,
giveaway: u64,
) -> prepared_transfer_t {
Expand Down Expand Up @@ -389,7 +391,7 @@ pub extern "C" fn mycitadel_invoice_pay(
inner.invoice_pay(
contract_id,
invoice,
None,
if amount > 0 { Some(amount) } else { None },
fee,
if giveaway > 0 { Some(giveaway) } else { None },
)
Expand Down
4 changes: 2 additions & 2 deletions packages/MyCitadelKit/CAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ extension CitadelVault {
}
*/

internal func pay(from contractId: String, invoice: String, fee: UInt64, giveaway: UInt64? = nil) throws -> Transfer {
let transfer = mycitadel_invoice_pay(rpcClient, contractId, invoice, fee, giveaway ?? 0)
internal func pay(from contractId: String, invoice: String, value: UInt64? = nil, fee: UInt64, giveaway: UInt64? = nil) throws -> Transfer {
let transfer = mycitadel_invoice_pay(rpcClient, contractId, invoice, value ?? 0, fee, giveaway ?? 0)
if !transfer.success {
guard let err = self.lastError() else {
throw CitadelError("MyCitadel C API is broken")
Expand Down
1 change: 1 addition & 0 deletions packages/MyCitadelKit/Vault.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ open class CitadelVault {
) throws {
self.network = network
dataDir = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!.appendingPathComponent(network.rawValue).path
print("Data directory: \(dataDir)")
rpcClient = mycitadel_run_embedded(network.rawValue, self.dataDir, electrumServer)
assets[network.nativeAssetId()] = NativeAsset(withCitadelVault: self)
}
Expand Down
4 changes: 2 additions & 2 deletions packages/MyCitadelKit/Wallet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ public class WalletContract: Identifiable {
}
*/

public func pay(invoice: String, fee: UInt64, giveaway: UInt64? = nil) throws -> PaymentResult {
let transfer = try vault.pay(from: id, invoice: invoice, fee: fee, giveaway: giveaway)
public func pay(invoice: String, value: UInt64? = nil, fee: UInt64, giveaway: UInt64? = nil) throws -> PaymentResult {
let transfer = try vault.pay(from: id, invoice: invoice, value: value, fee: fee, giveaway: giveaway)
let signedPsbt = try vault.sign(psbt: transfer.psbt)
let txid = try vault.publish(psbt: signedPsbt)

Expand Down
2 changes: 1 addition & 1 deletion src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ impl Client {
bitcoin_fee: fee,
asset_value: invoice.amount().atomic_value().or(amount).ok_or(Error::ServerFailure(Failure {
code: 0,
info: s!("Amount must be specified for invoices which does not provide default amount value")
info: s!("Amount must be specified for invoices if they do not provide default amount value")
}))?,
transfer_info,
invoice
Expand Down
2 changes: 1 addition & 1 deletion src/server/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ impl Runtime {
if transfer_info.is_rgb() {
""
} else {
" on bitcoin outputs which does not have RGB assets on them"
" on bitcoin outputs which do not have RGB assets on them"
}
)
}))?;
Expand Down

0 comments on commit 1e6381b

Please sign in to comment.