区块链上的查询与解密

查询包含某数据的第一个交易的哈希值

数据用base58解码

using System;
using BsvSimpleLibrary;
using System.Collections.Generic;
using System.Linq;
using NBitcoin;
using NBitcoin.DataEncoders;
using BitcoinSVCryptor;

namespace bsvAddress
{
    class Program
    {
        static void Main(string[] args)
        {
            //string WifprivateKeyStr = "cVkkQ9gmQWb7M7FKKSAnKzkj5b3VJfHZath9YzvtzWqSyshpjLdX";
            //string destAddress = "1L5D9V3hZQ4iFsXSXv41cwhyurLteP6kH1";//test
            //string privateKey = ""; //(test) your private key
            //string txid = "dfd5dbaac7cbc322995fc2f33dabff4d947a172f97f09933a5bc5e08f47760f1";
            string uri = bsvConfiguration_class.RestApiUri;
            string network = bsvConfiguration_class.testNetwork;
   
            string privateKeyStr = "cNNfJQD8k2awDySowmH631JEJ9AVeueVkwLs9ihDkELhJhpMJVSt";
            string opReturnData = "HquEky7h7KGkUkaccZt1R4";
            string destAddress = "mxe34JQpFvKcUjJ2pA6NK2HfAEe5nVuc2j";
            Dictionary<string, string> response;

            //get address tx 得到地址所对应的所有交易
            RestApiAddressHistoryTx[] addressHistory = RestApi_class.getAddressHistory(uri, network, destAddress);

            
            string[] txHashes = addressHistory.Select(tx => tx.TxHash).ToArray();
            int batchSize = 20;
            RestApiTransaction[] txs;
            for (int i = 0; i < txHashes.Length; i += batchSize)
            {
                string[] batchHashes = txHashes.Skip(i).Take(batchSize).ToArray();
                txs = RestApi_class.getTransactions(uri, network, batchHashes);
                foreach (RestApiTransaction tx in txs)
                {
                    string s = RestApi_class.getOpReturnData(tx, bsvConfiguration_class.encoding);
                    if (!string.IsNullOrEmpty(s) && s.Contains("HquEky7h7KGkUkaccZt1R4"))
                    {
                        Console.WriteLine("第一个交易的哈希地址:" + tx.Hash);
                        break;
                    }
                }
            }
            //ASE解码
            Base58Encoder base58Encoder = new Base58Encoder();
            string base58Str = "HquEky7h7KGkUkaccZt1R4";
            byte[] encryptedBytes = base58Encoder.DecodeData(base58Str);
            string privateKey1Str = "cNNfJQD8k2awDySowmH631JEJ9AVeueVkwLs9ihDkELhJhpMJVSt";
            string decryptedStr = AES_class.AesDecrypt(encryptedBytes, privateKey1Str);
            Console.WriteLine("Decrypted string: " + decryptedStr);
        }

    }
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值