C# Class BitSharper.Utils

A collection of various utility methods that are helpful for working with the BitCoin protocol. To enable debug logging from the library, run with -Dbitcoinj.logging=true on your command line.
Mostra file Open project: TangibleCryptography/BitSharper

Public Methods

Method Description
BitcoinValueToFriendlyString ( long value ) : string

Returns the given value in nanocoins as a 0.12 type string.

BitcoinValueToFriendlyString ( ulong value ) : string

Returns the given value in nanocoins as a 0.12 type string.

BytesToHexString ( byte bytes ) : string

Returns the given byte array hex encoded.

DoubleDigest ( byte input ) : byte[]

See DoubleDigest(byte[], int, int).

DoubleDigest ( byte input, int offset, int length ) : byte[]

Calculates the SHA-256 hash of the given byte range, and then hashes the resulting hash again. This is standard procedure in BitCoin. The resulting hash is in big endian form.

DoubleDigestTwoBuffers ( byte input1, int offset1, int length1, byte input2, int offset2, int length2 ) : byte[]

Calculates SHA256(SHA256(byte range 1 + byte range 2)).

ReadUint16Be ( byte bytes, int offset ) : ushort
ReadUint32 ( byte bytes, int offset ) : uint
ReadUint32Be ( byte bytes, int offset ) : uint
ReverseBytes ( byte bytes ) : byte[]

Returns a copy of the given byte array in reverse order.

Sha256Hash160 ( byte input ) : byte[]

Calculates RIPEMD160(SHA256(input)). This is used in Address calculations.

ToNanoCoins ( string coins ) : ulong

Convert an amount expressed in the way humans are used to into nanocoins.

This takes string in a format understood by System.Double.Parse(string), for example "0", "1", "0.10", "1.23E3", "1234.5E-5".

ToNanoCoins ( uint coins, uint cents ) : ulong

Convert an amount expressed in the way humans are used to into nanocoins.

Uint32ToByteArrayBe ( uint val, byte @out, int offset ) : void
Uint32ToByteArrayLe ( uint val, byte @out, int offset ) : void
Uint32ToByteStreamLe ( uint val, Stream stream ) : void
Uint64ToByteStreamLe ( ulong val, Stream stream ) : void

Private Methods

Method Description
DecodeCompactBits ( long compact ) : BigInteger
DecodeMpi ( byte mpi ) : BigInteger

MPI encoded numbers are produced by the OpenSSL BN_bn2mpi function. They consist of a 4 byte big endian length field, followed by the stated number of bytes representing the number in big endian format.

Method Details

BitcoinValueToFriendlyString() public static method

Returns the given value in nanocoins as a 0.12 type string.
public static BitcoinValueToFriendlyString ( long value ) : string
value long
return string

BitcoinValueToFriendlyString() public static method

Returns the given value in nanocoins as a 0.12 type string.
public static BitcoinValueToFriendlyString ( ulong value ) : string
value ulong
return string

BytesToHexString() public static method

Returns the given byte array hex encoded.
public static BytesToHexString ( byte bytes ) : string
bytes byte
return string

DoubleDigest() public static method

See DoubleDigest(byte[], int, int).
public static DoubleDigest ( byte input ) : byte[]
input byte
return byte[]

DoubleDigest() public static method

Calculates the SHA-256 hash of the given byte range, and then hashes the resulting hash again. This is standard procedure in BitCoin. The resulting hash is in big endian form.
public static DoubleDigest ( byte input, int offset, int length ) : byte[]
input byte
offset int
length int
return byte[]

DoubleDigestTwoBuffers() public static method

Calculates SHA256(SHA256(byte range 1 + byte range 2)).
public static DoubleDigestTwoBuffers ( byte input1, int offset1, int length1, byte input2, int offset2, int length2 ) : byte[]
input1 byte
offset1 int
length1 int
input2 byte
offset2 int
length2 int
return byte[]

ReadUint16Be() public static method

public static ReadUint16Be ( byte bytes, int offset ) : ushort
bytes byte
offset int
return ushort

ReadUint32() public static method

public static ReadUint32 ( byte bytes, int offset ) : uint
bytes byte
offset int
return uint

ReadUint32Be() public static method

public static ReadUint32Be ( byte bytes, int offset ) : uint
bytes byte
offset int
return uint

ReverseBytes() public static method

Returns a copy of the given byte array in reverse order.
public static ReverseBytes ( byte bytes ) : byte[]
bytes byte
return byte[]

Sha256Hash160() public static method

Calculates RIPEMD160(SHA256(input)). This is used in Address calculations.
public static Sha256Hash160 ( byte input ) : byte[]
input byte
return byte[]

ToNanoCoins() public static method

Convert an amount expressed in the way humans are used to into nanocoins.
This takes string in a format understood by System.Double.Parse(string), for example "0", "1", "0.10", "1.23E3", "1234.5E-5".
If you try to specify fractional nanocoins.
public static ToNanoCoins ( string coins ) : ulong
coins string
return ulong

ToNanoCoins() public static method

Convert an amount expressed in the way humans are used to into nanocoins.
public static ToNanoCoins ( uint coins, uint cents ) : ulong
coins uint
cents uint
return ulong

Uint32ToByteArrayBe() public static method

public static Uint32ToByteArrayBe ( uint val, byte @out, int offset ) : void
val uint
@out byte
offset int
return void

Uint32ToByteArrayLe() public static method

public static Uint32ToByteArrayLe ( uint val, byte @out, int offset ) : void
val uint
@out byte
offset int
return void

Uint32ToByteStreamLe() public static method

public static Uint32ToByteStreamLe ( uint val, Stream stream ) : void
val uint
stream Stream
return void

Uint64ToByteStreamLe() public static method

public static Uint64ToByteStreamLe ( ulong val, Stream stream ) : void
val ulong
stream Stream
return void