void Sample_04_02(QBitNinja.Client.Models.GetTransactionResponse transactionResponse, NBitcoin.Network network) { Debug.Log(transactionResponse.IsCoinbase); Money spentAmount = Money.Zero; foreach (var spentCoin in transactionResponse_04_01.SpentCoins) { spentAmount = (Money)spentCoin.Amount.Add(spentAmount); } Debug.Log(spentAmount.ToDecimal(MoneyUnit.BTC)); var fee = transactionResponse_04_01.Transaction.GetFee(transactionResponse_04_01.SpentCoins.ToArray()); Debug.Log(fee); }
void Sample_04_01(QBitNinja.Client.Models.GetTransactionResponse transactionResponse, NBitcoin.Network network) { /* * Debug.Log("----------------------------------------------------------------"); * * Debug.Log("transactionId : " + transactionResponse.TransactionId); // "f13dc48fb035bbf0a6e989a26b3ecb57b84f85e0836e777d6edf60d87a4a2d94" * Debug.Log("transactionId : " + transactionResponse.Transaction.GetHash()); * * Debug.Log("----------------------------------------------------------------"); * var recivedCoins = transactionResponse.ReceivedCoins; * * Debug.Log("RecivedCoins"); * foreach (var coin in recivedCoins) * { * Script paymentScript = coin.TxOut.ScriptPubKey; * BitcoinAddress destination = paymentScript.GetDestinationAddress(network); * Money amount = (Money)coin.Amount; * * Debug.Log(paymentScript); * Debug.Log(destination); * Debug.Log(amount.ToDecimal(MoneyUnit.BTC)); * } * * Debug.Log("----------------------------------------------------------------"); * Debug.Log("Out"); * TxOutList outPutList = transactionResponse.Transaction.Outputs; * foreach (TxOut output in outPutList) * { * Script paymentScript = output.ScriptPubKey; * BitcoinAddress destination = paymentScript.GetDestinationAddress(network); * Money amount = output.Value; * * Debug.Log(paymentScript); * Debug.Log(destination); * Debug.Log(amount.ToDecimal(MoneyUnit.BTC)); * } * * Debug.Log("----------------------------------------------------------------"); * Debug.Log("In"); * TxInList inList = transactionResponse.Transaction.Inputs; * foreach (TxIn input in inList) * { * OutPoint previousOutPoint = input.PrevOut; * Debug.Log(previousOutPoint.Hash); * Debug.Log(previousOutPoint.N); * } * * Debug.Log("----------------------------------------------------------------"); */ transactionResponse_04_01 = transactionResponse; Money twentyOneBTC = new Money(21, MoneyUnit.BTC); var scriptPubKey = transactionResponse.Transaction.Outputs[0].ScriptPubKey; TxOut txOut = new TxOut(twentyOneBTC, scriptPubKey); OutPoint firstOutPoint = transactionResponse.ReceivedCoins[0].Outpoint; Debug.Log(firstOutPoint.Hash); Debug.Log(firstOutPoint.N); Debug.Log(transactionResponse.Transaction.Inputs.Count); OutPoint firstPreviousPoint = transactionResponse.Transaction.Inputs[0].PrevOut; QBitNinja4Unity.QBitNinjaClient.GetTransaction(firstPreviousPoint.Hash, network, Sample_04_02); }
void Sample_05_01(QBitNinja.Client.Models.GetTransactionResponse transactionResponse, NBitcoin.Network network) { Debug.Log(transactionResponse.TransactionId); Debug.Log(transactionResponse.Block.Confirmations); var bitcoinPrivateKey = new BitcoinSecret("cUwC2Dk7VvVyxF3jGyHdz5HTtxHYqHuQgWX1pnYvqckwCyUGStd3"); // To where? var recivedCoins = transactionResponse.ReceivedCoins; OutPoint outPointToSpend = null; foreach (var coin in recivedCoins) { if (coin.TxOut.ScriptPubKey == bitcoinPrivateKey.ScriptPubKey) { outPointToSpend = coin.Outpoint; } } if (outPointToSpend == null) { Debug.Log("TxOut dosen't contain our ScriptPubKey"); } else { Debug.Log("We want to spend " + (outPointToSpend.N + 1) + ". outpoint :"); } var transaction = new Transaction(); transaction.Inputs.Add(new TxIn() { PrevOut = outPointToSpend }); // From Where ? var hallOfTheMakersAddress = new BitcoinPubKeyAddress("mwCwTceJvYV27KXBc3NJZys6CjsgsoeHmf"); // How much? TxOut hallOfTheMakersTxOut = new TxOut() { Value = new Money((decimal)0.5, MoneyUnit.BTC), ScriptPubKey = hallOfTheMakersAddress.ScriptPubKey }; TxOut changeBackTxOut = new TxOut() { Value = new Money((decimal)0.4999, MoneyUnit.BTC), ScriptPubKey = bitcoinPrivateKey.ScriptPubKey }; transaction.Outputs.Add(hallOfTheMakersTxOut); transaction.Outputs.Add(changeBackTxOut); var hallOfTheMakersAmmount = new Money(0.5m, MoneyUnit.BTC); var mineFee = new Money(0.0001m, MoneyUnit.BTC); var txInAmount = transactionResponse.ReceivedCoins[(int)outPointToSpend.N].TxOut.Value; Money changeBackAmount = txInAmount - hallOfTheMakersAmmount - mineFee; }