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
// Copyright (c) 2017 Alex Bosworth | |
// Copyright (c) 2017 Pieter Wuille | |
// | |
// Permission is hereby granted, free of charge, to any person obtaining a copy | |
// of this software and associated documentation files (the "Software"), to deal | |
// in the Software without restriction, including without limitation the rights | |
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
// copies of the Software, and to permit persons to whom the Software is | |
// furnished to do so, subject to the following conditions: | |
// |
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
/** Transaction input | |
*/ | |
struct TransactionInput { | |
/** Final sequence number marking the input as final | |
*/ | |
static let finalSequence = UInt32.max | |
/** Spending output | |
*/ | |
let outpoint: Outpoint |
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
import Foundation | |
/** Outpoint | |
*/ | |
struct Outpoint { | |
/** Index | |
*/ | |
let index: UInt32 | |
/** Number of bytes for the outpoint index |
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
import Foundation | |
/** Can be included after this time marker | |
*/ | |
enum Locktime { | |
case date(Date) | |
case height(Int) | |
/** Number of bytes | |
*/ |
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
/** Compact Size UInt | |
*/ | |
enum CompactSizeUInt { | |
case uint8(UInt8), uint16(UInt16), uint32(UInt32), uint64(UInt64) | |
// MARK: - Init | |
/** Create from hex string | |
*/ | |
init(from hex: String) throws { |
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
/** Compact size uint marker byte | |
*/ | |
enum CompactSizeMarker: Byte { | |
case uint8, uint16 = 253, uint32, uint64 | |
/** Byte length of discriminant | |
*/ | |
static let discriminantByteLength = 1 | |
/** Hex byte length |
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
/** Extensions to Data | |
*/ | |
extension Data { | |
/** Create data from hex string | |
*/ | |
init(hex: String) throws { | |
var bytes = Array<Byte>(repeating: Byte(), count: (hex.unicodeScalars.count + 1) >> 1) | |
try hex.unicodeScalars.enumerated().forEach { index, scalar in | |
var nibble = try scalar.hexNibble() |
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
/** Extensions to UnicodeScalar | |
*/ | |
extension UnicodeScalar { | |
/** Unicode scalar errors | |
*/ | |
enum UnicodeScalarError: String, Error { | |
case illegalHexValue | |
} | |
/** Get the byte value of a hex nibble |
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
package main | |
import ( | |
"io" | |
"os" | |
"strings" | |
) | |
type rot13Reader struct { | |
r io.Reader |
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
package main | |
import ( | |
"fmt" | |
) | |
type IPAddr [4]byte | |
func (ip IPAddr) String() string { | |
str := "" |