本文整理汇总了C#中Transaction.AddOutput方法的典型用法代码示例。如果您正苦于以下问题:C# Transaction.AddOutput方法的具体用法?C# Transaction.AddOutput怎么用?C# Transaction.AddOutput使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Transaction
的用法示例。
在下文中一共展示了Transaction.AddOutput方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanExtractTxOutDestinationEasily
public void CanExtractTxOutDestinationEasily()
{
var secret = new BitcoinSecret("KyJTjvFpPF6DDX4fnT56d2eATPfxjdUPXFFUb85psnCdh34iyXRQ");
var tx = new Transaction();
var p2pkh = new TxOut(new Money((UInt64)45000000), secret.GetAddress());
var p2pk = new TxOut(new Money((UInt64)80000000), secret.PrivateKey.PubKey);
tx.AddOutput(p2pkh);
tx.AddOutput(p2pk);
Assert.False(p2pkh.IsTo(secret.PrivateKey.PubKey));
Assert.True(p2pkh.IsTo(secret.GetAddress()));
Assert.True(p2pk.IsTo(secret.PrivateKey.PubKey));
Assert.False(p2pk.IsTo(secret.GetAddress()));
}
示例2: CreateFakeTx
public static Transaction CreateFakeTx(NetworkParameters @params, ulong nanocoins, Address to)
{
var t = new Transaction(@params);
var o1 = new TransactionOutput(@params, t, nanocoins, to);
t.AddOutput(o1);
// Make a previous tx simply to send us sufficient coins. This prev tx is not really valid but it doesn't
// matter for our purposes.
var prevTx = new Transaction(@params);
var prevOut = new TransactionOutput(@params, prevTx, nanocoins, to);
prevTx.AddOutput(prevOut);
// Connect it.
t.AddInput(prevOut);
return t;
}
示例3: EmitMoney
public Transaction EmitMoney(IDestination destination, Money amount, bool isCoinbase = true, bool indexBalance = false)
{
Transaction transaction = new Transaction();
if (isCoinbase)
transaction.AddInput(new TxIn()
{
ScriptSig = new Script(NoRandom ? new uint256(0).ToBytes() : RandomUtils.GetBytes(32)),
});
transaction.AddOutput(new TxOut()
{
ScriptPubKey = destination.ScriptPubKey,
Value = amount
});
Add(transaction, indexBalance);
return transaction;
}
示例4: CanSignTransaction
public void CanSignTransaction()
{
var key = new Key();
var scriptPubKey = PayToPubkeyHashTemplate.Instance.GenerateScriptPubKey(key.PubKey);
Transaction tx = new Transaction();
tx.AddInput(new TxIn(new OutPoint(tx.GetHash(), 0))
{
ScriptSig = scriptPubKey
});
tx.AddInput(new TxIn(new OutPoint(tx.GetHash(), 1))
{
ScriptSig = scriptPubKey
});
tx.AddOutput(new TxOut("21", key.PubKey.Hash));
var clone = tx.Clone();
tx.Sign(key, false);
AssertCorrectlySigned(tx, scriptPubKey);
clone.Sign(key, true);
AssertCorrectlySigned(clone, scriptPubKey.Hash.ScriptPubKey);
}
示例5: CreateCreditingTransaction
private static Transaction CreateCreditingTransaction(Script scriptPubKey)
{
var creditingTransaction = new Transaction();
creditingTransaction.AddInput(new TxIn()
{
ScriptSig = new Script(OpcodeType.OP_0, OpcodeType.OP_0)
});
creditingTransaction.AddOutput(Money.Zero, scriptPubKey);
return creditingTransaction;
}
示例6: CreateSpendingTransaction
private static Transaction CreateSpendingTransaction(Script scriptSig, Transaction creditingTransaction)
{
var spendingTransaction = new Transaction();
spendingTransaction.AddInput(new TxIn(new OutPoint(creditingTransaction, 0))
{
ScriptSig = scriptSig
});
spendingTransaction.AddOutput(new TxOut()
{
ScriptPubKey = new Script(),
Value = Money.Zero
});
return spendingTransaction;
}
示例7: Transactions
public void Transactions()
{
// This test covers a bug in which Transaction.getValueSentFromMe was calculating incorrectly.
var tx = TestUtils.CreateFakeTx(_params, Utils.ToNanoCoins(1, 0), _myAddress);
// Now add another output (ie, change) that goes to some other address.
var someOtherGuy = new EcKey().ToAddress(_params);
var output = new TransactionOutput(_params, tx, Utils.ToNanoCoins(0, 5), someOtherGuy);
tx.AddOutput(output);
// Note that tx is no longer valid: it spends more than it imports. However checking transactions balance
// correctly isn't possible in SPV mode because value is a property of outputs not inputs. Without all
// transactions you can't check they add up.
_wallet.Receive(tx, null, BlockChain.NewBlockType.BestChain);
// Now the other guy creates a transaction which spends that change.
var tx2 = new Transaction(_params);
tx2.AddInput(output);
tx2.AddOutput(new TransactionOutput(_params, tx2, Utils.ToNanoCoins(0, 5), _myAddress));
// tx2 doesn't send any coins from us, even though the output is in the wallet.
Assert.AreEqual(Utils.ToNanoCoins(0, 0), tx2.GetValueSentFromMe(_wallet));
}
示例8: Bounce
public void Bounce()
{
// This test covers bug 64 (False double spends). Check that if we create a spend and it's immediately sent
// back to us, this isn't considered as a double spend.
var coin1 = Utils.ToNanoCoins(1, 0);
var coinHalf = Utils.ToNanoCoins(0, 50);
// Start by giving us 1 coin.
var inbound1 = TestUtils.CreateFakeTx(_params, coin1, _myAddress);
_wallet.Receive(inbound1, null, BlockChain.NewBlockType.BestChain);
// Send half to some other guy. Sending only half then waiting for a confirm is important to ensure the tx is
// in the unspent pool, not pending or spent.
Assert.AreEqual(1, _wallet.GetPoolSize(Wallet.Pool.Unspent));
Assert.AreEqual(1, _wallet.GetPoolSize(Wallet.Pool.All));
var someOtherGuy = new EcKey().ToAddress(_params);
var outbound1 = _wallet.CreateSend(someOtherGuy, coinHalf);
_wallet.ConfirmSend(outbound1);
_wallet.Receive(outbound1, null, BlockChain.NewBlockType.BestChain);
// That other guy gives us the coins right back.
var inbound2 = new Transaction(_params);
inbound2.AddOutput(new TransactionOutput(_params, inbound2, coinHalf, _myAddress));
inbound2.AddInput(outbound1.Outputs[0]);
_wallet.Receive(inbound2, null, BlockChain.NewBlockType.BestChain);
Assert.AreEqual(coin1, _wallet.GetBalance());
}
示例9: CanIndexHugeTransaction
public void CanIndexHugeTransaction()
{
using(var tester = CreateTester())
{
var builder = tester.CreateChainBuilder();
Transaction tx = new Transaction();
for(int i = 0; i < 4; i++)
tx.AddOutput(new TxOut(Money.Zero, new Script(new byte[500 * 1024])));
tester.Indexer.Index(new TransactionEntry.Entity(null, tx, null));
var indexed = tester.Client.GetTransaction(tx.GetHash());
Assert.NotNull(indexed);
Assert.True(tx.GetHash() == indexed.Transaction.GetHash());
Transaction tx2 = new Transaction();
var txhash = tx.GetHash();
for(int i = 0; i < 4; i++)
tx2.Inputs.Add(new TxIn(new OutPoint(txhash, i)));
tx2.AddOutput(new TxOut(Money.Zero, new Script(RandomUtils.GetBytes(500 * 1024))));
tester.Indexer.Index(new TransactionEntry.Entity(null, tx2, null));
indexed = tester.Client.GetTransaction(tx2.GetHash());
Assert.NotNull(indexed);
Assert.True(tx2.GetHash() == indexed.Transaction.GetHash());
Assert.True(indexed.SpentCoins.Count == 4);
}
}
示例10: Pay
public Transaction Pay(Money money, bool fromConfirmedPool, params Chain[] chains)
{
var tx = new Transaction();
tx.AddOutput(money, OtherKey.PubKey.GetAddress(Network.Main));
Wallet.CompleteTx(tx, fromConfirmedPool ? Wallet.Accounts.Confirmed : Wallet.Accounts.Available);
return RecieveTransaction(tx, chains);
}
示例11: createNextBlock
private Block createNextBlock(Block baseBlock, int nextBlockHeight, TransactionOutPointWithValue prevOut,
Money additionalCoinbaseValue)
{
int height = 0;
if(blockToHeightMap.TryGetValue(baseBlock.GetHash(), out height))
Assert.True(height == nextBlockHeight - 1);
var coinbaseValue = Network.GetReward(nextBlockHeight) + (additionalCoinbaseValue ?? Money.Zero);
Block block = baseBlock.CreateNextBlockWithCoinbase(coinbaseOutKeyPubKey, coinbaseValue);
if(prevOut != null)
{
Transaction t = new Transaction();
// Entirely invalid scriptPubKey to ensure we aren't pre-verifying too much
t.AddOutput(new TxOut(new Money(0), new Script(Op.GetPushOp(1))));
t.AddOutput(new TxOut(Money.Parse("1"),
new PayToPubkeyHashTemplate().GenerateScriptPubKey(coinbaseOutKeyPubKey)));
// Spendable output
t.AddOutput(new TxOut(Money.Zero, new Script(Op.GetPushOp(1))));
addOnlyInputToTransaction(t, prevOut);
block.AddTransaction(t);
block.ComputeMerkleRoot();
}
return block;
}