private Models.Messages.BuyInResponse BuyIn(Models.Messages.BuyInRequest request) { var table = this.TableRepo.Find(request.TableId); if (table != null) { NBitcoin.Transaction tx = new NBitcoin.Transaction(); NBitcoin.TransactionBuilder builder = new NBitcoin.TransactionBuilder(); Boolean isValid = true; // builder.Verify(tx); if (isValid) { var utxos = tx.Outputs; var sum = tx.Outputs.Sum(u => u.Value); } else { throw new Exception(); } } else { throw new ArgumentException("Table id not found"); } return(new Models.Messages.BuyInResponse()); }
public void BuyIn(Models.Messages.BuyInRequest buyIn) { using (HttpClient httpClient = new HttpClient()) { //String json = Newtonsoft.Json.JsonConvert.SerializeObject //var json = httpClient.PostAsync(String.Format("{0}players", _apiUrl)).Result; //IEnumerable<BitPoker.Models.PlayerInfo> result = JsonConvert.DeserializeObject<IEnumerable<BitPoker.Models.PlayerInfo>>(json); //return result; } }
public void Should_Buy_In_To_Joined_Table() { //BitcoinSecret secret = new BitcoinSecret("91xCHwaMdufE8fmxachVhU12wdTjY7nGbZeGgjx4JQSuSDNizhf", Network.TestNet); //controller.TableRepo = new Repository.MockTableRepo(); ////"2NAxESoeuyA4KqudU3v9fh5idiBorgLpkUj"; //BitcoinScriptAddress tableAddress = new BitcoinScriptAddress("2NAxESoeuyA4KqudU3v9fh5idiBorgLpkUj", Network.TestNet); //BlockrTransactionRepository repo = new BlockrTransactionRepository(Network.TestNet); //BitcoinAddress myAddress = BitcoinAddress.Create("mypckwJUPVMi8z1kdSCU46hUY9qVQSrZWt", Network.TestNet); ////TODO: MAKE A JSON OBJECT ////var utxos = await repo.GetUnspentAsync(myAddress.ToString()); ////Coin[] coins = utxos.OrderByDescending(u => u.Amount).Select(u => new Coin(u.Outpoint, u.TxOut)).ToArray(); ////Money minersFee = new Money(50000); ////var txBuilder = new TransactionBuilder(); ////var tx = txBuilder //// //.AddCoins(coins) //// .AddCoins(utxos) //// .AddKeys(secret) //// .Send(tableAddress, new Money(100000)) //// .SendFees(minersFee) //// .SetChange(myAddress) //// .BuildTransaction(true); ////Debug.Assert(txBuilder.Verify(tx)); //check fully signed Models.Messages.BuyInRequest request = new Models.Messages.BuyInRequest() { BitcoinAddress = "mypckwJUPVMi8z1kdSCU46hUY9qVQSrZWt", TableId = new Guid(TABLE_ID), TimeStamp = new DateTime(2016, 12, 12) //, //TxID = "af651c3435b5a11a8d7792dbc1d20a20a23fce0beb0b6931bf0ce407bfd28a0a" }; //var response = _controller.BuyIn(request); //Assert.IsNotNull(response); //Assert.IsNull(response.Error); //Assert.AreEqual(response.Id.ToString(), REQUEST_ID); //Models.Messages.BuyInResponse buyInResponse = response.Result as Models.Messages.BuyInResponse; //Assert.IsNotNull(buyInResponse); }
public Models.Messages.BuyInResponse Post(Models.Messages.BuyInRequest request) { var table = this.TableRepo.Find(request.TableId); if (table != null) { //var peer = this.PeersRepo.All().First(p => p.BitcoinAddress == request.BitcoinAddress); //if (peer != null) //{ Boolean isValid = base.ValidateTx(request.Tx); if (isValid) { //var utxos = tx.Outputs; //var sum = tx.Outputs.Sum(u => u.Value); //NBitcoin.PubKey tablePubkey = new NBitcoin.PubKey(table.PublicKey); //NBitcoin.PubKey requestPubKey = new NBitcoin.PubKey(peer.PublicKey); //Useful to check msig //curl -d '{"pubkeys": ["02c716d071a76cbf0d29c29cacfec76e0ef8116b37389fb7a3e76d6d32cf59f4d3", "033ef4d5165637d99b673bcdbb7ead359cee6afd7aaf78d3da9d2392ee4102c8ea", "022b8934cc41e76cb4286b9f3ed57e2d27798395b04dd23711981a77dc216df8ca"], "script_type": "multisig-2-of-3"}' https://api.blockcypher.com/v1/btc/main/addr //NBitcoin.Script tableRedeemScript = NBitcoin.PayToMultiSigTemplate.Instance.GenerateScriptPubKey(2, new NBitcoin.PubKey[] { tablePubkey, requestPubKey }); return(new Models.Messages.BuyInResponse() { Id = request.Id, TimeStamp = DateTime.UtcNow //RedeemScript = tableRedeemScript.ToString() }); } else { throw new Exception(); } //} //else //{ // throw new ArgumentException("Peer not found or not seated"); //} } else { throw new ArgumentException("Table id not found"); } }
public void Should_Buy_In_For_Minimum() { BitPoker.Controllers.Rest.BuyInController controller = new Rest.BuyInController(); controller.TableRepo = new BitPoker.Repository.Mocks.TableRepository(); controller.Network = NBitcoin.Network.TestNet; BitPoker.Models.Messages.BuyInRequest request = new Models.Messages.BuyInRequest() { BitcoinAddress = "2MtFGSjUn1FLhwgyf7gAaX3n1wCg29B4wvh", TableId = new Guid("bf368921-346a-42d8-9cb8-621f9cad5e16") }; var actual = controller.Post(request); BitPoker.Models.Messages.BuyInResponse expected = new Models.Messages.BuyInResponse(); Assert.AreEqual(expected, actual); }