Skip to content

Commit

Permalink
- add ability to set an ID to a placeholder transaction, as thats nee…
Browse files Browse the repository at this point in the history
…ded for uniqueness checks
  • Loading branch information
simonmcl committed Feb 15, 2024
1 parent 463c439 commit 8c7849c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Sources/KukaiCoreSwift/Models/BakingBad/TzKTTransaction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,11 @@ public struct TzKTTransaction: Codable, CustomStringConvertible, Hashable, Ident
}

/// Used for creating "Pending" transactions
public static func placeholder(withStatus status: TransactionStatus, opHash: String, type: TransactionType, counter: Decimal, fromWallet: WalletMetadata, destination: TzKTAddress, xtzAmount: TokenAmount, parameters: [String: String]?, primaryToken: Token?) -> TzKTTransaction {
public static func placeholder(withStatus status: TransactionStatus, id: Decimal, opHash: String, type: TransactionType, counter: Decimal, fromWallet: WalletMetadata, destination: TzKTAddress, xtzAmount: TokenAmount, parameters: [String: String]?, primaryToken: Token?) -> TzKTTransaction {
let timestamp = TzKTTransaction.dateFormatter.string(from: Date())
let sender = TzKTAddress(alias: fromWallet.walletNickname ?? fromWallet.socialUsername ?? fromWallet.address, address: fromWallet.address)

var transaction = TzKTTransaction(type: .transaction, id: 0, level: 0, timestamp: timestamp, hash: opHash, counter: counter, initiater: nil, sender: sender, bakerFee: .zero(), storageFee: .zero(), allocationFee: .zero(), target: destination, prevDelegate: nil, newDelegate: nil, amount: xtzAmount, parameter: parameters, status: status, hasInternals: false, tokenTransfersCount: nil, errors: nil)
var transaction = TzKTTransaction(type: .transaction, id: id, level: id, timestamp: timestamp, hash: opHash, counter: counter, initiater: nil, sender: sender, bakerFee: .zero(), storageFee: .zero(), allocationFee: .zero(), target: destination, prevDelegate: nil, newDelegate: nil, amount: xtzAmount, parameter: parameters, status: status, hasInternals: false, tokenTransfersCount: nil, errors: nil)
transaction.processAdditionalData(withCurrentWalletAddress: fromWallet.address)

if let pToken = primaryToken {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ final class TzKTTransactionTests: XCTestCase {
let source = WalletMetadata(address: "tz1abc", hdWalletGroupName: nil, type: .hd, children: [], isChild: false, isWatchOnly: false, bas58EncodedPublicKey: "", backedUp: true)
let placeholder1 = TzKTTransaction.placeholder(withStatus: .unconfirmed, opHash: "abc123", type: .transaction, counter: 0, fromWallet: source, newDelegate: TzKTAddress(alias: "Baking Benjamins", address: "tz1YgDUQV2eXm8pUWNz3S5aWP86iFzNp4jnD"))

let placeholder2 = TzKTTransaction.placeholder(withStatus: .unconfirmed, opHash: "def456", type: .transaction, counter: 1, fromWallet: source, destination: TzKTAddress(alias: nil, address: "tz1def"), xtzAmount: .init(fromNormalisedAmount: 4.17, decimalPlaces: 6), parameters: nil, primaryToken: nil)
let placeholder2 = TzKTTransaction.placeholder(withStatus: .unconfirmed, id: 456, opHash: "def456", type: .transaction, counter: 1, fromWallet: source, destination: TzKTAddress(alias: nil, address: "tz1def"), xtzAmount: .init(fromNormalisedAmount: 4.17, decimalPlaces: 6), parameters: nil, primaryToken: nil)

XCTAssert(placeholder1.newDelegate?.address == "tz1YgDUQV2eXm8pUWNz3S5aWP86iFzNp4jnD", placeholder1.newDelegate?.address ?? "-")
XCTAssert(placeholder2.amount.description == "4.17", placeholder2.amount.description)
Expand Down

0 comments on commit 8c7849c

Please sign in to comment.