private async Task <Block> GetBlockAsync(object retVal, TxVerbosity txVerbosity, CancellationToken token, bool logOutput) { token.ThrowIfCancellationRequested(); var useHash = retVal is string; var key = useHash ? "hash" : "height"; var val = retVal.ToString(); var request = new NexusRequest(new Dictionary <string, string> { { key, val }, { "verbose", ((int)txVerbosity).ToString() } }); return(await GetAsync <Block>("ledger/block", request, token, logOutput)); }
public async Task <Block> GetBlockAsync(int height, TxVerbosity txVerbosity = TxVerbosity.PubKeySign, CancellationToken token = default, bool logOutput = true) { token.ThrowIfCancellationRequested(); if (height <= 0) { throw new ArgumentException("Height must be greater than 0"); } var block = await GetBlockAsync((object)height, txVerbosity, token, logOutput); if (string.IsNullOrWhiteSpace(block?.Hash)) { throw new InvalidOperationException($"Get block {height} failed"); } return(block); }
public async Task <Block> GetBlockAsync(string hash, TxVerbosity txVerbosity = TxVerbosity.PubKeySign, CancellationToken token = default, bool logOutput = true) { token.ThrowIfCancellationRequested(); if (string.IsNullOrWhiteSpace(hash)) { throw new ArgumentException("Hash must have a value"); } var block = await GetBlockAsync((object)hash, txVerbosity, token, logOutput); if (string.IsNullOrWhiteSpace(block?.Hash)) { throw new InvalidOperationException($"Get block {hash} failed"); } return(block); }
public async Task <IEnumerable <Block> > GetBlocksAsync(string hash, int count = GetBlocksDefaultCount, TxVerbosity txVerbosity = TxVerbosity.PubKeySign, CancellationToken token = default, bool logOutput = true) { token.ThrowIfCancellationRequested(); if (string.IsNullOrWhiteSpace(hash)) { throw new ArgumentException("Hash must have a value"); } var blocks = await GetBlocks(hash, count, txVerbosity, token, logOutput); if (blocks == null) { throw new InvalidOperationException($"Get {count} blocks from {hash} failed"); } return(blocks); }
public async Task <IEnumerable <Block> > GetBlocksAsync(int height, int count = GetBlocksDefaultCount, TxVerbosity txVerbosity = TxVerbosity.PubKeySign, CancellationToken token = default, bool logOutput = true) { token.ThrowIfCancellationRequested(); if (height <= 0) { throw new ArgumentException("Height must be greater than 0"); } var blocks = await GetBlocks(height, count, txVerbosity, token, logOutput); if (blocks == null) { throw new InvalidOperationException($"Get {count} blocks from {height} failed"); } return(blocks); }
public async Task <IEnumerable <Transaction> > GetNotificationsAsync(GenesisId genesis, TxVerbosity txVerbosity = TxVerbosity.PubKeySign, CancellationToken token = default) { token.ThrowIfCancellationRequested(); if (string.IsNullOrWhiteSpace(genesis?.Genesis)) { throw new ArgumentException("Genesis is required"); } var request = new NexusRequest(new Dictionary <string, string> { { "genesis", genesis.Genesis }, { "verbose", ((int)txVerbosity).ToString() } }); var txs = await PostAsync <IEnumerable <Transaction> >("accounts/notifications", request, token); return(txs ?? new List <Transaction>()); }
public async Task <IEnumerable <Transaction> > GetTransactionsAsync(string userName, TxVerbosity txVerbosity = TxVerbosity.PubKeySign, CancellationToken token = default) { token.ThrowIfCancellationRequested(); if (string.IsNullOrWhiteSpace(userName)) { throw new ArgumentException("Username is required"); } var request = new NexusRequest(new Dictionary <string, string> { { "username", userName }, { "verbose", ((int)txVerbosity).ToString() } }); var txs = await PostAsync <IEnumerable <Transaction> >("accounts/transactions", request, token); return(txs ?? new List <Transaction>()); }
public async Task <Transaction> GetTransactionAsync(string hash, TxVerbosity txVerbosity = TxVerbosity.PubKeySign, CancellationToken token = default, bool logOutput = true) { token.ThrowIfCancellationRequested(); if (string.IsNullOrWhiteSpace(hash)) { throw new ArgumentException("Hash must have a value"); } var request = new NexusRequest(new Dictionary <string, string> { { "hash", hash }, { "verbose", ((int)txVerbosity).ToString() } }); var tx = await GetAsync <Transaction>("ledger/transaction", request, token, logOutput); if (string.IsNullOrWhiteSpace(tx?.Hash)) { throw new InvalidOperationException($"Get tx {hash} failed"); } return(tx); }