z_shieldcoinbase appears to need time to mature before being useful
@@ -190,6 +190,95 @@ namespace MiningCore.Blockchain.ZCash
/// </summary>
private async Task ShieldCoinbaseAsync()
{
+ // Emulate z_shieldcoinbase until its stable
+#if true
+ // get t-addr balance
+ var balanceResult = await daemon.ExecuteCmdSingleAsync<object>(BitcoinCommands.GetBalance);
+
+ if (balanceResult.Error != null)
+ {
+ logger.Error(() => $"[{LogCategory}] Daemon command '{BitcoinCommands.GetBalance}' returned error: {balanceResult.Error.Message} code {balanceResult.Error.Code}");
+ return;
+ }
+
+ var balance = (decimal)(double)balanceResult.Response;
+
+ if (balance > 0)
+ {
+ logger.Info(() => $"[{LogCategory}] Transferring {FormatAmount(balance)} to pool's z-addr");
+
+ // transfer to z-addr
+ var recipient = new ZSendManyRecipient
+ {
+ Address = poolExtraConfig.ZAddress,
+ Amount = balance - TransferFee
+ };
+
+ var args = new object[]
+ {
+ poolConfig.Address, // default account
+ new object[] // addresses and associated amounts
+ {
+ recipient
+ },
+ 10, // only spend funds covered by this many confirmations
+ TransferFee
+ };
+
+ // send command
+ var sendResult = await daemon.ExecuteCmdSingleAsync<string>(ZCashCommands.ZSendMany, args);
+
+ if (sendResult.Error != null)
+ {
+ logger.Error(() => $"[{LogCategory}] {ZCashCommands.ZSendMany} returned error: {balanceResult.Error.Message} code {balanceResult.Error.Code}");
+ return;
+ }
+
+ var operationId = sendResult.Response;
+
+ logger.Info(() => $"[{LogCategory}] {ZCashCommands.ZSendMany} operation id: {operationId}");
+
+ var continueWaiting = true;
+
+ while(continueWaiting)
+ {
+ var operationResultResponse = await daemon.ExecuteCmdSingleAsync<ZCashAsyncOperationStatus[]>(
+ ZCashCommands.ZGetOperationResult, new object[] { new object[] { operationId } });
+
+ if (operationResultResponse.Error == null &&
+ operationResultResponse.Response?.Any(x => x.OperationId == operationId) == true)
+ {
+ var operationResult = operationResultResponse.Response.First(x => x.OperationId == operationId);
+
+ if (!Enum.TryParse(operationResult.Status, true, out ZOperationStatus status))
+ {
+ logger.Error(() => $"Unrecognized operation status: {operationResult.Status}");
+ break;
+ }
+
+ switch(status)
+ {
+ case ZOperationStatus.Success:
+ var txId = operationResult.Result?.Value<string>("txid") ?? string.Empty;
+ logger.Info(() => $"[{LogCategory}] Balance transfer transaction id: {txId}");
+
+ continueWaiting = false;
+ continue;
+
+ case ZOperationStatus.Cancelled:
+ case ZOperationStatus.Failed:
+ logger.Error(() => $"{ZCashCommands.ZSendMany} failed: {operationResult.Error.Message} code {operationResult.Error.Code}");
+
+ continueWaiting = false;
+ continue;
+ }
+ }
+
+ logger.Info(() => $"[{LogCategory}] Waiting for operation completion: {operationId}");
+ await Task.Delay(TimeSpan.FromSeconds(10));
+ }
+ }
+#else
var args = new object[]
{
poolConfig.Address, // source: pool's t-addr receiving coinbase rewards
@@ -246,6 +335,7 @@ namespace MiningCore.Blockchain.ZCash
logger.Info(() => $"[{LogCategory}] Waiting for operation completion: {operationId}");
await Task.Delay(TimeSpan.FromSeconds(10));
}
+#endif
}
}
}
