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.
Afficher le fichier Open project: TangibleCryptography/BitSharper

Méthodes publiques

Méthode 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

Méthode 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 méthode

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

BitcoinValueToFriendlyString() public static méthode

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

BytesToHexString() public static méthode

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

DoubleDigest() public static méthode

See DoubleDigest(byte[], int, int).
public static DoubleDigest ( byte input ) : byte[]
input byte
Résultat byte[]

DoubleDigest() public static méthode

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
Résultat byte[]

DoubleDigestTwoBuffers() public static méthode

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
Résultat byte[]

ReadUint16Be() public static méthode

public static ReadUint16Be ( byte bytes, int offset ) : ushort
bytes byte
offset int
Résultat ushort

ReadUint32() public static méthode

public static ReadUint32 ( byte bytes, int offset ) : uint
bytes byte
offset int
Résultat uint

ReadUint32Be() public static méthode

public static ReadUint32Be ( byte bytes, int offset ) : uint
bytes byte
offset int
Résultat uint

ReverseBytes() public static méthode

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

Sha256Hash160() public static méthode

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

ToNanoCoins() public static méthode

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
Résultat ulong

ToNanoCoins() public static méthode

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
Résultat ulong

Uint32ToByteArrayBe() public static méthode

public static Uint32ToByteArrayBe ( uint val, byte @out, int offset ) : void
val uint
@out byte
offset int
Résultat void

Uint32ToByteArrayLe() public static méthode

public static Uint32ToByteArrayLe ( uint val, byte @out, int offset ) : void
val uint
@out byte
offset int
Résultat void

Uint32ToByteStreamLe() public static méthode

public static Uint32ToByteStreamLe ( uint val, Stream stream ) : void
val uint
stream Stream
Résultat void

Uint64ToByteStreamLe() public static méthode

public static Uint64ToByteStreamLe ( ulong val, Stream stream ) : void
val ulong
stream Stream
Résultat void