/// <summary> /// Parses the given private key as created by the "dumpprivkey" BitCoin C++ RPC. /// </summary> /// <param name="networkParams">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="AddressFormatException">If the string is invalid or the header byte doesn't match the network params.</exception> public DumpedPrivateKey(NetworkParameters networkParams, string encoded) : base(encoded) { if (networkParams != null && Version != networkParams.DumpedPrivateKeyHeader) throw new AddressFormatException("Mismatched version number, trying to cross networks? " + Version + " vs " + networkParams.DumpedPrivateKeyHeader); }
/// <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 networkParams, string address) : base(address) { if (Version != networkParams.AddressHeader) throw new AddressFormatException("Mismatched version number, trying to cross networks? " + Version + " vs " + networkParams.AddressHeader); }
/// <summary> /// Used only in creation of the genesis block. /// </summary> internal TransactionInput(NetworkParameters networkParams, Transaction parentTransaction, byte[] scriptBytes) : base(networkParams) { ScriptBytes = scriptBytes; Outpoint = new TransactionOutPoint(networkParams, -1, null); _sequence = uint.MaxValue; ParentTransaction = parentTransaction; }
internal TransactionOutput(NetworkParameters networkParams, Transaction parent, ulong value, Address to) : base(networkParams) { _value = value; _scriptBytes = Script.CreateOutputScript(to); ParentTransaction = parent; _availableForSpending = true; }
/// <summary> /// Used only in creation of the genesis blocks and in unit tests. /// </summary> internal TransactionOutput(NetworkParameters networkParams, Transaction parent, byte[] scriptBytes) : base(networkParams) { _scriptBytes = scriptBytes; _value = Utils.ToNanoCoins(50, 0); ParentTransaction = parent; _availableForSpending = true; }
internal Transaction(NetworkParameters networkParams) : base(networkParams) { _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. }
/// <summary> /// Creates an UNSIGNED input that links to the given output /// </summary> internal TransactionInput(NetworkParameters networkParams, Transaction parentTransaction, TransactionOutput output) : base(networkParams) { var outputIndex = output.Index; Outpoint = new TransactionOutPoint(networkParams, outputIndex, output.ParentTransaction); ScriptBytes = EmptyArray; _sequence = uint.MaxValue; ParentTransaction = parentTransaction; }
/// <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 networkParams) { _params = networkParams; 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>(); }
public VersionMessage(NetworkParameters networkParams, uint newBestHeight) : base(networkParams) { 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, networkParams.Port, 0); TheirAddr = new PeerAddress(IPAddress.Loopback, networkParams.Port, 0); SubVer = "BitCoinSharp 0.3-SNAPSHOT"; BestHeight = newBestHeight; }
internal TransactionOutPoint(NetworkParameters networkParams, int index, Transaction fromTx) : base(networkParams) { Index = index; if (fromTx != null) { Hash = fromTx.Hash; FromTx = fromTx; } else { // This happens when constructing the genesis block. Hash = Sha256Hash.ZeroHash; } }
/// <exception cref="ProtocolException"/> internal Message(NetworkParameters networkParams, byte[] msg, int offset, uint protocolVersion = NetworkParameters.ProtocolVersion) { ProtocolVersion = protocolVersion; Params = networkParams; 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; }
/// <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="networkParams">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 networkParams, uint bestHeight, int connectTimeout) { _params = networkParams; remoteIp = peerAddress.Addr; var port = (peerAddress.Port > 0) ? peerAddress.Port : networkParams.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(networkParams, true); // SDL: Checksuming now ALWAYS necessary versionMessage = Handshake(networkParams, bestHeight); // newer clients use check-summing serializer.UseChecksumming(versionMessage.ClientVersion >= 209); // Handshake is done! }
/// <exception cref="ProtocolException"/> protected ListMessage(NetworkParameters networkParams, byte[] bytes) : base(networkParams, bytes, 0) { }
internal Message(NetworkParameters networkParams) { Params = networkParams; }
/// <exception cref="ProtocolException"/> internal AddressMessage(NetworkParameters networkParams, byte[] payload) : base(networkParams, payload, 0) { }
/// <summary> /// Special case constructor, used for the genesis node, cloneAsHeader and unit tests. /// </summary> internal Block(NetworkParameters networkParams) : base(networkParams) { // Set up a few basic things. We are not complete after this though. _version = 1; _difficultyTarget = 0x1d07fff8; _time = (uint) UnixTime.ToUnixTime(DateTime.UtcNow); _prevBlockHash = Sha256Hash.ZeroHash; }
/// <summary> /// Deserializes the message. This is usually part of a transaction message. /// </summary> /// <exception cref="ProtocolException"/> public TransactionOutPoint(NetworkParameters networkParams, byte[] payload, int offset) : base(networkParams, payload, offset) { }
/// <summary> /// Deserializes a transaction output message. This is usually part of a transaction message. /// </summary> /// <exception cref="ProtocolException"/> public TransactionOutput(NetworkParameters networkParams, Transaction parent, byte[] payload, int offset) : base(networkParams, payload, offset) { ParentTransaction = parent; _availableForSpending = true; }
/// <summary> /// Construct a peer that handles the given network connection and reads/writes from the given block chain. Note that /// communication won't occur until you call connect(). /// </summary> public Peer(NetworkParameters networkParams, PeerAddress address, BlockChain blockChain) : this(networkParams, address, 0, blockChain) { }
/// <summary> /// Constructs a BlockChain connected to the given list of wallets and a store. /// </summary> /// <exception cref="BlockStoreException"/> public BlockChain(NetworkParameters networkParams, IEnumerable<Wallet> wallets, IBlockStore blockStore) { _blockStore = blockStore; _chainHead = blockStore.GetChainHead(); Log.InfoFormat("chain head is:{0}{1}", Environment.NewLine, _chainHead.Header); _params = networkParams; _wallets = new List<Wallet>(wallets); }
internal Message(NetworkParameters networkParams) { Params = networkParams; }
/// <summary> /// Constructs a BlockChain that has no wallet at all. This is helpful when you don't actually care about sending /// and receiving coins but rather, just want to explore the network data structures. /// </summary> /// <exception cref="BlockStoreException"/> public BlockChain(NetworkParameters networkParams, IBlockStore blockStore) : this(networkParams, new List<Wallet>(), blockStore) { }
public GetBlocksMessage(NetworkParameters networkParams, IList<Sha256Hash> locator, Sha256Hash stopHash) : base(networkParams) { _locator = locator; _stopHash = stopHash; }
/// <summary> /// Construct a peer address from a serialized payload. /// </summary> /// <exception cref="ProtocolException"/> public PeerAddress(NetworkParameters networkParams, byte[] payload, int offset, uint protocolVersion) : base(networkParams, payload, offset, protocolVersion) { }
protected ListMessage(NetworkParameters networkParams) : base(networkParams) { _items = new List<InventoryItem>(); }
/// <summary> /// Returns the address that corresponds to the public part of this ECKey. Note that an address is derived from /// the RIPEMD-160 hash of the public key and is not the public key itself (which is too large to be convenient). /// </summary> public Address ToAddress(NetworkParameters networkParams) { var hash160 = Utils.Sha256Hash160(_pub); return(new Address(networkParams, hash160)); }
/// <summary> /// Construct a peer that handles the given network connection and reads/writes from the given block chain. Note that /// communication won't occur until you call Connect(). /// </summary> /// <param name="bestHeight">Our current best chain height, to facilitate downloading.</param> public Peer(NetworkParameters networkParams, PeerAddress address, uint bestHeight, BlockChain blockChain) { _params = networkParams; _address = address; _bestHeight = bestHeight; _blockChain = blockChain; _pendingGetBlockFutures = new List<GetDataFuture<Block>>(); }
/// <exception cref="ProtocolException"/> public UnknownMessage(NetworkParameters networkParams, string name, byte[] payloadBytes) : base(networkParams, payloadBytes, 0) { _name = name; }
/// <summary> /// Deserializes a transaction output message. This is usually part of a transaction message. /// </summary> /// <exception cref="ProtocolException"/> public TransactionOutput(NetworkParameters networkParams, Transaction parent, byte[] payload, int offset) : base(networkParams, payload, offset) { ParentTransaction = parent; _availableForSpending = true; }
/// <summary> /// Constructs a BitcoinSerializer with the given behavior. /// </summary> /// <param name="networkParams">MetworkParams used to create Messages instances and determining packetMagic</param> /// <param name="usesChecksumming">Set to true if checksums should be included and expected in headers</param> public BitcoinSerializer(NetworkParameters networkParams, bool usesChecksumming) { _params = networkParams; _usesChecksumming = usesChecksumming; }
/// <exception cref="ProtocolException"/> public VersionMessage(NetworkParameters networkParams, byte[] msg) : base(networkParams, msg, 0) { }
/// <exception cref="ProtocolException"/> internal AddressMessage(NetworkParameters networkParams, byte[] payload, int offset) : base(networkParams, payload, offset) { }
/// <summary> /// Constructs a BlockChain connected to the given wallet and store. To obtain a <see cref="Wallet"/> you can construct /// one from scratch, or you can deserialize a saved wallet from disk using <see cref="Wallet.LoadFromFile"/>. /// </summary> /// <remarks> /// For the store you can use a <see cref="MemoryBlockStore"/> if you don't care about saving the downloaded data, or a /// <see cref="BoundedOverheadBlockStore"/> if you'd like to ensure fast start-up the next time you run the program. /// </remarks> /// <exception cref="BlockStoreException"/> public BlockChain(NetworkParameters networkParams, Wallet wallet, IBlockStore blockStore) : this(networkParams, new List<Wallet>(), blockStore) { if (wallet != null) AddWallet(wallet); }
/// <summary> /// Exports the private key in the form used by the Satoshi client "dumpprivkey" and "importprivkey" commands. Use /// the <see cref="DumpedPrivateKey.ToString"/> method to get the string. /// </summary> /// <param name="networkParams">The network this key is intended for use on.</param> /// <returns>Private key bytes as a <see cref="DumpedPrivateKey"/>.</returns> public DumpedPrivateKey GetPrivateKeyEncoded(NetworkParameters networkParams) { return(new DumpedPrivateKey(networkParams, GetPrivKeyBytes())); }
/// <exception cref="ProtocolException"/> public VersionMessage(NetworkParameters networkParams, byte[] msg) : base(networkParams, msg, 0) { }
/// <summary> /// Construct a peer address from a serialized payload. /// </summary> /// <exception cref="ProtocolException"/> public PeerAddress(NetworkParameters networkParams, byte[] payload, int offset, uint protocolVersion) : base(networkParams, payload, offset, protocolVersion) { }