本文整理汇总了C#中BitCoinSharp.NetworkParameters类的典型用法代码示例。如果您正苦于以下问题:C# NetworkParameters类的具体用法?C# NetworkParameters怎么用?C# NetworkParameters使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NetworkParameters类属于BitCoinSharp命名空间,在下文中一共展示了NetworkParameters类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Address
/// <summary>
/// Construct an address from parameters and the standard "human readable" form.
/// </summary>
/// <remarks>
/// Example:<p/>
/// <pre>new Address(NetworkParameters.prodNet(), "17kzeh4N8g49GFvdDzSf8PjaPfyoD1MndL");</pre>
/// </remarks>
/// <exception cref="AddressFormatException"/>
public Address(NetworkParameters @params, string address)
: base(address)
{
if (Version != @params.AddressHeader)
throw new AddressFormatException("Mismatched version number, trying to cross networks? " + Version +
" vs " + @params.AddressHeader);
}
示例2: TransactionOutput
/// <summary>
/// Used only in creation of the genesis blocks and in unit tests.
/// </summary>
internal TransactionOutput(NetworkParameters @params, byte[] scriptBytes)
: base(@params)
{
_scriptBytes = scriptBytes;
_value = Utils.ToNanoCoins(50, 0);
_availableForSpending = true;
}
示例3: DumpedPrivateKey
/// <summary>
/// Parses the given private key as created by the "dumpprivkey" BitCoin C++ RPC.
/// </summary>
/// <param name="params">The expected network parameters of the key. If you don't care, provide null.</param>
/// <param name="encoded">The base58 encoded string.</param>
/// <exception cref="BitCoinSharp.AddressFormatException">If the string is invalid or the header byte doesn't match the network params.</exception>
public DumpedPrivateKey(NetworkParameters @params, string encoded)
: base(encoded)
{
if (@params != null && Version != @params.DumpedPrivateKeyHeader)
throw new AddressFormatException("Mismatched version number, trying to cross networks? " + Version +
" vs " + @params.DumpedPrivateKeyHeader);
}
示例4: TransactionOutput
internal TransactionOutput(NetworkParameters @params, Transaction parent, ulong value, Address to)
: base(@params)
{
_value = value;
_scriptBytes = Script.CreateOutputScript(to);
ParentTransaction = parent;
_availableForSpending = true;
}
示例5: Transaction
internal Transaction(NetworkParameters @params)
: base(@params)
{
_version = 1;
_inputs = new List<TransactionInput>();
_outputs = new List<TransactionOutput>();
// We don't initialize appearsIn deliberately as it's only useful for transactions stored in the wallet.
}
示例6: TransactionInput
/// <summary>
/// Used only in creation of the genesis block.
/// </summary>
internal TransactionInput(NetworkParameters @params, Transaction parentTransaction, byte[] scriptBytes)
: base(@params)
{
ScriptBytes = scriptBytes;
Outpoint = new TransactionOutPoint(@params, -1, null);
_sequence = uint.MaxValue;
ParentTransaction = parentTransaction;
}
示例7: NetworkConnection
/// <summary>
/// Connect to the given IP address using the port specified as part of the network parameters. Once construction
/// is complete a functioning network channel is set up and running.
/// </summary>
/// <param name="peerAddress">IP address to connect to. IPv6 is not currently supported by BitCoin. If port is not positive the default port from params is used.</param>
/// <param name="params">Defines which network to connect to and details of the protocol.</param>
/// <param name="bestHeight">How many blocks are in our best chain</param>
/// <param name="connectTimeout">Timeout in milliseconds when initially connecting to peer</param>
/// <exception cref="IOException">If there is a network related failure.</exception>
/// <exception cref="ProtocolException">If the version negotiation failed.</exception>
public NetworkConnection(PeerAddress peerAddress, NetworkParameters @params, uint bestHeight, int connectTimeout)
{
_params = @params;
_remoteIp = peerAddress.Addr;
var port = (peerAddress.Port > 0) ? peerAddress.Port : @params.Port;
var address = new IPEndPoint(_remoteIp, port);
_socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
_socket.Connect(address);
_socket.SendTimeout = _socket.ReceiveTimeout = connectTimeout;
_out = new NetworkStream(_socket, FileAccess.Write);
_in = new NetworkStream(_socket, FileAccess.Read);
// the version message never uses check-summing. Update check-summing property after version is read.
_serializer = new BitcoinSerializer(@params, false);
// Announce ourselves. This has to come first to connect to clients beyond v0.30.20.2 which wait to hear
// from us until they send their version message back.
WriteMessage(new VersionMessage(@params, bestHeight));
// When connecting, the remote peer sends us a version message with various bits of
// useful data in it. We need to know the peer protocol version before we can talk to it.
_versionMessage = (VersionMessage) ReadMessage();
// Now it's our turn ...
// Send an ACK message stating we accept the peers protocol version.
WriteMessage(new VersionAck());
// And get one back ...
ReadMessage();
// Switch to the new protocol version.
var peerVersion = _versionMessage.ClientVersion;
_log.InfoFormat("Connected to peer: version={0}, subVer='{1}', services=0x{2:X}, time={3}, blocks={4}",
peerVersion,
_versionMessage.SubVer,
_versionMessage.LocalServices,
UnixTime.FromUnixTime(_versionMessage.Time),
_versionMessage.BestHeight
);
// BitCoinSharp is a client mode implementation. That means there's not much point in us talking to other client
// mode nodes because we can't download the data from them we need to find/verify transactions.
if (!_versionMessage.HasBlockChain())
{
// Shut down the socket
try
{
Shutdown();
}
catch (IOException)
{
// ignore exceptions while aborting
}
throw new ProtocolException("Peer does not have a copy of the block chain.");
}
// newer clients use check-summing
_serializer.UseChecksumming(peerVersion >= 209);
// Handshake is done!
}
示例8: MemoryBlockStore
public MemoryBlockStore(NetworkParameters @params)
{
_blockMap = new Dictionary<ByteBuffer, byte[]>();
// Insert the genesis block.
var genesisHeader = @params.GenesisBlock.CloneAsHeader();
var storedGenesis = new StoredBlock(genesisHeader, genesisHeader.GetWork(), 0);
Put(storedGenesis);
SetChainHead(storedGenesis);
}
示例9: Wallet
/// <summary>
/// Creates a new, empty wallet with no keys and no transactions. If you want to restore a wallet from disk instead,
/// see loadFromFile.
/// </summary>
public Wallet(NetworkParameters @params)
{
_params = @params;
Keychain = new List<EcKey>();
Unspent = new Dictionary<Sha256Hash, Transaction>();
Spent = new Dictionary<Sha256Hash, Transaction>();
_inactive = new Dictionary<Sha256Hash, Transaction>();
Pending = new Dictionary<Sha256Hash, Transaction>();
_dead = new Dictionary<Sha256Hash, Transaction>();
}
示例10: VersionMessage
public VersionMessage(NetworkParameters @params, uint newBestHeight)
: base(@params)
{
ClientVersion = NetworkParameters.ProtocolVersion;
LocalServices = 0;
Time = UnixTime.ToUnixTime(DateTime.UtcNow);
// Note that the official client doesn't do anything with these, and finding out your own external IP address
// is kind of tricky anyway, so we just put nonsense here for now.
MyAddr = new PeerAddress(IPAddress.Loopback, @params.Port, 0);
TheirAddr = new PeerAddress(IPAddress.Loopback, @params.Port, 0);
SubVer = "BitCoinSharp 0.1";
BestHeight = newBestHeight;
}
示例11: BoundedOverheadBlockStore
/// <exception cref="BitCoinSharp.BlockStoreException" />
public BoundedOverheadBlockStore(NetworkParameters @params, FileInfo file)
{
_params = @params;
_notFoundMarker = new StoredBlock(null, null, uint.MaxValue);
try
{
Load(file);
}
catch (IOException e)
{
_log.Error("failed to load block store from file", e);
CreateNewStore(@params, file);
}
}
示例12: TransactionOutPoint
internal TransactionOutPoint(NetworkParameters @params, int index, Transaction fromTx)
: base(@params)
{
Index = index;
if (fromTx != null)
{
Hash = fromTx.Hash;
FromTx = fromTx;
}
else
{
// This happens when constructing the genesis block.
Hash = Sha256Hash.ZeroHash;
}
}
示例13: DiskBlockStore
/// <exception cref="BitCoinSharp.BlockStoreException" />
public DiskBlockStore(NetworkParameters @params, FileInfo file)
{
_params = @params;
_blockMap = new Dictionary<Sha256Hash, StoredBlock>();
try
{
Load(file);
if (_stream != null)
{
_stream.Dispose();
}
_stream = file.Open(FileMode.Append, FileAccess.Write); // Do append.
}
catch (IOException e)
{
_log.Error("failed to load block store from file", e);
CreateNewStore(@params, file);
}
}
示例14: Message
/// <exception cref="ProtocolException"/>
internal Message(NetworkParameters @params, byte[] msg, int offset, uint protocolVersion = NetworkParameters.ProtocolVersion)
{
ProtocolVersion = protocolVersion;
Params = @params;
Bytes = msg;
Cursor = Offset = offset;
Parse();
#if SELF_CHECK
// Useful to ensure serialize/deserialize are consistent with each other.
if (GetType() != typeof (VersionMessage))
{
var msgbytes = new byte[Cursor - offset];
Array.Copy(msg, offset, msgbytes, 0, Cursor - offset);
var reserialized = BitcoinSerialize();
if (!reserialized.SequenceEqual(msgbytes))
throw new Exception("Serialization is wrong: " + Environment.NewLine +
Utils.BytesToHexString(reserialized) + " vs " + Environment.NewLine +
Utils.BytesToHexString(msgbytes));
}
#endif
Bytes = null;
}
示例15: ListMessage
public ListMessage(NetworkParameters @params)
: base(@params)
{
_items = new List<InventoryItem>();
}