-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1382 from Electric-Coin-Company/1204-expose-propo…
…sals Expose APIs for working with transaction proposals
- Loading branch information
Showing
19 changed files
with
1,184 additions
and
252 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// | ||
// Proposal.swift | ||
// | ||
// | ||
// Created by Jack Grigg on 20/02/2024. | ||
// | ||
|
||
import Foundation | ||
|
||
/// A data structure that describes a series of transactions to be created. | ||
public struct Proposal: Equatable { | ||
let inner: FfiProposal | ||
|
||
/// Returns the number of transactions that this proposal will create. | ||
/// | ||
/// This is equal to the number of `TransactionSubmitResult`s that will be returned | ||
/// from `Synchronizer.createProposedTransactions`. | ||
/// | ||
/// Proposals always create at least one transaction. | ||
public func transactionCount() -> Int { | ||
inner.steps.count | ||
} | ||
|
||
/// Returns the total fee to be paid across all proposed transactions, in zatoshis. | ||
public func totalFeeRequired() -> Zatoshi { | ||
inner.steps.reduce(Zatoshi.zero) { acc, step in | ||
acc + Zatoshi(Int64(step.balance.feeRequired)) | ||
} | ||
} | ||
} | ||
|
||
public extension Proposal { | ||
/// IMPORTANT: This function is for testing purposes only. It produces fake invalid | ||
/// data that can be used to check UI elements, but will always produce an error when | ||
/// passed to `Synchronizer.createProposedTransactions`. It should never be called in | ||
/// production code. | ||
static func testOnlyFakeProposal(totalFee: UInt64) -> Self { | ||
var ffiProposal = FfiProposal() | ||
var balance = FfiTransactionBalance() | ||
|
||
balance.feeRequired = totalFee | ||
|
||
return Self(inner: ffiProposal) | ||
} | ||
} |
Oops, something went wrong.