-
-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathDashTransaction.swift
70 lines (59 loc) · 1.94 KB
/
DashTransaction.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//
// DashRawTransaction.swift
// Adamant
//
// Created by Anton Boyarkin on 19/05/2019.
// Copyright © 2019 Adamant. All rights reserved.
//
import Foundation
import BitcoinKit
final class DashTransaction: BaseBtcTransaction {
override var defaultCurrencySymbol: String? { DashWalletService.currencySymbol }
}
struct BtcBlock: Decodable {
let hash: String
let height: Int64
let time: Int64
enum CodingKeys: String, CodingKey {
case hash
case height
case time
}
init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
self.hash = try container.decode(String.self, forKey: .hash)
self.height = try container.decode(Int64.self, forKey: .height)
self.time = try container.decode(Int64.self, forKey: .time)
}
}
struct DashUnspentTransaction: Decodable {
let address: String
let txid: String
let outputIndex: UInt32
let script: String
let amount: UInt64
let height: UInt64
enum CodingKeys: String, CodingKey {
case address
case txid
case outputIndex
case script
case amount = "satoshis"
case height
}
func asUnspentTransaction(lockScript: Data) -> UnspentTransaction {
let txHash = Data(hex: txid).map { Data($0.reversed()) } ?? Data()
let unspentOutput = TransactionOutput(value: amount, lockingScript: lockScript)
let unspentOutpoint = TransactionOutPoint(hash: txHash, index: outputIndex)
let utxo = UnspentTransaction(output: unspentOutput, outpoint: unspentOutpoint)
return utxo
}
}
//{
// "address": "Xp6kFbogHMD4QRBDLQdqRp5zUgzmfj1KPn",
// "txid": "4270bdbdcf89c0a39fd3e81f8b8bd991507d66c643703a007f8f6b466504de83",
// "outputIndex": 0,
// "script": "76a914931ef5cbdad28723ba9596de5da1145ae969a71888ac",
// "satoshis": 3000000,
// "height": 1009632
//}