//TODO: should asset that the block came from main? Types.Block GetBlock(byte[] key) { using (TransactionContext context = _DBContext.GetTransactionContext()) { var location = BlockStore.GetLocation(context, key); if (location == LocationEnum.Main) { try { var bk = BlockStore.GetBlock(context, key); return(bk == null ? null : bk.Value); } catch (Exception e) { BlockChainTrace.Error("GetBlock", e); return(null); } } return(null); } }
//void HandleQueueAction(QueueAction action) async Task ConsumeAsync(ISourceBlock <QueueAction> source) { while (await source.OutputAvailableAsync()) { var action = source.Receive(); try { //((dynamic)this).Handle((dynamic)action); if (action is HandleBlockAction) { ((HandleBlockAction)action).SetResult(HandleBlock(action as HandleBlockAction)); } else if (action is GetActiveContractsAction) { ((GetActiveContractsAction)action).SetResult(GetActiveContracts()); } else if (action is GetContractPointedOutputsAction) { ((GetContractPointedOutputsAction)action).SetResult(GetContractPointedOutputs( ((GetContractPointedOutputsAction)action).ContractHash)); } else if (action is HandleOrphansOfTxAction) { HandleOrphansOfTransaction(action as HandleOrphansOfTxAction); } else if (action is GetIsContractActiveAction) { ((GetIsContractActiveAction)action).SetResult(IsContractActive( ((GetIsContractActiveAction)action).ContractHash)); } //else if (action is GetUTXOAction) //((GetUTXOAction)action).SetResult(GetUTXO(((GetUTXOAction)action).Outpoint, ((GetUTXOAction)action).IsInBlock)); else if (action is GetIsConfirmedUTXOExistAction) { var outpoint = ((GetIsConfirmedUTXOExistAction)action).Outpoint; ((GetIsConfirmedUTXOExistAction)action).SetResult(IsConfirmedUTXOExist(outpoint)); } else if (action is GetContractCodeAction) { ((GetContractCodeAction)action).SetResult(GetContractCode( ((GetContractCodeAction)action).ContractHash)); } else if (action is HandleTransactionAction) { ((HandleTransactionAction)action).SetResult(HandleTransaction(((HandleTransactionAction)action).Tx, ((HandleTransactionAction)action).CheckInDb)); } else if (action is GetBlockAction) { ((GetBlockAction)action).SetResult(GetBlock(((GetBlockAction)action).BkHash)); } else if (action is GetTxAction) { ((GetTxAction)action).SetResult(GetTransaction(((GetTxAction)action).TxHash)); } else if (action is ExecuteContractAction) { var executeContractAction = ((ExecuteContractAction)action); Types.Transaction tx; var result = AssembleAutoTx(executeContractAction.ContractHash, executeContractAction.Message, out tx, executeContractAction.Message != null); ((ExecuteContractAction)action).SetResult(new Tuple <bool, Types.Transaction>(result, tx)); } //TODO: remove else if (action is GetUTXOSetAction) { var getUTXOSetAction = (GetUTXOSetAction)action; HashDictionary <List <Types.Output> > txOutputs; HashDictionary <Types.Transaction> txs; GetUTXOSet(getUTXOSetAction.Predicate, out txOutputs, out txs); getUTXOSetAction.SetResult(new Tuple <HashDictionary <List <Types.Output> >, HashDictionary <Types.Transaction> >(txOutputs, txs)); } //TODO: rename else if (action is GetUTXOSetAction2) { using (var dbTx = _DBContext.GetTransactionContext()) { ((GetUTXOSetAction2)action).SetResult(UTXOStore.All(dbTx).ToList()); } } #if TEST else if (action is GetBlockLocationAction) { using (var dbTx = _DBContext.GetTransactionContext()) { ((GetBlockLocationAction)action).SetResult(BlockStore.GetLocation(dbTx, ((GetBlockLocationAction)action).Block)); } } #endif } catch (Exception e) { #if DEBUG BlockChainTrace.Error("Blockchain request handle got an exception.\n\nOriginal caller's stack:\n\n" + action.StackTrace + "\n\nException:\n\n", e); #else BlockChainTrace.Error("Blockchain request exception", e); #endif } } }