Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OpReturnDataIsHex in build-tx-request to store hex bytes #348

Merged
merged 8 commits into from
Aug 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using NBitcoin;
using NBitcoin.DataEncoders;

namespace Blockcore.Features.Wallet.Api.Controllers
{
Expand Down Expand Up @@ -421,6 +422,35 @@ public IActionResult GetHistory([FromQuery] WalletHistoryRequest request)
}
}

/// <summary>
/// Gets the history of a wallet with reduced metadata. Note: This method will filter out transactions sent to self wallet.
/// </summary>
/// <param name="request">An object containing the parameters used to retrieve a wallet's history.</param>
/// <returns>A JSON object containing the wallet history.</returns>
[Route("history/slim")]
[HttpGet]
public IActionResult GetHistorySlim([FromQuery] WalletHistoryRequest request)
{
Guard.NotNull(request, nameof(request));

if (!this.ModelState.IsValid)
{
return ModelStateErrors.BuildErrorResponse(this.ModelState);
}

try
{
WalletHistoryModel model = WalletModelBuilder.GetHistorySlim(this.walletManager, this.network, request);
sondreb marked this conversation as resolved.
Show resolved Hide resolved

return this.Json(model);
}
catch (Exception e)
{
this.logger.LogError("Exception occurred: {0}", e.ToString());
return ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString());
}
}

/// <summary>
/// Gets the balance of a wallet in STRAT (or sidechain coin). Both the confirmed and unconfirmed balance are returned.
/// </summary>
Expand Down Expand Up @@ -629,13 +659,18 @@ public IActionResult GetTransactionFeeEstimate([FromBody] TxFeeEstimateRequest r
});
}

var (opReturnRawData, isValid) = request.OpReturnDataIsHex ? TryGetHexValue(request.OpReturnData) : (null, true);
if (!isValid)
return ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, "Hex OpReturn error.", "The OpReturnData is set as a hex value and could not be decoded");

var context = new TransactionBuildContext(this.network)
{
AccountReference = new WalletAccountReference(request.WalletName, request.AccountName),
FeeType = FeeParser.Parse(request.FeeType),
MinConfirmations = request.AllowUnconfirmed ? 0 : 1,
Recipients = recipients,
OpReturnData = request.OpReturnData,
OpReturnRawData = opReturnRawData,
OpReturnAmount = string.IsNullOrEmpty(request.OpReturnAmount) ? null : Money.Parse(request.OpReturnAmount),
Sign = false
};
Expand Down Expand Up @@ -698,13 +733,18 @@ public IActionResult BuildTransaction([FromBody] BuildTransactionRequest request
}
}

var (opReturnRawData, isValid) = request.OpReturnDataIsHex ? TryGetHexValue(request.OpReturnData) : (null, true);
if (!isValid)
return ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, "Hex OpReturn error.", "The OpReturnData is set as a hex value and could not be decoded");

var context = new TransactionBuildContext(this.network)
{
AccountReference = new WalletAccountReference(request.WalletName, request.AccountName),
TransactionFee = string.IsNullOrEmpty(request.FeeAmount) ? null : Money.Parse(request.FeeAmount),
MinConfirmations = request.AllowUnconfirmed ? 0 : 1,
Shuffle = request.ShuffleOutputs ?? true, // We shuffle transaction outputs by default as it's better for anonymity.
OpReturnData = request.OpReturnData,
OpReturnRawData = opReturnRawData,
sondreb marked this conversation as resolved.
Show resolved Hide resolved
OpReturnAmount = string.IsNullOrEmpty(request.OpReturnAmount) ? null : Money.Parse(request.OpReturnAmount),
WalletPassword = request.Password,
SelectedInputs = request.Outpoints?.Select(u => new OutPoint(uint256.Parse(u.TransactionId), u.Index)).ToList(),
Expand Down Expand Up @@ -1602,5 +1642,17 @@ private void SyncFromBestHeightForRecoveredWallets(DateTime walletCreationDate)
this.walletSyncManager.SyncFromHeight(blockHeightToSyncFrom);
}
}

private (byte[], bool) TryGetHexValue(string hexString)
{
try
{
return (Encoders.Hex.DecodeData(hexString), true);
}
catch
{
return (null, false);
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,11 @@ public TxFeeEstimateRequest()
/// </summary>
public string OpReturnData { get; set; }

/// <summary>
/// Sets if the OpReturnData is a hex value and must be decoded
/// </summary>
public bool OpReturnDataIsHex { get; set; }

/// <summary>
/// The funds in STRAT (or a sidechain coin) to include with the OP_RETURN output. Currently, specifying
/// some funds helps OP_RETURN outputs be relayed around the network.
Expand Down
10 changes: 8 additions & 2 deletions src/Networks/Blockcore.Networks.OpenExo/OpenExoSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,14 @@ internal class OpenExoSetup
{ 400000, new CheckpointInfo(new uint256("0x78da79e80c94c2a175276eb4b903a15395d4213e8814d1f1fabc225e05c56e69"), new uint256("0xc7179fa14c296ebc661f2f1db32d4492cc176d86fe64ad14fb2058ac0f132294")) },
{ 450000, new CheckpointInfo(new uint256("0xfaa749cba84d1111affe61cb8c14ba43a452a265a136066554a22cfa14cabfcd"), new uint256("0x651884ceb30069212c90b5fb3a11d2e6263c0a5c76d6b9b92274ffd6cb3b8fea")) },
{ 600000, new CheckpointInfo(new uint256("0xa4bf14b94da99b72abafb66624e0f238bef68f9141f79f811f618d67bd8149d1"), new uint256("0x99199a7ac240838d58e362e834e43fc52b74e146f84ce3d879d4c213a4799745")) },
{ 790000, new CheckpointInfo(new uint256("0x11610eefff99c06e8fe4667adb07f8598c339ed04e6eed5414b115fb7d4cfd49"), new uint256("0x46cb091b43846e21b547ebf3787deab210628919421180d4cc8275d276fe1cda")) }

{ 790000, new CheckpointInfo(new uint256("0x11610eefff99c06e8fe4667adb07f8598c339ed04e6eed5414b115fb7d4cfd49"), new uint256("0x46cb091b43846e21b547ebf3787deab210628919421180d4cc8275d276fe1cda")) },
{ 900000, new CheckpointInfo(new uint256("0x960369823996b14b7f08b876e8f95378119831ce81a72886434c9fd41d04c580"), new uint256("0x019aec9d3716f63d5c645b860b752e1699f176eaa4830e2daeb4fa1831b119d1")) },
{ 1000000, new CheckpointInfo(new uint256("0x1a1fc554ec11796d1c98a674ebd419db9abeba14419b97964f3ce357986d0350"), new uint256("0x8f9b2589afadc9e1f56e6cc216f3feb267339a825b9fcbb36f25c90edac8f0bd")) },
{ 1300000, new CheckpointInfo(new uint256("0x260b7433a7c72694f57f2e0ea6821f5ab33afea3c567f9845c8a989eb443f9d4"), new uint256("0x79f20f2a22bb3c8a0808e6d5e0daa7d8ce0ecbefcd1d842fa2e5a23e14b22d45")) },
{ 1355000, new CheckpointInfo(new uint256("0x890101f0f9b4c16c39eafeca5aa744772b7612eb003583200a5836cbb0acb332"), new uint256("0x5c34eb0ef4759118e720bdc57a72ffe4d8d4048e2706d053f420e2a2c399fe6c")) },
{ 1401000, new CheckpointInfo(new uint256("0x9eb2e4d7650f401e5d27af3fd66848c3318e7a2a660d44b3c8196ab0c956e074"), new uint256("0xff4fd825959265782056f501e68406dcc50e2fe9bc9f82d773f26a6318cf1529")) },
{ 1464600, new CheckpointInfo(new uint256("0xb2fbdc8e6d87a8a3a5322e32939fb9c1c06527f5edfc818a500122985360763e"), new uint256("0x364d3e3cfe66fced6b101d8240106af46b951c500b20223b0ea23c47d51127ea")) },
{ 1567000, new CheckpointInfo(new uint256("0xd2bd6c7a2dec44a739d25cc669245107a97474abcfc8f94367fcbd19b829d28f"), new uint256("0x60c7ae802655cc063061e9d15a05444db0aa742f54dde3f4bdbca70670792737")) }
}
};

Expand Down