Skip to content

Commit

Permalink
Merge pull request stratisproject#31 from VisualCrypt/testrules
Browse files Browse the repository at this point in the history
x1 updates
  • Loading branch information
netsfx authored Nov 7, 2019
2 parents 9ce3ef7 + 5bd3d67 commit 81728bd
Show file tree
Hide file tree
Showing 70 changed files with 2,891 additions and 2,960 deletions.
1 change: 1 addition & 0 deletions src/Obsidian-Min.sln
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ Global
{E3B96125-6F07-477F-A3F1-5C76CF960485} = {E4693985-DDF7-4CF3-887B-0291135F9499}
{1685ED2A-97A5-446D-9A79-3DD2BC4EC579} = {E4693985-DDF7-4CF3-887B-0291135F9499}
{25B6933E-2ACC-43D9-BA85-7B5CAFDB6578} = {4208F272-5766-46B4-8648-B5B5666166C5}
{E0200816-8040-40B0-80E6-0AFD4006DC29} = {1B9A916F-DDAC-4675-B424-EDEDC1A58231}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {6C780ABA-5872-4B83-AD3F-A5BD423AD907}
Expand Down
94 changes: 30 additions & 64 deletions src/Obsidian.Features.X1Wallet.SecureApi/SecureApiController.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using NBitcoin;
using Obsidian.Features.X1Wallet.Models;
using Obsidian.Features.X1Wallet.Models.Api;
using Obsidian.Features.X1Wallet.Models.Api.Requests;
using Obsidian.Features.X1Wallet.Models.Api.Responses;
using Obsidian.Features.X1Wallet.SecureApi.Models;
using Obsidian.Features.X1Wallet.Staking;
using Stratis.Bitcoin.Controllers.Models;
using Stratis.Bitcoin.Features.Wallet.Models;
using Obsidian.Features.X1Wallet.Transactions;
using VisualCrypt.VisualCryptLight;

namespace Obsidian.Features.X1Wallet.SecureApi
Expand Down Expand Up @@ -36,7 +37,7 @@ public async Task<ECCModel> ExecuteAsync([FromBody]RequestObject request)
{
if (IsRequestForPublicKey(request))
return CreatePublicKey();
await Task.Delay(1000);

DecryptedRequest decryptedRequest = DecryptRequest(request, this.walletController);
CheckPermissions(decryptedRequest, this.secureApiSettings);

Expand All @@ -46,113 +47,78 @@ public async Task<ECCModel> ExecuteAsync([FromBody]RequestObject request)
case "createWallet":
{
WalletCreateRequest walletCreateRequest = Deserialize<WalletCreateRequest>(decryptedRequest.Payload);
await this.walletController.CreateKeyWalletAsync(walletCreateRequest);
this.walletController.CreateWallet(walletCreateRequest);
return CreateOk(request);
}
case "getWalletFiles":
{
WalletFileModel walletFileModel = await this.walletController.ListWalletsFilesAsync();
return CreateOk(walletFileModel, request);
}
case "loadWallet":
{
LoadWalletResponse loadWalletResponse = await this.walletController.LoadAsync();
LoadWalletResponse loadWalletResponse = this.walletController.LoadWallet();
return CreateOk(loadWalletResponse, request);
}
case "generalInfo":
{
WalletGeneralInfoModel walletGeneralInfoModel = await this.walletController.GetGeneralInfoAsync();
return CreateOk(walletGeneralInfoModel, request);
}
case "nodeStatus":
case "daemonInfo": // one-time information about the running daemon, includes list of wallet files
{
StatusModel nodeStatus = this.walletController.GetNodeStatus();
return CreateOk(nodeStatus, request);
DaemonInfo daemonStatus = this.walletController.GetDaemonInfo();
return CreateOk(daemonStatus, request);
}

case "balance":
{
Balance balanceModel = await this.walletController.GetBalanceAsync(decryptedRequest.Target);
return CreateOk(balanceModel, request);
}

case "history":
case "walletInfo": // does not depend on weather a wallet is loaded, but if a wallet is loaded, it includes all wallet info, including balance and staking info when enabled
{
// Deprecated
var walletHistoryRequest = Deserialize<WalletHistoryRequest>(decryptedRequest.Payload);
return CreateOk(new WalletHistoryModel(), request);
WalletInfo walletInfo = this.walletController.GetWalletInfo();
return CreateOk(walletInfo, request);
}

case "stakingInfo":
case "historyInfo":
{
GetStakingInfoModel stakingInfo = this.walletController.GetStakingInfo();
return CreateOk(stakingInfo, request);
var historyRequest = Deserialize<HistoryRequest>(decryptedRequest.Payload);
HistoryInfo historyInfo = this.walletController.GetHistoryInfo(historyRequest);
return CreateOk(historyInfo, request);
}

case "getReceiveAddresses":
{
// this command will only return one unused address or throw if the wallet is out of unused addresses
var addressesModel = await this.walletController.GetUnusedReceiveAddresses();
var addressesModel = this.walletController.GetUnusedReceiveAddresses();
return CreateOk(addressesModel, request);
}

case "estimateFee":
{
var txFeeEstimateRequest = Deserialize<TxFeeEstimateRequest>(decryptedRequest.Payload);
Money fee = await this.walletController.GetTransactionFeeEstimateAsync(txFeeEstimateRequest);
var txFeeEstimateRequest = Deserialize<TransactionRequest>(decryptedRequest.Payload);
long fee = this.walletController.EstimateFee(txFeeEstimateRequest);
return CreateOk(fee, request);
}
case "buildTransaction":
{
var buildTransactionRequest = Deserialize<BuildTransactionRequest>(decryptedRequest.Payload);
WalletBuildTransactionModel walletBuildTransactionModel = await this.walletController.BuildTransactionAsync(buildTransactionRequest);
return CreateOk(walletBuildTransactionModel, request);
}

case "sendTransaction":
{
SendTransactionRequest sendTransactionRequest = Deserialize<SendTransactionRequest>(decryptedRequest.Payload);
await this.walletController.SendTransactionAsync(sendTransactionRequest);
return CreateOk(request);
}

case "buildAndSendTransaction":
{
var buildTransactionRequest = Deserialize<BuildTransactionRequest>(decryptedRequest.Payload);
WalletBuildTransactionModel walletBuildTransactionModel = await this.walletController.BuildTransactionAsync(buildTransactionRequest);
var sendTransactionRequest = new SendTransactionRequest { Hex = walletBuildTransactionModel.Hex };
await this.walletController.SendTransactionAsync(sendTransactionRequest);
return CreateOk(walletBuildTransactionModel, request);
var buildTransactionRequest = Deserialize<TransactionRequest>(decryptedRequest.Payload);
TransactionResponse transactionResponse = this.walletController.BuildTransaction(buildTransactionRequest);
return CreateOk(transactionResponse, request);
}

case "syncFromDate":
case "repair":
{
var walletSyncFromDateRequest = Deserialize<WalletSyncFromDateRequest>(decryptedRequest.Payload);
await this.walletController.SyncFromDate(walletSyncFromDateRequest);
var walletSyncFromDateRequest = Deserialize<RepairRequest>(decryptedRequest.Payload);
this.walletController.Repair(walletSyncFromDateRequest);
return CreateOk(request);
}

case "importKeys":
{
var importKeysRequest = Deserialize<ImportKeysRequest>(decryptedRequest.Payload);
var importKeysResponse = await this.walletController.ImportKeysAsync(importKeysRequest);
var importKeysResponse = this.walletController.ImportKeys(importKeysRequest);
return CreateOk(importKeysResponse, request);
}
case "exportKeys":
{
var exportKeysRequest = Deserialize<ExportKeysRequest>(decryptedRequest.Payload);
var exportKeysResponse = await this.walletController.ExportKeysAsync(exportKeysRequest);
var exportKeysResponse = this.walletController.ExportKeys(exportKeysRequest);
return CreateOk(exportKeysResponse, request);
}
case "startStaking":
{
var startStakingRequest = Deserialize<StartStakingRequest>(decryptedRequest.Payload);
await this.walletController.StartStaking(startStakingRequest);
this.walletController.StartStaking(startStakingRequest);
return CreateOk(request);
}
case "stopStaking":
{
await this.walletController.StopStaking();
this.walletController.StopStaking();
return CreateOk(request);
}
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
using System.Net;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using Obsidian.Features.X1Wallet.Feature;
using Obsidian.Features.X1Wallet.Models.Wallet;
using Obsidian.Features.X1Wallet.SecureApi.Models;
using Obsidian.Features.X1Wallet.Tools;
using VisualCrypt.VisualCryptLight;
using VisualCrypt.VisualCryptLight.VisualCryptLib.ECC;

Expand Down Expand Up @@ -104,8 +105,8 @@ protected static DecryptedRequest DecryptRequest(RequestObject request, WalletCo
if (((IList)CommandsWithoutWalletNameCheck).Contains(decryptedRequest.Command))
return decryptedRequest;
if (decryptedRequest.Target == null)
throw new X1WalletException(HttpStatusCode.BadRequest, "No wallet name was supplied.", null);
walletController.SetWalletName(decryptedRequest.Target);
throw new X1WalletException(HttpStatusCode.BadRequest, "No wallet name was supplied.");
walletController.SetWalletName(decryptedRequest.Target.Replace($".{walletController.CoinTicker}{X1WalletFile.FileExtension}", ""));
return decryptedRequest;
}

Expand Down Expand Up @@ -139,21 +140,12 @@ protected static void CheckPermissions(DecryptedRequest decryptedRequest, Secure

protected static T Deserialize<T>(string json)
{
return JsonConvert.DeserializeObject<T>(json);
return Serializer.Deserialize<T>(json);
}

static string Serialize<T>(ResponseObject<T> responseObject)
{
DefaultContractResolver contractResolver = new DefaultContractResolver
{
NamingStrategy = new CamelCaseNamingStrategy()
};
string json = JsonConvert.SerializeObject(responseObject, new JsonSerializerSettings
{
ContractResolver = contractResolver,
Formatting = Formatting.Indented
});
return json;
return Serializer.Serialize(responseObject);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class SecureApiSettings
/// <summary>
/// Default for whether SecureApi is enabled.
/// </summary>
public const bool IsSecureApiEnabledDefaultValue = false;
public const bool IsSecureApiEnabledDefaultValue = true;

/// <summary>
/// Host, e.g. 'http://0.0.0.0' for remote access or 'http://localhost' for local-only access. Default: SecureApiDefaultHostBinding.
Expand Down
13 changes: 1 addition & 12 deletions src/Obsidian.Features.X1Wallet/Feature/FullNodeFeature.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
using System;
using Microsoft.Extensions.DependencyInjection;
using NBitcoin.Policy;
using Obsidian.Features.X1Wallet.Staking;
using Obsidian.Features.X1Wallet.Transactions;
using Stratis.Bitcoin.Builder;
using Stratis.Bitcoin.Configuration.Logging;
using Stratis.Bitcoin.Consensus;
using Stratis.Bitcoin.Features.BlockStore;
using Stratis.Bitcoin.Features.ColdStaking;
using Stratis.Bitcoin.Features.MemoryPool;
Expand All @@ -14,7 +10,6 @@
using Stratis.Bitcoin.Features.Wallet;
using Stratis.Bitcoin.Features.Wallet.Broadcasting;
using Stratis.Bitcoin.Features.Wallet.Interfaces;
using Stratis.Bitcoin.Interfaces;
using Stratis.Bitcoin.Mining;

namespace Obsidian.Features.X1Wallet.Feature
Expand Down Expand Up @@ -44,22 +39,16 @@ public static IFullNodeBuilder UseX1Wallet(this IFullNodeBuilder fullNodeBuilder
.FeatureServices(services =>
{
services.AddSingleton<WalletManagerFactory>();
services.AddSingleton<StakingCore>();
services.AddSingleton<BlockDefinition, PowBlockDefinition>();
services.AddSingleton<BlockDefinition, PosBlockDefinition>();
services.AddSingleton<BlockDefinition, PosPowBlockDefinition>();
services.AddSingleton<IBlockProvider, BlockProvider>();
services.AddSingleton<MinerSettings>();
services.AddSingleton<IPowMining, PowMining>();
services.AddSingleton<IWalletTransactionHandler, TransactionHandler>();
services.AddSingleton<IWalletFeePolicy, WalletFeePolicy>();
services.AddSingleton<WalletSettings>();
services.AddTransient<WalletController>();
services.AddSingleton<IBroadcasterManager, FullNodeBroadcasterManager>();
services.AddSingleton<BroadcasterBehavior>();
services.AddSingleton<IScriptAddressReader>(new ScriptAddressReader());
services.AddSingleton<StandardTransactionPolicy>();
services.AddSingleton<IAddressBookManager, AddressBookManager>();
services.AddSingleton<MinerSettings>();
});
});

Expand Down
Loading

0 comments on commit 81728bd

Please sign in to comment.