Skip to content

Instantly share code, notes, and snippets.

View alexbosworth's full-sized avatar

Alex Bosworth alexbosworth

View GitHub Profile
// 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:
//
/** Transaction input
*/
struct TransactionInput {
/** Final sequence number marking the input as final
*/
static let finalSequence = UInt32.max
/** Spending output
*/
let outpoint: Outpoint
import Foundation
/** Outpoint
*/
struct Outpoint {
/** Index
*/
let index: UInt32
/** Number of bytes for the outpoint index
import Foundation
/** Can be included after this time marker
*/
enum Locktime {
case date(Date)
case height(Int)
/** Number of bytes
*/
/** 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 {
/** 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
/** 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()
/** Extensions to UnicodeScalar
*/
extension UnicodeScalar {
/** Unicode scalar errors
*/
enum UnicodeScalarError: String, Error {
case illegalHexValue
}
/** Get the byte value of a hex nibble
package main
import (
"io"
"os"
"strings"
)
type rot13Reader struct {
r io.Reader
package main
import (
"fmt"
)
type IPAddr [4]byte
func (ip IPAddr) String() string {
str := ""