本文整理汇总了C#中Transaction.GetHash方法的典型用法代码示例。如果您正苦于以下问题:C# Transaction.GetHash方法的具体用法?C# Transaction.GetHash怎么用?C# Transaction.GetHash使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Transaction
的用法示例。
在下文中一共展示了Transaction.GetHash方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BroadcastTransaction
public Transaction BroadcastTransaction(Transaction tx)
{
var h = tx.GetHash();
Mempool.Add(h, tx);
OnNewTransaction(tx);
return tx;
}
示例2: GiveMoney
public Transaction GiveMoney(Script scriptPubKey, Money value)
{
var tx = new Transaction();
tx.Outputs.Add(new TxOut(value, scriptPubKey));
var h = tx.GetHash();
Mempool.Add(h, tx);
OnNewTransaction(tx);
return tx;
}
示例3: DoesNotCrashExtractingAddressFromBigTransaction
public void DoesNotCrashExtractingAddressFromBigTransaction()
{
var tx = new Transaction(Encoders.Hex.DecodeData(File.ReadAllText("Data/BigTransaction.txt")));
var txId = tx.GetHash();
var result = OrderedBalanceChange.ExtractScriptBalances(txId, tx, null, null, 0);
foreach(var e in result)
{
var entity = e.ToEntity();
}
}
示例4: WriteTransaction
protected override void WriteTransaction(JsonTextWriter writer, Transaction tx)
{
WritePropertyValue(writer, "hash", tx.GetHash().ToString());
WritePropertyValue(writer, "ver", tx.Version);
WritePropertyValue(writer, "vin_sz", tx.Inputs.Count);
WritePropertyValue(writer, "vout_sz", tx.Outputs.Count);
WritePropertyValue(writer, "lock_time", tx.LockTime.Value);
WritePropertyValue(writer, "size", tx.GetSerializedSize());
writer.WritePropertyName("in");
writer.WriteStartArray();
foreach(var input in tx.Inputs.AsIndexedInputs())
{
var txin = input.TxIn;
writer.WriteStartObject();
writer.WritePropertyName("prev_out");
writer.WriteStartObject();
WritePropertyValue(writer, "hash", txin.PrevOut.Hash.ToString());
WritePropertyValue(writer, "n", txin.PrevOut.N);
writer.WriteEndObject();
if(txin.PrevOut.Hash == uint256.Zero)
{
WritePropertyValue(writer, "coinbase", Encoders.Hex.EncodeData(txin.ScriptSig.ToBytes()));
}
else
{
WritePropertyValue(writer, "scriptSig", txin.ScriptSig.ToString());
}
if(input.WitScript != WitScript.Empty)
{
WritePropertyValue(writer, "witness", input.WitScript.ToString());
}
if(txin.Sequence != uint.MaxValue)
{
WritePropertyValue(writer, "sequence", (uint)txin.Sequence);
}
writer.WriteEndObject();
}
writer.WriteEndArray();
writer.WritePropertyName("out");
writer.WriteStartArray();
foreach(var txout in tx.Outputs)
{
writer.WriteStartObject();
WritePropertyValue(writer, "value", txout.Value.ToString(false, false));
WritePropertyValue(writer, "scriptPubKey", txout.ScriptPubKey.ToString());
writer.WriteEndObject();
}
writer.WriteEndArray();
}
示例5: SpendCoin
public Transaction SpendCoin(Coin coin, Script scriptPubKey, Money value)
{
var tx = new Transaction();
tx.Inputs.Add(new TxIn(coin.Outpoint));
tx.Outputs.Add(new TxOut(value, scriptPubKey));
tx.Outputs.Add(new TxOut(coin.Amount - value, coin.ScriptPubKey));
var h = tx.GetHash();
Mempool.Add(h, tx);
OnNewTransaction(tx);
return tx;
}
示例6: 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);
}
示例7: Entity
public Entity(uint256 txId, Transaction tx, uint256 blockId)
{
if(txId == null)
txId = tx.GetHash();
Timestamp = DateTimeOffset.UtcNow;
TxId = txId;
Transaction = tx;
BlockId = blockId;
if(blockId == null)
Type = TransactionEntryType.Mempool;
else
Type = TransactionEntryType.ConfirmedTransaction;
}
示例8: ColoredCoinTester
public ColoredCoinTester([CallerMemberName]string test = null)
{
var testcase = JsonConvert.DeserializeObject<TestCase[]>(File.ReadAllText("Data/openasset-known-tx.json"))
.First(t => t.test == test);
NoSqlTransactionRepository repository = new NoSqlTransactionRepository();
foreach(var tx in testcase.txs)
{
var txObj = new Transaction(tx);
repository.Put(txObj.GetHash(), txObj);
}
TestedTxId = uint256.Parse(testcase.testedtx);
Repository = new NoSqlColoredTransactionRepository(repository, new InMemoryNoSqlRepository());
}
示例9: Operation
public Operation(Transaction transaction, ChainedBlock block, MerkleBlock proof)
: this()
{
Transaction = transaction;
if(block != null)
{
proof = proof.Clone();
proof.PartialMerkleTree = proof.PartialMerkleTree.Trim(transaction.GetHash());
Height = block.Height;
BlockId = block.HashBlock;
Proof = proof;
}
UnconfirmedSeen = DateTimeOffset.UtcNow;
AddedDate = DateTimeOffset.UtcNow;
}
示例10: AutoDownloadMissingTransaction
public string AutoDownloadMissingTransaction(Action act)
{
StringBuilder builder = new StringBuilder();
while(true)
{
try
{
act();
break;
}
catch(TransactionNotFoundException ex)
{
WebClient client = new WebClient();
var result = client.DownloadString("http://btc.blockr.io/api/v1/tx/raw/" + ex.TxId);
var json = JObject.Parse(result);
var tx = new Transaction(json["data"]["tx"]["hex"].ToString());
builder.AppendLine("\"" + json["data"]["tx"]["hex"].ToString() + "\",\r\n");
Repository.Transactions.Put(tx.GetHash(), tx);
}
}
return builder.ToString();
}
示例11: CanParseTransaction
public void CanParseTransaction()
{
var tests = TestCase.read_json("data/can_parse_transaction.json");
foreach(var test in tests.Select(t => t.GetDynamic(0)))
{
string raw = test.Raw;
Transaction tx = new Transaction(raw);
Assert.Equal((int)test.JSON.vin_sz, tx.Inputs.Count);
Assert.Equal((int)test.JSON.vout_sz, tx.Outputs.Count);
Assert.Equal((uint)test.JSON.lock_time, tx.LockTime);
for(int i = 0 ; i < tx.Inputs.Count ; i++)
{
var actualVIn = tx.Inputs[i];
var expectedVIn = [email protected][i];
Assert.Equal(new uint256((string)expectedVIn.prev_out.hash), actualVIn.PrevOut.Hash);
Assert.Equal((uint)expectedVIn.prev_out.n, actualVIn.PrevOut.N);
if(expectedVIn.sequence != null)
Assert.Equal((uint)expectedVIn.sequence, actualVIn.Sequence);
Assert.Equal((string)expectedVIn.scriptSig, actualVIn.ScriptSig.ToString());
//Can parse the string
Assert.Equal((string)expectedVIn.scriptSig, (string)expectedVIn.scriptSig.ToString());
}
for(int i = 0 ; i < tx.Outputs.Count ; i++)
{
var actualVOut = tx.Outputs[i];
var expectedVOut = [email protected][i];
Assert.Equal((string)expectedVOut.scriptPubKey, actualVOut.ScriptPubKey.ToString());
Assert.Equal(Money.Parse((string)expectedVOut.value), actualVOut.Value);
}
var hash = (string)test.JSON.hash;
var expectedHash = new uint256(Encoders.Hex.DecodeData(hash), false);
Assert.Equal(expectedHash, tx.GetHash());
}
}
示例12: script_CHECKMULTISIG12
public void script_CHECKMULTISIG12()
{
EnsureHasLibConsensus();
Key key1 = new Key(true);
Key key2 = new Key(false);
Key key3 = new Key(true);
Script scriptPubKey12 = new Script(
OpcodeType.OP_1,
Op.GetPushOp(key1.PubKey.ToBytes()),
Op.GetPushOp(key2.PubKey.ToBytes()),
OpcodeType.OP_2,
OpcodeType.OP_CHECKMULTISIG
);
Transaction txFrom12 = new Transaction();
txFrom12.Outputs.Add(new TxOut());
txFrom12.Outputs[0].ScriptPubKey = scriptPubKey12;
Transaction txTo12 = new Transaction();
txTo12.Inputs.Add(new TxIn());
txTo12.Outputs.Add(new TxOut());
txTo12.Inputs[0].PrevOut.N = 0;
txTo12.Inputs[0].PrevOut.Hash = txFrom12.GetHash();
txTo12.Outputs[0].Value = 1;
txTo12.Inputs[0].ScriptSig = sign_multisig(scriptPubKey12, key1, txTo12);
AssertValidScript(scriptPubKey12, txTo12, 0, flags);
txTo12.Outputs[0].Value = 2;
AssertInvalidScript(scriptPubKey12, txTo12, 0, flags);
txTo12.Inputs[0].ScriptSig = sign_multisig(scriptPubKey12, key2, txTo12);
AssertValidScript(scriptPubKey12, txTo12, 0, flags);
txTo12.Inputs[0].ScriptSig = sign_multisig(scriptPubKey12, key3, txTo12);
AssertInvalidScript(scriptPubKey12, txTo12, 0, flags);
}
示例13: CanBuildColoredTransaction
//.........这里部分代码省略.........
AssertHasAsset(tx, colored, colored.Transfers[0], goldId, 470, bob.PubKey);
AssertHasAsset(tx, colored, colored.Transfers[1], goldId, 30, satoshi.PubKey);
repo.Transactions.Put(tx);
//Can swap :
//satoshi wants to send 100 gold to bob
//bob wants to send 200 silver, 5 gold and 0.9 BTC to satoshi
//Satoshi receive gold
txBuilder = new TransactionBuilder();
txBuilder.StandardTransactionPolicy = RelayPolicy;
tx = txBuilder
.AddKeys(gold)
.AddCoins(issuanceCoins)
.IssueAsset(satoshi.PubKey, new AssetMoney(goldId, 1000UL))
.SetChange(gold.PubKey)
.SendFees(Money.Coins(0.0004m))
.BuildTransaction(true);
Assert.True(txBuilder.Verify(tx));
repo.Transactions.Put(tx);
var satoshiCoin = ColoredCoin.Find(tx, repo).First();
//Gold receive 2.5 BTC
tx = new Transaction()
{
Outputs =
{
new TxOut("2.5",gold.PubKey)
}
};
repo.Transactions.Put(tx.GetHash(), tx);
//Bob receive silver and 2 btc
txBuilder = new TransactionBuilder();
txBuilder.StandardTransactionPolicy = RelayPolicy;
tx = txBuilder
.AddKeys(silver, gold)
.AddCoins(issuanceCoins)
.AddCoins(new Coin(new OutPoint(tx.GetHash(), 0), new TxOut("2.5", gold.PubKey.ScriptPubKey)))
.IssueAsset(bob.PubKey, new AssetMoney(silverId, 300UL))
.Send(bob.PubKey, "2.00")
.SendFees(Money.Coins(0.0004m))
.SetChange(gold.PubKey)
.BuildTransaction(true);
Assert.True(txBuilder.Verify(tx));
repo.Transactions.Put(tx);
var bobSilverCoin = ColoredCoin.Find(tx, repo).First();
var bobBitcoin = new Coin(new OutPoint(tx.GetHash(), 2), tx.Outputs[2]);
//Bob receive gold
txBuilder = new TransactionBuilder();
txBuilder.StandardTransactionPolicy = RelayPolicy;
tx = txBuilder
.AddKeys(gold)
.AddCoins(issuanceCoins)
.IssueAsset(bob.PubKey, new AssetMoney(goldId, 50UL))
.SetChange(gold.PubKey)
.SendFees(Money.Coins(0.0004m))
.BuildTransaction(true);
Assert.True(txBuilder.Verify(tx));
repo.Transactions.Put(tx.GetHash(), tx);
示例14: CanBuildShuffleColoredTransaction
public void CanBuildShuffleColoredTransaction()
{
var gold = new Key();
var silver = new Key();
var goldId = gold.PubKey.ScriptPubKey.Hash.ToAssetId();
var silverId = silver.PubKey.ScriptPubKey.Hash.ToAssetId();
var satoshi = new Key();
var bob = new Key();
var repo = new NoSqlColoredTransactionRepository(new NoSqlTransactionRepository(), new InMemoryNoSqlRepository());
var init = new Transaction()
{
Outputs =
{
new TxOut("1.0", gold.PubKey),
new TxOut("1.0", silver.PubKey),
new TxOut("1.0", satoshi.PubKey)
}
};
repo.Transactions.Put(init.GetHash(), init);
var issuanceCoins =
init
.Outputs
.Take(2)
.Select((o, i) => new IssuanceCoin(new OutPoint(init.GetHash(), i), init.Outputs[i]))
.OfType<ICoin>().ToArray();
var satoshiBTC = new Coin(new OutPoint(init.GetHash(), 2), init.Outputs[2]);
var coins = new List<ICoin>();
coins.AddRange(issuanceCoins);
var txBuilder = new TransactionBuilder(1);
txBuilder.StandardTransactionPolicy = RelayPolicy;
//Can issue gold to satoshi and bob
var tx = txBuilder
.AddCoins(coins.ToArray())
.AddKeys(gold)
.IssueAsset(satoshi.PubKey, new AssetMoney(goldId, 1000))
.IssueAsset(bob.PubKey, new AssetMoney(goldId, 500))
.SendFees("0.1")
.SetChange(gold.PubKey)
.BuildTransaction(true);
Assert.True(txBuilder.Verify(tx, "0.1"));
//Ensure BTC from the IssuanceCoin are returned
Assert.Equal(Money.Parse("0.89994240"), tx.Outputs[2].Value);
Assert.Equal(gold.PubKey.ScriptPubKey, tx.Outputs[2].ScriptPubKey);
//Can issue and send in same transaction
repo.Transactions.Put(tx.GetHash(), tx);
var cc = ColoredCoin.Find(tx, repo);
for(int i = 0 ; i < 20 ; i++)
{
txBuilder = new TransactionBuilder(i);
txBuilder.StandardTransactionPolicy = RelayPolicy;
tx = txBuilder
.AddCoins(satoshiBTC)
.AddCoins(cc)
.AddKeys(satoshi)
.SendAsset(gold, new AssetMoney(goldId, 10))
.SetChange(satoshi)
.Then()
.AddKeys(gold)
.AddCoins(issuanceCoins)
.IssueAsset(bob, new AssetMoney(goldId, 1))
.SetChange(gold)
.Shuffle()
.BuildTransaction(true);
repo.Transactions.Put(tx.GetHash(), tx);
var ctx = tx.GetColoredTransaction(repo);
Assert.Equal(1, ctx.Issuances.Count);
Assert.Equal(2, ctx.Transfers.Count);
}
}
示例15: CreateCreditAndSpend
void CreateCreditAndSpend(CKeyStore keystore, Script outscript, ref Transaction output, ref Transaction input, bool success = true)
{
Transaction outputm = new Transaction();
outputm.Version = 1;
outputm.Inputs.Add(new TxIn());
outputm.Inputs[0].PrevOut = new OutPoint();
outputm.Inputs[0].ScriptSig = Script.Empty;
outputm.Inputs[0].WitScript = new WitScript();
outputm.Outputs.Add(new TxOut());
outputm.Outputs[0].Value = Money.Satoshis(1);
outputm.Outputs[0].ScriptPubKey = outscript;
output = outputm.Clone();
Assert.True(output.Inputs.Count == 1);
Assert.True(output.Inputs[0].ToBytes().SequenceEqual(outputm.Inputs[0].ToBytes()));
Assert.True(output.Outputs.Count == 1);
Assert.True(output.Inputs[0].ToBytes().SequenceEqual(outputm.Inputs[0].ToBytes()));
Assert.True(!output.HasWitness);
Transaction inputm = new Transaction();
inputm.Version = 1;
inputm.Inputs.Add(new TxIn());
inputm.Inputs[0].PrevOut.Hash = output.GetHash();
inputm.Inputs[0].PrevOut.N = 0;
inputm.Inputs[0].WitScript = new WitScript();
inputm.Outputs.Add(new TxOut());
inputm.Outputs[0].Value = Money.Satoshis(1);
inputm.Outputs[0].ScriptPubKey = Script.Empty;
bool ret = SignSignature(keystore, output, inputm, 0);
Assert.True(ret == success);
input = inputm.Clone();
Assert.True(input.Inputs.Count == 1);
Assert.True(input.Inputs[0].ToBytes().SequenceEqual(inputm.Inputs[0].ToBytes()));
Assert.True(input.Outputs.Count == 1);
Assert.True(input.Outputs[0].ToBytes().SequenceEqual(inputm.Outputs[0].ToBytes()));
if(!inputm.HasWitness)
{
Assert.True(!input.HasWitness);
}
else
{
Assert.True(input.HasWitness);
Assert.True(input.Inputs[0].WitScript.ToBytes().SequenceEqual(inputm.Inputs[0].WitScript.ToBytes()));
}
}