This repository has been archived by the owner on Oct 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
77 additions
and
10 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
11 changes: 8 additions & 3 deletions
11
BitcoinCore/Classes/Network/Messages/TransactionMessage.swift
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 |
---|---|---|
@@ -1,11 +1,16 @@ | ||
import UIExtensions | ||
|
||
struct TransactionMessage: IMessage { | ||
public struct TransactionMessage: IMessage { | ||
let transaction: FullTransaction | ||
let size: Int | ||
|
||
var description: String { | ||
return "\(transaction.header.dataHash.reversedHex)" | ||
public init(transaction: FullTransaction, size: Int) { | ||
self.transaction = transaction | ||
self.size = size | ||
} | ||
|
||
public var description: String { | ||
"\(transaction.header.dataHash.reversedHex)" | ||
} | ||
|
||
} |
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,11 @@ | ||
import Foundation | ||
import BitcoinCore | ||
|
||
class SpecialTransaction: FullTransaction { | ||
let extraPayload: Data | ||
|
||
init(transaction: FullTransaction, extraPayload: Data) { | ||
self.extraPayload = extraPayload | ||
super.init(header: transaction.header, inputs: transaction.inputs, outputs: transaction.outputs) | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
DashKit/Classes/Network/Messages/TransactionMessageParser.swift
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,40 @@ | ||
import Foundation | ||
import BitcoinCore | ||
import OpenSslKit | ||
|
||
class TransactionMessageParser: IMessageParser { | ||
let id: String = "tx" | ||
|
||
let hasher: IDashHasher | ||
|
||
init(hasher: IDashHasher) { | ||
self.hasher = hasher | ||
} | ||
|
||
private func parseSpecialTxData(input: ByteStream, transaction: FullTransaction) -> SpecialTransaction { | ||
let payloadSize = input.read(VarInt.self) | ||
let payload = input.read(Data.self, count: Int(payloadSize.underlyingValue)) | ||
|
||
var output = TransactionSerializer.serialize(transaction: transaction) | ||
output += payloadSize.data | ||
output += payload | ||
|
||
let hash = hasher.hash(data: output) | ||
transaction.set(hash: hash) | ||
|
||
return SpecialTransaction(transaction: transaction, extraPayload: payload) | ||
} | ||
|
||
func parse(data: Data) -> IMessage { | ||
let byteStream = ByteStream(data) | ||
var transaction = TransactionSerializer.deserialize(byteStream: byteStream) | ||
|
||
let version = Data(from: transaction.header.version) | ||
let isSpecialTransaction = (Int(version[0]) + Int(version[1])) > 0 | ||
This comment has been minimized.
Sorry, something went wrong. |
||
if isSpecialTransaction { | ||
transaction = parseSpecialTxData(input: byteStream, transaction: transaction) | ||
} | ||
|
||
return TransactionMessage(transaction: transaction, size: data.count) | ||
} | ||
} |
I believe this is always true