private int gitCreateBranch(VaultVersionInfo info, out string currentBranch) { /* get vault items (itempath1/itempath2) * filter by itempath2 = branchpath * get source branch from end of itempath1 * get hash of latest commit in the identified branch * use the hash as the source of the branch */ TxInfo txDetail = ServerOperations.ProcessCommandTxDetail(info.TxId); string sourceBranch; var items = txDetail.items.Where(i => (i.ItemPath2 == info.Path || info.Path.StartsWith(i.ItemPath2 + "/"))); if (items.Count() > 0) { sourceBranch = items.FirstOrDefault().ItemPath1.Split('/').LastOrDefault(); } else { sourceBranch = "master:"; } string gitStartPoint = GetMapping(new VaultVersionInfo { Branch = Tools.GetBranchMapping(sourceBranch), TxId = 0 }); string[] msgs; int ticks = runGitCommand(string.Format(_gitCreateBranch, info.Branch, gitStartPoint), string.Empty, out msgs); currentBranch = info.Branch; return(ticks); }
public void Submit() { txtStatus.text = "Sending..."; TxInfo txInfo = new TxInfo() { sender = lamdenTest.GetWallet(), contractName = contractName, methodName = methodName, stampLimit = 100, kwargs = new Dictionary <string, KwargType> { { "UID", new KT_UID(inUid.text) }, { "Str", new KT_String(inStr.text) }, { "Float", new KT_Numeric(float.Parse(inFloat.text)) }, { "Int", new KT_Int(int.Parse(InInt.text)) }, { "Bool", new KT_Bool(ddBool.value == 0 ? true : false) }, { "Dict", new KT_Dict(new Dictionary <string, KwargType> { { "test", new KT_String("my test") } }) }, { "List", new KT_List(new List <KwargType> { new KT_Numeric(1.2f), new KT_String("test2") }) }, { "ANY", new KT_Numeric(1.1f) }, { "DateTime", new KT_DateTime(DateTime.Now) }, { "TimeDelta", new KT_TimeDelta(4898) } } //kwargs = new Dictionary<string, KwargType> // { // {"UID", new KT_UID("testing2")}, // {"Str", new KT_String("this is another string")}, // {"Float", new KT_Numeric(1.1f)}, // {"Int", new KT_Int(2)}, // {"Bool", new KT_Bool(false)}, // {"Dict", new KT_Dict(new Dictionary<string, KwargType>{ {"test", new KT_String("my test")}})}, // {"List", new KT_List(new List<KwargType>{ new KT_Numeric(1.2f), new KT_String("test2")})}, // {"ANY", new KT_Numeric(1.1f) }, // {"DateTime", new KT_DateTime(DateTime.Now)}, // {"TimeDelta", new KT_TimeDelta(4898)} // } }; Transaction tx = new Transaction(lamdenTest.masterNodeApi, txInfo, (Transaction.TransactionStatus txStatus, TxResponse txResponse) => { if (txStatus == Transaction.TransactionStatus.SubmittedProcessing) { txtStatus.text = "Sumbitted and processing..."; } if (txStatus == Transaction.TransactionStatus.Completed) { txtStatus.text = "Processed successfully!"; } if (txStatus == Transaction.TransactionStatus.Error) { txtStatus.text = txResponse.error; } }); }
public IEnumerator TestKwargs() { SetupGood(); Wallet wallet = new Wallet(); wallet.Load("3b1efc0a2cfd9d92581afc927c443bb53157fffae0f533995f2830643542467c"); TxInfo txInfo = new TxInfo() { sender = wallet, contractName = "con_values_testing", methodName = "test_values", stampLimit = 100, kwargs = new Dictionary <string, KwargType> { { "UID", new KT_UID("testing") }, { "Str", new KT_String("this is another string") }, { "Float", new KT_Numeric(1.1f) }, { "Int", new KT_Int(2) }, { "Bool", new KT_Bool(false) }, { "Dict", new KT_Dict(new Dictionary <string, KwargType> { { "test", new KT_String("my test") } }) }, { "List", new KT_List(new List <KwargType> { new KT_Numeric(1.2f), new KT_String("test2") }) }, { "ANY", new KT_Numeric(1.1f) }, { "DateTime", new KT_DateTime(DateTime.Now) }, { "TimeDelta", new KT_TimeDelta(4898) } } }; Transaction tx = new Transaction(masterNodeApiGood, txInfo, (Transaction.TransactionStatus txStatus, TxResponse txResponse) => { if (txStatus == Transaction.TransactionStatus.SubmittedProcessing) { Assert.IsTrue(txResponse.success.Equals("Transaction successfully submitted to the network.")); } if (txStatus == Transaction.TransactionStatus.Completed) { Assert.AreEqual(txResponse.transactionData.status, 0); } if (txStatus == Transaction.TransactionStatus.Completed || txStatus == Transaction.TransactionStatus.Error) { calledBack = true; } }); // Use the Assert class to test conditions. // Use yield to skip a frame. yield return(null); while (!calledBack) { yield return(null); } }
public IEnumerator TestTransaction() { SetupGood(); Wallet wallet = new Wallet(); wallet.Load("c8a3c5333aa3b058c4fa16d48db52355ab62ddc8daa9a183706a912e522440b6"); TxInfo txInfo = new TxInfo() { sender = wallet, contractName = "currency", methodName = "transfer", stampLimit = 100, kwargs = new Dictionary <string, KwargType> { { "to", new KT_String("4680c6ea89ffc29b0b670a5712edef2b62bc0cf40bfba2f20bbba759cdd185b9") }, { "amount", new KT_Numeric(1.0f) } } }; Transaction tx = new Transaction(masterNodeApiGood, txInfo, (Transaction.TransactionStatus txStatus, TxResponse txResponse) => { if (txStatus == Transaction.TransactionStatus.SubmittedProcessing) { Assert.IsTrue(txResponse.success.Equals("Transaction successfully submitted to the network.")); } if (txStatus == Transaction.TransactionStatus.Completed) { Assert.AreEqual(txResponse.transactionData.status, 0); } if (txStatus == Transaction.TransactionStatus.Completed || txStatus == Transaction.TransactionStatus.Error) { calledBack = true; } }); // Use the Assert class to test conditions. // Use yield to skip a frame. yield return(null); while (!calledBack) { yield return(null); } }
private void SetupViews() { Messenger.Default.Register <string>(this, "OpenAboutView", (string s) => About.ShowDialog()); Messenger.Default.Register <string>(this, "CloseAboutView", (string s) => About.Close()); Messenger.Default.Register <string>(this, "OpenCreateWalletView", (string s) => CreateWallet.ShowDialog()); Messenger.Default.Register <string>(this, "CloseCreateWalletView", (string s) => CreateWallet.Close()); Messenger.Default.Register <string>(this, "OpenLicenseView", (string s) => License.ShowDialog()); Messenger.Default.Register <string>(this, "CloseLicenseView", (string s) => License.Close()); Messenger.Default.Register <string>(this, "OpenManageWalletView", (string s) => ManageWallet.ShowDialog()); Messenger.Default.Register <string>(this, "CloseManageWalletView", (string s) => ManageWallet.Close()); Messenger.Default.Register <string>(this, "OpenPromptPasswordView", (string s) => PromptPassword.ShowDialog()); Messenger.Default.Register <string>(this, "ClosePromptPasswordView", (string s) => PromptPassword.Close()); Messenger.Default.Register <string>(this, "OpenReceiveView", (string s) => Receive.ShowDialog()); Messenger.Default.Register <string>(this, "CloseReceiveView", (string s) => Receive.Close()); Messenger.Default.Register <string>(this, "OpenRecoverWalletView", (string s) => RecoverWallet.ShowDialog()); Messenger.Default.Register <string>(this, "CloseRecoverWalletView", (string s) => RecoverWallet.Close()); Messenger.Default.Register <string>(this, "OpenRecoveryPhraseView", (string s) => RecoveryPhrase.ShowDialog()); Messenger.Default.Register <string>(this, "CloseRecoveryPhraseView", (string s) => RecoveryPhrase.Close()); Messenger.Default.Register <string>(this, "OpenSendView", (string s) => Send.ShowDialog()); Messenger.Default.Register <string>(this, "CloseSendView", (string s) => Send.Close()); Messenger.Default.Register <string>(this, "OpenSetLanguageView", (string s) => SetLanguage.ShowDialog()); Messenger.Default.Register <string>(this, "CloseSetLanguageView", (string s) => SetLanguage.Close()); Messenger.Default.Register <string>(this, "OpenSetPasswordView", (string s) => SetPassword.ShowDialog()); Messenger.Default.Register <string>(this, "CloseSetPasswordView", (string s) => SetPassword.Close()); Messenger.Default.Register <string>(this, "OpenSimpleDialogView", (string s) => SimpleDialog.ShowDialog()); Messenger.Default.Register <string>(this, "CloseSimpleDialogView", (string s) => SimpleDialog.Close()); Messenger.Default.Register <string>(this, "OpenTxInfoView", (string s) => TxInfo.ShowDialog()); Messenger.Default.Register <string>(this, "CloseTxInfoView", (string s) => TxInfo.Close()); Messenger.Default.Register <string>(this, "OpenWalletInfoView", (string s) => WalletInfo.ShowDialog()); Messenger.Default.Register <string>(this, "CloseWalletInfoView", (string s) => WalletInfo.Close()); Messenger.Default.Register <string>(this, "OpenWelcomeView", (string s) => Welcome.ShowDialog()); Messenger.Default.Register <string>(this, "CloseWelcomeView", (string s) => Welcome.Close()); }
private void GetAndCommitTransaction(string vaultRepoPath, VaultTxHistoryItem txHistoryItem, TxInfo txInfo, string gitBranch, Stopwatch perTransactionWatch) { var files = string.Join(",", txInfo.items.Select(x => string.IsNullOrEmpty(x.ItemPath1) ? x.Name : x.ItemPath1)); Log.Debug($"Processing transaction ID {txHistoryItem.TxID}: commit time: {txHistoryItem.TxDate.GetDateTime():u}, comment: {txHistoryItem.Comment}, author: {txHistoryItem.UserLogin}, files/dirs: {files}"); var itemsFailedToGet = new HashSet <string>(); // It has been noticed that renames tend to be listed at the end of txnInfo.items. Make sure this event precedes content updates foreach (var txDetailItem in txInfo.items.OrderBy(x => x.RequestType != VaultRequestType.Rename && x.RequestType != VaultRequestType.Move)) { if (!TryFindMatchingSubdir(vaultRepoPath, txDetailItem.ItemPath1, out var vaultSubdirectory) && !TryFindMatchingSubdir(vaultRepoPath, txDetailItem.ItemPath2, out vaultSubdirectory)) { continue; } if (ForceFullFolderGet) { continue; } var itemPath = RemoveRepoFromItemPath(vaultRepoPath, string.IsNullOrEmpty(txDetailItem.ItemPath1) ? txDetailItem.Name : txDetailItem.ItemPath1); var versionToGet = txDetailItem.Version; switch (txDetailItem.RequestType) { // Do deletions, renames and moves ourselves case VaultRequestType.Delete: { var filesystemPath = txDetailItem.ItemPath1.Replace(vaultRepoPath, WorkingFolder); if (File.Exists(filesystemPath)) { File.Delete(filesystemPath); } else if (Directory.Exists(filesystemPath)) { Directory.Delete(filesystemPath, true); } continue; } case VaultRequestType.Share: case VaultRequestType.CheckOut: case VaultRequestType.LabelItem: case VaultRequestType.AddFolder: // Nothing in a CopyBranch to do. Its just a place marker case VaultRequestType.CopyBranch: // Git doesn't add empty folders continue; case VaultRequestType.Move: case VaultRequestType.Rename: { Log.Debug($"Handling rename/move from {txDetailItem.ItemPath1} to {txDetailItem.ItemPath2}"); var item1NoRepoPath = RemoveRepoFromItemPath(vaultRepoPath, txDetailItem.ItemPath1); var item1FsPath = Path.Combine(WorkingFolder, item1NoRepoPath); var item2NoRepoPath = txDetailItem.RequestType == VaultRequestType.Move ? RemoveRepoFromItemPath(vaultRepoPath, txDetailItem.ItemPath2) : // Move item1NoRepoPath.Remove(item1NoRepoPath.Length - Path.GetFileName(txDetailItem.ItemPath1).Length) + txDetailItem.ItemPath2; // Rename var item2FsPath = Path.Combine(WorkingFolder, item2NoRepoPath); DeleteFileOrFolder(item2FsPath); if (!TryFindMatchingSubdir(vaultRepoPath, item2NoRepoPath, out _)) { DeleteFileOrFolder(item1FsPath); continue; } if (Directory.Exists(item1FsPath)) { var item2FsPathNoSlashEnding = item2FsPath.EndsWith("/") || item2FsPath.EndsWith("\\") ? item2FsPath.Substring(item2FsPath.Length - 1) : item2FsPath; Directory.CreateDirectory(Path.GetDirectoryName(item2FsPathNoSlashEnding)); Directory.Move(item1FsPath, item2FsPath); } else if (File.Exists(item1FsPath)) { Directory.CreateDirectory(Path.GetDirectoryName(item2FsPath)); File.Move(item1FsPath, item2FsPath); } else { versionToGet = txDetailItem.OtherVersion; itemPath = item2NoRepoPath; break; } continue; } } // Apply the changes from vault of the correct version for this file try { _vault.VaultGetVersion(vaultRepoPath, itemPath, versionToGet, false); } catch { itemsFailedToGet.Add(itemPath); continue; } var fsPath = Path.Combine(WorkingFolder, itemPath); if (!File.Exists(fsPath)) { continue; } // Remove Source Code Control switch (Path.GetExtension(fsPath).ToLower()) { case ".sln": RemoveSccFromSln(fsPath); break; case ".csproj": RemoveSccFromCsProj(fsPath); break; case ".vdproj": RemoveSccFromVdProj(fsPath); break; } } GetParentsOfFailedItems(vaultRepoPath, itemsFailedToGet, txHistoryItem.TxID); if (GitCommit(vaultRepoPath, txHistoryItem.TxID, gitBranch, txHistoryItem.UserLogin, txHistoryItem.Comment, txHistoryItem.TxDate.GetDateTime())) { Log.Information($"Committing transaction {txHistoryItem.TxID} took {perTransactionWatch.Elapsed}. Author: {txHistoryItem.UserLogin}, Comment: {txHistoryItem.Comment}, commit time: {txHistoryItem.TxDate.GetDateTime():u}"); } perTransactionWatch.Restart(); }
public async Task <TxInfo> GetTransByHash(string hash) { try { var client = LyraRestClient.Create(_config["network"], Environment.OSVersion.ToString(), "LyraBroker", "1.0"); var result = await client.GetBlockAsync(hash); if (result.ResultCode == Lyra.Core.Blocks.APIResultCodes.Success && result.GetBlock() is TransactionBlock block) { var tx = new TxInfo { TxHash = block.Hash, Height = block.Height, Time = block.TimeStamp }; tx.TxType = block is SendTransferBlock ? TransactionType.Send : TransactionType.Receive; if (tx.TxType == TransactionType.Send) { tx.OwnerAccountId = block.AccountID; tx.PeerAccountId = (block as SendTransferBlock).DestinationAccountId; var rcvBlockQuery = await client.GetBlockBySourceHashAsync(block.Hash); if (rcvBlockQuery.ResultCode == APIResultCodes.Success) { tx.IsReceived = true; tx.RecvHash = rcvBlockQuery.GetBlock().Hash; } else { tx.IsReceived = false; tx.RecvHash = ""; //gRPC don't like null } } else { tx.OwnerAccountId = block.AccountID; var sndBlockQuery = await client.GetBlockAsync((block as ReceiveTransferBlock).SourceHash); if (sndBlockQuery.ResultCode == APIResultCodes.Success) { tx.PeerAccountId = (sndBlockQuery.GetBlock() as SendTransferBlock).AccountID; } tx.IsReceived = true; tx.RecvHash = block.Hash; } return(tx); } } catch (Exception ex) { _logger.LogWarning("In OpenWallet: " + ex.ToString()); } return(new TxInfo { TxHash = "" }); }