本文整理汇总了C#中Transaction.Sign方法的典型用法代码示例。如果您正苦于以下问题:C# Transaction.Sign方法的具体用法?C# Transaction.Sign怎么用?C# Transaction.Sign使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Transaction
的用法示例。
在下文中一共展示了Transaction.Sign方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: witnessHasPushSizeLimit
public void witnessHasPushSizeLimit()
{
Key bob = new Key();
Transaction tx = new Transaction();
tx.Outputs.Add(new TxOut(Money.Coins(1.0m), bob.PubKey.ScriptPubKey.WitHash));
WitScriptCoin coin = new WitScriptCoin(tx.Outputs.AsCoins().First(), bob.PubKey.ScriptPubKey);
Transaction spending = new Transaction();
spending.AddInput(tx, 0);
spending.Sign(bob, coin);
ScriptError error;
Assert.True(spending.Inputs.AsIndexedInputs().First().VerifyScript(coin, out error));
spending.Inputs[0].WitScript = new WitScript(new[] { new byte[521] }.Concat(spending.Inputs[0].WitScript.Pushes).ToArray());
Assert.False(spending.Inputs.AsIndexedInputs().First().VerifyScript(coin, out error));
Assert.Equal(ScriptError.PushSize, error);
}
示例3: NonStandardScriptPubKeyDoesNotReturnsWrongBalanceCore
private static void NonStandardScriptPubKeyDoesNotReturnsWrongBalanceCore(IndexerTester tester, Key bob, Key alice, BalanceId bobId)
{
var chainBuilder = tester.CreateChainBuilder();
chainBuilder.EmitMoney(bob, "50.0");
var prev = chainBuilder.Emit(new Transaction()
{
Outputs =
{
new TxOut(Money.Coins(1.0m), bob.ScriptPubKey + OpcodeType.OP_NOP)
}
});
chainBuilder.SubmitBlock();
chainBuilder.SyncIndexer();
var bobBalance = tester.Client.GetOrderedBalance(bobId).ToArray();
Assert.True(bobBalance.Length == 1);
var tx = new Transaction();
tx.Inputs.Add(new TxIn()
{
PrevOut = prev.Outputs.AsCoins().First().Outpoint,
ScriptSig = bob.ScriptPubKey
});
tx.Outputs.Add(new TxOut(Money.Coins(0.1m), alice));
tx.Sign(bob, false);
chainBuilder.Emit(tx);
chainBuilder.SubmitBlock();
chainBuilder.SyncIndexer();
for(int i = 0; i < 2; i++)
{
bobBalance = tester.Client.GetOrderedBalance(bobId).ToArray();
Assert.True(bobBalance.Length < 2); //OP_NOP spending should not appear
}
}
示例4: NonStandardScriptPubKeyDoesNotReturnsWrongBalance
public void NonStandardScriptPubKeyDoesNotReturnsWrongBalance()
{
using(var tester = CreateTester())
{
var bob = new Key();
var alice = new Key();
BalanceId bobId = new BalanceId(bob);
NonStandardScriptPubKeyDoesNotReturnsWrongBalanceCore(tester, bob, alice, bobId);
bob = new Key();
alice = new Key();
bobId = new BalanceId("bob");
tester.Client.AddWalletRule("bob", new ScriptRule()
{
ScriptPubKey = bob.ScriptPubKey
});
NonStandardScriptPubKeyDoesNotReturnsWrongBalanceCore(tester, bob, alice, bobId);
bob = new Key();
alice = new Key();
bobId = new BalanceId("bob2");
tester.Client.AddWalletRule("bob2", new ScriptRule()
{
ScriptPubKey = bob.ScriptPubKey
});
var chainBuilder = tester.CreateChainBuilder();
List<Coin> bobCoins = new List<Coin>();
bobCoins.AddRange(chainBuilder.EmitMoney(bob, "50.0").Outputs.AsCoins());
bobCoins.AddRange(chainBuilder.EmitMoney(bob, "5.0").Outputs.AsCoins());
bobCoins.AddRange(chainBuilder.EmitMoney(bob, "15.0").Outputs.AsCoins());
var prev = chainBuilder.Emit(new Transaction()
{
Outputs =
{
new TxOut(Money.Coins(1.0m), bob.ScriptPubKey + OpcodeType.OP_NOP),
new TxOut(Money.Coins(1.5m), bob.ScriptPubKey + OpcodeType.OP_NOP),
new TxOut(Money.Coins(2.0m), bob.ScriptPubKey + OpcodeType.OP_NOP),
}
});
bobCoins.AddRange(prev.Outputs.AsCoins());
Shuffle(bobCoins);
chainBuilder.SubmitBlock();
chainBuilder.SyncIndexer();
var bobBalance = tester.Client.GetOrderedBalance(bobId).ToArray();
Assert.True(bobBalance.Length == 3);
var tx = new Transaction();
foreach(var coin in bobCoins)
{
tx.Inputs.Add(new TxIn()
{
PrevOut = coin.Outpoint,
ScriptSig = bob.ScriptPubKey
});
}
tx.Outputs.Add(new TxOut(Money.Coins(0.1m), alice));
tx.Sign(bob, false);
chainBuilder.Emit(tx);
chainBuilder.SubmitBlock();
chainBuilder.SyncIndexer();
for(int i = 0; i < 2; i++)
{
bobBalance = tester.Client.GetOrderedBalance(bobId).ToArray();
Assert.True(bobBalance.Length == 4); //OP_NOP spending should not appear
Assert.True(bobBalance[0].SpentCoins.Count == 3);
foreach(var coin in bobBalance[0].SpentCoins)
{
Assert.Equal(bob.ScriptPubKey, coin.TxOut.ScriptPubKey);
}
}
}
}