本文整理汇总了C#中Transaction.ReadPayload方法的典型用法代码示例。如果您正苦于以下问题:C# Transaction.ReadPayload方法的具体用法?C# Transaction.ReadPayload怎么用?C# Transaction.ReadPayload使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Transaction
的用法示例。
在下文中一共展示了Transaction.ReadPayload方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetTransactionAsync
public async override Task<Transaction> GetTransactionAsync(Transaction.Info info) {
var json = JToken.Parse(await SendRPCAsync("blockchain.transaction.get", info.Hash, info.Height));
var rawTx = BinaryHelpers.HexToByteArray(json["result"].Value<string>());
var tx = new Transaction(info.Height);
tx.ReadPayload(new BinaryReader(new MemoryStream(rawTx)));
return tx;
}
示例2: GetTransactionAsync
public override async Task<Transaction> GetTransactionAsync(Transaction.Info info) {
PathInfo txCache = DefaultCachePath.SubPath("transactions");
FileInfo cache = FileInfo.Create(txCache, String.Format("{0}.{1}", info.Hash, "tx"));
Transaction tx;
if(cache.Exists) {
tx = new Transaction();
tx.ReadPayload(new BinaryReader(FileStream.Create(cache, FileMode.Open)));
tx.Height = info.Height;
}
else {
tx = await base.GetTransactionAsync(info);
tx.WritePayload(new BinaryWriter(FileStream.Create(cache, FileMode.Create)));
}
return tx;
}
示例3: GenerateSig
public void GenerateSig() {
ECKey key1 = ECKey.FromWalletImportFormat("5JQpgdeNmFSBf261z5q58eT89GJ8VQ4v4FwW1ibGkDXTB8Br7ZZ");
ECKey key2 = ECKey.FromWalletImportFormat("5K1yDmGvZtDdFhFpXLwLFy5Z6smJZ65LqnNurG2iNTQWG2k9yci");
byte[] raw = new byte[] { 0x01, 0x00, 0x00, 0x00, 0x01, 0xE4, 0x1C, 0x5B, 0x7D, 0x6C, 0xF9, 0x67, 0x47, 0x45, 0x0F, 0xAB, 0xC7, 0x31, 0xEE, 0x2B, 0x7A, 0x91, 0x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C3, 0xF9, 0xE9, 0xC7, 0xCD, 0x01, 0xB0, 0xDF, 0xC0, 0xA6, 0xF3, 0xE3, 0x88, 0xAC, 0x00, 0x35, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19, 0x76, 0xA9, 0x14, 0x06, 0xF1, 0xC4, 0xA7, 0xCD, 0x50, 0x29, 0x84, 0xB7, 0xC6, 0xEA, 0xE9, 0x5D, 0xB1, 0x76, 0xB9, 0xAE, 0x4A, 0x6E, 0x08, 0x88, 0xAC, 0x00, 0x00, 0x00, 0x00 };
Script pubKeyScript = Script.FromString("OP_DUP OP_HASH160 06f1c4a7cd502984b7c6eae95db176b9ae4a6e08 OP_EQUALVERIFY OP_CHECKSIG");
using(BinaryReader reader = new BinaryReader(new MemoryStream(raw))) {
Transaction tx = new Transaction();
tx.ReadPayload(reader);
int trials = 3;
for(int i = 0; i < trials; i++) {
byte[] sig1 = tx.GenerateInputSignature(key1, SigHash.All, pubKeyScript, 0);
byte[] sig2 = tx.GenerateInputSignature(key2, SigHash.All, pubKeyScript, 0);
Assert.IsTrue(tx.SigIsValid(key1.PubKey, sig1, pubKeyScript, 0));
Assert.IsTrue(tx.SigIsValid(key2.PubKey, sig2, pubKeyScript, 0));
Assert.IsFalse(tx.SigIsValid(key1.PubKey, sig2, pubKeyScript, 0));
Assert.IsFalse(tx.SigIsValid(key2.PubKey, sig1, pubKeyScript, 0));
}
}
}
示例4: ValidateSig
public void ValidateSig() {
// TODO: Refactor this spec to use a Tuple array
// http://blockchain.info/tx/ec8775eab96692a59a32556669faf305ecc0b45064c6d6259a8097767f65fcf8
byte[] raw = new byte[] { 0x01, 0x00, 0x00, 0x00, 0x01, 0xE4, 0x1C, 0x5B, 0x7D, 0x6C, 0xF9, 0x67, 0x47, 0x45, 0x0F, 0xAB, 0xC7, 0x31, 0xEE, 0x2B, 0x7A, 0x91, 0x6B, 0x37, 0x1C, 0xDF, 0xC1, 0x9C, 0x9C, 0x6A, 0xB1, 0xBC, 0xC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3, 0xE3, 0x88, 0xAC, 0x00, 0x35, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19, 0x76, 0xA9, 0x14, 0x06, 0xF1, 0xC4, 0xA7, 0xCD, 0x50, 0x29, 0x84, 0xB7, 0xC6, 0xEA, 0xE9, 0x5D, 0xB1, 0x76, 0xB9, 0xAE, 0x4A, 0x6E, 0x08, 0x88, 0xAC, 0x00, 0x00, 0x00, 0x00 };
byte[] sig = new byte[] { 0x30, 0x44, 0x02, 0x20, 0x56, 0x37, 0x2E, 0x90, 0x4B, 0xE1, 0x15, 0xD2, 0xFC, 0x1E, 0x7C, 0xDC, 0xBC, 0x2A, 0x89, 0xB7, 0xC5, 0xC8, 0xC4, 0x3F, 0x79, 0x23, 0x12, 0x1F, 0x1D, 0xF6, 0xA8, 0xB0, 0x2C, 0xE9, 0xC3, 0xEF, 0x02, 0x20, 0x4A, 0x68, 0xD3, 0x96, 0x72, 0xA0, 0xEB, 0xB2, 0xB4, 0x65, 0x8B, 0x96, 0xB9, 0xC6, 0x2E, 0x8E, 0x25, 0x37, 0xCD, 0x98, 0x1E, 0x59, 0xE0, 0x85, 0xE6, 0x21, 0x0F, 0xC7, 0xB6, 0xDB, 0xF8, 0x3C, 0x01 };
byte[] pubKey = new byte[] { 0x04, 0xEF, 0x96, 0xE3, 0xBC, 0xCC, 0x8F, 0xFF, 0x6B, 0x21, 0xD2, 0x8E, 0x81, 0xF6, 0x1C, 0x4A, 0x93, 0xCF, 0xE0, 0xF1, 0x33, 0x21, 0x4C, 0x95, 0x47, 0xC0, 0xD6, 0x83, 0xA9, 0xFC, 0x12, 0xF5, 0x29, 0x22, 0x9C, 0x8D, 0x1A, 0xB2, 0x00, 0x04, 0xC0, 0xF7, 0xF1, 0x39, 0x61, 0x56, 0x6B, 0x65, 0x49, 0x2C, 0x62, 0x67, 0xFA, 0x45, 0x27, 0x84, 0xC0, 0x72, 0x4B, 0x4F, 0x54, 0x2E, 0x40, 0x01, 0xF1 };
// http://blockchain.info/tx-index/78799607/6
Script pubKeyScript = Script.FromString("OP_DUP OP_HASH160 06f1c4a7cd502984b7c6eae95db176b9ae4a6e08 OP_EQUALVERIFY OP_CHECKSIG");
using(BinaryReader reader = new BinaryReader(new MemoryStream(raw))) {
Transaction tx = new Transaction();
tx.ReadPayload(reader);
Assert.IsTrue(tx.SigIsValid(pubKey, sig, pubKeyScript, 0)); // TODO: Get sig from transaction (use console; Script s = new Script(new byte[] { <copy/paste script> }); s.ToString();) Manually parse for string
}
}