public async Task <ISegwitPrivateWallet> CreateSegwitWallet(PubKey pubKey, string clientPubKey = null) { var segwitAddress = pubKey.WitHash.ScriptPubKey.Hash.GetAddress(_connectionParams.Network); return(await _segwitPrivateWalletRepository.AddSegwitPrivateWallet(clientPubKey, segwitAddress.ToString(), pubKey.ToString(), pubKey.WitHash.ScriptPubKey.ToString())); }
private void AddInputs(Transaction transaction, PubKey pubKey, List <Coin> coins, ref int index, Money money) { Money spentMoney = Money.Zero; for (int i = 0; i < coins.Count; i++) { transaction.AddInput(new TxIn(coins[i].Outpoint)); transaction.Inputs[i + index].ScriptSig = new Script(pubKey.ToString()); spentMoney += coins[i].Amount; if (spentMoney >= money) { if (spentMoney - money > 0) { transaction.AddOutput(spentMoney - money, pubKey.ScriptPubKey); } index = i + 1; return; } } index = coins.Count; }
public virtual JObject ToJson() { var json = new JObject(); json["pubKey"] = PubKey.ToString(); json["signature"] = Signature.ToHexString(); return(json); }
public async Task <List <ChannelResponse> > Channels(PubKey nodeId = null, CancellationToken cts = default(CancellationToken)) { return(await SendCommandAsync <ChannelsRequest, List <ChannelResponse> >("channels", new ChannelsRequest() { NodeId = nodeId?.ToString() }, cts)); }
public virtual JObject ToJson() { var json = new JObject(); json["pubKey"] = PubKey.ToString(); json["signature"] = Convert.ToBase64String(Signature); return(json); }
public async Task <string> Connect(PubKey nodeId, string host, int?port = null, CancellationToken cts = default(CancellationToken)) { return(await SendCommandAsync <ConnectManualRequest, string>("connect", new ConnectManualRequest() { Host = host, Port = port, NodeId = nodeId.ToString() }, cts)); }
public async Task <List <string> > FindRouteToNode(PubKey nodeId, int amountMsat, CancellationToken cts = default(CancellationToken)) { return(await SendCommandAsync <FindRouteToNodeRequest, List <string> >("findroutetonode", new FindRouteToNodeRequest() { NodeId = nodeId.ToString(), AmountMsat = amountMsat }, cts)); }
public async Task <ConnectResponse> Connect(PubKey nodeId, string peerAddr, int?peerPort = null, CancellationToken cts = default(CancellationToken)) { return(await SendCommandAsync <ConnectRequest, ConnectResponse>("connect", new ConnectRequest() { PeerNodeId = nodeId.ToString(), PeerAddr = peerAddr, PeerPort = peerPort, }, cts)); }
public async Task <string> SendToNode(PubKey nodeId, int amountMsat, string paymentHash, int?maxAttempts = null, CancellationToken cts = default(CancellationToken)) { return(await SendCommandAsync <SendToNodeRequest, string>("sendtonode", new SendToNodeRequest() { NodeId = nodeId.ToString(), AmountMsat = amountMsat, PaymentHash = paymentHash, MaxAttempts = maxAttempts }, cts)); }
public async Task <OpenResponse> OpenChannel(PubKey nodeId, long fundingSat = 0, int pushMsat = 0, long feeratePerKw = 0, CancellationToken cts = default(CancellationToken)) { return(await SendCommandAsync <OpenRequest, OpenResponse>("openchannel", new OpenRequest() { PeerNodeId = nodeId.ToString(), FundingSat = fundingSat, PushMsat = pushMsat, FeeratePerKw = feeratePerKw, }, cts)); }
public async Task <string> Open(PubKey nodeId, long fundingSatoshis, int?pushMsat = null, long?fundingFeerateSatByte = null, ChannelFlags?channelFlags = null, CancellationToken cts = default(CancellationToken)) { return(await SendCommandAsync <OpenRequest, string>("open", new OpenRequest() { NodeId = nodeId.ToString(), FundingSatoshis = fundingSatoshis, ChannelFlags = channelFlags, PushMsat = pushMsat, FundingFeerateSatByte = fundingFeerateSatByte }, cts)); }
public static string generateAddress() { // Currently we get PrivateKey and PubKey and Wif from the NBitcoin library. Haven't written my own code yet. // https://github.com/MetacoSA/NBitcoin (available from the Nu-Get package manager) Key privateKey = new Key(); // generate a random private key BitcoinSecret wif = privateKey.GetWif(Network.Main); PubKey pubKey = privateKey.PubKey; string publicKey = pubKey.ToString(); //"03c18bc24ea4b6e1fc08c356f436d9ffaca4f583c0adc0c83a36b3a1b3abeef762"; //Console.WriteLine("Publickey: " + publicKey); //var hash = getHashSha256(publicKeyHex); var hash = getHash("sha256", publicKey); //Console.WriteLine("hash:" + hash); //Console.ReadLine(); //RIPEMD160 r = RIPEMD160Managed.Create("SHA256"); string hashed = getHash("ripemd160", hash); //Console.WriteLine("hashed:" + hashed); hashed = "3c" + hashed; //Console.WriteLine("<hashed:" + hashed); //Console.ReadLine(); string newhash1 = getHash("sha256", hashed); string newhash2 = getHash("sha256", newhash1); string checksum = newhash2.Substring(0, 8); // 4 hex-bytes = 8 characters //Console.WriteLine("first hash256: " + newhash1); //Console.WriteLine("2nd hash256: " + newhash2); //Console.WriteLine("Checksum: " + checksum); //Console.ReadLine(); string withChecksum = hashed + checksum; string address = ConvertToBase58(withChecksum); //Console.WriteLine(address); //var r = ripemd160(Crypto.SHA256(Crypto.util.hexToBytes(h), { asBytes: true})); //r.unshift(byte || coinjs.pub); //var hash = Crypto.SHA256(Crypto.SHA256(r, { asBytes: true}), { asBytes: true}); //var checksum = hash.slice(0, 4); //return coinjs.base58encode(r.concat(checksum)) return(wif + "," + privateKey.ToHex() + "," + pubKey.Decompress().ToString() + "," + address + "\n"); }
public static KeyInfo GenerateKey(string password, string hrp) { Mnemonic mnemonic = new Mnemonic(Wordlist.English, WordCount.TwentyFour); ExtKey extKey = mnemonic.DeriveExtKey(password); Key privateKey = extKey.PrivateKey; PubKey publicKey = privateKey.PubKey; string address = GetAddress(publicKey.Hash.ToBytes(), hrp); KeyInfo keyInfo = new KeyInfo(); keyInfo.Mnemonic = mnemonic.ToString(); keyInfo.PrivateKey = EncodeUtils.BytesToHex(privateKey.ToBytes()).ToLower(); keyInfo.PublicKey = publicKey.ToString(); keyInfo.Address = address; return(keyInfo); }
public static KeyInformation GenerateKey(string password, string hrp) { Mnemonic mnemonic = new Mnemonic(Wordlist.English, WordCount.TwentyFour); ExtKey extKey = mnemonic.DeriveExtKey(password); Key privateKey = extKey.PrivateKey; PubKey publicKey = privateKey.PubKey; string address = GetAddress(publicKey.Hash.ToBytes(), hrp); KeyInformation keyInformation = new KeyInformation { Address = address, Mnemonic = mnemonic.ToString(), PrivateKey = privateKey.ToBytes().ToHexString(), PublicKey = publicKey.ToString() }; return(keyInformation); }
public static KeyInformation GetKeyFromMnemonic(string mnenonicWords, string password, string hrp) { Mnemonic mnemonic = new Mnemonic(mnenonicWords, Wordlist.English); ExtKey key = new ExtKey(mnemonic.DeriveSeed(password)); ExtKey extKey = key.Derive(new KeyPath("m/44'/714'/0'/0/0")); Key privateKey = extKey.PrivateKey; PubKey publicKey = privateKey.PubKey; string address = GetAddress(publicKey.Hash.ToBytes(), hrp); KeyInformation keyInformation = new KeyInformation { Address = address, Mnemonic = mnemonic.ToString(), PrivateKey = privateKey.ToBytes().ToHexString(), PublicKey = publicKey.ToString() }; return(keyInformation); }
private void AddComponentStats(StringBuilder log) { log.AppendLine(">> Miner"); if (this.ibdState.IsInitialBlockDownload()) { log.AppendLine("Mining information is not available whilst the node is syncing."); log.AppendLine("The node will mine once it reaches the network's height."); log.AppendLine(); return; } ChainedHeader tip = this.consensusManager.Tip; ChainedHeader currentHeader = tip; int pubKeyTakeCharacters = 5; int hitCount = 0; // If the node is in DevMode just use the genesis members via the federation manager. List <IFederationMember> modifiedFederation; if (this.nodeSettings.DevMode != null) { modifiedFederation = this.federationManager.GetFederationMembers(); } else { modifiedFederation = this.votingManager?.GetModifiedFederation(currentHeader) ?? this.federationManager.GetFederationMembers(); } int maxDepth = modifiedFederation.Count; log.AppendLine($"Mining information for the last { maxDepth } blocks."); log.AppendLine("Note that '<' and '>' surrounds a slot where a miner didn't produce a block."); uint timeHeader = (uint)this.dateTimeProvider.GetAdjustedTimeAsUnixTimestamp(); timeHeader -= timeHeader % this.network.ConsensusOptions.TargetSpacingSeconds; if (timeHeader < currentHeader.Header.Time) { timeHeader += this.network.ConsensusOptions.TargetSpacingSeconds; } // Iterate mining slots. for (int i = 0; i < maxDepth; i++) { int headerSlot = (int)(timeHeader / this.network.ConsensusOptions.TargetSpacingSeconds) % modifiedFederation.Count; PubKey pubKey = modifiedFederation[headerSlot].PubKey; string pubKeyRepresentation = (pubKey == this.federationManager.CurrentFederationKey?.PubKey) ? "█████" : pubKey.ToString().Substring(0, pubKeyTakeCharacters); // Mined in this slot? if (timeHeader == currentHeader.Header.Time) { log.Append($"[{ pubKeyRepresentation }] "); currentHeader = currentHeader.Previous; hitCount++; if (this.nodeSettings.DevMode != null) { modifiedFederation = this.federationManager.GetFederationMembers(); } else { modifiedFederation = this.votingManager?.GetModifiedFederation(currentHeader) ?? this.federationManager.GetFederationMembers(); } } else { log.Append($"<{ pubKeyRepresentation }> "); } timeHeader -= this.network.ConsensusOptions.TargetSpacingSeconds; if ((i % 20) == 19) { log.AppendLine(); } } log.Append("..."); log.AppendLine(); log.AppendLine($"Miner hits".PadRight(LoggingConfiguration.ColumnLength) + $": {hitCount} of {maxDepth}({(((float)hitCount / (float)maxDepth)).ToString("P2")})"); log.AppendLine($"Miner idle time".PadRight(LoggingConfiguration.ColumnLength) + $": { TimeSpan.FromSeconds(this.network.ConsensusOptions.TargetSpacingSeconds * (maxDepth - hitCount)).ToString(@"hh\:mm\:ss")}"); log.AppendLine(); }
private void AddComponentStats(StringBuilder log) { log.AppendLine(); log.AppendLine("======PoA Miner======"); if (this.ibdState.IsInitialBlockDownload()) { log.AppendLine($"Mining information is not available during IBD."); log.AppendLine(); return; } ChainedHeader tip = this.consensusManager.Tip; ChainedHeader currentHeader = tip; int pubKeyTakeCharacters = 5; int hitCount = 0; List <IFederationMember> modifiedFederation = this.votingManager?.GetModifiedFederation(currentHeader) ?? this.federationManager.GetFederationMembers(); int maxDepth = modifiedFederation.Count; log.AppendLine($"Mining information for the last { maxDepth } blocks."); log.AppendLine("Note that '<' and '>' surrounds a slot where a miner didn't produce a block."); uint timeHeader = (uint)this.dateTimeProvider.GetAdjustedTimeAsUnixTimestamp(); timeHeader -= timeHeader % this.network.ConsensusOptions.TargetSpacingSeconds; if (timeHeader < currentHeader.Header.Time) { timeHeader += this.network.ConsensusOptions.TargetSpacingSeconds; } // Iterate mining slots. for (int i = 0; i < maxDepth; i++) { int headerSlot = (int)(timeHeader / this.network.ConsensusOptions.TargetSpacingSeconds) % modifiedFederation.Count; PubKey pubKey = modifiedFederation[headerSlot].PubKey; string pubKeyRepresentation = (pubKey == this.federationManager.CurrentFederationKey?.PubKey) ? "█████" : pubKey.ToString().Substring(0, pubKeyTakeCharacters); // Mined in this slot? if (timeHeader == currentHeader.Header.Time) { log.Append($"[{ pubKeyRepresentation }] "); currentHeader = currentHeader.Previous; hitCount++; modifiedFederation = this.votingManager?.GetModifiedFederation(currentHeader) ?? this.federationManager.GetFederationMembers(); } else { log.Append($"<{ pubKeyRepresentation }> "); } timeHeader -= this.network.ConsensusOptions.TargetSpacingSeconds; if ((i % 20) == 19) { log.AppendLine(); } } log.Append("..."); log.AppendLine(); log.AppendLine($"Block producers hits : {hitCount} of {maxDepth}({(((float)hitCount / (float)maxDepth)).ToString("P2")})"); log.AppendLine($"Block producers idle time : {TimeSpan.FromSeconds(this.network.ConsensusOptions.TargetSpacingSeconds * (maxDepth - hitCount)).ToString(@"hh\:mm\:ss")}"); log.AppendLine(); }